1
import gtk, gobject, gconf
2
import colorblind, colorblind.keybinder
4
class Keybinder(gobject.GObject):
6
"activated" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
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]),
11
def __init__(self, keybinding):
12
gobject.GObject.__init__(self)
15
self.prevbinding = None
17
# Set and retreive global keybinding from gconf
18
self.keybinding = colorblind.GCONF_CLIENT.get_string(keybinding)
19
colorblind.GCONF_CLIENT.notify_add(keybinding, lambda x, y, z, a: self.on_config_keybinding(z.value))
23
def on_config_keybinding(self, value=None):
24
if value != None and value.type == gconf.VALUE_STRING:
25
self.prevbinding = self.keybinding
26
self.keybinding = value.get_string()
29
def on_keyboard_shortcut(self):
30
print "Keyboard shortcut"
31
self.emit ("activated")
38
print 'Binding Global shortcut %s to focus the colorblind' % self.keybinding
39
colorblind.keybinder.tomboy_keybinder_bind(self.keybinding, self.on_keyboard_shortcut)
42
# if the requested keybinding conflicts with an existing one, a KeyError will be thrown
45
self.emit('changed', self.bound)
49
colorblind.keybinder.tomboy_keybinder_unbind(self.prevbinding)
52
# if the requested keybinding is not bound, a KeyError will be thrown
55
if gtk.pygtk_version < (2,8,0):
56
gobject.type_register(Keybinder)
58
keybinder_on_off = Keybinder(colorblind.GCONF_KEYBINDING_ONOFF)
59
keybinder_switch = Keybinder(colorblind.GCONF_KEYBINDING_SWITCH)
60
def get_colorblind_keybinder_on_off():
61
return keybinder_on_off
63
def get_colorblind_keybinder_switch():
64
return keybinder_switch