* Fixed bug #436949, Need util to list all supported interfaces
[platform/core/uifw/at-spi2-atk.git] / pyatspi / accessible.py
index d1fc358..17f4916 100644 (file)
@@ -162,9 +162,6 @@ def _makeQuery(iid):
         self._icache[iid] = None
       raise NotImplementedError
     
-    # not needed according to ORBit2 spec, but makes Java queries work
-    # more reliably according to Orca experience
-    i._narrow(i.__class__)
     if caching:
       # cache the narrow'ed result, but only if we're caching for this object
       self._icache[iid] = i
@@ -222,6 +219,8 @@ def _mixExceptions(cls):
   @param cls: Class to mix interface methods into
   @type cls: class
   '''
+  # get a method type as a reference from a known method
+  method_type = Accessibility.Accessible.getRole.__class__
   # loop over all names in the new class
   for name in cls.__dict__.keys():
     obj = cls.__dict__[name]
@@ -229,10 +228,10 @@ def _mixExceptions(cls):
     if name.startswith('_'):
       continue
     # check if we're on a method
-    elif isinstance(obj, types.FunctionType):
+    elif isinstance(obj, method_type):
       # wrap the function in an exception handler
       method = _makeExceptionHandler(obj)
-      # add the wrpped function to the class
+      # add the wrapped function to the class
       setattr(cls, name, method)
     # check if we're on a property
     elif isinstance(obj, property):
@@ -249,7 +248,7 @@ def _mixExceptions(cls):
         setter = None
       setattr(cls, name, property(getter, setter))
 
-def _mixClass(cls, new_cls):
+def _mixClass(cls, new_cls, ignore=[]):
   '''
   Adds the methods in new_cls to cls. After mixing, all instances of cls will
   have the new methods. If there is a method name clash, the method already in
@@ -264,10 +263,12 @@ def _mixClass(cls, new_cls):
   @type cls: class
   @param new_cls: Class containing features to add
   @type new_cls: class
+  @param ignore: Ignore these methods from the mixin
+  @type ignore: iterable
   '''
   # loop over all names in the new class
   for name, func in new_cls.__dict__.items():
-    if name in ['_get_name', '_get_description']:
+    if name in ignore:
       continue
     if isinstance(func, types.FunctionType):
       # build a new function that is a clone of the one from new_cls
@@ -411,6 +412,13 @@ class _AccessibleMixin(object):
     @return: Accessible child
     @rtype: Accessibility.Accessible
     '''
+    n = self.childCount
+    if index >= n:
+      raise IndexError
+    elif index < -n:
+      raise IndexError
+    elif index < 0:
+      index += n
     return self.getChildAtIndex(index)
   
   def __len__(self):
@@ -559,6 +567,7 @@ map(_mixExceptions, constants.ALL_INTERFACES)
 # 2. mix the exception handlers into other Accessibility objects
 map(_mixExceptions, [Accessibility.StateSet])
 # 3. mix the new functions
-_mixClass(Accessibility.Accessible, _AccessibleMixin)
+_mixClass(Accessibility.Accessible, _AccessibleMixin,
+          ['_get_name', '_get_description'])
 # 4. mix queryInterface convenience methods
 _mixInterfaces(Accessibility.Accessible, constants.ALL_INTERFACES)