Add PluginEnabledEvent

Add PluginDisabledEvent
Add event handlers to enable/disable plugins on events
This commit is contained in:
Andrew Resch 2009-08-26 16:59:29 +00:00
parent 6ca835314e
commit f10bf6961b
4 changed files with 52 additions and 0 deletions

View File

@ -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 = {}

View File

@ -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]

View File

@ -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)

View File

@ -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.