embutils.utils.events module

Event handling utilities.

date

2021

author

Christian Wiche

contact

cwichel@gmail.com

license

The MIT License (MIT)

class embutils.utils.events.EventHook[source]

Bases: object

Simple event hook implementation. This utility allows emitting events to several callbacks in a simple fashion.

Note

  • All the callbacks subscribed to a hook need to handle the same arguments.

This class don’t require any input from the user to be initialized.

clear() None[source]

Remove all the callbacks from the hook.

emit(*args, **kwargs) None[source]

Emit the given arguments to all the callbacks.

Parameters
  • args – Arguments.

  • kwargs – Key arguments.

property empty: bool

Returns if the event hook has callbacks subscribed.

subscribe(callback: Callable[[...], None]) bool[source]

Subscribes a callback to the event hook.

Parameters

callback (callable) – Event callback.

Returns

True if subscribed, false otherwise.

Return type

bool

unsubscribe(callback: Callable[[...], None]) bool[source]

Unsubscribes a callback from the event hook.

Parameters

callback (callable) – Event callback.

Returns

True if unsubscribed, false otherwise.

Return type

bool