Die Dokumentation ab Version 39.5.17 von PLANTA project finden Sie in der neuen PLANTA Online-Hilfe.

user_interface

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

Classes

Button

Static variables

Variable Description
Button.YES Text constant for "Yes"
Button.NO Text constant for "No"
Button.OK Text constant for "OK"
Button.BACK Text constant for "Back"
Button.PREVIOUS Text constant for "Previous"
Button.NEXT Text constant for "Next"
Button.SELECT Text constant for "Select"
Button.CANCEL Text constant for "Cancel"

ButtonList

Static variables

Variable Description
ButtonList.YES_NO Constant for getting a ["Yes", "No"] button list from ButtonList.get_button_text_from_value()
ButtonList.OK_BACK Constant for getting a ["Ok", "Back"] button list from ButtonList.get_button_text_from_value()

Classmethods

Function Parameters Return Value Description
ButtonList.get_button_text_from_value(cls, value) value: One of the values defined in the static variables of this class A list or None Retrieves a list populated with text constants for use in message boxes

Functions

Function Parameters Return Value Description
ask_for_confirmation_via_dialog(dialog_message_id) dialog_message_id: MSG True or False Display a dialog message and check if 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 False Display a message and check if 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
The user input Ask the user for a 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 if 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: A iterable of values

heading: Text
transform_value_to_text: A callable that takes one argument and returns a String representation
_selected_index: Internal argument
A object from the iterable of values or None Display a list of objects in a messagebox and let 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 if you want to replace the original text or extend it
  Display a dialog message with a custom text.
ask_user_to_select_from_objects(message, possible_objects, title='', transform_value_to_text=str, 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 (a object from the list of values) and returns a proper string
ole_id: ole_id that you want to have
  Present the user a dialog where he can choose from multiple replies.

Examples

Utilizing ask_user_for_confirmation

New

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...

Old

from ppms import ppms
from ppms.constants import *

ppms.ui_message_box('Should something be done?', ole_id=OLE_QUESTION_MARK, button_list=['Yes', 'No'])
msg = ppms.msg_pop()
reply = msg.get_reply()

if reply == MSG_REPLY_YES:
    # Do something...

Utilizing ask_for_confirmation_via_dialog

New

from ppms.user_interface import ask_for_confirmation_via_dialog

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

Old

from ppms import ppms
from ppms.constants import *

ppms.ui_message_id('1110')
msg = ppms.msg_pop()
reply = msg.get_reply()

if reply == MSG_REPLY_YES:
    # Do something...

Select a logfile and display the last 1000 characters

The selection box will look like this:

Selection.png

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)

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
Topic attachments
I Attachment History Size Date Comment
Pngpng Selection.png r1 10.8 K 2017-10-04 - 14:38  

         PLANTA project









 
  • Suche in Topic-Namen

  • Suche in Topic-Inhalten
This site is powered by the TWiki collaboration platform Powered by Perl