opensourcejason.info
deskbar skeleton
# This is a basic skeleton for deskbar applet handlers. This doesn't do anything, but you can load it!

import deskbar.Handler
import deskbar.Match
from gettext import gettext as _
#During development, set the _debug global variable to True so that when you test your handler, you see all of the errors and exceptions generated by your python code.
_debug=True
if _debug:
    import traceback

#We register our handler with deskbar applet using the HANDLERS variable. This is a dictionary, and the elements of the dictionary are mostly self-explanatory. The key of the HANDLER ("HelloHandler" in this case) should be the name of the class that subclasses deskbar.Handler.Handler.
HANDLERS = {
    "HelloHandler" : {
    "name" : _("Hello"),
    "description" : _("Greet the world!"),
    "version" : "0.1",
    }
}

#This is the bare minimum Match subclass example.
#It simply always displays "Hello World" in the dropdown list.
#Clicking on the item in the list does nothing.
class HelloMatch(deskbar.Match.Match):
    def get_verb(self):
        return "Hello World"
    def get_category(self):
        return None
    def action(self):
        pass

#This is the bare minimum handler. No matter what the query is, it returns one match. The match has no interesting information.
class HelloHandler(deskbar.Handler.Handler):
    def __init__ (self):
        deskbar.Handler.Handler.__init__ (self, "gnome-logo-icon")
    def query(self, text):
        return [HelloMatch(self)]

#Thanks to Leo Szumel for this unit test code.
#This allows you to test your plugin using the command line
#Instead of loading deskbar-applet over and over.
#For this basic skeleton, the unit test should just print out
#Hello World, and then do nothing, no matter how you respond.
if __name__ == '__main__':
  import sys

  print __file__,': Running unit test'
  ah = HelloHandler()
  ah.initialize()

  hits = ah.query('the')

  for h in hits:
    print '%s: action %s ? (y/n/q)' % (h.get_category(), h.get_verb()),
    ask = sys.stdin.read(1)
    if ask == 'y':
      h.action()
    if ask == 'q':
      break
    print

Add Comment 
Sign as Author 
Enter code 582