holypipette.interface.base module¶
Package defining the TaskInterface
class, central to the interface between
GUI and TaskController
objects.
- class holypipette.interface.base.TaskInterface[source]¶
Bases:
QObject
,LoggingObject
Class defining the basic interface between the GUI and the objects controlling the hardware. Classes inheriting from this class should:
Call this class’s
__init__
function in its__init__
Annotate all functions providing commands with the
@command
or@blocking_command
decorator.To correctly interact with the GUI for blocking commands (show that task is running, show error message if task fails, etc.), the method needs to call the
execute
function to execute the command.
- abort_task()[source]¶
The user asked for an abort of the currently running (blocking) command. We transmit this information to all executing objects (for simplicity, only one should be running) by setting the
TaskController.abort_requested
attribute. The object runs in a separate thread, but will finish its operation as soon as it checks for this attribute (either by explicitly checking withTaskController.abort_if_requested
, or by usingTaskController.sleep
or one of the logging methods).
- command_received(command, argument)[source]¶
Slot that is triggered when the GUI triggers a command handled by this
TaskInterface
. If an error occurs in the handling of the command (e.g., the command does not exist or received the wrong number of arguments), an error is logged and thetask_finished
signal is emitted. Note that the handling of errors within the command, as well as the handling of abort requests is performed in theexecute
method.- Parameters:
command (method) – A reference to the requested command.
argument (object) – The argument of the requested command (possibly
None
).
- connect(main_gui)[source]¶
Connect signals to slots in the main GUI. Will be called automatically during initialization of the GUI.
- Parameters:
main_gui (
CameraGui
) – The main GUI in control.
- execute(task, argument=None)[source]¶
Execute a function in a
TaskController
and signal the (successful or unsuccessful) completion via thetask_finished
signal.Can either execute a single task or a chain of tasks where each task is only executed when the previous was successful.
- Parameters:
task (method or list of methods) – A method of a
TaskController
object that should be executed, or a list of such methods.argument (object or list of object, optional) – An argument that will be provided to
task
orNone
(the default). For a chain of function calls, provide a list of arguments.
- Returns:
success – Whether the execution was completed successfully. This can be used to manually enchain multiple tasks to avoid calling subsequent tasks after a failed/aborted task. Note that it can be easier to pass a list of functions instead.
- Return type:
- reset_requested(controller)[source]¶
Slot that will be triggered when the user asks for resetting the state after an aborted or failed command.
- Parameters:
controller (
TaskController
) – The object that was executing the task that failed or was aborted. This object is requested to reset its state.
- task_finished¶
Signals the end of a task with an “error code”: 0: successful execution; 1: error during execution; 2: aborted
- holypipette.interface.base.blocking_command(category, description, task_description, default_arg=None)[source]¶
Decorator that annotates a function with information about the implemented (blocking) command.
- Parameters:
category (str) – The command category (used for structuring the help window).
description (str) – A descriptive text for the command (used in the help window).
task_description (str) – Text that will be displayed to the user while the task is running
default_arg (object, optional) – A default argument provided to the method or
None
(the default).
- holypipette.interface.base.command(category, description, default_arg=None, success_message=None)[source]¶
Decorator that annotates a function with information about the implemented command.
- Parameters:
category (str) – The command category (used for structuring the help window).
description (str) – A descriptive text for the command (used in the help window).
default_arg (object, optional) – A default argument provided to the method or
None
(the default).success_message (str, optional) – A message that will be displayed in the status bar of the GUI window after the execution of the command. For simple commands that have visual feedback, e.g. moving the manipulator or changing the exposure time, this should not be set to avoid unnecessary messages. For actions that have no visual feedback, e.g. storing a position, this should be set to give the user an indication that something happened.