Events

class Event[source]

Base class for Events.

Add fields to your subclass, whatever is needed to communicate the event to your Handler class(es). An Event itself does not do anything but carry data to its Handler(s).

Using @define and field from attrs is recommended to keep it short.

class Handler(event: Event)[source]

Abstract base class for handling one or more Event.

Event handlers should do as little as possible, such as send a quick notification, log an action, or issue Command(s). If an Event implies anything significant needs to be done in response, the Handler should return Command object(s). We can’t enforce this guideline for you, but recommend you follow it.

Your handler may return a list containing Command and/or ReturnMessage objects.

If one or more ReturnMessage are returned, your application should do something with them.

Note

Event handlers are located by searching through all subclasses of Handler, to find Handler(s) that accept the Event. They are cached once located. If any of your Handlers are not being used when they should be, make sure they are imported when your application starts up. Usually, importing them in an __init__.py file or keeping them in the same file with their Event will fix it.

abstract handle_event() HandlerReturnType[source]

Your implementation of a response to self.event.

classmethod handles_event(event: Event) bool[source]

Determines whether this handler should respond to event.

handles_events: ClassVar[list[type[Event]]]

A list of the Event class(es) this Handler should respond to.