1 '''
2 Defines tools for assisting L{AEScript <AEScript.AEScript>} developers.
3
4 @author: Peter Parente
5 @organization: IBM Corporation
6 @copyright: Copyright (c) 2005, 2007 IBM Corporation
7
8 @author: Frank Zenker
9 @author: Nicole Anacker
10 @organization: IT Science Center Ruegen gGmbH, Germany
11 @copyright: Copyright (c) 2007, 2008 ITSC Ruegen
12
13 @license: I{The BSD License}
14 All rights reserved. This program and the accompanying materials are made
15 available under the terms of the BSD license which accompanies
16 this distribution, and is available at
17 U{http://www.opensource.org/licenses/bsd-license.php}
18 '''
19
20 from AccessEngine import AEScript, AccessEngineAPI
21 from AccessEngine import AEConstants
22
23 from Tools.i18n import _
24
25 __uie__ = dict(kind='script', all_tiers=True)
26
28 '''
29 A special L{AEScript <AEScript.AEScript>} for assisting Script developers.
30
31 It defines special hotkeys.
32 - I{(Strg)} - Mute/unmute all output.
33 - I{(Alt+Shift+J)} - Report all Scripts in the current L{AETier}.
34 - I{(Alt+Shift+K)} - Refresh all Scripts in the current L{AETier}.
35 - I{(Alt+Shift+L)} - Show/hide all monitors registered in the current
36 profile.
37 '''
39 '''
40 Registers L{event tasks <AEScript.event_tasks>} to handle
41 L{focus <AEEvent.FocusChange>} and L{view <AEEvent.ViewChange>}
42 change events. Registers L{tasks <AEScript.registered_tasks>} that can be
43 mapped to L{AEInput.Gesture}s.
44 '''
45
46 AccessEngineAPI.setScriptIdealOutput(self, 'audio')
47
48
49 self.registerEventTask('developer focus debug',
50 AEConstants.EVENT_TYPE_FOCUS_CHANGE,
51 focus=True, tier=True, background=True)
52 self.registerEventTask('developer view debug',
53 AEConstants.EVENT_TYPE_VIEW_CHANGE)
54
55
56 self.registerTask('developer toggle mute', self.onMute)
57 self.registerTask('developer say scripts', self.sayScripts)
58 self.registerTask('developer reload scripts', self.reloadScripts)
59 self.registerTask('developer toggle monitors', self.showHideMonitors)
60
61
62 kbd = AccessEngineAPI.getInputDevice(None, 'keyboard')
63
64 AccessEngineAPI.addInputModifiers(self, kbd, kbd.AEK_ALT_L, kbd.AEK_ALT_R,
65 kbd.AEK_CAPS_LOCK, kbd.AEK_CONTROL_R,
66 kbd.AEK_CONTROL_L)
67 self.registerCommand(kbd, 'developer toggle mute',
68 _('developer toggle mute'),
69 False, [kbd.AEK_CONTROL_R, kbd.AEK_CONTROL_L])
70
71 pairs = [[kbd.AEK_ALT_L, kbd.AEK_CAPS_LOCK],
72 [kbd.AEK_ALT_R, kbd.AEK_CAPS_LOCK]]
73
74 for pair in pairs:
75 self.registerCommand(kbd, 'developer say scripts',
76 _('developer say scripts'),
77 False, pair+[kbd.AEK_J])
78 self.registerCommand(kbd, 'developer reload scripts',
79 _('developer reload scripts'),
80 False, pair+[kbd.AEK_K])
81 self.registerCommand(kbd, 'developer toggle monitors',
82 _('developer toggle monitors'),
83 False, pair+[kbd.AEK_L])
84
86 '''
87 Provides the localized name of this L{AEScript <AEScript.AEScript>}.
88
89 @return: Human readable name of this script.
90 @rtype: string
91 '''
92 return _('Developer tools')
93
94
95
96
98 '''
99 Task to mute output indefinitely or unmute it if it has already been muted.
100
101 @param kwargs: Arbitrary keyword arguments to pass to the task
102 @type kwargs: dictionary
103 '''
104 AccessEngineAPI.stopAll(self)
105 mute = AccessEngineAPI.getStyleVal(self, 'Mute', **kwargs)
106 if mute:
107 AccessEngineAPI.sayInfo(self, text=_('unmuted'),
108 cap='audio', role='output', **kwargs)
109 AccessEngineAPI.setStyleVal(self, 'Mute', False, **kwargs)
110 else:
111 AccessEngineAPI.sayInfo(self, text=_('muted'),
112 cap='audio', role='output', **kwargs)
113 AccessEngineAPI.setStyleVal(self, 'Mute', True, **kwargs)
114
116 '''
117 Says the number of L{AEScript <AEScript.AEScript>}s loaded on the active
118 L{AETier} followed by their names.
119
120 @param kwargs: Arbitrary keyword arguments to pass to the task
121 @type kwargs: dictionary
122 '''
123 AccessEngineAPI.stopNow(self, cap='audio', role='output', **kwargs)
124 names = AccessEngineAPI.getScriptNames(self.tier)
125 n = len(names)
126
127 AccessEngineAPI.sayInfo(self, cap='audio', role='output',
128 text=(n, AccessEngineAPI.getAppName(kwargs['por'])),
129 template=_('%d scripts in %s.'), **kwargs)
130 AccessEngineAPI.sayInfo(self, text=', '.join(names),
131 cap='audio', role='output', **kwargs)
132
134 '''
135 Reloads all L{AEScript <AEScript.AEScript>}s in the current L{AETier}.
136 Useful during Script development when changes have been made to a Script and
137 those changes should be tested without restarting SUE.
138
139 @param kwargs: Arbitrary keyword arguments to pass to the task
140 @type kwargs: dictionary
141 '''
142 AccessEngineAPI.stopNow(self, cap='audio', role='output', **kwargs)
143
144 AccessEngineAPI.sayInfo(self, cap='audio', role='output',
145 text=AccessEngineAPI.getAppName(kwargs['por']),
146 template=_('reloaded scripts in %s'), **kwargs)
147 AccessEngineAPI.reloadScripts(self.getAETier())
148
150 '''
151 Shows all monitors associated with the current profile if all are hidden.
152 Hides all monitors associated with the current profile if any one is shown.
153
154 @param kwargs: Arbitrary keyword arguments to pass to the task
155 @type kwargs: dictionary
156 '''
157 AccessEngineAPI.stopNow(self, cap='audio', role='output', **kwargs)
158 AccessEngineAPI.inhibitMayStop()
159 if not AccessEngineAPI.loadAllMonitors():
160 AccessEngineAPI.unloadAllMonitors()
161 AccessEngineAPI.sayInfo(self, text=_('hiding monitors'),
162 cap='audio', role='output', **kwargs)
163 else:
164 AccessEngineAPI.sayInfo(self, text=_('showing monitors'),
165 cap='audio', role='output', **kwargs)
166
167
168
169
171 '''
172 Prints the focus L{AEPor}.
173
174 @param kwargs: Arbitrary keyword arguments to pass to the task
175 @type kwargs: dictionary
176 @return: C{True} to allow other tasks to process this event.
177 @rtype: boolean
178 '''
179 print 'focus:', kwargs['por']
180 return True
181
183 '''
184 Prints the lost focus L{AEPor}.
185
186 @param kwargs: Arbitrary keyword arguments to pass to the task
187 @type kwargs: dictionary
188 @return: C{True} to allow other tasks to process this event.
189 @rtype: boolean
190 '''
191 print 'unfocus:', kwargs['por']
192 return True
193
194
195
196
198 '''
199 Prints the view L{AEPor}.
200
201 @param kwargs: Arbitrary keyword arguments to pass to the task
202 @type kwargs: dictionary
203 @return: C{True} to allow other tasks to process this event.
204 @rtype: boolean
205 '''
206 print 'view:', kwargs['por'], kwargs['gained']
207 return True
208