Changes to python test code to reflect an update in
authorMark Doffman <mdoff@silver-wind.(none)>
Wed, 7 May 2008 09:33:49 +0000 (10:33 +0100)
committerMark Doffman <mdoff@silver-wind.(none)>
Wed, 7 May 2008 09:33:49 +0000 (10:33 +0100)
the Accessible_Tree interface.

tools/python/AccessibleTree.py
tools/python/AccessibleTreeCache.py
tools/python/testClient.py
tools/python/testServer.py

index 29ca3c4..ba76d80 100644 (file)
@@ -1,9 +1,6 @@
 import dbus
 import dbus.service
 
-TREE_UPDATE_ACCESSIBLE = 0
-TREE_REMOVE_ACCESSIBLE = 1
-
 class AccessibleTree(dbus.service.Object):
        """
        The Accessible tree provides the interface,
@@ -20,6 +17,7 @@ class AccessibleTree(dbus.service.Object):
                """
                dbus.service.Object.__init__(self, bus, path)
                self._toSend = {}
+               self._toRemove = []
                self._objects = {}
                self._root = '/'
 
@@ -29,29 +27,29 @@ class AccessibleTree(dbus.service.Object):
                return self._root
 
        @dbus.service.method(dbus_interface='org.freedesktop.atspi.Tree',
-                            out_signature='a(qooaoassus)')
+                            out_signature='a(ooaoassus)')
        def getTree(self):
-               wireObjects = []
-               for object in self._objects.values():
-                       wireObjects.append((TREE_UPDATE_ACCESSIBLE,) + object)
-               return wireObjects
+               return self._objects.values()
 
        @dbus.service.signal(dbus_interface='org.freedesktop.atspi.Tree',
-                            signature='a(qooaoassus)')
-       def updateTree(self, values):
+                            signature=('a(ooaoassus)ao'))
+       def updateTree(self, objects, paths):
                #There are some locking issues here.
                #Need to make sure that updates are not missed.
                oldSend = self._toSend.values()
                self._toSend = {}
-               return oldSend
+               oldRemove = self._toRemove
+               self._toRemove = []
+               return (oldSend, oldRemove)
 
        def updateObject(self, path, object):
                self._objects[path] = object
-               self._toSend[path] = (TREE_UPDATE_ACCESSIBLE,) + object
+               self._toSend[path] = object
                
        def removeObject(self, path):
-               self._toSend[path] = (TREE_REMOVE_ACCESSIBLE,) + self._objects[path]
-               del(self._objects[path])
+               if path in self._objects:
+                       self._toRemove.append(path)
+                       del(self._objects[path])
 
        def setRoot(self, root):
                self._root = root
index b91ca3c..f762101 100644 (file)
@@ -1,8 +1,5 @@
 import dbus
 
-TREE_UPDATE_ACCESSIBLE = 0
-TREE_REMOVE_ACCESSIBLE = 1
-
 class AccessibleObjectDoesNotExist(Exception):
        def __init__(self, path):
                self.path = path
@@ -16,6 +13,7 @@ class AccessibleTreeCache():
        """
 
        _TREE_INTERFACE = 'org.freedesktop.atspi.Tree'
+       _UPDATE_SIGNAL = 'updateTree'
 
        def __init__(self, connection, busName, objectStorePath):
                """
@@ -37,6 +35,10 @@ class AccessibleTreeCache():
 
                self._updateObjects(self._accessibleStore.getTree())
 
+               #Connect to update signal
+               self._signalMatch = self._accessibleStore.connect_to_signal(self._UPDATE_SIGNAL,
+                                                                           self._updateHandler)
+
        def getRootAccessible(self):
                """
                Gets the accessible object at the root of the tree.
@@ -58,37 +60,42 @@ class AccessibleTreeCache():
                array of wire format Accessible objects.
                """
                for object in objects:
-                       (flag, 
-                        path,
+                       (path,
                         parent,
                         children,
                         interfaces,
                         name, 
                         role,
                         description) = object
-                       if flag == TREE_REMOVE_ACCESSIBLE:
-                               #TODO need to set object as invalid
-                               del(self._objects[path])
+                       if path in self._objects:
+                               self._objects[path].update(path,
+                                                          parent,
+                                                          children, 
+                                                          interfaces, 
+                                                          name, 
+                                                          role, 
+                                                          description)
                        else:
-                               if path in self._objects:
-                                       self._objects[path].update(path,
-                                                                  parent,
-                                                                  children, 
-                                                                  interfaces, 
-                                                                  name, 
-                                                                  role, 
-                                                                  description)
-                               else:
-                                       acc = AccessibleObjectProxy(self,
-                                                                   self._busName,
-                                                                   path,
-                                                                   parent,
-                                                                   children,
-                                                                   interfaces,
-                                                                   name,
-                                                                   role,
-                                                                   description)
-                                       self._objects[path] = acc;
+                               acc = AccessibleObjectProxy(self,
+                                                           self._busName,
+                                                           path,
+                                                           parent,
+                                                           children,
+                                                           interfaces,
+                                                           name,
+                                                           role,
+                                                           description)
+                               self._objects[path] = acc;
+
+       def _removeObjects(self, paths):
+               for path in paths:
+                       #Probably want to set object as invalid first
+                       del(self._objects[path])
+
+       def _updateHandler(self, updates):
+               objects, paths = updates
+               self._removeObjects(paths)
+               self._updateObjects(objects)
 
 class AccessibleObjectProxy():
        """
index 5bc37c4..e9c1ea0 100644 (file)
@@ -1,10 +1,14 @@
 import sys
+import gobject
 import dbus
+from dbus.mainloop.glib import DBusGMainLoop
 
 from xml.dom import minidom
 
 from AccessibleTreeCache import AccessibleTreeCache, AccessibleObjectProxy
 
+DBusGMainLoop(set_as_default=True)
+
 def createNode(accessible, parentRef, parentElement):
        e = minidom.Element("accessible")
 
@@ -27,6 +31,9 @@ def createNode(accessible, parentRef, parentElement):
 def main(argv):
        filename = argv[1]
        bus = dbus.SessionBus()
+       
+       loop = gobject.MainLoop()
+
        cache = AccessibleTreeCache(bus, 'test.atspi.tree', '/org/freedesktop/atspi/tree')
        root = cache.getRootAccessible()
 
index 0fe315a..7c360a8 100644 (file)
@@ -1,8 +1,7 @@
 import sys
-from dbus.mainloop.glib import DBusGMainLoop
-
 import gobject
 import dbus
+from dbus.mainloop.glib import DBusGMainLoop
 
 from xml.dom import minidom