2007-02-15 21:30:17 +00:00
|
|
|
# An example plugin for use with Deluge
|
2007-01-09 00:37:57 +00:00
|
|
|
|
2007-02-15 21:30:17 +00:00
|
|
|
# This plugin is intended to be used with Deluge's default GTK interface
|
|
|
|
class plugin_Example: # The plugin's class
|
|
|
|
## Your plugin's contructor should follow this format
|
|
|
|
## path = A string containing the path to the plugin
|
|
|
|
## deluge_core = The active instance of the Deluge Manager
|
|
|
|
## deluge_interface = The active instance of the Deluge Interface
|
2007-02-15 00:41:22 +00:00
|
|
|
def __init__(self, path, deluge_core, deluge_interface):
|
2007-02-15 21:30:17 +00:00
|
|
|
# Save the path, interface, and core so they can be used later
|
2007-02-15 00:41:22 +00:00
|
|
|
self.path = path
|
2007-01-09 00:37:57 +00:00
|
|
|
self.core = deluge_core
|
|
|
|
self.interface = deluge_interface
|
2007-02-15 21:30:17 +00:00
|
|
|
# Classes must be imported as they are needed from within
|
|
|
|
# the plugin's functions
|
2007-03-01 20:29:33 +00:00
|
|
|
import dcommon, gtk, gtk.glade, dgtk, pref
|
2007-02-15 21:30:17 +00:00
|
|
|
# Create an options file and try to load existing Values
|
|
|
|
self.config_file = dcommon.CONFIG_DIR + "/example.conf"
|
2007-03-01 20:29:33 +00:00
|
|
|
self.config = pref.Preferences()
|
2007-02-15 21:30:17 +00:00
|
|
|
try:
|
|
|
|
self.config.load_from_file(self.config_file)
|
|
|
|
except IOError:
|
|
|
|
# File does not exist
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Extract the configuration dialog from the gladefile
|
|
|
|
self.glade = gtk.glade.XML(path + "/example.glade")
|
|
|
|
self.dialog = self.glade.get_widget("dialog")
|
|
|
|
self.dialog.set_icon_from_file(self.path + "/example-plugin.png")
|
|
|
|
# Access the interface's toolbar
|
|
|
|
self.toolbar = self.interface.toolbar
|
|
|
|
# Make a toolbar button
|
|
|
|
icon = gtk.Image()
|
|
|
|
icon.set_from_file(self.path + "/example-plugin.png") # Toolbar items should be 22x22 pixel images
|
|
|
|
self.button = gtk.ToolButton(icon_widget=icon, label="Example Plugin")
|
|
|
|
self.button.connect("clicked", self.clicked) # Connect the signal handler for the button
|
|
|
|
self.toolbar.add(self.button) # Add button to toolbar
|
|
|
|
self.button.show_all() # Show the button
|
2007-01-09 00:37:57 +00:00
|
|
|
|
2007-02-15 21:30:17 +00:00
|
|
|
|
|
|
|
## unload is called when the plugin is removed or Deluge is shut down
|
2007-01-09 00:37:57 +00:00
|
|
|
def unload(self):
|
2007-02-15 21:30:17 +00:00
|
|
|
self.toolbar.remove(self.button) # Remove the button from the toolbar
|
|
|
|
self.config.save_to_file(self.config_file)
|
2007-01-09 00:37:57 +00:00
|
|
|
|
2007-02-15 21:30:17 +00:00
|
|
|
## update will be called every UPDATE_INTERVAL (usually about 1 second)
|
2007-01-09 00:37:57 +00:00
|
|
|
def update(self):
|
2007-02-15 21:54:55 +00:00
|
|
|
# As this plugin doesn't need to do anything every interval, this
|
|
|
|
# function will remain empty
|
|
|
|
pass
|
2007-02-15 21:30:17 +00:00
|
|
|
|
|
|
|
## This will be only called if your plugin is configurable
|
|
|
|
def configure(self):
|
|
|
|
entry1 = self.glade.get_widget("entry1")
|
|
|
|
entry2 = self.glade.get_widget("entry2")
|
|
|
|
try:
|
|
|
|
entry1.set_text(self.config.get("option1"))
|
|
|
|
entry2.set_text(self.config.get("option2"))
|
|
|
|
except KeyError:
|
|
|
|
entry1.set_text("")
|
|
|
|
entry2.set_text("")
|
|
|
|
self.dialog.show()
|
|
|
|
response = self.dialog.run()
|
|
|
|
self.dialog.hide()
|
|
|
|
if response:
|
|
|
|
self.config.set("option1", entry1.get_text())
|
|
|
|
self.config.set("option2", entry2.get_text())
|
|
|
|
|
|
|
|
|
2007-02-14 22:43:48 +00:00
|
|
|
|
2007-02-15 21:30:17 +00:00
|
|
|
## This will be called whenever self.button is clicked
|
|
|
|
def clicked(self, button):
|
|
|
|
# Build a dialog from scratch rather than from a glade file
|
|
|
|
import gtk
|
|
|
|
dialog = gtk.Dialog(title="Example Plugin", parent=self.interface.window,
|
|
|
|
buttons=(gtk.STOCK_OK, 0))
|
|
|
|
dialog.set_icon_from_file(self.path + "/example-plugin.png")
|
|
|
|
try:
|
|
|
|
text = "This is a popup notification from Example Plugin\n" + \
|
|
|
|
"Your value for option1 is %s\n"%self.config.get("option1") + \
|
|
|
|
"and option2 is %s"%self.config.get("option2")
|
|
|
|
except KeyError:
|
|
|
|
text = "This is a popup notification from Example Plugin\n" + \
|
|
|
|
"If you had set options by configuring this plugin,\n" + \
|
|
|
|
"they would appear here"
|
|
|
|
label = gtk.Label(text)
|
|
|
|
dialog.vbox.pack_start(label)
|
|
|
|
|
|
|
|
dialog.show_all()
|
|
|
|
dialog.run()
|
|
|
|
dialog.hide()
|
|
|
|
dialog.destroy()
|
2007-01-09 00:37:57 +00:00
|
|
|
|
|
|
|
|
2007-02-15 21:30:17 +00:00
|
|
|
register_plugin("Example Plugin", # The name of the plugin
|
|
|
|
plugin_Example, # The plugin's class
|
2007-03-18 16:23:08 +00:00
|
|
|
"Zach Tibbitts", # The author's Name
|
2007-02-15 21:30:17 +00:00
|
|
|
"0.5.0", # The plugin's version number
|
|
|
|
"An example plugin", # A description of the plugin
|
|
|
|
config=True, # If the plugin can be configured
|
|
|
|
)
|