3 class AccessibleObjectDoesNotExist(Exception):
4 def __init__(self, path):
8 return "Object %s does not exist" % (self.path)
10 class AccessibleTreeCache():
12 Caches a collection of Accessible Objects.
15 _TREE_INTERFACE = 'org.freedesktop.atspi.Tree'
16 _UPDATE_SIGNAL = 'updateTree'
18 def __init__(self, connection, busName, objectStorePath):
20 Creates a cache for accessible objects.
22 All accessible objects are created and accessed through this cache.
25 connection - DBus connection.
26 busName - DBus bus name where accessible tree resides.
27 objectStorePath - Path where the accessible tree can be accessed.
29 storeObject = connection.get_object(busName, objectStorePath)
31 self._busName = busName
32 self._accessibleStore = dbus.Interface(storeObject, self._TREE_INTERFACE)
34 self._root = self._accessibleStore.getRoot()
36 self._updateObjects(self._accessibleStore.getTree())
38 #Connect to update signal
39 self._signalMatch = self._accessibleStore.connect_to_signal(self._UPDATE_SIGNAL,
42 def getRootAccessible(self):
44 Gets the accessible object at the root of the tree.
46 return self.getAccessible(self._root)
48 def getAccessible(self, objectPath):
50 Gets the accessible object for the given object path.
52 if objectPath in self._objects:
53 return self._objects[objectPath]
55 raise AccessibleObjectDoesNotExist(objectPath)
57 def _updateObjects(self, objects):
59 Updates the object cache from an
60 array of wire format Accessible objects.
62 for object in objects:
70 if path in self._objects:
71 self._objects[path].update(path,
79 acc = AccessibleObjectProxy(self,
88 self._objects[path] = acc;
90 def _removeObjects(self, paths):
92 #Probably want to set object as invalid first
93 del(self._objects[path])
95 def _updateHandler(self, updates):
96 objects, paths = updates
97 self._removeObjects(paths)
98 self._updateObjects(objects)
100 class AccessibleObjectProxy():
102 A D-Bus proxy for an element that implements one or more of the AT-SPI
103 Accessibility interfaces.
106 def __init__(self, cache, bus,
108 children, interfaces,
109 name, role, description):
111 Create an accessible object.
115 cache - The accessible cache that this object is owned by.
116 bus - Bus name where proxied object can be located.
117 path - The D-Bus object path of object proxied by this object.
118 parent - The parent accessible or '/' if the root object.
119 children - List of child accessible objects.
120 interfaces - List of interfaces supported by this object.
121 name - Name of the accessible.
122 role - The accessibles role.
123 description - Description of the accessible
127 self.update(path, parent, children, interfaces, name, role, description)
129 def update(self, path, parent,
130 children, interfaces,
131 name, role, description):
133 update an accessible object.
137 path - The D-Bus object path of object proxied by this object.
138 parent - The parent accessible or '/' if the root object.
139 children - List of child accessible objects.
140 interfaces - List of interfaces supported by this object.
141 name - Name of the accessible.
142 role - The accessibles role.
143 description - Description of the accessible
147 self.children = children
148 self.interfaces = interfaces
151 self.description = description
153 def getChildren(self):
154 return [self._cache.getAccessible(path) for path in self.children]