2008-11-13 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / pyatspi / accessible.py
index 093ac03..c9323a8 100644 (file)
 #along with this program; if not, write to the Free Software
 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-import interfaces
+from interfaces import ATSPI_ACCESSIBLE, ATSPI_APPLICATION
 from base import BaseProxy, Enum
-from factory import create_accessible, add_accessible_class
+from factory import accessible_factory
 from state import StateSet, _marshal_state_set
 from relation import _marshal_relation_set
 from role import Role
 
 __all__ = [
-          "LOCALE_TYPE",
-          "LOCALE_TYPE_COLLATE",
-          "LOCALE_TYPE_CTYPE",
-          "LOCALE_TYPE_MESSAGES",
-          "LOCALE_TYPE_MONETARY",
-          "LOCALE_TYPE_NUMERIC",
-          "LOCALE_TYPE_TIME",
-          "BoundingBox",
-          "Accessible",
-         ]
+           "LOCALE_TYPE",
+           "LOCALE_TYPE_COLLATE",
+           "LOCALE_TYPE_CTYPE",
+           "LOCALE_TYPE_MESSAGES",
+           "LOCALE_TYPE_MONETARY",
+           "LOCALE_TYPE_NUMERIC",
+           "LOCALE_TYPE_TIME",
+           "BoundingBox",
+           "Accessible",
+          ]
 
 #------------------------------------------------------------------------------
 
@@ -57,7 +57,10 @@ class BoundingBox(list):
         return list.__new__(cls, (x, y, width, height))
     def __init__(self, x, y, width, height):
         list.__init__(self, (x, y, width, height))
-    
+
+    def __str__(self):
+        return ("(%d, %d, %d, %d)" % (self.x, self.y, self.width, self.height))
+
     def _get_x(self):
         return self[0]
     def _set_x(self, val):
@@ -89,25 +92,22 @@ class Accessible(BaseProxy):
     whether or not they actually have children.
     """
 
+    def __nonzero__(self):
+            return True
+
     def __len__(self):
-           return self.getChildCount()
+            return self.getChildCount()
 
     def __getitem__(self, index):
-           return self.getChildAtIndex(index)
-    
+            return self.getChildAtIndex(index)
+
     def getApplication(self):
         """
         Get the containing Application for this object.
         @return the Application instance to which this object belongs.
         """
-       application_root = self._cache[self._app_name]._get_root()
-       #TODO Set the desktop object as the parent of this.
-       return create_accessible(self._cache,
-                                self._app_name,
-                                application_root,
-                                interfaces.ATSPI_APPLICATION,
-                                connection=self._cache._connection)
-    
+        return self._cache.create_application(self._app_name)
+
     def getAttributes(self):
         """
         Get a list of properties applied to this object as a whole, as
@@ -137,11 +137,11 @@ class Accessible(BaseProxy):
 
         @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'.
+        with each string comprising an name-value pair format 'name:value'.
         """
-        func = self.get_dbus_method("getAttributes")
+        func = self.get_dbus_method("getAttributes", dbus_interface=ATSPI_ACCESSIBLE)
         return func()
-    
+
     def getChildAtIndex(self, index):
         """
         Get the accessible child of this object at index. 
@@ -149,25 +149,21 @@ class Accessible(BaseProxy):
         an in parameter indicating which child is requested (zero-indexed).
         @return : the 'nth' Accessible child of this object.
         """
-       path = self.cached_data.children[index]
-       return create_accessible(self._cache,
-                                self._app_name,
-                                path,
-                                interfaces.ATSPI_ACCESSIBLE,
-                                connection=self._cache._connection)
-    
+        path = self.cached_data.children[index]
+        return self._cache.create_accessible(self._app_name, path, ATSPI_ACCESSIBLE)
+
     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
         parent's list.
         """
