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

Source Code for Module MetacityScript

  1  ''' 
  2  Defines a special L{AEScript <AEScript.AEScript>} for the metacity desktop 
  3  and app switcher. 
  4   
  5  @author: Brett Clippingdale 
  6  @author: Peter Parente 
  7  @organization: IBM Corporation 
  8  @copyright: Copyright (c) 2005, 2007 IBM Corporation 
  9   
 10  @author: Nicole Anacker 
 11  @organization: IT Science Center Ruegen gGmbH, Germany 
 12  @copyright: Copyright (c) 2007, 2008 ITSC Ruegen 
 13   
 14  @license: I{The BSD License} 
 15  All rights reserved. This program and the accompanying materials are made  
 16  available under the terms of the BSD license which accompanies 
 17  this distribution, and is available at 
 18  U{http://www.opensource.org/licenses/bsd-license.php} 
 19  ''' 
 20  from AccessEngine import AEScript, AccessEngineAPI 
 21  from AccessEngine import AEConstants 
 22  from Tools.i18n import _ 
 23   
 24  __uie__ = dict(kind='script', tier='metacity') 
 25   
26 -class MetacityScript(AEScript.EventScript):
27 ''' 28 Defines a special L{AEScript <AEScript.AEScript>} to announce information in 29 the metacity desktop and application switcher windows. 30 '''
31 - def init(self):
32 ''' 33 Registers L{event tasks <AEScript.event_tasks>} to handle 34 L{state <AEEvent.StateChange>} and L{property <AEEvent.PropertyChange>} 35 events. 36 ''' 37 AccessEngineAPI.setScriptIdealOutput(self, 'audio') 38 39 # register events 40 self.registerEventTask('metacity', AEConstants.EVENT_TYPE_PROPERTY_CHANGE, tier=True) 41 self.registerEventTask('metacity state', AEConstants.EVENT_TYPE_STATE_CHANGE, all=True) 42 self.registerEventTask('metacity view', AEConstants.EVENT_TYPE_VIEW_CHANGE) 43 44 self.chainTask('metacity view', AEConstants.CHAIN_AROUND, 45 'read view', 'BasicSpeechScript')
46
47 - def _sayStatusBar(self, text=None, **kwargs):
48 ''' 49 Read the accessible name of the status text. 50 51 @param text: Text to speech 52 @type text: string 53 @param kwargs: Arbitrary keyword arguments to pass to the task 54 @type kwargs: dictionary 55 ''' 56 # pretend we're on the focus layer even though text is changing elsewhere 57 kwargs['layer'] = AEConstants.LAYER_FOCUS 58 AccessEngineAPI.stopNow(self, cap='audio', role='output', **kwargs) 59 AccessEngineAPI.sayName(self, cap='audio', role='output', text=text, 60 sem=AEConstants.SEM_WINDOW, **kwargs)
61
62 - def getName(self):
63 ''' 64 Provides the localized name of this L{AEScript <AEScript.AEScript>}. 65 66 @return: Human readable translated name of this script. 67 @rtype: string 68 ''' 69 return _('Metacity')
70
71 - def getDescription(self):
72 ''' 73 Describe which L{AETier} this script applies to by default. 74 75 @return: Human readable translated description of this script. 76 @rtype: string 77 ''' 78 return _('Applies to metacity by default.')
79
80 - def onPropertyChange(self, **kwargs):
81 ''' 82 Announces I{Alt+Tab} application switching by reading the accessible name of 83 the status text when it changes. 84 85 @param kwargs: Arbitrary data given by the observer. 86 @type kwargs: dictionary 87 @return: C{True} to allow other tasks to process this event 88 @rtype: boolean 89 ''' 90 # get the text in status bar 91 text = AccessEngineAPI.getItemText(kwargs['por']) 92 self._sayStatusBar(text, **kwargs) 93 return True
94
95 - def onStateChange(self, **kwargs):
96 ''' 97 Announces the I{Alt+Tab} application by reading the accessible name of 98 the status text when it open the metacity window. 99 100 @param kwargs: Arbitrary data given by the observer. 101 @type kwargs: dictionary 102 @return: C{True} to allow other tasks to process this event 103 @rtype: boolean 104 ''' 105 # get the text in status bar 106 text = AccessEngineAPI.getItemText(kwargs['por']) 107 if (len(text) != 0 and kwargs['name'] == 'showing'): 108 self._sayStatusBar(text, **kwargs) 109 return True 110 return False
111
112 - def onViewFirstGained(self, **kwargs):
113 ''' 114 When the Metacity window opens, the L{BasicSpeechScript.onViewFirstGained 115 <BasicSpeechScript.BasicSpeechScript.onViewFirstGained>}-method cuts off the 116 reading of the accessible name of the status bar. There is no window-title 117 in metacity, so we make a chain around to stop the L{BasicSpeechScript} and 118 get the full name of the status bar. 119 120 @param kwargs: Arbitrary data given by the observer. 121 @type kwargs: dictionary 122 ''' 123 pass
124