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 c
(self, event: str, function: Callable[..., Any])
| 60 | self.print_on_error = print_on_error |
| 61 | |
| 62 | def register(self, event: str, function: Callable[..., Any]) -> None: |
| 63 | """Register a new event callback. |
| 64 | |
| 65 | Parameters |
| 66 | ---------- |
| 67 | event : str |
| 68 | The event for which to register this callback. |
| 69 | function : callable |
| 70 | A function to be called on the given event. It should take the same |
| 71 | parameters as the appropriate callback prototype. |
| 72 | |
| 73 | Raises |
| 74 | ------ |
| 75 | TypeError |
| 76 | If ``function`` is not callable. |
| 77 | KeyError |
| 78 | If ``event`` is not one of the known events. |
| 79 | """ |
| 80 | if not callable(function): |
| 81 | raise TypeError('Need a callable, got %r' % function) |
| 82 | if function not in self.callbacks[event]: |
| 83 | self.callbacks[event].append(function) |
| 84 | |
| 85 | def unregister(self, event: str, function: Callable[..., Any]) -> None: |
| 86 | """Remove a callback from the given event.""" |
no outgoing calls