2008-08-18 Mark Doffman <mark.doffman@codethink.co.uk>
authorMark Doffman <mdoff@silver-wind.(none)>
Mon, 18 Aug 2008 16:26:05 +0000 (17:26 +0100)
committerMark Doffman <mdoff@silver-wind.(none)>
Mon, 18 Aug 2008 16:26:05 +0000 (17:26 +0100)
* pyatspi/*
Complete the relation interface and the
getRelationSet method of the Accessible class.

pyatspi/accessible.py
pyatspi/relation.py

index b7ac7f3..5853778 100644 (file)
@@ -16,6 +16,7 @@ import interfaces
 from base import BaseProxy
 from factory import create_accessible, add_accessible_class
 from stateset import StateSet, _marshal_state_set
+from relation import _marshal_relation_set
 
 __all__ = [
           "Accessible",
@@ -44,7 +45,7 @@ class Accessible(BaseProxy):
                                 interfaces.ATSPI_APPLICATION,
                                 dbus_object=self._dbus_object)
     
-    def getAttributes(self, *args, **kwargs):
+    def getAttributes(self):
         """
         Get a list of properties applied to this object as a whole, as
         an AttributeSet consisting of name-value pairs. As such these
@@ -70,11 +71,13 @@ class Accessible(BaseProxy):
         Similarly, relevant structural metadata should be exposed using
         attribute names and values chosen from the CSS2 and WICD specification:
         http://www.w3.org/TR/1998/REC-CSS2-19980512 WICD (http://www.w3.org/TR/2005/WD-WICD-20051121/).
-        @return : an AttributeSet encapsulating any "attribute values"
-        currently defined for the object.
+
+        @return : An AttributeSet encapsulating any "attribute values"
+        currently defined for the object. An attribute set is a list of strings
+       with each string comprising an name-value pair format 'name:value'.
         """
         func = self.get_dbus_method("getAttributes")
-        return func(*args, **kwargs)
+        return func()
     
     def getChildAtIndex(self, index):
         """
@@ -90,7 +93,7 @@ class Accessible(BaseProxy):
                                 interfaces.ATSPI_ACCESSIBLE,
                                 dbus_object=self._dbus_object)
     
-    def getIndexInParent(self, *args, **kwargs):
+    def getIndexInParent(self):
         """
         Get the index of this object in its parent's child list. 
         @return : a long integer indicating this object's index in the
@@ -102,7 +105,7 @@ class Accessible(BaseProxy):
                        return i
        raise AccessibleObjectNoLongerExists("Child not found within parent")
     
-    def getLocalizedRoleName(self, *args, **kwargs):
+    def getLocalizedRoleName(self):
         """
         Get a string indicating the type of UI role played by this object,
         translated to the current locale.
@@ -110,16 +113,17 @@ class Accessible(BaseProxy):
         by this object.
         """
         func = self.get_dbus_method("getLocalizedRoleName")
-        return func(*args, **kwargs)
+        return func()
     
-    def getRelationSet(self, *args, **kwargs):
+    def getRelationSet(self):
         """
         Get a set defining this object's relationship to other accessible
         objects. 
         @return : a RelationSet defining this object's relationships.
         """
         func = self.get_dbus_method("getRelationSet")
-        return func(*args, **kwargs)
+        relation_set = func()
+        return _marshal_relation_set(self._cache, self._dbus_object, self._app_name, relation_set)
     
     def getRole(self):
         """
@@ -129,23 +133,23 @@ class Accessible(BaseProxy):
         """
         return self.cached_data.role
     
-    def getRoleName(self, *args, **kwargs):
+    def getRoleName(self):
         """
         Get a string indicating the type of UI role played by this object.
         @return : a UTF-8 string indicating the type of UI role played
         by this object.
         """
         func = self.get_dbus_method("getRoleName")
-        return func(*args, **kwargs)
+        return func()
     
-    def getState(self, *args, **kwargs):
+    def getState(self):
         """
         Get the current state of the object as a StateSet. 
         @return : a StateSet encapsulating the currently true states
         of the object.
         """
         func = self.get_dbus_method("getState")
-        bitfield = func(*args, **kwargs)
+        bitfield = func()
        return _marshal_state_set(bitfield)
     
     def isEqual(self, accessible):
index 343ab82..86e3a76 100644 (file)
@@ -19,7 +19,9 @@
 
 #authors: Peter Parente, Mark Doffman
 
+import interfaces
 from base import Enum as _Enum
+from factory import create_accessible
 
 #------------------------------------------------------------------------------
 
@@ -97,7 +99,7 @@ RELATION_VALUE_TO_NAME = dict(((value, name[9:].lower().replace('_', ' '))
 
 #------------------------------------------------------------------------------
 
-def _marshal_relation_set(bitfield):
+def _marshal_relation_set(cache, dbus_object, app_name, relation_set):
        """
        The D-Bus protocol has a relation set passed as an array of
        relation types and object arrays.
@@ -105,22 +107,7 @@ def _marshal_relation_set(bitfield):
        This function marshals the D-Bus message into a list of relation
        objects.
        """
-       (lower, upper) = bitfield
-
-       states = []
-
-       pos = 0
-       while (lower):
-               if (1L)&lower:
-                       #TODO Return the state objects rather than integers.
-                       states.append(pos)
-               pos+=1
-       while (upper):
-               if (1L)&upper:
-                       #TODO return the state objects rather than integers.
-                       states.append(pos)
-
-       return StateSet(*states)
+       return [Relation(cache, dbus_object, app_name, *relation) for relation in relation_set]
 
 #------------------------------------------------------------------------------
 
@@ -130,35 +117,43 @@ class Relation(object):
     to one another are indicated. An instance of Relations represents
     a "one-to-many" correspondance.
     """
+
+    def __init__(self, cache, dbus_object, app_name, type, objects):
+       self._type = type
+       self._objects = objects
+
+       self._dbus_object = dbus_object
+       self._cache = cache
+       self._app_name = app_name
     
-    def getNTargets(self, *args, **kwargs):
+    def getNTargets(self):
         """
         @return the number of objects to which this relationship applies.
         """
-        func = self.get_dbus_method("getNTargets")
-        return func(*args, **kwargs)
+        return len(self._objects)
     
-    def getRelationType(self, *args, **kwargs):
+    def getRelationType(self):
         """
         @return the RelationType of this Relation.
         """
-        func = self.get_dbus_method("getRelationType")
-        return func(*args, **kwargs)
+        return self._type
     
-    def getRelationTypeName(self, *args, **kwargs):
+    def getRelationTypeName(self):
         """
         @return an unlocalized string representing the relation type.
         """
-        func = self.get_dbus_method("getRelationTypeName")
-        return func(*args, **kwargs)
+       return RELATION_VALUE_TO_NAME[self._type]
     
-    def getTarget(self, *args, **kwargs):
+    def getTarget(self, index):
         """
         @return an Object which is the 'nth'target of this Relation,
         e.g. the Object at index i in the list of Objects having the
         specified relationship to this Accessible.
         """
-        func = self.get_dbus_method("getTarget")
-        return func(*args, **kwargs)
+       return create_accessible(self._cache,
+                                self._app_name,
+                                self._objects[index],
+                                interfaces.ATSPI_ACCESSIBLE,
+                                dbus_object=self._dbus_object)
 
 #END----------------------------------------------------------------------------