1 '''
2 Defines an L{AccAdapt.Adapter}s for the L{AEInterfaces.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 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 from DefaultInfo import *
18 from DefaultEventHandler import *
19 from AEInterfaces import *
20 from pyLinAcc import Constants, Interfaces
21 import pyLinAcc
22
24 '''
25 Overrides L{DefaultNavAdapter} to provide correct visibility information about
26 menus and menu items. Expects the subject to be a L{POR}.
27
28 Adapts accessibles that have the string "menu" in their role names
29 (unlocalized) and a parent with ROLE_MENU.
30 '''
31 provides = [IAccessibleInfo]
32
33 @staticmethod
35 '''
36 Tests if the given subject can be adapted by this class.
37
38 @param subject: L{POR} containing an accessible to test
39 @type subject: L{POR}
40 @return: True when the subject meets the condition named in the docstring
41 for this class, False otherwise
42 @rtype: boolean
43 '''
44 acc = subject.accessible
45 pr = acc.parent.getRole()
46 c = Constants
47 return (pr == c.ROLE_MENU and acc.getRoleName().find('menu') > -1)
48
49 @pyLinAcc.errorToLookupError
51 '''
52 Gets if a menu item (item, check item, submenu, etc.) is visible by testing
53 if its parent menu is selected.
54
55 @return: Does the accessible consider itself visible?
56 @rtype: boolean
57 @raise LookupError: When the accessible object is dead
58 '''
59 ss = self.accessible.parent.getState()
60 return ss.contains(Constants.STATE_SELECTED) or \
61 ss.contains(Constants.STATE_EXPANDED)
62
64 '''
65 Overrides L{DefaultEventHandlerAdapter} to avoid generating focus events on
66 selection. Expects the subject to be a raw L{pyLinAcc.Accessible}.
67
68 Adapts accessibles with ROLE_MENU.
69 '''
70 provides = [IEventHandler]
71
72 @staticmethod
74 '''
75 Tests if the given subject can be adapted by this class.
76
77 @param subject: L{POR} containing an accessible to test
78 @type subject: L{POR}
79 @return: True when the subject meets the condition named in the docstring
80 for this class, False otherwise
81 @rtype: boolean
82 '''
83 c = Constants
84 return subject.getRole() == c.ROLE_MENU
85
87 '''
88 Creates an L{AEEvent.FocusChange} indicating that the accessible being
89 adapted has gained the focus. Also creates a L{AEEvent.SelectorChange}.
90 These two L{AEEvent}s will be posted by the caller.
91
92 @param event: Raw focus change event
93 @type event: L{pyLinAcc.Event.Event}
94 @param kwargs: Parameters to be passed to any created L{AEEvent}
95 @type kwargs: dictionary
96 @return: L{AEEvent.FocusChange} and L{AEEvent.SelectorChange}
97 @rtype: tuple of L{AEEvent}
98 '''
99 kwargs['focused'] = True
100 try:
101 sel = Interfaces.ISelection(self.subject)
102 count = sel.nSelectedChildren
103 except NotImplementedError:
104 count = 0
105 if count == 0:
106 por = POR(self.subject, None, 0)
107
108
109 item = IAccessibleInfo(por).getAccItemText()
110 return (FocusChange(por, True, **kwargs),
111 SelectorChange(por, item, **kwargs))
112