Register a new event callback. Parameters ---------- event : str The event for which to register this callback. function : callable A function to be called on the given event. It should take the same parameters as the appropriate
(self, event, function)
| 40 | self.callbacks = {n:[] for n in available_events} |
| 41 | |
| 42 | def register(self, event, function): |
| 43 | """Register a new event callback. |
| 44 | |
| 45 | Parameters |
| 46 | ---------- |
| 47 | event : str |
| 48 | The event for which to register this callback. |
| 49 | function : callable |
| 50 | A function to be called on the given event. It should take the same |
| 51 | parameters as the appropriate callback prototype. |
| 52 | |
| 53 | Raises |
| 54 | ------ |
| 55 | TypeError |
| 56 | If ``function`` is not callable. |
| 57 | KeyError |
| 58 | If ``event`` is not one of the known events. |
| 59 | """ |
| 60 | if not callable(function): |
| 61 | raise TypeError('Need a callable, got %r' % function) |
| 62 | callback_proto = available_events.get(event) |
| 63 | self.callbacks[event].append(callback_proto.adapt(function)) |
| 64 | |
| 65 | def unregister(self, event, function): |
| 66 | """Remove a callback from the given event.""" |
no outgoing calls