user_interface
package provides functions for interacting with files to and from the client.
Function | Parameters | Return Value | Description |
---|---|---|---|
choose_remote_file(save_file=False, title=None, filter=None, suggested_filename=None) |
save_file: True or False title: Dialog title text filter: FileDialog.Filter text suggested_filename: Text |
Path to the remote file or None if no file was chosen |
Shows a open dialog on the Client to let the user select a file |
copy_local_file_remote(local_file, remote_path) |
local_file: A file-like descriptor remote_path: Path to a folder on the Client side |
Amount of bytes written | Copy a file from the Server to the Client |
copy_remote_file_locally(remote_path, local_file) |
remote_path: Path to a folder on the Client side local_file: A file-like descriptor |
Amount of bytes written | Copy a file from the Client to the Server |
get_file(title, filter, encoding=utf-8) |
title: Dialog title text filter: FileDialog.Filter text encoding: Encoding |
A RemoteFile object that behaves like a local file object |
Shows a open dialog and reads the selected file |
open_remote_file(remote_path, mode, encoding=None) |
remote_path: Path to a folder on the Client side mode: The mode in which the file should be opened (For example 'r' for reading or 'wb' for writing binaryencoding: Encoding |
A RemoteFile object that behaves like a local file object |
Open a remote file to read or write it |
read_remote_file(remote_path, encoding=utf-8) |
remote_path: Path to a folder on the Client side encoding: Encoding |
A file-like object to read from (io.TextIOWrapper ) |
Read a file located on the Client from the Server |
store_file(local_file, title, filter, suggested_filename=None) |
local_file: A file-like descriptor title: Dialog title text filter: FileDialog.Filter text suggested_filename: Filename |
Amount of bytes written or None |
Open a save file dialog on the Client to store the content of the local_file object. The local file must be opened with 'rb' to read binary |
store_file_without_dialog(local_file, remote_path, remote_file_name) |
local_file: A file-like descriptor remote_path: Path to a folder on the Client side remote_file_name: Filename |
Copies the content of a file on the Server to the Client. The local file must be opened with 'rb' to read binary |
import os from ppms.user_interface import ask_user_to_select_from_list, store_file def get_all_logfiles(): return [logfile for logfile in os.listdir('log') if logfile.endswith('.log')] def ending_stripper(logfile): return logfile.rstrip('.log') logfiles = get_all_logfiles() selected_logfile = ask_user_to_select_from_list(possible_values=logfiles, heading='Please select a logfile:', transform_value_to_text=ending_stripper) if selected_logfile is not None: logfile_path = os.path.join('log', selected_logfile) with open(logfile_path, 'rb') as logfile: title = 'Where do you want to save this logfile?' filter = 'Log files (*.log)|*.log|All files (*.*)|*.*' store_file(local_file=logfile, title=title, filter=filter, suggested_filename=selected_logfile)