module documentation

Generic event and event handling classes and functions.

Class Event This class represents an event. It is actially a list of callable functions, which are the event handlers for this event. Calling an instance of this class will call all the registered event handlers for this event.
Class EventData Event data class. This class is used to pass data to event handlers.
Class EventManager Base class for an event manager. This class manages events and event handlers. It is implememted as a Singleton, so there is only one instance of the event manager in the whole application.
Function eventHandler Class decorator to automatically register event handlers. Any method of the decorated class that is decorated with an Event decorator will be automatically registered as an event handler for that event.
Function onEvent Marks a method for event registration — deferred until instantiation.
Type Variable _F The F TypeVar on the decorator overload is important — it tells the type checker that whatever callable goes in comes back out unchanged, so the handler's own signature is preserved after decoration.
def eventHandler(cls: type) -> type:

Class decorator to automatically register event handlers. Any method of the decorated class that is decorated with an Event decorator will be automatically registered as an event handler for that event.

It is necessary to use this decorator for any class that has methods decorated with onEvent, otherwise the event handlers will not be registered and the decorated methods will not be correctly called when the event is raised.

def onEvent(event: Event) -> Callable[[_F], _F]:

Marks a method for event registration — deferred until instantiation.

_F =

The F TypeVar on the decorator overload is important — it tells the type checker that whatever callable goes in comes back out unchanged, so the handler's own signature is preserved after decoration.

Value
TypeVar('_F',
        bound=Callable)