Ok guys, as you know I just released USP with full plugin support. I am hoping that all you talented programmers out ther start coding some plugins!
Some notes: Plugins and their associated files are stored in ~/.usp/plugins Plugins must have a .py extension The plugin name is the filename (without the .py extension) for example the time plugin is USPtime.py so the plugin name is USPtime
Here is the structure of the time plugin USPtime.py
# Basic USP plugin
import gtk
import gtk.glade
import sys
import os
import gobject
import datetime
class pluginclass:
"""This is the main class for the plugin"""
"""It MUST be named pluginclass"""
def __init__(self, __usp=False):
#The Glade file for the plugin
self.gladefile = os.path.join(os.path.dirname(__file__), "myplugin.glade")
#Read GLADE file
self.wTree = gtk.glade.XML(self.gladefile,"window1")
#These properties are [COLOR="Red"]NECESSARY[/COLOR] to maintain consistency
#throughout USP
#Set 'window' property for the plugin (Must be the root widget)
[COLOR="Red"]self.window[/COLOR] = self.wTree.get_widget("window1")
#Set 'heading' property for plugin
[COLOR="Red"]self.heading[/COLOR] = "Time and Date"
#This should be the first item added to the window in glade
[COLOR="Red"]self.content_holder[/COLOR] = self.wTree.get_widget("eventbox1")
#Specify plugin width
[COLOR="Red"]self.width[/COLOR] = 150
#Plugin icon
[COLOR="Red"]self.icon[/COLOR] = 'gnome-set-time'
#Connect event handlers
dic = {"on_window1_destroy" : gtk.main_quit}
self.wTree.signal_autoconnect(dic)
# Set up usp instance pointer
self.__usp = __usp
gobject.timeout_add(1000, self.date_time)
#Actually do something with the plugin
[COLOR="Red"]def do_plugin(self):[/COLOR]
#This is the MAIN section where all the work is done
pass
def date_time(self):
try:
self.wTree.get_widget("label1").set_label('<span size="large" weight="bold">' + datetime.datetime.today().strftime("%m-%d-%Y") + '</span>')
self.wTree.get_widget("label2").set_label('<span size="30000" weight="bold">' + datetime.datetime.today().strftime("%H:%M:%S") + '</span>')
except:
pass
return True
self.window - the window object self.heading - the heading for the plugin in USP self.content_holder - the container (must be eventbox) holding the plugin self.width - the default width of the plugin self.icon - the icon to use for the plugin in the plugin-tray def do_plugin(self): - the MAIN section of the plugin where the work is done def __init__(self, __usp=False): - __usp is the main USP object. By being creative in plugin development the user should be able to modify nearly all of the paramaters of the USP window and its children
USP currently offers the following API. It will be extended in the future Filename
- easygconf.py
Methods
- SetGconf(client,type,key,default)
- SetGconfList(client,type,key,default)
client is the default gconf client type - this is the key type such as string, int, bool key - the actual key such as /apps/usp/plugins/foo/something default - the default key to set
Filename
- execute.py
Methods
- Execute(widget,cmd)
widget - widget calling the execute command cmd - the command to execute in list format, first value is the command and the following is the arguments each as its own item in the list