Move event priority mechanics to get_hooks() to factor in contextual events

This commit is contained in:
jesopo 2018-08-31 13:32:46 +01:00 committed by dongfix
parent 38e1b5d0ad
commit fd653ba117

View file

@ -110,13 +110,10 @@ class EventHook(object):
if context == None: if context == None:
self._hooks.append(callback) self._hooks.append(callback)
hooks = self._hooks
else: else:
if not context in self._context_hooks: if not context in self._context_hooks:
self._context_hooks[context] = [] self._context_hooks[context] = []
self._context_hooks[context].append(callback) self._context_hooks[context].append(callback)
hooks = self._context_hooks[context]
hooks.sort(key=lambda x: x.priority)
if replay and not self._stored_events == None: if replay and not self._stored_events == None:
for kwargs in self._stored_events: for kwargs in self._stored_events:
@ -223,5 +220,5 @@ class EventHook(object):
child.purge_context(context) child.purge_context(context)
def get_hooks(self): def get_hooks(self):
return self._hooks + list(itertools.chain.from_iterable( return sorted(self._hooks + list(itertools.chain.from_iterable(
self._context_hooks.values())) self._context_hooks.values())), key=lambda e: e.priority)