blatann.event_type module
- class blatann.event_type.Event(name)
Bases:
Generic[TSender,TEvent]Represents an event that can have handlers registered and deregistered. All handlers registered to an event should take in two parameters: the event sender and the event arguments.
Those familiar with the C#/.NET event architecture, this should look very similar, though registration is done using the
register()method instead of+= event_handler- register(handler, weak=False)
Registers a handler to be called whenever the event is emitted. If the given handler is already registered, function does not register the handler a second time.
This function can be used in a with context block which will automatically deregister the handler when the context is exited.
- Example:
>>> with device.client.on_connected.register(my_connected_handler): >>> # Do something, my_connected_handler will be deregistered upon leaving this context
- Parameters:
- Return type:
EventSubscriptionContext[TypeVar(TSender),TypeVar(TEvent)]- Returns:
a context block that can be used to automatically unsubscribe the handler
- class blatann.event_type.EventSource(name, logger=None)
Bases:
EventRepresents an Event object along with the controls to emit the events and notify handlers. This is done to “hide” the notify method from subscribers.
- clear_handlers()
Clears all handlers from the event
- notify(sender, event_args=None)
Notifies all subscribers with the given sender and event arguments