2008-04-30 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / tools / python / AccessibleTree.py
1 import dbus
2 import dbus.service
3
4 TREE_UPDATE_ACCESSIBLE = 0
5 TREE_REMOVE_ACCESSIBLE = 1
6
7 class AccessibleTree(dbus.service.Object):
8         """
9         The Accessible tree provides the interface,
10         for accessing all the accessible objects
11         available on a particular application.
12         """
13
14         def __init__(self, bus, path):
15                 """
16                 Parameters:
17
18                 bus - The D-Bus bus object to use
19                 path - The object path this interface should use
20                 """
21                 dbus.service.Object.__init__(self, bus, path)
22                 self._toSend = {}
23                 self._objects = {}
24                 self._root = '/'
25
26         @dbus.service.method(dbus_interface='org.freedesktop.atspi.Tree',
27                              out_signature='o')
28         def getRoot(self):
29                 return self._root
30
31         @dbus.service.method(dbus_interface='org.freedesktop.atspi.Tree',
32                              out_signature='a(qooaoassus)')
33         def getTree(self):
34                 wireObjects = []
35                 for object in self._objects.values():
36                         wireObjects.append((TREE_UPDATE_ACCESSIBLE,) + object)
37                 return wireObjects
38
39         @dbus.service.signal(dbus_interface='org.freedesktop.atspi.Tree',
40                              signature='a(qooaoassus)')
41         def updateTree(self, values):
42                 #There are some locking issues here.
43                 #Need to make sure that updates are not missed.
44                 oldSend = self._toSend.values()
45                 self._toSend = {}
46                 return oldSend
47
48         def updateObject(self, path, object):
49                 self._objects[path] = object
50                 self._toSend[path] = (TREE_UPDATE_ACCESSIBLE,) + object
51                 
52         def removeObject(self, path):
53                 self._toSend[path] = (TREE_REMOVE_ACCESSIBLE,) + self._objects[path]
54                 del(self._objects[path])
55
56         def setRoot(self, root):
57                 self._root = root