-       for i in range(0, self.parent.childCount):
-               child = self.parent.getChildAtIndex(i)
-               if self.isEqual(child):
-                       return i
-       raise AccessibleObjectNoLongerExists("Child not found within parent")
-    
+        for i in range(0, self.parent.childCount):
+                child = self.parent.getChildAtIndex(i)
+                if self.isEqual(child):
+                        return i
+        raise AccessibleObjectNoLongerExists("Child not found within parent")
+
     def getLocalizedRoleName(self):
         """
         Get a string indicating the type of UI role played by this object,
@@ -175,19 +171,19 @@ class Accessible(BaseProxy):
         @return : a UTF-8 string indicating the type of UI role played
         by this object.
         """
-        func = self.get_dbus_method("getLocalizedRoleName")
+        func = self.get_dbus_method("getLocalizedRoleName", dbus_interface=ATSPI_ACCESSIBLE)
         return func()
-    
+
     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")
+        func = self.get_dbus_method("getRelationSet", dbus_interface=ATSPI_ACCESSIBLE)
         relation_set = func()
-        return _marshal_relation_set(self._cache, self._dbus_object, self._app_name, relation_set)
-    
+        return _marshal_relation_set(self._cache, self._app_name, relation_set)
+
     def getRole(self):
         """
         Get the Role indicating the type of UI role played by this object.
@@ -195,26 +191,26 @@ class Accessible(BaseProxy):
         object.
         """
         return Role(self.cached_data.role)
-    
+
     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")
+        func = self.get_dbus_method("getRoleName", dbus_interface=ATSPI_ACCESSIBLE)
         return func()
-    
+
     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")
+        func = self.get_dbus_method("getState", dbus_interface=ATSPI_ACCESSIBLE)
         bitfield = func()
-       return _marshal_state_set(bitfield)
-    
+        return _marshal_state_set(bitfield)
+
     def isEqual(self, accessible):
         """
         Determine whether an Accessible refers to the same object as
@@ -228,8 +224,9 @@ class Accessible(BaseProxy):
         point to the same object.
         """
         return  (self._app_name == accessible._app_name) and \
-               (self._acc_path == accessible._acc_path)        
-    
+                (self._acc_path == accessible._acc_path)        
+
+
     def get_childCount(self):
         return len(self.cached_data.children)
     _childCountDoc = \
@@ -237,7 +234,9 @@ class Accessible(BaseProxy):
         childCount: the number of children contained by this object.
         """
     childCount = property(fget=get_childCount, doc=_childCountDoc)
-    
+
+    getChildCount = get_childCount
+
     def get_description(self):
         return self.cached_data.description
     _descriptionDoc = \
@@ -245,7 +244,7 @@ class Accessible(BaseProxy):
         a string describing the object in more detail than name.
         """
     description = property(fget=get_description, doc=_descriptionDoc)
-    
+
     def get_name(self):
         return self.cached_data.name
     _nameDoc = \
@@ -253,16 +252,11 @@ class Accessible(BaseProxy):
         a (short) string representing the object's name.
         """
     name = property(fget=get_name, doc=_nameDoc)
-    
+
     def get_parent(self):
-       if self._parent:
-               return self._parent
-       else:
-               return create_accessible(self._cache,
-                                        self._app_name,
-                                        self.cached_data.parent,
-                                        interfaces.ATSPI_ACCESSIBLE,
-                                        connection=self._cache._connection)
+        return self._cache.create_accessible(self._app_name,
+                                             self.cached_data.parent,
+                                             ATSPI_ACCESSIBLE)
 
     _parentDoc = \
         """
@@ -270,7 +264,7 @@ class Accessible(BaseProxy):
         """
     parent = property(fget=get_parent, doc=_parentDoc)
 
-# Register the Accessible class with the accessible factory.
-add_accessible_class(interfaces.ATSPI_ACCESSIBLE, Accessible)
+# Register the accessible class with the factory.
+accessible_factory.register_accessible_class(ATSPI_ACCESSIBLE, Accessible)
 
 #END----------------------------------------------------------------------------