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:
|
|
|
|
print("registering lambda: {} {}".format(len(args), len(kwargs)))
|
|
|
|
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-03-29 14:37:30 +02:00
|
|
|
for callback in __callbacks.get(event, []):
|
2020-04-04 08:44:41 +02:00
|
|
|
if len(args) + len(kwargs) == 0:
|
|
|
|
callback()
|
|
|
|
else:
|
|
|
|
callback(*args, **kwargs)
|
2020-02-16 14:27:17 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|