mafw.ui.abstract_user_interface
An abstract generic user interface.
The module provides a generic user interface that can be implemented to allow MAFw to communicate with different user interfaces.
MAFw is designed to operate seamlessly without a user interface; however, users often appreciate the added benefit of communication between the process execution and themselves.
There are several different interfaces and different interface types (Command Line, Textual, Graphical…) and everyone has its own preferences. In order to be as generic as possible, MAFw is allowing for an abstract interface layer so that the user can either decide to use one of the few coming with MAFw or to implement the interface to their favorite interface.
Classes
An abstract base user interface class that defines the interface for communicating with different user interfaces. |
|
A metaclass used for the creation of user interface |
- class mafw.ui.abstract_user_interface.UserInterfaceBase[source]
Bases:
objectAn abstract base user interface class that defines the interface for communicating with different user interfaces.
This class provides a standardized way for MAFw to interact with various user interfaces including command-line, textual, and graphical interfaces. It defines the required methods that any concrete implementation must provide.
The interface allows for task management, progress reporting, status updates, and user interaction capabilities.
Added in version v1.0.
- create_task(task_name: str, task_description: str = '', completed: int = 0, increment: int | None = None, total: int | None = None, **kwargs: Any) None[source]
Create a new task.
- Parameters:
task_name (str) – A unique identifier for the task. You cannot have more than 1 task with the same name in the whole execution. If you want to use the processor name, it is recommended to use the
unique_name.task_description (str, Optional) – A short description for the task. Defaults to None.
completed (int, Optional) – The amount of task already completed. Defaults to None.
increment (int, Optional) – How much of the task has been done since last update. Defaults to None.
total (int, Optional) – The total amount of task. Defaults to None.
- display_progress_message(message: str, i_item: int, n_item: int | None, frequency: float) None[source]
Display a message during the process execution.
- Parameters:
message (str) – The message to be displayed.
i_item (int) – The current item enumerator.
n_item (int | None) – The total number of items or None for an indeterminate progress (while loop).
frequency (float) – How often (in percentage of n_item) to display the message.
- enter_interactive_mode() Generator[None, Any, None][source]
A context manager for entering interactive mode.
This method provides a way to temporarily switch to interactive mode, allowing for direct user interaction during processing. It should be used as a context manager with a
withstatement.Added in version v2.0.0.
- Returns:
A context manager that yields control to the interactive section
- Return type:
Generator
- prompt_question(question: str, **kwargs: Any) Any[source]
Prompt the user with a question and return their response.
This method should display a question to the user and wait for their input. The implementation may vary depending on the specific user interface being used.
Added in version v2.0.0.
- Parameters:
question (str) – The question to be asked to the user.
kwargs – Additional keyword arguments that might be used by specific implementations.
- Returns:
The user’s response to the question.
- Return type:
Any
- update_task(task_name: str, completed: int = 0, increment: int | None = None, total: int | None = None, **kwargs: Any) None[source]
Update an existing task.
- Parameters:
task_name (str) – A unique identifier for the task. You cannot have more than 1 task with the same name in the whole execution. If you want to use the processor name, it is recommended to use the
replica_name.completed (int, Optional) – The amount of task already completed. Defaults to None.
increment (int, Optional) – How much of the task has been done since last update. Defaults to None.
total (int, Optional) – The total amount of task. Defaults to None.
- always_display_progress_message = 10
Threshold for displaying progress messages.
If the total number of events is below this value, then the progress message is always displayed, otherwise follow the standard update frequency.
- name = 'base'
The name of the interface