first plugin

This commit is contained in:
Zach Tibbitts 2007-01-09 00:37:57 +00:00
parent b2f68ac69e
commit abfcb4f124
4 changed files with 74 additions and 8 deletions

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python
# #
# delugeplugins.py # delugeplugins.py
# #
@ -19,6 +20,43 @@
# 51 Franklin Street, Fifth Floor # 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
import os
class PluginManager: class PluginManager:
def __init__(self): def __init__(self):
pass self.plugin_dirs = []
self.plugins = {}
def add_plugin_dir(self, directory):
self.plugin_dirs.append(directory)
def scan_for_plugins(self):
register_plugin = self.register_plugin
for folder in self.plugin_dirs:
print "Looking in", folder
plugin_folders = os.listdir(folder)
for plugin in plugin_folders:
if os.path.isfile(folder + plugin + "/plugin.py"):
execfile(folder + plugin + "/plugin.py")
def register_plugin(self,
name,
plugin_class,
version,
description,
config=False,
default=False,
requires=None,
interface=None,
required_plugins=None):
self.plugins[name] = (plugin_class, version, description, config, default, requires, interface, required_plugins)
## Few lines of code to test functionality
if __name__ == "__main__":
p = PluginManager()
p.add_plugin_dir("plugins/")
p.scan_for_plugins()
for x in p.plugins:
print x
for y in p.plugins[x]:
print "\t", y

View File

@ -30,7 +30,7 @@ import gtk.glade
## Right now this only supports PyGTK's native ## Right now this only supports PyGTK's native
## tray library. I will add egg support into ## tray library. I may add egg support into
## this class at a later time. ## this class at a later time.
class TrayIcon: class TrayIcon:
def __init__(self, parent): def __init__(self, parent):
@ -111,6 +111,13 @@ class PreferencesDialog:
self.prf = self.wtree.get_widget("pref_dialog") self.prf = self.wtree.get_widget("pref_dialog")
self.notebook = self.wtree.get_widget("pref_notebook") self.notebook = self.wtree.get_widget("pref_notebook")
self.prf.set_icon_from_file(dcommon.get_pixmap("deluge32.png")) self.prf.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
self.plugin_view = self.wtree.get_widget("plugin_view")
self.plugin_store = gtk.ListStore(str, 'gboolean')
self.plugin_view.set_model(self.plugin_store)
self.plugin_name_column = add_text_column(self.plugin_view, "Plugin", 0)
self.plugin_name_column.set_expand(True)
self.plugin_toggle_column = add_toggle_column(self.plugin_view, "Enable", 1)
def show_pref(self, arg=None): def show_pref(self, arg=None):
self.prf.show_all() self.prf.show_all()

View File

@ -6,6 +6,8 @@
<property name="width_request">480</property> <property name="width_request">480</property>
<property name="border_width">5</property> <property name="border_width">5</property>
<property name="title" translatable="yes">Preferences Dialog</property> <property name="title" translatable="yes">Preferences Dialog</property>
<property name="default_width">583</property>
<property name="default_height">431</property>
<property name="has_separator">False</property> <property name="has_separator">False</property>
<child internal-child="vbox"> <child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox1"> <widget class="GtkVBox" id="dialog-vbox1">
@ -105,8 +107,8 @@
</child> </child>
<child> <child>
<widget class="GtkFileChooserButton" id="filechooserbutton1"> <widget class="GtkFileChooserButton" id="filechooserbutton1">
<property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
@ -135,7 +137,6 @@
<child> <child>
<widget class="GtkExpander" id="expander2"> <widget class="GtkExpander" id="expander2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="expanded">True</property>
<child> <child>
<widget class="GtkTable" id="table4"> <widget class="GtkTable" id="table4">
<property name="visible">True</property> <property name="visible">True</property>
@ -183,7 +184,6 @@ their share ratio reaches:</property>
<child> <child>
<widget class="GtkExpander" id="expander3"> <widget class="GtkExpander" id="expander3">
<property name="visible">True</property> <property name="visible">True</property>
<property name="expanded">True</property>
<child> <child>
<widget class="GtkCheckButton" id="checkbutton2"> <widget class="GtkCheckButton" id="checkbutton2">
<property name="visible">True</property> <property name="visible">True</property>
@ -462,7 +462,7 @@ their share ratio reaches:</property>
<property name="n_rows">2</property> <property name="n_rows">2</property>
<property name="n_columns">2</property> <property name="n_columns">2</property>
<child> <child>
<widget class="GtkTextView" id="textview1"> <widget class="GtkTextView" id="plugin_text">
<property name="visible">True</property> <property name="visible">True</property>
<property name="editable">False</property> <property name="editable">False</property>
<property name="wrap_mode">GTK_WRAP_WORD</property> <property name="wrap_mode">GTK_WRAP_WORD</property>
@ -481,7 +481,9 @@ their share ratio reaches:</property>
<child> <child>
<widget class="GtkButton" id="button1"> <widget class="GtkButton" id="button1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">button</property> <child>
<placeholder/>
</child>
</widget> </widget>
</child> </child>
<child> <child>
@ -513,7 +515,7 @@ their share ratio reaches:</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkTreeView" id="treeview1"> <widget class="GtkTreeView" id="plugin_view">
<property name="visible">True</property> <property name="visible">True</property>
</widget> </widget>
<packing> <packing>

View File

@ -0,0 +1,19 @@
#!/usr/bin/python
class plugin_Example:
def __init__(self, deluge_core, deluge_interface):
self.core = deluge_core
self.interface = deluge_interface
def unload(self):
pass
def update(self):
pass
register_plugin("Example",
plugin_Example,
"0.2",
"An example plugin",
requires="0.5.0")