OpenBlox’s event system (obengine.event)

New in version 0.7.

OpenBlox’s event system forms OpenBlox’s backbone, along with OpenBlox’s plugin system and asynchronous system.

Some examples of OpenBlox modules that use the event system are:

Here’s a quick example on how to make your own event:

>>> import obengine.event
>>> e = obengine.event.Event()
>>> def test_handler():
...     print 'Test handler fired!'
...
>>> e += test_handler
>>> e()
Test handler fired!

You can also remove bound event handlers:

>>> e -= test_handler
>>> e()

Let’s define a handler that takes some arguments:

>>> def second_test_handler(arg1, arg2):
...     print arg1, arg2
...
>>> e += second_test_handler
>>> e('Hello,', 'World!')
Hello, World!

Reference

class obengine.event.Event
fire([*args, **kwargs])

Fires this event, and calls all bound event handlers in the order they were added (i.e, in a FIFO fashion), passing any given arguments to each event handler.

Warning

If any of the event handlers throw an exception, subsequent event handlers (i.e, those that haven’t been fired yet) won’t get called.

add_handler(handler)

Adds handler to the list of event handlers bound to this event. Nothing is done if handler is already bound to this event.

Parameter:handler (any callable object) – The handler to add
remove_handler(handler)

Removes handler from the list of event handlers bound to this event.

Parameter:handler – The handler to remove
Raises:ValueError if the handler isn’t already handling this event.
enable()
Enables this event, if it wasn’t already enabled.
disable()
Disables this event (so calls to fire() or __call__() do nothing).
enabled

A bool, which enables (if set to True) or disables (if set to False) this event.

The reason this attribute exists (when enable() and disable() exist) is to enable users to easily select the enabling/disabling system that works best for them (enable()/disable() for event handlers, this attribute otherwise).

handler_count()
Returns the number of handlers currently bound to this event.
__iadd__(handler)
See add_handler().
__isub__(handler)
See remove_handler().
__call__([*args, **kwargs])
See fire().
__len__()
See handler_count().

Table Of Contents

Previous topic

OpenBlox’s documentation standard

Next topic

The OpenBlox GUI toolkit

This Page