3 TREE_UPDATE_ACCESSIBLE = 0
4 TREE_REMOVE_ACCESSIBLE = 1
6 class AccessibleObjectDoesNotExist(Exception):
7 def __init__(self, path):
11 return "Object %s does not exist" % (self.path)
13 class AccessibleTreeCache():
15 Caches a collection of Accessible Objects.
18 _TREE_INTERFACE = 'org.freedesktop.atspi.Tree'
20 def __init__(self, connection, busName, objectStorePath):
22 Creates a cache for accessible objects.
24 All accessible objects are created and accessed through this cache.
27 connection - DBus connection.
28 busName - DBus bus name where accessible tree resides.
29 objectStorePath - Path where the accessible tree can be accessed.
31 storeObject = connection.get_object(busName, objectStorePath)
33 self._busName = busName
34 self._accessibleStore = dbus.Interface(storeObject, self._TREE_INTERFACE)
36 self._root = self._accessibleStore.getRoot()
38 self._updateObjects(self._accessibleStore.getTree())
40 def getRootAccessible(self):
42 Gets the accessible object at the root of the tree.
44 return self.getAccessible(self._root)
46 def getAccessible(self, objectPath):
48 Gets the accessible object for the given object path.
50 if objectPath in self._objects:
51 return self._objects[objectPath]
53 raise AccessibleObjectDoesNotExist(objectPath)
55 def _updateObjects(self, objects):
57 Updates the object cache from an
58 array of wire format Accessible objects.
60 for object in objects:
69 if flag == TREE_REMOVE_ACCESSIBLE:
70 #TODO need to set object as invalid
71 del(self._objects[path])
73 if path in self._objects:
74 self._objects[path].update(path,
82 acc = AccessibleObjectProxy(self,
91 self._objects[path] = acc;
93 class AccessibleObjectProxy():
95 A D-Bus proxy for an element that implements one or more of the AT-SPI
96 Accessibility interfaces.
99 def __init__(self, cache, bus,
101 children, interfaces,
102 name, role, description):
104 Create an accessible object.
108 cache - The accessible cache that this object is owned by.
109 bus - Bus name where proxied object can be located.
110 path - The D-Bus object path of object proxied by this object.
111 parent - The parent accessible or '/' if the root object.
112 children - List of child accessible objects.
113 interfaces - List of interfaces supported by this object.
114 name - Name of the accessible.
115 role - The accessibles role.
116 description - Description of the accessible
120 self.update(path, parent, children, interfaces, name, role, description)
122 def update(self, path, parent,
123 children, interfaces,
124 name, role, description):
126 update an accessible object.
130 path - The D-Bus object path of object proxied by this object.
131 parent - The parent accessible or '/' if the root object.
132 children - List of child accessible objects.
133 interfaces - List of interfaces supported by this object.
134 name - Name of the accessible.
135 role - The accessibles role.
136 description - Description of the accessible
140 self.children = children
141 self.interfaces = interfaces
144 self.description = description
146 def getChildren(self):
147 return [self._cache.getAccessible(path) for path in self.children]