diff options
Diffstat (limited to 'module/HookManager.py')
-rw-r--r-- | module/HookManager.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/module/HookManager.py b/module/HookManager.py index b915341e3..3691fe3ed 100644 --- a/module/HookManager.py +++ b/module/HookManager.py @@ -28,6 +28,9 @@ from module.threads.HookThread import HookThread from module.plugins.PluginManager import literal_eval from utils import lock, to_string +def class_name(p): + return p.rpartition(".")[2] + class HookManager: """ Manages hooks, loading, unloading. """ @@ -68,7 +71,7 @@ class HookManager: print_exc() def addRPC(self, plugin, func, doc): - plugin = plugin.rpartition(".")[2] + plugin = class_name(plugin) doc = doc.strip() if doc else "" if plugin in self.methods: @@ -141,6 +144,7 @@ class HookManager: # active the hook in new thread start_new_thread(plugin.activate, tuple()) + self.registerEvents() @lock def deactivateHook(self, plugin): @@ -168,6 +172,8 @@ class HookManager: if plugin.isActivated(): self.call(plugin, "activate") + self.registerEvents() + def deactivateHooks(self): """ Called when core is shutting down """ self.log.info(_("Deactivating Plugins...")) @@ -219,10 +225,21 @@ class HookManager: return info def addEventListener(self, plugin, func, event): - pass + plugin = class_name(plugin) + if plugin not in self.events: + self.events[plugin] = [] + self.events[plugin].append((func, event)) + + def registerEvents(self): + for name, plugin in self.plugins.iteritems(): + if name in self.events: + for func, event in self.events[name]: + self.addEvent(event, getattr(plugin, func)) + # clean up + del self.events[name] def addConfigHandler(self, plugin, func): - pass + pass #TODO def addEvent(self, *args): self.core.eventManager.addEvent(*args) |