1 '''
2 Defines an L{AEAccAdapter.AEAccAdapter}s for the L{AEAccInterfaces.IAccessibleInfo}
3 interface to correct for the problem of pop-up items (e.g menus) always having
4 states visible and showing after having been activated once.
5
6 @author: Peter Parente
7 @organization: IBM Corporation
8 @copyright: Copyright (c) 2005, 2007 IBM Corporation
9 @license: The BSD License
10
11 @author: Frank Zenker
12 @organization: IT Science Center Ruegen gGmbH, Germany
13 @copyright: Copyright (c) 2007, 2008 ITSC Ruegen
14 @license: The BSD License
15
16 All rights reserved. This program and the accompanying materials are made
17 available under the terms of the BSD license which accompanies
18 this distribution, and is available at
19 U{http://www.opensource.org/licenses/bsd-license.php}
20 '''
21
22 from DefaultInfo import *
23 from DefaultEventHandler import *
24 from AccessEngine.AEAccInterfaces import *
25 from AccessEngine.AEPor import AEPor
26 import pyatspi
27
29 '''
30 Overrides L{DefaultNavAdapter} to provide correct visibility information about
31 menus and menu items. Expects the subject to be a L{AEPor}.
32
33 Adapts accessibles that have the string "menu" in their role names
34 (unlocalized) and a parent with ROLE_MENU.
35 '''
36 provides = [IAccessibleInfo]
37
38 @staticmethod
40 '''
41 Tests if the given subject can be adapted by this class.
42
43 @param subject: L{AEPor} containing an accessible to test
44 @type subject: L{AEPor}
45 @return: True when the subject meets the condition named in the docstring
46 for this class, False otherwise
47 @rtype: boolean
48 '''
49 acc = subject.accessible
50 pr = acc.parent.getRole()
51 return (pr == pyatspi.ROLE_MENU and acc.getRoleName().find('menu') > -1)
52
53
55 '''
56 Gets if a menu item (item, check item, submenu, etc.) is visible by testing
57 if its parent menu is selected.
58
59 @return: Does the accessible consider itself visible?
60 @rtype: boolean
61 @raise LookupError: When the accessible object is dead
62 '''
63 ss = self.accessible.parent.getState()
64 return ss.contains(pyatspi.STATE_SELECTED) or \
65 ss.contains(pyatspi.STATE_EXPANDED)
66
68 '''
69 Overrides L{DefaultEventHandlerAdapter} to avoid generating focus events on
70 selection. Expects the subject to be a raw C{pyatspi.Accessibility.Accessible}.
71
72 Adapts accessibles with ROLE_MENU.
73 '''
74 provides = [IEventHandler]
75
76 @staticmethod
78 '''
79 Tests if the given subject can be adapted by this class.
80
81 @param subject: L{AEPor} containing an accessible to test
82 @type subject: L{AEPor}
83 @return: True when the subject meets the condition named in the docstring
84 for this class, False otherwise
85 @rtype: boolean
86 '''
87 return subject.getRole() == pyatspi.ROLE_MENU
88
90 '''
91 Creates an L{AEEvent.FocusChange} indicating that the accessible being
92 adapted has gained the focus. Also creates a L{AEEvent.SelectorChange}.
93 These two L{AEEvent}s will be posted by the caller.
94
95 @param event: Raw focus change event
96 @type event: C{pyatspi.event.Event}
97 @param kwargs: Parameters to be passed to any created L{AEEvent}
98 @type kwargs: dictionary
99 @return: L{AEEvent.FocusChange} and L{AEEvent.SelectorChange}
100 @rtype: tuple of L{AEEvent}
101 '''
102 kwargs['focused'] = True
103 try:
104 sel = (self.subject).querySelection()
105 count = sel.nSelectedChildren
106 except NotImplementedError:
107 count = 0
108 if count == 0:
109 por = AEPor(self.subject, None, 0)
110
111
112 item = IAccessibleInfo(por).getAccItemText()
113 return (FocusChange(por, True, **kwargs),
114 SelectorChange(por, item, **kwargs))
115