Event managers

A class responsible for grouping of events, and for ending the screens displayed by the application.

An event manager is started by an eventful screen when the screen is displayed, and is stopped when the screen exits. Callbacks can be registered to be called when an event happens, which is used by experiment runner to go to the next screen.

An instance of an event manager can also be cloned, which allows it to be used as a prototype by screen sequencers.

Interface

class src.data_acquisition.event_manager.EventManager(*, logger: Logger | None = None)[source]

Bases: Generic[T], ABC

abstractmethod clone() EventManager[T][source]

Method used to create a clone of the event manager, so that it can be used as a prototype and reused by multiple screens generated by a screen sequencer.

Returns:

A new instance of the same type as this event manager, with the same configuration.

deregister_callback(callback: Callable[[T], None]) None[source]
Parameters:

callback – The callback function to be deregister.

Raises:

EventManagerError – If the callback is not registered.

register_callback(callback: Callable[[T], None]) None[source]
Parameters:

callback – The callback function to be called when an event occurs that should end the current screen.

start() None[source]
stop() None[source]

How to subclass

Note

If you want to create an event manager that is based on events, you should subclass SimpleEventManager. Subclass this class only if you want to implement some custom event logic or create a composite event manager.

Subclasses should implement the following methods:

  • clone() - should return a new instance of the subclass, with the same parameters as the original.

  • _start()

  • _stop()

Available properties and methods:

  • _trigger_callbacks(result: T) - should be used to trigger the screen-end callback, usually as a callback to subscribed events.

  • _clone_registered_callbacks_from(event_manager: EventManager) - can be used to clone the registered callbacks from another event manager.

Catalog