home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / pycentral / deskbar-applet / site-packages / deskbar / Keybinder.py < prev    next >
Encoding:
Python Source  |  2006-08-29  |  1.9 KB  |  59 lines

  1. import gtk, gobject, gconf
  2. import deskbar, deskbar.keybinder
  3.  
  4. class Keybinder(gobject.GObject):
  5.     __gsignals__ = {
  6.         "activated" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_ULONG]),
  7.         # When the keybinding changes, passes a boolean indicating wether the keybinding is successful
  8.         "changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_BOOLEAN]),
  9.     }
  10.     def __init__(self):
  11.         gobject.GObject.__init__(self)
  12.         
  13.         self.bound = False
  14.         
  15.         # Set and retreive global keybinding from gconf
  16.         self.keybinding = deskbar.GCONF_CLIENT.get_string(deskbar.GCONF_KEYBINDING)
  17.         if self.keybinding == None:
  18.             # This is for uninstalled cases, the real default is in the schema
  19.             self.keybinding = "<Alt>F3"
  20.         deskbar.GCONF_CLIENT.notify_add(deskbar.GCONF_KEYBINDING, lambda x, y, z, a: self.on_config_keybinding(z.value))
  21.         self.bind()
  22.         
  23.     def on_config_keybinding(self, value=None):
  24.         if value != None and value.type == gconf.VALUE_STRING:
  25.             self.keybinding = value.get_string()
  26.             self.bind()
  27.     
  28.     def on_keyboard_shortcut(self):
  29.         self.emit('activated', deskbar.keybinder.tomboy_keybinder_get_current_event_time())
  30.         
  31.     def bind(self):
  32.         if self.bound:
  33.             self.unbind()
  34.             
  35.         try:
  36.             print 'Binding Global shortcut %s to focus the deskbar' % self.keybinding
  37.             deskbar.keybinder.tomboy_keybinder_bind(self.keybinding, self.on_keyboard_shortcut)
  38.             self.bound = True
  39.         except KeyError:
  40.             # if the requested keybinding conflicts with an existing one, a KeyError will be thrown
  41.             self.bound = False
  42.         
  43.         self.emit('changed', self.bound)
  44.                     
  45.     def unbind(self):
  46.         try:
  47.             deskbar.keybinder.tomboy_keybinder_unbind(self.keybinding)
  48.             self.bound = False
  49.         except KeyError:
  50.             # if the requested keybinding is not bound, a KeyError will be thrown
  51.             pass
  52.  
  53. if gtk.pygtk_version < (2,8,0):
  54.     gobject.type_register(Keybinder)
  55.  
  56. keybinder = Keybinder()
  57. def get_deskbar_keybinder():
  58.     return keybinder
  59.