piripherals.event module¶
-
class
piripherals.event.
Event
(name='event', condition=<function Event.<lambda>>)[source]¶ Bases:
object
Event with attached handlers and optional condition.
Parameters: - name (str) – name of the event, usuful for debugging
- condition (callable) – condition to suppress firing, if it evaluates to False
-
add
(handler)[source]¶ add an event handler.
Handlers can be added with
Event >> handler
.Parameters: handler (callable) – handler to attach. If the handler is an Event, its fire()
method will be attach as handler.
-
conditional
(cond)[source]¶ derive a new conditional event
A conditional Event can created with
Event & condition
.Parameters: condition (callable) – see Event
Returns: conditional Event, with this Event’s fire()
as handlerReturn type: Event
-
fire
(*args, **kwargs)[source]¶ Fire the event, call all attached handlers.
The event is only fired, if the condition evaluates to True. All arguments are passed to the handlers.
-
join
(other)[source]¶ derive Event as combination of two Events
Events can be joined with
EventA + EventB
. This differs fromadd()
, because it creates a new Event and leaves this untouched.Parameters: other (callable) – handler to join with, can be another Event Returns: Event with this and other’s fire()
as handlersReturn type: Event
-
queue
(*args, **kwargs)[source]¶ Enqueue the event on eventloop.
This is equivalent to just calling the Event itself.
fire()
will be enqueued in the eventloop, such that it will be called on the loop thread and not on the thread callingqueue()
. All arguments are passed to the handlers.
-
loop
= <piripherals.event.EventLoop object>¶