ae.gui.app
abstract Framework-independent base class for python applications with a graphical user interface
Module Attributes
flow actions that are extending the flow path. |
|
flow actions that are shrinking/reducing the flow paths. |
|
flow actions that are processed without the need to be confirmed. |
|
flow id to close opened dropdown/popup |
|
tuple of flow ids never search/show help text for |
|
tuple of app state names never searched help for |
|
tuple of global/module variable names that are hidden in |
Classes
|
abstract base class to implement a GUIApp-conform app class |
- ACTIONS_EXTENDING_FLOW_PATH = ['add', 'confirm', 'edit', 'enter', 'open', 'show', 'suggest']
flow actions that are extending the flow path.
- ACTIONS_REDUCING_FLOW_PATH = ['close', 'leave']
flow actions that are shrinking/reducing the flow paths.
- ACTIONS_CHANGING_FLOW_WITHOUT_CONFIRMATION = ['', 'enter', 'focus', 'leave', 'suggest']
flow actions that are processed without the need to be confirmed.
- CLOSE_POPUP_FLOW_ID = 'close_flow_popup'
flow id to close opened dropdown/popup
- IGNORED_HELP_FLOWS = ('close_flow_popup',)
tuple of flow ids never search/show help text for
- IGNORED_HELP_STATES = ('flow_id', 'flow_path', 'win_rectangle')
tuple of app state names never searched help for
- HIDDEN_GLOBALS = ('ABC', 'abstractmethod', '_add_base_globals', 'Any', '__builtins__', '__cached__', 'Callable', '_d_', '__doc__', '__file__', '__loader__', 'module_globals', '__name__', 'Optional', '__package__', '__path__', '__spec__', 'Type', '__version__')
tuple of global/module variable names that are hidden in
global_variables()
- class MainAppBase(**console_app_kwargs)[source]
Bases:
ConsoleApp,ABCabstract base class to implement a GUIApp-conform app class
- cancel_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.99, 0.09, 0.09, 0.69]
rgba color for create/add/register actions
- confirm_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.09, 0.99, 0.09, 0.69]
rgba color for create/add/register actions
- create_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.39, 0.99, 0.69, 0.69]
rgba color for create/add/register actions
- delete_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.99, 0.69, 0.69, 0.69]
rgba color for delete/remove actions
- error_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.99, 0.09, 0.39, 0.69]
rgba color for error actions
- flow_id_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.99, 0.99, 0.69, 0.69]
rgba color for flow id / drag&drop node placeholder
- flow_path_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.99, 0.99, 0.39, 0.48]
rgba color for flow_path/drag&drop item placeholder
- help_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.09, 0.69, 0.99, 0.69]
rgba color to mark widgets with context-sensitive help
- info_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.99, 0.99, 0.09, 0.69]
rgba color for info actions
- read_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.09, 0.99, 0.69, 0.69]
rgba color for read actions
- selected_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.69, 0.99, 0.39, 0.18]
rgba color for selected list items
- unselected_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.39, 0.39, 0.39, 0.18]
rgba color for unselected list items
- update_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.99, 0.09, 0.99, 0.69]
rgba color for edit/modify/update actions
- warn_ink: tuple[float, float, float] | list[float] | tuple[float, float, float, float] = [0.99, 0.99, 0.09, 0.69]
rgba color for hint/warn actions
- image_files: FilesRegister | None = None
image/icon files
- sound_files: FilesRegister | None = None
sound/audio files
- tour_overlay_class: Type | None = None
UI-framework-specific tour overlay class, set by main app subclass
- __init__(**console_app_kwargs)[source]
create an instance of app class.
- Parameters:
console_app_kwargs¶ – kwargs to be passed to the __init__ method of
ConsoleApp.
- _exit_code
init by stop_app() and passed onto OS by run_app()
- _last_focus_flow_id
id of the last valid focused window/widget/item/context
- _init_default_theme_cfg_vars()[source]
called from self._init_default_user_cfg_vars() to extend user config vars after/in self.__init__()
- _init_default_user_cfg_vars()[source]
init user default config variables.
override this method to add module-/app-specific config vars that can be set individually per user.
- abstractmethod call_method_delayed(delay, callback, *args, **kwargs)[source]
delayed call of passed callable/method with args/kwargs catching and logging exceptions preventing app exit.
- Parameters:
delay¶ (
float) – delay in seconds before calling the callable/method specified bycallback.callback¶ (
Union[Callable,str]) – either callable or name of the main app method to call.args¶ – args passed to the callable/main-app-method to be called.
kwargs¶ – kwargs passed to the callable/main-app-method to be called.
- Return type:
- Returns:
delayed call event object instance, providing a cancel method to allow the cancellation of the delayed call within the delay time.
- abstractmethod call_method_repeatedly(interval, callback, *args, **kwargs)[source]
repeated call of passed callable/method with args/kwargs catching and logging exceptions preventing app exit
- Parameters:
interval¶ (
float) – interval in seconds between two calls of the callable/method specified bycallback.callback¶ (
Union[Callable,str]) – either callable or name of the main app method to call.args¶ – args passed to the callable/main-app-method to be called.
kwargs¶ – kwargs passed to the callable/main-app-method to be called.
- Return type:
- Returns:
repeatedly call event object instance, providing a cancel method to allow the cancellation of the repeated call within the interval time.
- abstractmethod ensure_top_most_z_index(widget)[source]
ensure visibility of the passed widget to be the top most in the z index/order.
- abstractmethod help_activation_toggle()[source]
button tapped event handler to switch help mode between active and inactive (also inactivating tour).
- abstractmethod init_app(framework_app_class=None)[source]
initialize framework app instance and root window/layout, return GUI event loop start/stop methods.
- app_state_keys()[source]
determine current config variable names/keys of the app state section
APP_STATE_SECTION_NAME.
- backup_config_resources()[source]
backup config files and image/sound/translations resources to {ado}<now_str>.
config files are collected from {ado}, {usr} or {cwd} (the first found file name only - see/sync-with
ae.console.ConsoleApp.add_cfg_files()).resources are copied from {ado} or {cwd} (only the first found resources root path).
- Return type:
- change_app_state(app_state_name, state_value, send_event=True, old_name='')[source]
change app state and show help text in active help mode.
- Parameters:
state_value¶ (
Any) – the new value of the app status to change.send_event¶ (
bool) – pass False to prevent send/call of the main_app.on_<app_state_name> event.old_name¶ (
str) – pass to add state to the main config file: old state name to rename/migrate orUNSETto only add a new app state variable with the name specified inapp_state_name.
- change_flow(new_flow_id, **event_kwargs)[source]
try to change/switch the current flow id to the value passed in
new_flow_id.- Parameters:
new_flow_id¶ (
str) – new flow id (maybe overwritten by flow change confirmation event handlers by assigning a flow id to event_kwargs[‘flow_id’]).event_kwargs¶ –
optional args to pass additional data or info onto and from the flow change confirmation event handler.
the following keys are currently supported/implemented by this module/portion (additional keys can be added by the modules/apps using this method):
changed_event_name: optional main app event method name to be called if the flow got confirmed and changed.
count: optional number used to render a pluralized help text for this flow change (this number gets also passed to the help text formatter by/in
change_flow()).edit_widget: optional widget instance for edit/input.
flow_id: process
flow_pathas specified by thenew_flow_idargument, but then overwrite this flow id with this event arg value to setflow_id.popup_kwargs: optional dict passed to the Popup __init__ method, like e.g., dict(opener=opener_widget_of_popup, data=…).
popups_to_close: optional, either the number of top/most-recent popups to close, or a tuple of popup instances to be closed. the closing is done by this method after the flow change got confirmed.
’reset_last_focus_flow_id’: pass True to reset the last focus flow id, pass False or None to ignore the last focus id (and not use to set flow id) or pass a flow id string value to change the last focus flow id to the passed value.
tap_widget: optional tapped button widget instance (initiating this flow change).
some of these keys get specified directly on the call of this method, e.g., via
tap_kwargsortap_kwargs, where others get added by the flow change confirmation handlers/callbacks.
- Return type:
- Returns:
boolean True if flow got confirmed by a declared custom flow change confirmation event handler (either event method or Popup class) of the app, and if the flow changed accordingly.
returning False if the help mode is active and the calling widget is not selected.
some flow actions are handled internally independent of the return value of a custom event handler, like e.g. ‘enter’ or ‘leave’ will always extend or reduce the flow path and the action ‘focus’ will give the indexed widget the input focus (these exceptions are configurable via
ACTIONS_CHANGING_FLOW_WITHOUT_CONFIRMATION).
- change_observable(name, value, is_app_state=False)[source]
change observable attribute/member/property in framework_app instance (and shadow copy in the main app).
- static class_by_name(class_name)[source]
search class name in framework modules as well as in app main.py to return the related class/type object.
- property color_attr_names: set[str]
determine the app state attribute/config-var names of all UI colors, including app-specific colors.
- Returns:
set of app state attribute names of all colors, declared/configured by ae-framework+app.
- static dpi_factor()[source]
dpi scaling factor - override if the used GUI framework supports dpi scaling.
- Return type:
- close_popups(classes=(), count=-1, force=False)[source]
close specified/all opened popups (starting with the foremost popup).
- Parameters:
classes¶ (
tuple) – optional class filter - if not passed, then only the first foremost widgets underneath the app win with an open method will be closed. pass tuple to restrict found popup widgets to certain classes. like e.g., pass (Popup, DropDown, FlowPopup) to get all popups of an app (in Kivy use Factory.WidgetClass if the widget is declared only in kv lang).count¶ (
int) – maximum number of popups to close (if it is negative or not specified, then all currently opened popups will be closed).force¶ (
bool) – pass True force the remove of popup without calling its close/dismiss method.
- find_image(image_name, height=32.0, light_theme=True)[source]
find the best fitting image in the registered img folders.
- Parameters:
- Return type:
- Returns:
image file object (RegisteredFile/CachedFile) if found else None.
- find_sound(sound_name)[source]
find sound by name.
- Parameters:
- Return type:
- Returns:
cached sound file object (RegisteredFile/CachedFile) if sound name was found else None.
- find_widget(match, root_widget=None)[source]
bottom-up-search the widget tree returning the first matching widget in reversed z-order (foremost first).
- Parameters:
- Return type:
- Returns:
the first found widget in reversed z-order (top-most widget first).
- flow_path_action(flow_path=None, path_index=-1)[source]
determine the action of the last (newest) entry in the flow_path.
- Parameters:
- Return type:
- Returns:
flow action string or an empty string if the flow path is empty or the index does not exist.
- global_variables(**patches)[source]
determine generic/most-needed global variables to evaluate expressions/macros.
- help_app_state_display(help_vars, changed=False)[source]
actualize the help layout if active, before and after the change of the app state.
- Parameters:
help context args/kwargs of the
change_flow()method.- items passed to the help text formatter:
count: optional number used to render a pluralized help text for this app state change.
changed¶ (
bool) – pass False before change of the app state, or True if the app state has already changed.
- Return type:
- Returns:
boolean True if help mode and layout are active and the found target widget is locked, else False.
- help_display(help_id, help_vars, key_suffix='', must_have=False)[source]
display help text to the user in activated help mode.
- Parameters:
help_vars¶ (
dict[str,Any]) – variables used in the conversion of the f-string expression to a string. optional items passed to the help text formatter: * count: optional number used to render a pluralized help text. * self: target widget to show help text for.key_suffix¶ (
str) – suffix to the key used if the translation is a dict.must_have¶ (
bool) – pass True to display error help text and console output if no help text exists.
- Return type:
- Returns:
boolean True if help text got found and displayed.
- help_flow_display(help_vars, changed=False)[source]
actualize the help layout if active, exclusively called by
change_flow().- Parameters:
- Return type:
- Returns:
boolean True if the help layout is active and the found target widget is locked, else False.
- help_is_inactive(help_id)[source]
check if help mode is inactive and reserve/notedown current help id for next help mode activation.
- help_target_and_id(help_vars)[source]
find a help widget/target and help id on help mode activation.
- help_widget(help_id, help_vars)[source]
ensure/find the help target widget via attribute name/value and extend
help_vars.- Parameters:
- Return type:
- Returns:
the found target widget or self.help_activator if not found.
- img_file(image_name, font_size=None, light_theme=None)[source]
shortcutting
find_image()method w/o bound property to get the image file path.- Parameters:
- Return type:
- Returns:
file path of an image file or empty string if a matching image file could not be found.
- key_press_from_framework(modifiers, key)[source]
dispatch key press event, coming normalized from the UI framework.
- load_app_states()[source]
prepare app.run_app by loading app states from config files and check for added/updated state vars
- on_app_state_version_upgrade(from_version)[source]
upgrade app state config vars from the specified app state version to the next one.
- on_app_tour_toggle(_flow_key, _event_kwargs)[source]
event handler for to start/stop an app onboarding tour.
- on_debug_level_change(level_name, _event_kwargs)[source]
debug level app state change flow change confirmation event handler.
- on_flow_change(flow_id, event_kwargs)[source]
checking if exists a Popup class for the new flow and if yes, then open it.
- Parameters:
- Return type:
- Returns:
boolean True if Popup class was found and displayed.
this method is mainly used as the last fallback clicked flow change confirmation event handler of a FlowButton.
- on_flow_id_ink()[source]
redirect flow id back ink app state color change event handler to actualize mixed_back_ink.
- on_flow_path_ink()[source]
redirect flow path back ink app state color change event handler to actualize mixed_back_ink.
- on_flow_popup_close(_flow_key, _event_kwargs)[source]
default popup close handler of FlowPopup widget, updates of
flow_pathand resets help widget/text.
- on_font_size()[source]
app state change event handler to synchronize the
MainAppBase.space_widthattribute.
- on_key_press(modifiers, key_code)[source]
check key press event to be handled and processed as command/action.
- on_lang_code_change(lang_code, _event_kwargs)[source]
language app state change flow change confirmation event handler.
- on_light_theme_change(_flow_key, event_kwargs)[source]
app theme app state change flow change confirmation event handler.
- on_selected_ink()[source]
redirect the selected item back ink app state color change event handler to actualize mixed_back_ink.
- on_theme_save(theme_id, _event_kwargs)[source]
event handler to save app theme if not exist, or overwrite it after confirmation.
- on_theme_update(theme_id, _event_kwargs)[source]
event handler to update/overwrite an existing app theme.
- on_unselected_ink()[source]
redirect unselected item back ink app state color change event handler to actualize mixed_back_ink.
- on_user_register(user_id, event_kwargs)[source]
called on close of UserNameEditorPopup to check user input and create/register the current os user.
- Parameters:
user_id¶ (
str) – new/old user id, passed asnew_user_idkwarg to the methodConsoleApp.register_user().event_kwargs¶ (
dict[str,Any]) – event kwargs, plus optionally the following kwargs which will be extracted from the event kwargs and passed onto theae.console.ConsoleApp.register_user()method: *reset_cfg_vars*set_as_default
- Return type:
- Returns:
True if user got registered else False.
- open_popup(popup_class, **popup_kwargs)[source]
open Popup/DropDown, calling the open/show method of the instance created from the passed popup class.
- Parameters:
- Return type:
- Returns:
the created and displayed/opened popup class instance.
Hint
overwrite this method if the used GUI framework is providing a different method to open a popup window or if a widget in the Popup/DropDown needs to get the input focus.
- play_sound(sound_name)[source]
play an audio/sound file, should be overwritten by the GUI framework.
- play_vibrate(pattern=(0.0, 0.09, 0.21, 0.3, 0.09, 0.09, 0.21, 0.09))[source]
play a vibration pattern, to be overwritten by GUI-framework-specific implementation.
- popups_opened(classes=())[source]
determine all popup-like container widgets that are currently opened.
- Parameters:
classes¶ (
tuple) – optional class filter - if not passed, then only the widgets underneath win/root with an open method will be added. pass tuple of popup widget classes to restrict the returned popup instances. like e.g., pass (Popup, DropDown, FlowPopup) to get all popups of an ae/Kivy app (in Kivy use Factory.WidgetClass if widget is declared only in kv lang).- Return type:
- Returns:
list of the foremost opened/visible popup class instances (children of the app window), matching the
classesor having an open method, ordered by their z-coordinate (the most front widget first).
- register_user(**kwargs)[source]
on user registration always disable app onboarding tours on app start
- Parameters:
kwargs¶ – see the
ConsoleApp.register_user()method.- Return type:
- Returns:
see the
ConsoleApp.register_user()method.
Hint
also called on the tour end, after the user has entered a valid username/id in UserNameEditorPopup and confirmed it via the FlowButton id_of_flow(‘register’, ‘user’).
- retrieve_app_states()[source]
determine the state of a running app from the main app instance and return it as dict.
- save_app_states()[source]
save app state in the main config file.
- Return type:
- Returns:
empty string if app status could be saved into config files else error message.
- setup_app_states(app_states, send_event=True)[source]
put app state variables into the main app instance to prepare framework app.run_app.
- show_confirmation(message, title='', confirm_flow_id='', confirm_kwargs=None, confirm_text='')[source]
display a simple confirmation popup to the user, implemented by the used UI-framework.
- Parameters:
- Return type:
- Returns:
boolean True if the flow got accepted and changed, else False.
- show_input(message, title='', input_default='', enter_confirms=True, confirm_flow_id='', confirm_kwargs=None, confirm_text='')[source]
display a simple input box popup to the user, implemented by the used UI-framework.
- Parameters:
title¶ (
str) – title of input box. no title string will be displayed if not specified.input_default¶ (
str) – input default text. if not specified, then the input field will be empty.enter_confirms¶ (
bool) – pass False to disable the confirmation via pressing the enter key in the input field.confirm_flow_id¶ (
str) – tap_flow_id of the ‘confirm’ button. the string entered by the user will be amended as the flow key to it.confirm_kwargs¶ (
Optional[dict[str,Any]]) – tap_kwargs event args of the ‘confirm’ button.confirm_text¶ (
str) – confirmation button text. if not passed, then the i18n translation of “confirm” is used.
- Return type:
- Returns:
boolean True value if the flow got accepted and changed, else False.
- show_message(message, title='', is_error=True)[source]
display (error) message popup to the user, implemented by the used UI-framework.
- start_app_tour(tour_class=None)[source]
start a new app tour, automatically cancelling a currently running app tour.
- theme_update_names(theme_id, delete=False)[source]
delete or update the app state list of available themes, on update sets the specified theme as the 1st item.
- upgraded_config_app_state_version()[source]
determine the app state version of an app upgrade.
- Return type:
- Returns:
value of app state variable APP_STATE_VERSION_VAR_NAME if the app got upgraded (and has a config file from a previous app installation), else 0.
- widget_by_app_state_name(app_state_name)[source]
determine the first (top-most on z-axis) widget having the passed app state name (app_state_name).
- widget_by_attribute(att_name, att_value, root_widget=None)[source]
determine the first (top-most on z-axis) widget having the passed attribute name and value.
- Parameters:
- Return type:
- Returns:
widget that has the specified attribute with the specified value or None if not found.
- widget_by_id(widget_id, root_widget=None)[source]
determine the first (top-most on z-axis) widget identified by the passed widget_id.
- widget_by_flow_id(flow_id)[source]
determine the first (top-most on z-axis) widget having the passed flow_id.
- widget_by_page_id(page_id)[source]
determine the first (top-most on z-axis) widget having the passed tour page id.
- widget_children(wid, only_visible=False)[source]
determine the children of the widget or its container (if exists) in z-order (top-/foremost first).
- widget_tourable_children_page_ids(parent_widget)[source]
determine all visible and tourable children widgets of the passed parent and its child container widgets.
- widgets_enclosing_rectangle(widgets)[source]
calculate the minimum bounding rectangle of all the passed widgets.
- static widget_visible(wid)[source]
determine if the passed widget is visible (has width and height and (visibility or opacity) set).