1 '''
2 A special L{AEScript <AEScript.AEScript>} for handling GKeybinding.
3 Silences the pronunciation of "<" and ">" in key combinations such as
4 <Ctrl><Alt>K. Informs the user of a new shortcut when pressing Enter or Space,
5 and when cancelling with Escape or Backspace.
6
7 @author: Andy Shi
8 @author: Peter Parente
9 @organization: UNC Chapel Hill
10 @copyright: Copyright (c) 2007, Andy Shi
11
12 @license: I{The BSD Licence}
13 All rights reserved. This program and the accompanying materials are made
14 available under the terms of the BSD which is available at
15 U{http://www.opensource.org/licenses/bsd-license.php}
16
17 @see: U{http://www.unc.edu/campus/policies/copyright.html} Section 5.D.2.A for
18 UNC copyright rules.
19 '''
20
21 from AccessEngine import AEScript, AccessEngineAPI
22 from AccessEngine import AEConstants
23
24 from Tools.i18n import bind, _
25
26
27 __uie__ = dict(kind='script', tier='gnome-keybinding-properties', all_tiers=False)
28
30 '''
31 A special L{AEScript <AEScript.AEScript>} for handling GKeybinding.
32 '''
34 '''
35 Registers L{tasks <AEScript.registered_tasks>} to correct speech reporting
36 of keyboard bindings.
37 '''
38
39 self.registerTask('read keybinding', self.readKeybinding)
40 self.registerTask('new shortcut', self.enterNewShortcut)
41 self.registerTask('leave shortcut', self.leaveShortcut)
42
43
44 kbd = AccessEngineAPI.getInputDevice(None, 'keyboard')
45
46 keys = [kbd.AEK_ENTER, kbd.AEK_SPACE]
47 for key in keys:
48 self.registerCommand(kbd, 'new shortcut', _('new shortcut'),
49 True, [key])
50
51 keys = [kbd.AEK_BACK_SPACE, kbd.AEK_ESCAPE]
52 for key in keys:
53 self.registerCommand(kbd, 'leave shortcut', _('leave shortcut'),
54 True, [key])
55
56
57 self.chainTask('read keybinding', AEConstants.CHAIN_AROUND,
58 'read caret', 'BasicSpeechScript')
59 self.chainTask('read keybinding', AEConstants.CHAIN_AROUND,
60 'read selector', 'BasicSpeechScript')
61
63 '''
64 Describe which L{AETier} this script applies to by default.
65
66 @return: Human readable translated description of this script.
67 @rtype: string
68 '''
69 return _('Improves usability of gnome-keybindings-properties dialog.')
70
72 '''
73 Remove the angle brackets and replace with a space between Control, Alt,
74 Shift, and other keys.
75
76 @param kwargs: Arbitrary keyword arguments to pass to the task
77 @type kwargs: dictionary
78 @return: C{True} to allow other tasks to process this event.
79 @rtype: boolean
80
81 '''
82 col = AccessEngineAPI.getAccColumn(kwargs['por'])
83 if col == 1:
84 text = kwargs['text']
85
86 text = text.replace('>', ' ')
87 text = text.replace('<', ' ')
88 kwargs['text'] = text
89
90 self.doTask(self.getAnchorTaskId(), self.getAnchorScriptClassName(),
91 chain=False, **kwargs)
92 return True
93
95 '''
96 Announces the phrase 'new accelerator'.
97
98 @param kwargs: Arbitrary keyword arguments to pass to the task
99 @type kwargs: dictionary
100 @return: C{True} to allow other tasks to process this event.
101 @rtype: boolean
102 '''
103 AccessEngineAPI.stopNow(self, cap='audio', role='output', **kwargs)
104 AccessEngineAPI.sayItem(self, cap='audio', role='output',
105 text=_('new accelerator'), **kwargs)
106 return True
107
109 '''
110 Announces the existing accelerator.
111
112 @param kwargs: Arbitrary keyword arguments to pass to the task
113 @type kwargs: dictionary
114 @return: C{True} to allow other tasks to process this event.
115 @rtype: boolean
116 '''
117 col = AccessEngineAPI.getAccColumn(kwargs['por'])
118 if col == 1:
119 AccessEngineAPI.stopNow(self, cap='audio', role='output', **kwargs)
120 text = AccessEngineAPI.getItemText(kwargs['por'])
121 text = text.replace('>', ' ')
122 text = text.replace('<', ' ')
123 AccessEngineAPI.sayItem(self, cap='audio', role='output', text=text,
124 **kwargs)
125