Event Objects

class, target, dispatcher=None, **kwargs)

An event should never need to be created directly. Use events(obj).etrigger to start a chain of events.

  • event_type – type of event
  • target

call a listener object


The target this event will trigger action for.

Snitch Objects


Snitch object handles events. and propegates them to the object’s upstream nodes.

etrigger(target, **metadata)

trigger an event.

Parameters:target – only listeners listening to this target will fire
listen(target, listener, weak=None)

Add a listener to listen to events with target ‘target’.

queue(*args, **kwds)

queue listened to events for this object.

quiet(*args, **kwds)

Context manager to stop events being propegated.

Parameters:eventEvent object to trigger
unique(*args, **kwds)

remove duplicate events.

unlisten(target, listener=None)

Remove a listener.

Functions, downstream, target, init=True)

Connect two objects together so that events will bubble upstream., downstream, target, init=True)

Discnnect two objects., downstream)

Test if to objects are connected.

See also

connect(), init=False)

Get the events class associated with this object. If init is true. call init_events if events are uninitialized, otherwize, raise an exception.*instances)

Initialize the events for an object*instances)

Initialize the events for an object

Global liteners, target=None)

Add a listener to events on all objects., target=None)

remove a add_global_listener*args, **kwds)
  • listener – callable object, signature must be listener(event)
  • target – target tuple

Context manager for global listeners

def print_event(event):
    print event
with global_listener(print_event):


Global dispatchers

Add a dispatcher to the stack.

Parameters:dispatcher – callable object. signature must be dispatcher(event, listener)

remove the last global disopatcher from the stack

remove the last dispatcher from the stack

Parameters:dispatcher – specific dispatcher to remove*args, **kwds)
Parameters:dispatcher – callable object. signature must be dispatcher(event, listener)

Add a global dispatcher in a context:

with global_dispatcher(myfunc):
    #Trigger events

ok*args, **kwds)

Do not dispatch any events*args, **kwds)

Put all events into a queue. example:

with queue() as todo:

print "I have cought %i events" % len(todo)

this*args, **kwds)

Only process unique events eg:

num_calls = 0
with global_listener(inc_num_calls):
    with unique():

assert num_calls == 1 

and how