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 handler
Return 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 from add(), 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 handlers
Return type:Event
partial(*args, **kwargs)[source]

creat new Event with partially set arguments

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 calling queue(). All arguments are passed to the handlers.

remove(handler)[source]

remove an attached handler

loop = <piripherals.event.EventLoop object>