class documentation

class EventManager:

Known subclasses: acme.runtime.EventManager.EventManager

View In Hierarchy

Event topics are added as new methods to an EventManager instance. Events can be raised by calling those new methods.

Example

manager.addEvent("anEvent")
Add new Event topic anEvent to manager.
manager.addHandler(manager.anEvent, handlerFunction)
Add an event handler for the anEvent Event.
manager.anEvent(anArg)
Raise the anEvent Event with an anArg argument.
Method __getattr__ Dynamically create and return an Event instance when accessing an attribute that does not exist.
Method addEvent Create and add a new Event.
Method addHandler Add a new event handler to an Event or to a list of Event instance.
Method hasEvent Check whether an Event instance exists.
Method hasHandler Test whether one or more events have a specific handler assigned.
Method removeAllEvents Remove all registered Event instances.
Method removeEvent Remove an Event instance by its name.
Method removeHandler Remove an event handler from an Event instance or a list of Event instances.
def __getattr__(self, name: str) -> Event:

Dynamically create and return an Event instance when accessing an attribute that does not exist.

Parameters
name:strThe name of the attribute to access, which will be used as the name of the Event instance.
Returns
EventThe created Event instance.
Raises
AttributeErrorIf the attribute name starts with an underscore (to prevent access to private attributes).
def addEvent(self, name: str, runInBackground: bool | None = True) -> Event:

Create and add a new Event.

Parameters
name:strName of the Event.
runInBackground:bool | None(optional, default = True) Execute the callbacks in a thread.
Returns
EventThe created Event.
def addHandler(self, event: Event | list[Event], func: Callable):

Add a new event handler to an Event or to a list of Event instance.

Parameters
event:Event | list[Event]Either a single Event instance or a list of Event instances.
func:CallableThe function callback to call when the event is raised.
def hasEvent(self, name: str) -> bool:

Check whether an Event instance exists.

Parameters
name:strName of the Event instance to check.
Returns
boolTrue if an Event instance with name exists.
def hasHandler(self, event: Event | list[Event], func: Callable) -> bool:

Test whether one or more events have a specific handler assigned.

Parameters
event:Event | list[Event]Either a single Event or a list of Event instances.
func:CallableThe function callback to call when the event is raised.
Returns
boolTrue if func is a registered event handler.
def removeAllEvents(self):

Remove all registered Event instances.

def removeEvent(self, name: str):

Remove an Event instance by its name.

Parameters
name:strThe name of the Event instance to remove.
def removeHandler(self, event: Event | list[Event], func: Callable):

Remove an event handler from an Event instance or a list of Event instances.

Parameters
event:Event | list[Event]Either a single Event or a list of Event instances.
func:CallableThe function callback to remove from the Event instance(s).