Die nachfolgenden Inhalte sind nur in englischer Sprache verfügbar.

The user_interface package provides functions for interacting with files to and from the client.

Functions

FunctionParametersReturn ValueDescription
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 selectedShows an 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 part of the Client
Number of bytes writtenCopy a file from the Server to the Client
copy_remote_file_locally(remote_path, local_file)remote_path: Path to a folder on the part of the Client
local_file: A file-like descriptor
Number of bytes writtenCopy 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 objectShows an open dialog and reads the selected file
open_remote_file(remote_path, mode, encoding=None)remote_path: Path to a folder on the part of the Client
mode: The mode in which the file should be opened (For example 'r' for reading or 'wb' for writing binary

encoding: Encoding
A RemoteFile object that behaves like a local file objectOpen a remote file to read or write it
read_remote_file(remote_path, encoding=utf-8)remote_path: Path to a folder on the part of the Client

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
Number of bytes written or NoneOpen 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 part of the Client
remote_file_name: Filename

Copies the content of a file located on the Server to the Client. The local file must be opened with 'rb' to read binary

Warning:

  • When you try to copy files the size of which amounts to several megabytes or more, the execution might be interrupted due to a service timeout

Examples

Select a logfile and send it to the Client

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)
PY