Pass events to plugins in a more resource aware way. Based on andar's

proposition.
This commit is contained in:
Alex Dedul 2007-07-13 05:14:29 +00:00
parent a0ca8a031e
commit 27d5db228a
3 changed files with 17 additions and 9 deletions

View file

@ -226,6 +226,9 @@ class Manager:
# Apply preferences. Note that this is before any torrents are added
self.apply_prefs()
# Event callbacks for use with plugins
self.event_callbacks = {}
PREF_FUNCTIONS["enable_dht"] = self.set_DHT
# Unpickle the state, or create a new one
@ -248,8 +251,6 @@ class Manager:
else:
self.state = persistent_state()
def quit(self):
# Analyze data needed for pickling, etc.
self.pre_quitting()
@ -500,6 +501,11 @@ class Manager:
# Event handling
def connect_event(self, event_type, plugin_instance):
if event_type not in self.event_callbacks:
self.event_callbacks[event_type] = []
self.event_callbacks[event_type].append(plugin_instance)
def handle_events(self):
# Handle them for the backend's purposes, but still send them up in case the client
# wants to do something - show messages, for example
@ -528,7 +534,12 @@ class Manager:
except KeyError:
event = pop_event()
continue
# Call event callbacks
if event['event_type'] in self.event_callbacks:
for plugin_instance in self.event_callbacks[event['event_type']]:
plugin_instance.handle_event(event)
if event['event_type'] is self.constants['EVENT_FINISHED']:
# Queue seeding torrent to bottom if needed
if(self.get_pref('enable_move_completed')):

View file

@ -848,7 +848,7 @@ class DelugeGTK:
# Handle the events
try:
events = self.manager.handle_events()
self.manager.handle_events()
except core.SystemError, e:
print "SystemError", e
dialogs.show_popup_warning(self.window, _("You cannot move torrent to a different partition. Please fix your preferences"))
@ -863,7 +863,7 @@ class DelugeGTK:
self.update_statusbar_and_tray()
#Update any active plugins
self.plugins.update_active_plugins(events)
self.plugins.update_active_plugins()
# Put the generated message into the statusbar
# This gives plugins a chance to write to the

View file

@ -93,14 +93,11 @@ class PluginManager:
def configure_plugin(self, name):
self.enabled_plugins[name].configure()
def update_active_plugins(self, events):
def update_active_plugins(self):
for name in self.enabled_plugins.keys():
plugin = self.enabled_plugins[name]
if 'update' in dir(plugin):
plugin.update()
if 'handle_events' in dir(plugin):
plugin.handle_events(events)
def shutdown_all_plugins(self):
for name in self.enabled_plugins.keys():