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

The user_interface package provides various functions for common use cases with message boxes.

Classes

Button

Static variables

VariableDescription
Button.YESText constant for "Yes"
Button.NOText constant for "No"
Button.OKText constant for "OK"
Button.BACKText constant for "Back"
Button.PREVIOUSText constant for "Previous"
Button.NEXTText constant for "Next"
Button.SELECTText constant for "Select"
Button.CANCELText constant for "Cancel"

ButtonList

Static variables

VariableDescription
ButtonList.YES_NOConstant for getting a =["Yes", "No"]= button list from ButtonList.get_button_text_from_value()
ButtonList.OK_BACKConstant for getting a =["Ok", "Back"]= button list from ButtonList.get_button_text_from_value()

Classmethods

FunctionParametersReturn ValueDescription
ButtonList.get_button_text_from_value(cls, value)value: One of the values defined in the static variables of this classA list or NoneRetrieves a list populated with text constants for use in message boxes

Functions

FunctionParametersReturn ValueDescription
ask_for_confirmation_via_dialog(dialog_message_id)dialog_message_id: MSGTrue or FalseDisplays a dialog message and checks whether the reply is positive
ask_user_for_confirmation(message_text, button_enum, ole_id=OLE_QUESTION_MARK)message_text: The text that should be displayed
button_enum: One of the static variables of the ButtonList class

ole_id: OLE
True or FalseDisplays a message and checks whether the reply is positive.
ask_user_for_input_via_dialog(dialog_message_id, verification_function=None)dialog_message_id: MSG

verification_function: A callable that takes one argument and returns True or False
User inputAsks the user for input. The dialog message should be configured to have 1 input field. The verification_function should be a callable that gets called with the user input and returns True / False depending on whether the input is valid.
Will loop the question until a valid value is found, or return None when the user cancels
ask_user_to_select_from_list(possible_values, heading='', transform_value_to_text=None, _selected_index=0)possible_values: An iterable of values

heading: Text
transform_value_to_text: A callable that takes one argument and returns a string representation
_selected_index: Internal argument
An object from the iterable of values or NoneDisplays a list of objects in a message box and lets the user choose one of the elements.
show_custom_dialog_message(dialog_message_id, text, extend_original_text=False)dialog_message_id: The dialog message to replicate
text: The text that should be displayed

extend_original_text: True / False depending on whether you want to replace the original text or extend it

Displays a dialog message with a custom text.
ask_user_to_select_from_objects(message, possible_objects, title='', transform_value_to_textstr, ole_id=None)message: message that you want to show
possible_objects: list of possible replies
title: title of the dialog
transform_value_to_text: A function that takes a single argument (an object from the list of values) and returns a proper string
ole_id: ole_id that you want to have

Presents the user with a dialog where he/she can choose from multiple replies.

Examples

Utilizing ask_user_for_confirmation

from ppms.user_interface import ask_user_for_confirmation, ButtonList

message_text = 'Should something be done?'
if ask_user_for_confirmation(message_text=message_text, button_enum=ButtonList.YES_NO)
    # Do something...
PY

Utilizing ask_for_confirmation_via_dialog

from ppms.user_interface import ask_for_confirmation_via_dialog

if ask_for_confirmation_via_dialog('1110'):
    # Do something...
PY

Select a logfile and display the last 1000 characters

The selection box will look like this:


import os

from ppms.user_interface import ask_user_to_select_from_list


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, encoding='utf-8') as f:
        content = f.read()[-1000:]
        
        ppms.ui_message_box(content)
PY

Asking the user for a valid port number

from ppms.user_interface import ask_user_for_input_via_dialog

# A port must be a valid integer
def _port_checker(port):
    try:
        int(port)
    except ValueError:
        return False

    return True
    
port = ask_user_for_input_via_dialog(dialog_message_id='1242', verification_function=_port_checker)
if port is not None:
    # Do something with the port number
PY