From d64d12f8fd170c29e8314dd6aa887b26d5b39c77 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 18 May 2019 18:35:23 +0100 Subject: [PATCH] give EventCallbacks their event name --- src/EventManager.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/EventManager.py b/src/EventManager.py index eae8a121..5687ca74 100644 --- a/src/EventManager.py +++ b/src/EventManager.py @@ -28,8 +28,9 @@ class Event(object): self.eaten = True class EventCallback(object): - def __init__(self, function: CALLBACK_TYPE, priority: int, kwargs: dict, - context: typing.Optional[str], one_shot: bool=False): + def __init__(self, event_name: str, function: CALLBACK_TYPE, priority: int, + kwargs: dict, context: typing.Optional[str], one_shot: bool=False): + self.event_name = event_name self.function = function self.priority = priority self.kwargs = kwargs @@ -45,7 +46,7 @@ class EventCallback(object): return item or self.docstring.items.get(name, default) class EventHook(object): - def __init__(self, log: Logging.Log, name: str = None, + def __init__(self, log: Logging.Log, name: str = "", parent: "EventHook" = None): self.log = log self.name = name @@ -84,7 +85,8 @@ class EventHook(object): return self._hook(function, context, priority, replay, kwargs) def _hook(self, function: CALLBACK_TYPE, context: typing.Optional[str], priority: int, replay: bool, kwargs: dict) -> EventCallback: - callback = EventCallback(function, priority, kwargs, context) + callback = EventCallback(self.name, function, priority, kwargs, + context) if context == None: self._hooks.append(callback)