Event API¶
Events are classes implementing the AbstractEvent interface
The EventHandler class is for creating objects with events.
These events can occur once only during the life of an EventHandler
or can occur several times. Check the
event dispatching tutorial for an overview.
Abstract Event¶
Event¶
-
class
pulsar.async.events.Event(loop=None, name=None)[source]¶ The default implementation of
AbstractEvent.
One time¶
-
class
pulsar.async.events.OneTime(*, loop=None, name=None)[source]¶ An
AbstractEventwhich can be fired once only.This event handler is a subclass of
Future. Implemented mainly for the one time events of theEventHandler.
Events Handler¶
-
class
pulsar.async.events.EventHandler(loop=None, one_time_events=None, many_times_events=None)[source]¶ A Mixin for handling events on async objects.
It handles
OneTimeevents andEventthat occur several times.-
ONE_TIME_EVENTS= ()¶ Event names which occur once only.
-
MANY_TIMES_EVENTS= ()¶ Event names which occur several times.
-
events¶ The dictionary of all events.
-
bind_event(name, callback)[source]¶ Register a
callbackwithevent.The callback must be a callable accepting one positional parameter and at least the
excoptional parameter:def callback(arg, ext=None): ... o.bind_event('start', callback)
the instance firing the event or the first positional argument passed to the
fire_event()method.Parameters: - name – the event name. If the event is not available a warning message is logged.
- callback – a callable receiving one positional parameter. It can also be a list/tuple of callables.
Returns: nothing.
-
fire_event(name, *args, **kwargs)[source]¶ Dispatches
argorselfto eventnamelisteners.- If event at
nameis a one-time event, it makes sure that it was not fired before.
Parameters: - args – optional argument passed as positional parameter to the event handler.
- kwargs – optional key-valued parameters to pass to the event handler. Can only be used for many times events.
Returns: the
Eventfired- If event at
-
copy_many_times_events(other)[source]¶ Copy many times events from
other.All many times events of
otherare copied to this handler provided the events handlers already exist.
-