Package Adapters :: Package ATSPI :: Module DefaultNav
[hide private]
[frames] | no frames]

Source Code for Module Adapters.ATSPI.DefaultNav

  1  ''' 
  2  Defines default L{AccAdapt.Adapter}s for the L{AEInterfaces.IAccessibleNav} and 
  3  L{AEInterfaces.IItemNav} interfaces on L{POR.POR} objects. 
  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  from POR import POR 
 16  from AccAdapt import PORAdapter 
 17  from AEInterfaces import * 
 18  from pyLinAcc import Interfaces 
 19  import pyLinAcc 
 20   
21 -class DefaultNavAdapter(PORAdapter):
22 ''' 23 Adapts all AT-SPI accessibles to the L{IAccessibleNav} and L{IItemNav} 24 interfaces. No condition for adaptation is given implying that this adapter is 25 used as a default by L{AccAdapt} when no better adapter is available. Expects 26 the subject to be a L{POR}. 27 ''' 28 provides = [IAccessibleNav, IItemNav] 29
30 - def getNextItem(self, only_visible=True):
31 ''' 32 Always raises IndexError as this default adapter assumes the subject has 33 only one item. 34 35 @param only_visible: True when Item in the returned L{POR} must be visible 36 @type only_visible: boolean 37 @return: Point of regard to the next item in the same accessible 38 @rtype: L{POR} 39 @raise IndexError: When there is no next item 40 ''' 41 raise IndexError
42
43 - def getPrevItem(self, only_visible=True):
44 ''' 45 Always raises IndexError as this default adapter assumes the subject has 46 only one item. 47 48 @param only_visible: True when Item in the returned L{POR} must be visible 49 @type only_visible: boolean 50 @return: Point of regard to the previous item in the same accessible 51 @rtype: L{POR} 52 @raise IndexError: When there is no previous item 53 ''' 54 raise IndexError
55
56 - def getFirstItem(self, only_visible=True):
57 ''' 58 Gets a L{POR} pointing to the first item in the subject L{POR}. Ignores the 59 only visible flag. 60 61 @param only_visible: True when Item in the returned L{POR} must be visible 62 @type only_visible: boolean 63 @return: Point of regard to the first item in the same accessible 64 @rtype: L{POR} 65 @raise IndexError: When there is no first item 66 ''' 67 return POR(self.accessible, None, 0)
68
69 - def getLastItem(self, only_visible=True):
70 ''' 71 Gets a L{POR} pointing to the first item in the subject L{POR} since it is 72 assumed to be the only item in this default adapter. Ignores the only 73 visible flag. 74 75 @param only_visible: True when Item in the returned L{POR} must be visible 76 @type only_visible: boolean 77 @return: Point of regard to the last item in the same accessible 78 @rtype: L{POR} 79 @raise IndexError: When there is no last item 80 ''' 81 return POR(self.accessible, None, 0)
82
83 - def getAccAsItem(self, por):
84 ''' 85 Always raises IndexError as this default adapter assumes the subject has 86 only one item. 87 88 @param por: Point of regard to a child of the subject 89 @type por: L{POR} 90 @return: Point of regard to an item of the subject 91 @rtype: L{POR} 92 @raise IndexError: When there is no next item 93 ''' 94 raise IndexError
95 96 @pyLinAcc.errorToLookupError
97 - def getNextAcc(self):
98 ''' 99 Gets the next peer accessible object if possible and if it exists. 100 101 @return: Point of regard to the next accessible, or None if there is no next 102 peer 103 @rtype: L{POR} 104 @raise IndexError: When there is no next accessible 105 @raise LookupError: When lookup for the next accessible fails even though 106 it may exist 107 ''' 108 acc = self.accessible 109 # get the index of this accessible 110 i = acc.getIndexInParent() 111 has_parent = acc.parent is not None 112 if i < 0 or not has_parent: 113 # indicate lookup of the next peer failed 114 raise LookupError 115 # get the accessible at the next index (the peer) 116 child = acc.parent.getChildAtIndex(i+1) 117 if child is None: 118 # indicate there is no next peer 119 raise IndexError 120 return POR(child, None, 0)
121 122 @pyLinAcc.errorToLookupError
123 - def getPrevAcc(self):
124 ''' 125 Gets the previous peer accessible object if possible and if it exists. 126 127 @return: Point of regard to the previous accessible 128 @rtype: L{POR} 129 @raise IndexError: When there is no previous accessible 130 @raise LookupError: When lookup for the previous accessible fails even 131 though it may exist 132 ''' 133 acc = self.accessible 134 # get the index of this accessible 135 i = acc.getIndexInParent() 136 has_parent = acc.parent is not None 137 if i <= 0 or not has_parent: 138 # indicate lookup of the previous peer failed 139 raise LookupError 140 # get the accessible at the previous index (the peer) 141 child = acc.parent.getChildAtIndex(i-1) 142 if child is None: 143 # indicate there is no previous peer 144 raise IndexError 145 return POR(child, None, 0)
146 147 @pyLinAcc.errorToLookupError
148 - def getParentAcc(self):
149 ''' 150 Gets the parent accessible object if possible and if it exists. 151 152 @return: Point of regard to the parent accessible 153 @rtype: L{POR} 154 @raise LookupError: When lookup for the parent accessible fails because it 155 does not exist 156 ''' 157 # get the parent of this accessible 158 parent = self.accessible.parent 159 if parent is None: 160 raise LookupError 161 return POR(parent, None, 0)
162 163 @pyLinAcc.errorToLookupError
164 - def getFirstAccChild(self):
165 ''' 166 Gets the first accessible child relative to the subject accessible. 167 168 @return: Point of regard to the first child accessible 169 @rtype: L{POR} 170 @raise LookupError: When lookup for child fails because it does not exist 171 ''' 172 child = self.accessible.getChildAtIndex(0) 173 if child is None: 174 raise LookupError 175 return POR(child, None, 0)
176 177 @pyLinAcc.errorToLookupError
178 - def getLastAccChild(self):
179 ''' 180 Gets the last accessible child relative to the subject accessible. 181 182 @return: Point of regard to the last child accessible 183 @rtype: L{POR} 184 @raise LookupError: When lookup for child fails because it does not exist 185 ''' 186 child = self.accessible.getChildAtIndex(self.accessible.childCount-1) 187 if child is None: 188 raise LookupError 189 return POR(child, None, 0)
190 191 @pyLinAcc.errorToLookupError
192 - def getChildAcc(self, index):
193 ''' 194 Gets the child accessible at the given index relative to the one providing 195 this interface. 196 197 @param index: Index of the child to retrieve 198 @type index: integer 199 @return: Point of regard to the child accessible 200 @rtype: L{POR} 201 @raise IndexError: When there is no child at the given index 202 @raise LookupError: When the lookup for the child fails even though it may 203 exist 204 ''' 205 child = self.accessible.getChildAtIndex(index) 206 if child is None: 207 raise IndexError 208 return POR(child, None, 0)
209 210 @pyLinAcc.errorToLookupError
211 - def findDescendantAcc(self, predicate, depth_first):
212 ''' 213 Searches all descendants for one matching the given predicate. 214 215 @warning: The predicate is currently supplied with accessibles, not PORs. 216 This behavior will likely change in the future. 217 218 @param predicate: Search predicate 219 @type predicate: callable 220 @param depth_first: Perform the search in depth-first (True) or breadth 221 first (False) order? 222 @type depth_first: boolean 223 @return: Point of regard to the target or None if not found 224 @rtype: L{POR} 225 @raise LookupError: When the lookup fails during the search 226 ''' 227 # define our own predicate which will create PORs 228 def por_predicate(acc): 229 if acc is not None: 230 por = IPORFactory(acc).create() 231 return predicate(por) 232 return False
233 acc = self.accessible.findDescendant(por_predicate, not depth_first) 234 if acc is not None: 235 acc = IPORFactory(acc).create() 236 return acc 237 238 @pyLinAcc.errorToLookupError
239 - def findAncestorAcc(self, predicate):
240 ''' 241 Searches all ancestors for one matching the given predicate. 242 243 @warning: The predicate is currently supplied with accessibles, not PORs. 244 This behavior will likely change in the future. 245 246 @param predicate: Search predicate 247 @type predicate: callable 248 @return: Point of regard to the target or None if not found 249 @rtype: L{POR} 250 @raise LookupError: When the lookup fails during the search 251 ''' 252 # define our own predicate which will create PORs 253 def por_predicate(acc): 254 if acc is not None: 255 por = IPORFactory(acc).create() 256 return predicate(por) 257 return False
258 acc = self.accessible.findAncestor(por_predicate) 259 if acc is not None: 260 acc = IPORFactory(acc).create() 261 return acc 262