~vcs-imports/gnome-mag/master

« back to all changes in this revision

Viewing changes to colorblind/Keybinder.py

  • Committer: Carlos Eduardo Rodrigues Diógenes
  • Date: 2007-06-03 23:52:07 UTC
  • Revision ID: git-v1:42a8898cb38357218626e4c81555423da8ab37cd
Tags: GNOME_MAG_0_14_5
commit the changes of the colorblind applet

svn path=/trunk/; revision=515

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import gtk, gobject, gconf
 
2
import colorblind, colorblind.keybinder
 
3
 
 
4
class Keybinder(gobject.GObject):
 
5
        __gsignals__ = {
 
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]),
 
9
        }
 
10
 
 
11
        def __init__(self, keybinding):
 
12
                gobject.GObject.__init__(self)
 
13
                
 
14
                self.bound = False
 
15
                self.prevbinding = None
 
16
                
 
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))
 
20
                
 
21
                self.bind()
 
22
                
 
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()
 
27
                        self.bind()
 
28
 
 
29
        def on_keyboard_shortcut(self):
 
30
                print "Keyboard shortcut"
 
31
                self.emit ("activated")
 
32
        
 
33
        def bind(self):
 
34
                if self.bound:
 
35
                        self.unbind()
 
36
                        
 
37
                try:
 
38
                        print 'Binding Global shortcut %s to focus the colorblind' % self.keybinding
 
39
                        colorblind.keybinder.tomboy_keybinder_bind(self.keybinding, self.on_keyboard_shortcut)
 
40
                        self.bound = True
 
41
                except KeyError:
 
42
                        # if the requested keybinding conflicts with an existing one, a KeyError will be thrown
 
43
                        self.bound = False
 
44
                
 
45
                self.emit('changed', self.bound)
 
46
                                        
 
47
        def unbind(self):
 
48
                try:
 
49
                        colorblind.keybinder.tomboy_keybinder_unbind(self.prevbinding)
 
50
                        self.bound = False
 
51
                except KeyError:
 
52
                        # if the requested keybinding is not bound, a KeyError will be thrown
 
53
                        pass
 
54
 
 
55
if gtk.pygtk_version < (2,8,0):
 
56
        gobject.type_register(Keybinder)
 
57
 
 
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
 
62
 
 
63
def get_colorblind_keybinder_switch():
 
64
        return keybinder_switch