Package AEEvent :: Module ViewChange
[hide private]
[frames] | no frames]

Source Code for Module AEEvent.ViewChange

  1  ''' 
  2  Defines an L{AEEvent} indicating the view has been updated by the 
  3  L{ViewManager}. 
  4   
  5  @author: Peter Parente 
  6  @author: Pete Brunet 
  7  @organization: IBM Corporation 
  8  @copyright: Copyright (c) 2005, 2007 IBM Corporation 
  9  @license: The BSD License 
 10   
 11  All rights reserved. This program and the accompanying materials are made 
 12  available under the terms of the BSD license which accompanies 
 13  this distribution, and is available at 
 14  U{http://www.opensource.org/licenses/bsd-license.php} 
 15  ''' 
 16   
 17  import Base 
 18  import AEConstants 
 19  from AEInterfaces import * 
 20   
21 -class ViewChange(Base.AccessEngineEvent):
22 ''' 23 Event that fires when the L{ViewManager} is creating or updating its view. 24 25 This class registers its name and whether it should be monitored by default 26 in an L{AEMonitor} using the L{Base.registerEventType} function when 27 this module is first imported. An L{AEMonitor} can use this information to 28 build its menus. 29 30 @ivar gained: Type of view change 31 @type gained: boolean 32 @ivar title: Name of the root element of the new view (e.g. title of the 33 foreground window) 34 @type title: string 35 ''' 36 Base.registerEventType('ViewChange', True)
37 - def __init__(self, por, gained, **kwargs):
38 ''' 39 Stores the type of view change and intializes the title attribute to 40 an empty string. 41 42 @param por: Point-of-regard to the accessible at the root of the new view 43 @type por: L{POR} 44 @param gained: Type of view change 45 @type gained: integer 46 ''' 47 focused = gained in (AEConstants.EVENT_VIEW_GAINED, 48 AEConstants.EVENT_VIEW_FIRST_GAINED) 49 Base.AccessEngineEvent.__init__(self, focused=focused, **kwargs) 50 self.por = por 51 self.gained = gained 52 self.title = ''
53
54 - def __str__(self):
55 ''' 56 Returns a human readable representation of this event including its name, 57 its L{POR}, its type, and the title of the new view. 58 59 @return: Information about this event 60 @rtype: string 61 ''' 62 name = Base.AccessEngineEvent.__str__(self) 63 if self.gained == AEConstants.EVENT_VIEW_GAINED: 64 action = 'gained' 65 elif self.gained == AEConstants.EVENT_VIEW_LOST: 66 action = 'lost' 67 elif self.gained == AEConstants.EVENT_VIEW_FIRST_GAINED: 68 action = 'first gained' 69 elif self.gained == AEConstants.EVENT_VIEW_STARTUP: 70 action = 'startup' 71 return '%s:\n\tPOR: %s\n\ttitle: %s\n\taction: %s' % (name, self.por, 72 self.title, action)
73
74 - def execute(self, tier_manager, view_manager, **kwargs):
75 ''' 76 Stores the name of the root element of the new view in the title 77 attribute. Calls L{TierManager.TierManager.switchTier} to switch to the 78 appropriate L{Tier} for this view. Calls 79 L{TierManager.TierManager.manageEvent} to allow it to dispatch this 80 L{AEEvent} to the active L{Tier} and its registered L{Perk}. 81 82 @param tier_manager: TierManager that will handle the event 83 @type tier_manager: L{TierManager} 84 @param view_manager: ViewManager defining the current View 85 @type view_manager: L{ViewManager} 86 @param kwargs: Packed references to other managers not of interest here 87 @type kwargs: dictionary 88 @return: True to indicate the event executed properly 89 @rtype: boolean 90 ''' 91 # get the accessible name of the root element 92 ai = IAccessibleInfo(self.por) 93 try: 94 self.title = ai.getAccName() 95 except LookupError: 96 # view is dead 97 return True 98 if self.gained in (AEConstants.EVENT_VIEW_GAINED, 99 AEConstants.EVENT_VIEW_FIRST_GAINED): 100 # get information about the accessible's application 101 try: 102 aid = ai.getAccAppID() 103 aname = ai.getAccAppName() 104 except LookupError: 105 # view is dead 106 return True 107 # inform the view manager of the AE view change 108 view_manager.setAEView(self.por) 109 # ask the tier manager to switch tiers first 110 tier_manager.switchTier(aname, aid, self.por) 111 elif self.gained == AEConstants.EVENT_VIEW_LOST: 112 if self.por == view_manager.getAEView(): 113 # only unset if the view being deactivated is still the active view 114 view_manager.setAEView(None) 115 # then process the view change event 116 tier_manager.manageEvent(self) 117 return True
118
119 - def getDataForTask(self):
120 ''' 121 Fetches data out of this L{ViewChange} for use by a L{Task.ViewTask}. 122 123 @return: Dictionary of parameters to be passed to a L{Task.ViewTask} as 124 follows: 125 - por: Point of regard to the top of the new view 126 - title: String containing the window title of the view which changed 127 - gained: The type of view change, indicated by one of the integer 128 class variables 129 @rtype: dictionary 130 ''' 131 return {'title':self.title, 'gained':self.gained, 'por':self.getPOR()}
132