persistent plugins

This commit is contained in:
Zach Tibbitts 2007-02-15 21:54:55 +00:00
parent f2d2ac6c8e
commit fdfc10e01c
3 changed files with 28 additions and 13 deletions

View File

@ -38,18 +38,16 @@ class plugin_Example: # The plugin's class
self.button.show_all() # Show the button
print "Example Plugin loaded"
## unload is called when the plugin is removed or Deluge is shut down
def unload(self):
self.toolbar.remove(self.button) # Remove the button from the toolbar
self.config.save_to_file(self.config_file)
print "Example Plugin unloaded"
## update will be called every UPDATE_INTERVAL (usually about 1 second)
def update(self):
print "Example Plugin has been updated"
# As this plugin doesn't need to do anything every interval, this
# function will remain empty
pass
## This will be only called if your plugin is configurable
def configure(self):

View File

@ -61,11 +61,17 @@ class DelugeGTK(dbus.service.Object):
f = open(self.conf_file, mode='w')
f.flush()
f.close()
#Start the Deluge Manager:
self.manager = deluge.Manager("DE", "0490", "Deluge 0.4.90", dcommon.CONFIG_DIR)
self.plugins = delugeplugins.PluginManager(self.manager, self)
self.plugins.add_plugin_dir(dcommon.PLUGIN_DIR)
if os.path.isdir(dcommon.CONFIG_DIR + '/plugins'):
self.plugins.add_plugin_dir(dcommon.CONFIG_DIR + '/plugins')
self.plugins.scan_for_plugins()
self.pref = dcommon.DelugePreferences()
self.load_default_settings()
self.pref.load_from_file(self.conf_file)
#Start the Deluge Manager:
self.manager = deluge.Manager("DE", "0490", "Deluge 0.4.90", dcommon.CONFIG_DIR)
#Set up the interface:
self.wtree = gtk.glade.XML(dcommon.get_glade_file("delugegtk.glade"))
self.window = self.wtree.get_widget("main_window")
@ -76,11 +82,7 @@ class DelugeGTK(dbus.service.Object):
self.window.set_title('%s %s'%(dcommon.PROGRAM_NAME, dcommon.PROGRAM_VERSION))
self.window.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
self.plugins = delugeplugins.PluginManager(self.manager, self)
self.plugins.add_plugin_dir(dcommon.PLUGIN_DIR)
if os.path.isdir(dcommon.CONFIG_DIR + '/plugins'):
self.plugins.add_plugin_dir(dcommon.CONFIG_DIR + '/plugins')
self.plugins.scan_for_plugins()
## Construct the Interface
self.build_tray_icon()
@ -95,6 +97,14 @@ class DelugeGTK(dbus.service.Object):
self.apply_prefs()
enable_plugins = self.pref.get('enabled_plugins').split(';')
print enable_plugins
for plugin in enable_plugins:
try:
self.plugins.enable_plugin(plugin)
except KeyError:
pass
def connect_signals(self):
self.wtree.signal_autoconnect({
## File Menu
@ -315,6 +325,11 @@ class DelugeGTK(dbus.service.Object):
self.pref.set("max_number_uploads", 0)
self.pref.set("max_download_rate", 0)
self.pref.set("max_number_downloads", 0)
default_plugins = []
for name in self.plugins.get_available_plugins():
if self.plugins.get_plugin(name)['default']:
default_plugins.append(name)
self.pref.set("enabled_plugins", ';'.join(default_plugins))
@ -696,6 +711,9 @@ class DelugeGTK(dbus.service.Object):
self.shutdown()
def shutdown(self):
enabled_plugins = ';'.join(self.plugins.get_enabled_plugins())
self.pref.set('enabled_plugins', enabled_plugins)
self.pref.save_to_file(self.conf_file)
self.plugins.shutdown_all_plugins()
self.manager.quit()
gtk.main_quit()

View File

@ -60,7 +60,6 @@ class PluginManager:
self.enabled_plugins.pop(name)
def configure_plugin(self, name):
print "configuring", name
self.enabled_plugins[name].configure()
def update_active_plugins(self):