from gettext import gettext as _
import gnomevfs
from deskbar.Handler import Handler
from deskbar.Match import Match
import gtk, gtk.gdk
# Look up Python GStreamer documentation as well
try:
import pygst
pygst.require("0.10")
import gst
except:
gst = None
HANDLERS = {
"PyGtkAPIHandler" : {
"name": _("Python Gtk and GStreamer API"),
"description": _("Look up PyGtk and PyGst API class documentation"),
}
}
class PyGtkAPIMatch(Match):
def __init__(self, backend, url=None, module=None, **args):
Match.__init__(self, backend, **args)
self.url = url
self.module = module
def action(self, text=None):
gnomevfs.url_show(self.url)
def get_verb(self):
if self.module == 'gst':
return _("Show Python GStreamer API for %(name)s")
else:
return _("Show PyGtk API for %(name)s")
def get_hash(self, text=None):
return self.url
class PyGtkAPIHandler(Handler):
def __init__(self):
Handler.__init__(self, "gnome-mime-application-x-python.png")
self.ITEMS = {}
def initialize(self):
self.load_items(gtk, 'http://www.pygtk.org/pygtk2reference/class-gtk%s.html')
self.load_items(gtk.gdk, 'http://www.pygtk.org/pygtk2reference/class-gdk%s.html')
if gst:
self.load_items(gst, 'http://pygstdocs.berlios.de/class-gst%s.html')
self.ITEM_KEYS = self.ITEMS.keys()
self.ITEM_KEYS.sort()
def load_items(self, module, url):
for x in dir(module):
if x.startswith('_'):
pass
elif x == x.upper():
# x looks like a constant, like gtk.FILL
pass
elif x[0].isupper():
# x looks like a classname, like EntryCompletion
# some classes, like gtk.SelectionMode, are actually gtk._gtk.SelectionMode.
# we don't want them
if str(getattr(module, x).__module__).find('_') != -1:
continue
# otherwise, we're (probably) good. add x to ITEMS
xx = x.lower()
value = (x + ' (' + module.__name__ + ')', url % x.lower(),
module.__name__)
if self.ITEMS.has_key(xx):
self.ITEMS[xx].append(value)
else:
self.ITEMS[xx] = [value]
def query(self, query):
result = []
query = query.lower()
for k in self.ITEM_KEYS:
if k.find(query) != -1:
for name, url, module_name in self.ITEMS[k]:
result.append(PyGtkAPIMatch(self, name=name, url=url,
module=module_name))
return result