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:
- obengine.gui (the OpenBlox GUI)
- obengine.plugin (the OpenBlox plugin system)
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!
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.
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 |
---|
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. |
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).