Tweaks to plugins events.

This commit is contained in:
Alex Dedul 2007-07-16 11:51:12 +00:00
parent ac81d240bd
commit 3115498790
3 changed files with 12 additions and 6 deletions

View File

@ -42,7 +42,7 @@ class TorrentNotification:
self.interface = interface
self.window = self.interface.window
self.window.connect("focus_in_event", self.set_tray_flashing_off)
self.core.connect_event(self.core.constants['EVENT_FINISHED'], self)
self.core.connect_event(self.core.constants['EVENT_FINISHED'], self.handle_event)
# Create an options file and try to load existing Values
self.config_file = deluge.common.CONFIG_DIR + "/notification.conf"
@ -63,6 +63,7 @@ class TorrentNotification:
self.show_notification(event)
def unload(self):
self.core.disconnect_event(self.core.constants['EVENT_FINISHED'], self.handle_event)
self.config.save(self.config_file)
def set_tray_flashing_off(self, focusdata1, focusdata2):

View File

@ -505,10 +505,15 @@ class Manager:
# Event handling
def connect_event(self, event_type, plugin_instance):
def connect_event(self, event_type, callback):
if event_type not in self.event_callbacks:
self.event_callbacks[event_type] = []
self.event_callbacks[event_type].append(plugin_instance)
self.event_callbacks[event_type].append(callback)
def disconnect_event(self, event_type, callback):
if event_type in self.event_callbacks and \
callback in self.event_callbacks[event_type]:
self.event_callbacks[event_type].remove(callback)
def handle_events(self):
# Handle them for the backend's purposes, but still send them up in case the client
@ -544,8 +549,8 @@ class Manager:
# Call plugins events callbacks
if event['event_type'] in self.event_callbacks:
for plugin_instance in self.event_callbacks[event['event_type']]:
plugin_instance.handle_event(event)
for callback in self.event_callbacks[event['event_type']]:
callback(event)
if event['event_type'] is self.constants['EVENT_STORAGE_MOVED']:
if event['message'] == "move_failed":

View File

@ -82,7 +82,7 @@ class PluginManager:
plugin = self.enabled_plugins[name]
if 'unload' in dir(plugin):
plugin.unload()
self.enabled_plugins.pop(name)
del self.enabled_plugins[name]
def configurable_plugin(self, name):
if name in self.enabled_plugins: