Skip to content
campadrenalin edited this page Feb 15, 2012 · 1 revision

ConcurrenTree.model.event

EventGrid

Registers and triggers callbacks. Generally used to alert non-library code of a change to a node.

Events work by labels. To listen for a type of event, call eg.register("myevent", myfunc). Later, other code will trigger that with eg.happen("myevent"). In this case, "myevent" is a label. Labels can be any arbitrary string. Callbacks should take the args (evgrid, label).

There is also a special label "all", added automatically during the init function. Triggering any label will also trigger all the callbacks in "all" afterwards, although direct triggers of "all" will only trigger the callbacks once.

You can access the callback list for a label with the dict interface. evgrid['gravy'] = [], for example.

Methods:
* __init__(labels=[]) # Sets up initial labels
* setup_labels(labels) # Add labels to the internal label set
* register(label, func) # Add a callback for this label
* happen(label) # Trigger all callbacks for this label

Python Library

Clone this wiki locally