diff --git a/plugins/TorrentNotification/__init__.py b/plugins/TorrentNotification/__init__.py index 9266cf1fc..ce1fe3b7e 100644 --- a/plugins/TorrentNotification/__init__.py +++ b/plugins/TorrentNotification/__init__.py @@ -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): diff --git a/src/core.py b/src/core.py index 70e447600..277028c13 100644 --- a/src/core.py +++ b/src/core.py @@ -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": diff --git a/src/plugins.py b/src/plugins.py index 792be9906..489c2f063 100644 --- a/src/plugins.py +++ b/src/plugins.py @@ -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: