1 '''
2 Defines an L{AEEvent} indicating that the focus has changed.
3
4 @author: Peter Parente
5 @organization: IBM Corporation
6 @copyright: Copyright (c) 2005, 2007 IBM Corporation
7 @license: The BSD License
8
9 All rights reserved. This program and the accompanying materials are made
10 available under the terms of the BSD license which accompanies
11 this distribution, and is available at
12 U{http://www.opensource.org/licenses/bsd-license.php}
13 '''
14
15 import Base
16 from AEConstants import LAYER_FOCUS
17
19 '''
20 Event that fires when the focused accessible changes.
21
22 This class registers its name and whether it should be monitored by default in
23 an L{AEMonitor} using the L{Base.registerEventType} function
24 when this module is first imported. The L{AEMonitor} can use this
25 information to build its menus.
26
27 @ivar gained: Type of focus change: True if gained, False if lost
28 @type gained: boolean
29 '''
30 Base.registerEventType('FocusChange', True)
31
32 - def __init__(self, por, gained, **kwargs):
33 '''
34 Stores the L{POR} for the focused object and the type of focus event.
35
36 @param por: Point-of-regard from the accessible that just got focus
37 @type por: L{POR}
38 @param gained: Was focused gained or lost?
39 @type gained: boolean
40 '''
41 Base.AccessEngineEvent.__init__(self, **kwargs)
42 self.por = por
43 self.gained = gained
44
46 '''
47 Returns a human readable representation of this event including its name,
48 its L{POR}, and its type.
49
50 @return: Information about this event
51 @rtype: string
52 '''
53 name = Base.AccessEngineEvent.__str__(self)
54 if self.gained:
55 action = 'gained'
56 else:
57 action = 'lost'
58 return '%s:\n\tPOR: %s\n\taction: %s' % (name, self.por, action)
59
61 '''
62 Returns the L{POR} for this focus event. Used by L{Tier} to maintain a
63 focus L{POR}.
64
65 @return: Point-of-regard for this focus event
66 @rtype: L{POR}
67 '''
68 return self.por
69
71 '''
72 Fetches data out of this L{FocusChange} for use by a
73 L{Task.FocusTask}.
74
75 @return: Dictionary of parameters to be passed to a L{Task.FocusTask}
76 as follows:
77 - por: The L{POR} of the accessible in which the focus change occured
78 - type: Whether focus was gained (True) or lost (False)
79 @rtype: dictionary
80 '''
81 return {'por' : self.getPOR(), 'gained' : self.gained}
82
83 - def execute(self, tier_manager, view_manager, **kwargs):
84 '''
85 Contacts the L{TierManager} so it can manage the focus change event.
86
87 @param tier_manager: TierManager that will handle the event
88 @type tier_manager: L{TierManager}
89 @param kwargs: Packed references to other managers not of interest here
90 @type kwargs: dictionary
91 @return: True if there is an active view, False if not to delay execution
92 of this event until there is
93 @rtype: boolean
94 '''
95 if view_manager.getAEView() is None and self.layer == LAYER_FOCUS:
96 return False
97 else:
98 tier_manager.manageEvent(self)
99 return True
100