#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-from base import BaseProxy
+import interfaces
+from base import BaseProxy, Enum
+from factory import create_accessible, add_accessible_class
+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",
+ ]
+
+#------------------------------------------------------------------------------
+
+class LOCALE_TYPE(Enum):
+ _enum_lookup = {
+ 0:'LOCALE_TYPE_MESSAGES',
+ 1:'LOCALE_TYPE_COLLATE',
+ 2:'LOCALE_TYPE_CTYPE',
+ 3:'LOCALE_TYPE_MONETARY',
+ 4:'LOCALE_TYPE_NUMERIC',
+ 5:'LOCALE_TYPE_TIME',
+ }
+
+LOCALE_TYPE_COLLATE = LOCALE_TYPE(1)
+LOCALE_TYPE_CTYPE = LOCALE_TYPE(2)
+LOCALE_TYPE_MESSAGES = LOCALE_TYPE(0)
+LOCALE_TYPE_MONETARY = LOCALE_TYPE(3)
+LOCALE_TYPE_NUMERIC = LOCALE_TYPE(4)
+LOCALE_TYPE_TIME = LOCALE_TYPE(5)
+
+#------------------------------------------------------------------------------
+
+class BoundingBox(list):
+ def __new__(cls, x, y, width, height):
+ return list.__new__(cls, (x, y, width, height))
+ def __init__(self, x, y, width, height):
+ list.__init__(self, (x, y, width, height))
+
+ def _get_x(self):
+ return self[0]
+ def _set_x(self, val):
+ self[0] = val
+ x = property(fget=_get_x, fset=_set_x)
+ def _get_y(self):
+ return self[1]
+ def _set_y(self, val):
+ self[1] = val
+ y = property(fget=_get_y, fset=_set_y)
+ def _get_width(self):
+ return self[2]
+ def _set_width(self, val):
+ self[2] = val
+ width = property(fget=_get_width, fset=_set_width)
+ def _get_height(self):
+ return self[3]
+ def _set_height(self, val):
+ self[3] = val
+ height = property(fget=_get_height, fset=_set_height)
+
+#------------------------------------------------------------------------------
class Accessible(BaseProxy):
"""
'children' and position in the accessible-object hierarchy,
whether or not they actually have children.
"""
+
+ def __len__(self):
+ return self.getChildCount()
+
+ def __getitem__(self, index):
+ return self.getChildAtIndex(index)
- def getApplication(self, *args, **kwargs):
+ def getApplication(self):
"""
Get the containing Application for this object.
@return the Application instance to which this object belongs.
"""
- func = self.get_dbus_method("getApplication")
- return func(*args, **kwargs)
+ 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)
- 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
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, *args, **kwargs):
+ def getChildAtIndex(self, index):
"""
Get the accessible child of this object at index.
@param : index
an in parameter indicating which child is requested (zero-indexed).
@return : the 'nth' Accessible child of this object.
"""
- func = self.get_dbus_method("getChildAtIndex")
- return func(*args, **kwargs)
+ path = self.cached_data.children[index]
+ return create_accessible(self._cache,
+ self._app_name,
+ path,
+ interfaces.ATSPI_ACCESSIBLE,
+ connection=self._cache._connection)
- 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
parent's list.
"""
- func = self.get_dbus_method("getIndexInParent")
- return func(*args, **kwargs)
+ 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, *args, **kwargs):
+ def getLocalizedRoleName(self):
"""
Get a string indicating the type of UI role played by this object,
translated to the current locale.
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, *args, **kwargs):
+ def getRole(self):
"""
Get the Role indicating the type of UI role played by this object.
@return : a Role indicating the type of UI role played by this
object.
"""
- func = self.get_dbus_method("getRole")
- return func(*args, **kwargs)
+ return Role(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")
- return func(*args, **kwargs)
+ bitfield = func()
+ return _marshal_state_set(bitfield)
- def isEqual(self, *args, **kwargs):
+ def isEqual(self, accessible):
"""
Determine whether an Accessible refers to the same object as
another. This method should be used rather than brute-force comparison
@return : a boolean indicating whether the two object references
point to the same object.
"""
- func = self.get_dbus_method("isEqual")
- return func(*args, **kwargs)
-
- def unimplemented(self, *args, **kwargs):
- """
- /cond future expansion
- """
- func = self.get_dbus_method("unimplemented")
- return func(*args, **kwargs)
+ return (self._app_name == accessible._app_name) and \
+ (self._acc_path == accessible._acc_path)
def get_childCount(self):
- self._pgetter(self._dbus_interface, "childCount")
- def set_childCount(self, value):
- self._psetter(self._dbus_interface, "childCount", value)
+ return len(self.cached_data.children)
_childCountDoc = \
"""
childCount: the number of children contained by this object.
"""
- childCount = property(fget=get_childCount, fset=set_childCount, doc=_childCountDoc)
+ childCount = property(fget=get_childCount, doc=_childCountDoc)
def get_description(self):
- self._pgetter(self._dbus_interface, "description")
- def set_description(self, value):
- self._psetter(self._dbus_interface, "description", value)
+ return self.cached_data.description
_descriptionDoc = \
"""
a string describing the object in more detail than name.
"""
- description = property(fget=get_description, fset=set_description, doc=_descriptionDoc)
+ description = property(fget=get_description, doc=_descriptionDoc)
def get_name(self):
- self._pgetter(self._dbus_interface, "name")
- def set_name(self, value):
- self._psetter(self._dbus_interface, "name", value)
+ return self.cached_data.name
_nameDoc = \
"""
a (short) string representing the object's name.
"""
- name = property(fget=get_name, fset=set_name, doc=_nameDoc)
+ name = property(fget=get_name, doc=_nameDoc)
def get_parent(self):
- self._pgetter(self._dbus_interface, "parent")
- def set_parent(self, value):
- self._psetter(self._dbus_interface, "parent", value)
+ 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)
+
_parentDoc = \
"""
an Accessible object which is this object's containing object.
"""
- parent = property(fget=get_parent, fset=set_parent, doc=_parentDoc)
+ parent = property(fget=get_parent, doc=_parentDoc)
+
+# Register the Accessible class with the accessible factory.
+add_accessible_class(interfaces.ATSPI_ACCESSIBLE, Accessible)
+
+#END----------------------------------------------------------------------------