1 '''
2 Defines a class for storing point-of-regard information.
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 '''
15 '''
16 Stores point-of-regard data for accessibles, the user, a L{Tier}'s focus, etc.
17
18 @ivar accessible: The accessible of the control which has the point of regard.
19 @type accessible: L{pyLinAcc.Accessible}
20 @ivar item_offset: Offset of the Item within the accessible which has the
21 point of regard. Set to None to indicate the accessible has only 1 item.
22 When restricting to visible, this offset will still be relative to total.
23 For example, when the first item in a table is not visible, but the first
24 item is requested, this index will not be 0 (the first in the table), but
25 instead will be the index of the first visible cell. For text, this will
26 be the character index of the first character in the line requested (i.e.
27 the first visible line in the example above).
28 @type item_offset: integer or None
29 @ivar char_offset: Offset of the character at the caret or virtual cursor
30 within the accessible and the item which has the point of regard.
31 @type char_offset: integer
32 @ivar incomplete: Indicates that a L{POR} might need additional processing
33 before it is used when True. Some L{AEInterfaces.IEventHandler} may create
34 L{POR}s that have an item in the L{accessible} slot instead of its parent as
35 the L{accessible} and its index as the L{item_offset} in order to save time
36 for events that may never be handled. This flag indicates this situation and
37 suggests that the L{POR} be corrected properly before it reaches a L{Perk}
38 and its L{Task}s for processing.
39 @type incomplete: boolean
40 @ivar adapters: Cached adapters for L{AEInterfaces} for this L{POR}
41 @type adapters: dictionary
42
43 @note: This class is a structure and based on the LSR coding conventions its
44 members (except for the adapters dictionary) can be accessed directly.
45 '''
46 - def __init__(self, accessible=None, item_offset=None, char_offset=0,
47 incomplete=False):
48 '''
49 Stores the provided accessible, offset to an item within the accessible, and
50 offset to a character within the accessible.
51
52 @param accessible: Accessible of the control which has the point of regard.
53 @type accessible: L{pyLinAcc.Accessible}
54 @param item_offset: Offset of the Item within the accessible which has the
55 point of regard. Set to None to indicate the accessible has only 1 item.
56 When restricting to visible, this offset will still be relative to total.
57 For example, when the first item in a table is not visble, but the first
58 item is requested, this index will not be 0 (the first in the table), but
59 instead will be the index of the first visible cell. For text, this will
60 be the character index of the first character in the line requested (i.e.
61 the first visible line in the example above).
62 @type item_offset: integer or None
63 @param char_offset: Offset of the character at the caret or virtual cursor
64 within the accessible which has the point of regard.
65 @type char_offset: integer
66 @param incomplete: Indicates that a L{POR} might need additional processing
67 before it is used when True. Some L{AEInterfaces.IEventHandler} may
68 create L{POR}s that have an item in the L{accessible} slot instead of
69 its parent as the L{accessible} and its index as the L{item_offset} in
70 order to save time for events that may never be handled. This flag
71 indicates this situation and suggests that the L{POR} be corrected
72 properly before it reaches a L{Perk} and its L{Task}s for processing.
73 @type incomplete: boolean
74 '''
75 self.accessible = accessible
76 self.item_offset = item_offset
77 self.char_offset = char_offset
78 self.incomplete = incomplete
79 self.adapters = {}
80
82 '''
83 Gets a cached instead of an adapter for this L{POR} to one of the
84 L{AEInterfaces}.
85
86 @param interface: Interface serving as the key for the cache
87 @type interface: L{AccAdapt.Interface} class
88 '''
89 return self.adapters[interface]
90
92 '''
93 Caches an adapter instance that has been previously used for this L{POR}
94 to provide the given interface.
95
96 @param interface: Interface serving as the key for the cache
97 @type interface: L{AccAdapt.Interface} class
98 @param adapter: Adapter instance to cache
99 @type adapter: L{AccAdapt.PORAdapter}
100 '''
101 self.adapters[interface] = adapter
102
104 '''
105 Compares this L{POR} to the one provided based on all their properties.
106
107 @param other: Point of regard to compare
108 @type other: L{POR}
109 '''
110 try:
111 return (self.item_offset == other.item_offset) and \
112 (self.char_offset == other.char_offset) and \
113 (self.accessible == other.accessible)
114 except:
115 return False
116
118 '''
119 Hashes based on the accessible, item offset, and character offset rather
120 than the ID of the L{POR} itself.
121
122 @return: Immutable hash code based on the attributes of the L{POR}
123 @rtype: integer
124 '''
125 return hash(self.accessible)^(self.item_offset or 0)^(self.char_offset)
126
128 '''
129 Compares this L{POR} to the one provided based on all their properties.
130
131 @param other: Point of regard to compare
132 @type other: L{POR}
133 '''
134 return not self.__eq__(other)
135
137 '''
138 Gets a string describing this POR in terms of its L{accessible},
139 L{item_offset}, and L{char_offset}
140
141 @return: String representation
142 @rtype: string
143 '''
144 s = 'POR(%s, %s, %d)' % (self.accessible, self.item_offset,
145 self.char_offset)
146 return s
147
149 '''
150 Checks if the character offset in this L{POR} is the same as the one in the
151 given L{POR}.
152
153 @param other: Point of regard with the character offset to compare
154 @type other: L{POR}
155 @return: Same character offset?
156 @rtype: boolean
157 '''
158 return self.char_offset == other.char_offset
159
161 '''
162 Checks if the item offset in this L{POR} is the same as the one in the
163 given L{POR}.
164
165 @param other: Point of regard with the item offset to compare
166 @type other: L{POR}
167 @return: Same item offset?
168 @rtype: boolean
169 '''
170 return self.item_offset == other.item_offset
171
173 '''
174 Checks if the accessible object in this L{POR} is the same as the one in the
175 given L{POR}.
176
177 @param other: Point of regard with the accessible to compare
178 @type other: L{POR}
179 @return: Same accessible?
180 @rtype: boolean
181 '''
182 return self.accessible == other.accessible
183
185 '''
186 Checks if the character offset in this L{POR} is after the one in the given
187 L{POR}.
188
189 @param other: Point of regard with the character offset to compare
190 @type other: L{POR}
191 @return: Character after the other?
192 @rtype: boolean
193 '''
194 return self.char_offset > other.char_offset
195
197 '''
198 Checks if the character offset in this L{POR} is before the one in the given
199 L{POR}.
200
201 @param other: Point of regard with the character offset to compare
202 @type other: L{POR}
203 @return: Character before the other?
204 @rtype: boolean
205 '''
206 return self.char_offset < other.char_offset
207
209 '''
210 Checks if the item offset in this L{POR} is before the one in the given
211 L{POR}.
212
213 @param other: Point of regard with the item offset to compare
214 @type other: L{POR}
215 @return: Item before the other?
216 @rtype: boolean
217 '''
218 return self.item_offset < other.item_offset
219
221 '''
222 Checks if the item offset in this L{POR} is after the one in the given
223 L{POR}.
224
225 @param other: Point of regard with the item offset to compare
226 @type other: L{POR}
227 @return: Item after the other?
228 @rtype: boolean
229 '''
230 return self.item_offset > other.item_offset
231