1 '''
2 Defines L{AccAdapt.Adapter}s for producing complete L{POR}s for AT-SPI
3 accessibles.
4
5 @author: Peter Parente
6 @organization: IBM Corporation
7 @copyright: Copyright (c) 2005, 2007 IBM Corporation
8 @license: The BSD License
9
10 All rights reserved. This program and the accompanying materials are made
11 available under the terms of the BSD license which accompanies
12 this distribution, and is available at
13 U{http://www.opensource.org/licenses/bsd-license.php}
14 '''
15
16 from POR import POR
17 from AccAdapt import PORAdapter, Adapter
18 from AEInterfaces import *
19 from pyLinAcc import Constants
20 import pyLinAcc
21
23 '''
24 Adapts a L{POR} to the L{IPORFactory} interface. Expects the subject to be a
25 L{POR}.
26 '''
27 provides = [IPORFactory]
28
29 @staticmethod
31 '''
32 Tests if the given subject can be adapted by this class.
33
34 @param subject: L{POR} to test
35 @type subject: L{POR}
36 @return: True when the subject meets the condition named in the docstring
37 for this class, False otherwise
38 @rtype: boolean
39 '''
40 try:
41 subject.accessible
42 return True
43 except AttributeError:
44 return False
45
46 @pyLinAcc.errorToLookupError
48 '''
49 Returns a complete L{POR} built based on the subject L{POR}. The complete
50 L{POR} is guaranteed to match the definition of an LSR point of regard
51 with a proper accessible and item index.
52
53 This method resolves any problems introduced by the
54 L{DefaultEventHandlerAdapter} when it creates L{POR}s for state, property,
55 and children events. These events can originate from children that are
56 items according to LSR, not full accessibles. When this method is called,
57 it checks if the accessible in the L{POR} is an immediate descendant of an
58 accessible that has STATE_MANAGES_DESCENDANT. If so, it create a L{POR} with
59 that parent as the accessible and the item of the descendant as the item
60 index. Otherwise, the original L{POR} is returned.
61
62 @return: Point of regard
63 @rtype: L{POR}
64 '''
65 acc = self.accessible
66 try:
67 parent = acc.parent
68 ss = parent.getState()
69 except AttributeError:
70 pass
71 else:
72 if ss.contains(Constants.STATE_MANAGES_DESCENDANTS):
73 return POR(parent, acc.getIndexInParent(), 0)
74 return POR(acc, self.item_offset, self.char_offset)
75
77 '''
78 Adapts all AT-SPI accessibles to the L{IPORFactory} interface. No condition
79 for adaption is given implying that this adapter is used as a default by
80 L{AccAdapt} when no better adapter is available.
81 '''
82 provides = [IPORFactory]
83
84 @pyLinAcc.errorToLookupError
86 '''
87 Returns a complete L{POR} built based on the subject L{POR}. The complete
88 L{POR} is guaranteed to match the definition of an LSR point of regard
89 with a proper accessible and item index.
90
91 This method resolves any problems introduced by the adapters that create
92 L{POR}s that are actually items according to LSR.
93
94 @return: Point of regard
95 @rtype: L{POR}
96 '''
97 acc = self.subject
98 try:
99 parent = acc.parent
100 ss = parent.getState()
101 except AttributeError:
102 pass
103 else:
104 if ss.contains(Constants.STATE_MANAGES_DESCENDANTS):
105 return POR(parent, acc.getIndexInParent(), 0)
106 return POR(acc, None, 0)
107