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

Source Code for Module GPanelScript

  1  ''' 
  2  Defines a special L{AEScript <AEScript.AEScript>} for the GNOME-Panel. 
  3   
  4  @author: Nicole Anacker 
  5  @organization: IT Science Center Ruegen gGmbH, Germany 
  6  @copyright: Copyright (c) 2007, 2008 ITSC Ruegen 
  7   
  8  @license: I{The BSD License} 
  9  All rights reserved. This program and the accompanying materials are made  
 10  available under the terms of the BSD license which is available at 
 11  U{http://www.opensource.org/licenses/bsd-license.php}. 
 12  ''' 
 13  # import useful modules for Scripts 
 14  import logging 
 15  from AccessEngine import AEScript, AccessEngineAPI 
 16  from AccessEngine import AEConstants 
 17  #from AccessEngine.AEPor import AEPor 
 18  from Tools.i18n import bind, _ 
 19  import logging 
 20   
 21  log = logging.getLogger('GPanelScript') 
 22   
 23  # metadata describing this Script 
 24  __uie__ = dict(kind='script', tier='gnome-panel', all_tiers=False) 
 25   
26 -class GPanelScript(AEScript.EventScript):
27 ''' 28 A special L{AEScript <AEScript.AEScript>} for handling the gnome panel. 29 It defines the hotkey I{Alt+Shift+F12} that reads the current time. 30 '''
31 - def init(self):
32 ''' 33 Registers L{event tasks <AEScript.event_tasks>} to handle 34 L{selector <AEEvent.SelectorChange>}. Registers 35 L{tasks <AEScript.registered_tasks>} that can be mapped to 36 L{AEInput.Gesture}s. 37 ''' 38 AccessEngineAPI.setScriptIdealOutput(self, 'audio') 39 40 # register event tasks 41 self.registerEventTask('read selector', 42 AEConstants.EVENT_TYPE_SELECTOR_CHANGE, tier=True) 43 self.registerTask('read clock', self.readClock) 44 45 # register input events and commands 46 kbd = AccessEngineAPI.getInputDevice(None, 'keyboard') 47 pairs = [[kbd.AEK_ALT_L, kbd.AEK_SHIFT_L], [kbd.AEK_ALT_R, kbd.AEK_SHIFT_R]] 48 49 for pair in pairs: 50 self.registerCommand(kbd, 'read clock', 'GPanelScript', 51 True, pair+[kbd.AEK_F12]) 52 53 # do some work around normal announcements 54 self.chainTask('read selector', AEConstants.CHAIN_AROUND, 55 'read selector', 'BasicSpeechScript')
56
57 - def getName(self):
58 ''' 59 Provides the localized name of this L{AEScript <AEScript.AEScript>}. 60 61 @return: Human readable name of this script. 62 @rtype: string 63 ''' 64 return _('Gnome panel')
65
66 - def getDescription(self):
67 ''' 68 Describe which L{AETier} this script applies to by default. 69 70 @return: Human readable translated description of this script. 71 @rtype: string 72 ''' 73 return _('Applies to gnome-panel by default.')
74 75 76 ##### 77 ## Input Task 78 #####
79 - def readClock(self, **kwargs):
80 ''' 81 Is invoked whenever user hits I{Alt+Shift+F12}. It reads the current time. 82 83 @param kwargs: Arbitrary keyword arguments to pass to the task 84 @type kwargs: dictionary 85 @return: C{True} to allow other tasks to process this event. 86 @rtype: boolean 87 ''' 88 root = AccessEngineAPI.getRootAcc(kwargs['por']) 89 por = AccessEngineAPI.getAccFromPath(root, 0, 0, 0) 90 self.clock_por = AccessEngineAPI.findAccByRole('toggle button', por) 91 por = AccessEngineAPI.getAccFromPath(self.clock_por, 1) 92 label = AccessEngineAPI.getItemText(por) 93 AccessEngineAPI.sayInfo(self, cap='audio', role='output', 94 text=label, **kwargs) 95 AccessEngineAPI.inhibitMayStop() 96 return True
97 98 ##### 99 ### Event Tasks 100 #####
101 - def onSelectorActive(self, **kwargs):
102 ''' 103 Announces the text of the active item. Or if the item the toggle button, 104 then say system clock. 105 106 @param kwargs: Arbitrary keyword arguments to pass to the task 107 @type kwargs: dictionary 108 @return: C{True} to allow other tasks to process this event. 109 @rtype: boolean 110 ''' 111 if AccessEngineAPI.hasAccRole('toggle button', kwargs['por']): 112 parent = AccessEngineAPI.getParentAcc(kwargs['por']) 113 name = AccessEngineAPI.getAccName(parent) 114 desc = AccessEngineAPI.getAccDesc(parent) 115 if (name != ''): 116 kwargs['text'] = name 117 elif (desc != ''): 118 kwargs['text'] = desc 119 120 doIt = self.doTask('read selector', 'BasicSpeechScript', chain=False, **kwargs) 121 122 return True
123