Module DeveloperScript
[hide private]
[frames] | no frames]

Source Code for Module DeveloperScript

  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  # import useful modules for Scripts 
 20  from AccessEngine import AEScript, AccessEngineAPI 
 21  from AccessEngine import AEConstants 
 22  #from AccessEngine.AEPor import AEPor 
 23  from Tools.i18n import _ 
 24   
 25  __uie__ = dict(kind='script', all_tiers=True) 
 26   
27 -class DeveloperScript(AEScript.EventScript):
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 '''
38 - def init(self):
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 # set an audio device as the default output 46 AccessEngineAPI.setScriptIdealOutput(self, 'audio') 47 48 # register event tasks 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 # register named tasks 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 # register keyboard bindings 62 kbd = AccessEngineAPI.getInputDevice(None, 'keyboard') 63 # set Alt+CapsLock as the modifier 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
85 - def getName(self):
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 ## InputTask 96 ##############
97 - def onMute(self, **kwargs):
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
115 - def sayScripts(self, **kwargs):
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 # i18n: %d is number of scripts, %s is application name 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
133 - def reloadScripts(self, **kwargs):
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 # i18n: %s is application name 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
149 - def showHideMonitors(self, **kwargs):
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 ## FocusChange 169 ################
170 - def onFocusGained(self, **kwargs):
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
182 - def onFocusLost(self, **kwargs):
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 ## ViewChange 196 ###############
197 - def onViewChange(self, **kwargs):
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