2020-02-16 14:27:17 +01:00
|
|
|
|
2020-03-29 14:37:30 +02:00
|
|
|
__callbacks = {}
|
2020-02-16 14:27:17 +01:00
|
|
|
|
|
|
|
def register(event, callback, *args, **kwargs):
|
2020-04-04 08:44:41 +02:00
|
|
|
cb = callback
|
|
|
|
if len(args) + len(kwargs) > 0:
|
|
|
|
cb = lambda: callback(*args, **kwargs)
|
|
|
|
|
|
|
|
__callbacks.setdefault(event, []).append(cb)
|
2020-02-16 14:27:17 +01:00
|
|
|
|
2020-02-22 13:42:44 +01:00
|
|
|
def clear():
|
2020-03-29 14:37:30 +02:00
|
|
|
__callbacks.clear()
|
2020-02-22 13:42:44 +01:00
|
|
|
|
2020-04-04 08:44:41 +02:00
|
|
|
def trigger(event, *args, **kwargs):
|
2020-05-02 13:54:45 +02:00
|
|
|
cb = __callbacks.get(event, [])
|
|
|
|
if len(cb) == 0: return False
|
|
|
|
|
|
|
|
for callback in cb:
|
2020-04-04 08:44:41 +02:00
|
|
|
if len(args) + len(kwargs) == 0:
|
|
|
|
callback()
|
|
|
|
else:
|
|
|
|
callback(*args, **kwargs)
|
2020-05-02 13:54:45 +02:00
|
|
|
return True
|
2020-02-16 14:27:17 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|