Simple event manager

A simple event/callback module, for use in any python project. It has no dependencies beyond python itself. It is used in Pyplanes as the method of communication between game objects.

Callback functions are registered with a manager object, along with a set of key/value pairs to listen for. When an event is triggered through the manager which matches all given key/value pairs, the relevant registered function/s are called.

Alternatively, an EventQueue manager can be used, which will queue up triggered events and only action them when it's tick() method is called.

Download

Latest version: 1.1.0

This module is released under the MIT license.

Usage example

import event
 
def foo(event):
print event['message']
 
# Create a manager object, and register the foo function as a callback
manager = event.EventManager()
manager.register(foo, type='foo')
 
# This event will trigger the 'foo' function.
manager.trigger(event.Event(type='foo', message='Foo!', something='else'))
# This event will not trigger 'foo'.
manager.trigger(event.Event(type='bar', message='Baa!'))
 
# We no longer care about calling foo
manager.unregister(foo)

See also

The inspiration behind my writing a simple event module; OcempGUI contains a far more complex event-managing module than this one.