From f10bf6961b0128bc57cb02f0be5e5acdb78b0abb Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Wed, 26 Aug 2009 16:59:29 +0000 Subject: [PATCH] Add PluginEnabledEvent Add PluginDisabledEvent Add event handlers to enable/disable plugins on events --- deluge/core/pluginmanager.py | 13 +++++++++++++ deluge/event.py | 22 ++++++++++++++++++++++ deluge/ui/console/eventlog.py | 8 ++++++++ deluge/ui/gtkui/pluginmanager.py | 9 +++++++++ 4 files changed, 52 insertions(+) diff --git a/deluge/core/pluginmanager.py b/deluge/core/pluginmanager.py index 96035d484..647a297c1 100644 --- a/deluge/core/pluginmanager.py +++ b/deluge/core/pluginmanager.py @@ -39,6 +39,7 @@ from twisted.internet import reactor from twisted.internet.task import LoopingCall +from deluge.event import PluginEnabledEvent, PluginDisabledEvent import deluge.pluginmanagerbase import deluge.component as component from deluge.log import LOG as log @@ -76,6 +77,18 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, except Exception, e: log.exception(e) + def enable_plugin(self, name): + if name not in self.plugins: + super(PluginManager, self).enable_plugin(name) + if name in self.plugins: + component.get("EventManager").emit(PluginEnabledEvent(name)) + + def disable_plugin(self, name): + if name in self.plugins: + super(PluginManager, self).disable_plugin(name) + if name not in self.plugins: + component.get("EventManager").emit(PluginDisabledEvent(name)) + def get_status(self, torrent_id, fields): """Return the value of status fields for the selected torrent_id.""" status = {} diff --git a/deluge/event.py b/deluge/event.py index dc99933ec..118a76e59 100644 --- a/deluge/event.py +++ b/deluge/event.py @@ -190,3 +190,25 @@ class ConfigValueChangedEvent(DelugeEvent): :param value: the new value of the `:param:key` """ self._args = [key, value] + +class PluginEnabledEvent(DelugeEvent): + """ + Emitted when a plugin is enabled in the Core. + """ + def __init__(self, name): + """ + :param name: the plugin name + :type name: string + """ + self._args = [name] + +class PluginDisabledEvent(DelugeEvent): + """ + Emitted when a plugin is disabled in the Core. + """ + def __init__(self, name): + """ + :param name: the plugin name + :type name: string + """ + self._args = [name] diff --git a/deluge/ui/console/eventlog.py b/deluge/ui/console/eventlog.py index babd1b9eb..91e258ae1 100644 --- a/deluge/ui/console/eventlog.py +++ b/deluge/ui/console/eventlog.py @@ -58,6 +58,8 @@ class EventLog(component.Component): client.register_event_handler("SessionPausedEvent", self.on_session_paused_event) client.register_event_handler("SessionResumedEvent", self.on_session_resumed_event) client.register_event_handler("ConfigValueChangedEvent", self.on_config_value_changed_event) + client.register_event_handler("PluginEnabledEvent", self.on_plugin_enabled_event) + client.register_event_handler("PluginDisabledEvent", self.on_plugin_disabled_event) def on_torrent_added_event(self, torrent_id): def on_torrent_status(status): @@ -101,3 +103,9 @@ class EventLog(component.Component): self.console.write(self.prefix + "ConfigValueChanged: {!input!}%s: %s%s" % (key, color, value)) + + def on_plugin_enabled_event(self, name): + self.console.write(self.prefix + "PluginEnabled: {!info!}%s" % name) + + def on_plugin_disabled_event(self, name): + self.console.write(self.prefix + "PluginDisabled: {!info!}%s" % name) diff --git a/deluge/ui/gtkui/pluginmanager.py b/deluge/ui/gtkui/pluginmanager.py index 8e3a30cc6..126f7b348 100644 --- a/deluge/ui/gtkui/pluginmanager.py +++ b/deluge/ui/gtkui/pluginmanager.py @@ -53,6 +53,9 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, "on_show_prefs": [] } + client.register_event_handler("PluginEnabledEvent", self._on_plugin_enabled_event) + client.register_event_handler("PluginDisabledEvent", self._on_plugin_disabled_event) + def register_hook(self, hook, function): """Register a hook function with the plugin manager""" try: @@ -84,6 +87,12 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, for plugin in enabled_plugins: self.enable_plugin(plugin) + def _on_plugin_enabled_event(self, name): + self.enable_plugin(name) + + def _on_plugin_disabled_event(self, name): + self.disable_plugin(name) + ## Hook functions def run_on_show_prefs(self): """This hook is run before the user is shown the preferences dialog.