[pyatspi2] Re-factor cache to use a single dictionary. Fix cache updating when objects are added or removed.



commit bb6668060a1dd2c825bd30c3031257d0cf2694d4
Author: Mark Doffman <mark doffman codethink co uk>
Date:   Mon Jan 25 16:15:45 2010 -0800

    Re-factor cache to use a single dictionary.
    Fix cache updating when objects are added or removed.

 pyatspi/accessible.py |   70 +++++-------
 pyatspi/cache.py      |  294 ++++++++++++++++++++++---------------------------
 pyatspi/collection.py |    2 +-
 pyatspi/component.py  |    2 +-
 pyatspi/hyperlink.py  |    2 +-
 pyatspi/hypertext.py  |    2 +-
 pyatspi/registry.py   |   32 ++---
 pyatspi/selection.py  |    2 +-
 pyatspi/table.py      |   10 +-
 9 files changed, 185 insertions(+), 231 deletions(-)
---
diff --git a/pyatspi/accessible.py b/pyatspi/accessible.py
index 4c4e1dd..8a42f15 100644
--- a/pyatspi/accessible.py
+++ b/pyatspi/accessible.py
@@ -152,10 +152,6 @@ class BaseProxy (object):
                                                      dbus_interface="org.freedesktop.DBus.Properties")
 
         @property
-        def acc_factory (self):
-                return self._acc_factory
-
-        @property
         def app_name (self):
                 return self._app_name
 
@@ -163,10 +159,6 @@ class BaseProxy (object):
         def acc_path (self):
                 return self._acc_path
 
-        @property
-        def dbus_object (self):
-                return self._dbus_object
-
         # Proxy Equality ----------------------------------------------------------
 
         def __eq__(self, other):
@@ -184,7 +176,7 @@ class BaseProxy (object):
         # D-Bus method wrapper ----------------------------------------------------------
 
         def get_dbus_method (self, *args, **kwargs):
-                method =  self.dbus_object.get_dbus_method(*args, **kwargs)
+                method =  self._dbus_object.get_dbus_method(*args, **kwargs)
 
                 def dbus_method_func(*iargs, **ikwargs):
                         # Need to throw an AccessibleObjectNoLongerExists exception
@@ -257,8 +249,8 @@ class Accessible(BaseProxy):
                 is not supported.
                 """
                 if interface in self.interfaces or interface == "org.freedesktop.atspi.Collection":
-                        return self.acc_factory (self.app_name, self.acc_path, interface,
-                                                                  dbus_object=self.dbus_object)
+                        return self._acc_factory (self.app_name, self.acc_path, interface,
+                                                                  dbus_object=self._dbus_object)
                 else:
                         raise NotImplementedError(
                                 "%s not supported by accessible object at path %s"
@@ -267,7 +259,7 @@ class Accessible(BaseProxy):
         # Cache data --------------------------------------------------------------------
 
         @property
-	def _cached (self):
+	def cached (self):
                 if self._cache is not None:
 		        return (self.app_name, self.acc_path) in self._cache
                 else:
@@ -287,12 +279,12 @@ class Accessible(BaseProxy):
                 Get the containing Application for this object.
                 @return the Application instance to which this object belongs.
                 """
-                if self._cached:
-                	return self.acc_factory (*self._cached_data.application)
+                if self.cached:
+			name, path = self._cached_data.application
 		else:
                         func = self.get_dbus_method("GetApplication", dbus_interface=ATSPI_ACCESSIBLE)
 			name, path = func ()
-			return self.acc_factory (name, path, ATSPI_ACCESSIBLE)
+		return self._acc_factory (name, path, ATSPI_ACCESSIBLE)
 
         def getAttributes(self):
                 """
@@ -336,7 +328,7 @@ class Accessible(BaseProxy):
                 an in parameter indicating which child is requested (zero-indexed).
                 @return : the 'nth' Accessible child of this object.
                 """
-                if self._cached:
+                if self.cached:
                         (name, path) = self._cached_data.children[index]
                 else:
                         count = Int32(self._pgetter(ATSPI_ACCESSIBLE, "ChildCount"))
@@ -345,7 +337,7 @@ class Accessible(BaseProxy):
                         func = self.get_dbus_method("GetChildAtIndex", dbus_interface=ATSPI_ACCESSIBLE)
                         (name, path) = func (index)
 
-                return self.acc_factory (name, path, ATSPI_ACCESSIBLE)
+                return self._acc_factory (name, path, ATSPI_ACCESSIBLE)
 
         def getIndexInParent(self):
                 """
@@ -353,7 +345,7 @@ class Accessible(BaseProxy):
                 @return : a long integer indicating this object's index in the
                 parent's list.
                 """
-                parent = self.get_parent()
+                parent = self.parent
                 if parent == None:
                         return -1
                 for i in range(0, parent.childCount):
@@ -386,7 +378,7 @@ class Accessible(BaseProxy):
                 else:
                         func = self.get_dbus_method("GetRelationSet", dbus_interface=ATSPI_ACCESSIBLE)
                         relation_set = func()
-                        self._relation_set = _marshal_relation_set(self.acc_factory, self._app_name, relation_set)
+                        self._relation_set = _marshal_relation_set(self._acc_factory, self._app_name, relation_set)
                         return self._relation_set
 
         def getRole(self):
@@ -395,7 +387,7 @@ class Accessible(BaseProxy):
                 @return : a Role indicating the type of UI role played by this
                 object.
                 """
-                if self._cached:
+                if self.cached:
                         return Role(self._cached_data.role)
                 else:
                         func = self.get_dbus_method("GetRole", dbus_interface=ATSPI_ACCESSIBLE)
@@ -415,8 +407,8 @@ class Accessible(BaseProxy):
                 @return : a StateSet encapsulating the currently true states
                 of the object.
                 """
-                if self._cached:
-                        return _marshal_state_set(_cached_data.state)
+                if self.cached:
+                        return _marshal_state_set(self._cached_data.state)
                 else:
                         func = self.get_dbus_method("GetState", dbus_interface=ATSPI_ACCESSIBLE)
                         return _marshal_state_set(func())
@@ -435,8 +427,8 @@ class Accessible(BaseProxy):
                 """
                 return self.__eq__(other)
 
-        def get_childCount(self):
-                if self._cached:
+        def _get_childCount(self):
+                if self.cached:
                         return len(self._cached_data.children)
                 else:
                         return Int32(self._pgetter(ATSPI_ACCESSIBLE, "ChildCount"))
@@ -444,12 +436,12 @@ class Accessible(BaseProxy):
                 """
                 childCount: the number of children contained by this object.
                 """
-        childCount = property(fget=get_childCount, doc=_childCountDoc)
+        childCount = property(fget=_get_childCount, doc=_childCountDoc)
 
-        getChildCount = get_childCount
+        getChildCount = _get_childCount
 
-        def get_description(self):
-                if self._cached:
+        def _get_description(self):
+                if self.cached:
                         return self._cached_data.description
                 else:
                         return self._pgetter(ATSPI_ACCESSIBLE, "Description")
@@ -457,10 +449,10 @@ class Accessible(BaseProxy):
                 """
                 a string describing the object in more detail than name.
                 """
-        description = property(fget=get_description, doc=_descriptionDoc)
+        description = property(fget=_get_description, doc=_descriptionDoc)
 
-        def get_name(self):
-                if self._cached:
+        def _get_name(self):
+                if self.cached:
                         return self._cached_data.name
                 else:
                         return self._pgetter(ATSPI_ACCESSIBLE, "Name")
@@ -468,22 +460,22 @@ class Accessible(BaseProxy):
                 """
                 a (short) string representing the object's name.
                 """
-        name = property(fget=get_name, doc=_nameDoc)
+        name = property(fget=_get_name, doc=_nameDoc)
 
-        def get_parent(self):
-                if self._cached:
+        def _get_parent(self):
+                if self.cached:
                         name, path = self._cached_data.parent
                 else:
 		        name, path = self._pgetter (ATSPI_ACCESSIBLE, "Parent")
-                return self.acc_factory (name, path, ATSPI_ACCESSIBLE)
+                return self._acc_factory (name, path, ATSPI_ACCESSIBLE)
         _parentDoc = \
                 """
                 an Accessible object which is this object's containing object.
                 """
-        parent = property(fget=get_parent, doc=_parentDoc)
+        parent = property(fget=_get_parent, doc=_parentDoc)
 
-        def get_interfaces(self):
-                if self._cached:
+        def _get_interfaces(self):
+                if self.cached:
                         return self._cached_data.interfaces
                 else:
                         func = self.get_dbus_method("GetInterfaces", dbus_interface=ATSPI_ACCESSIBLE)
@@ -492,6 +484,6 @@ class Accessible(BaseProxy):
                 """
                 D-Bus interfaces supported by this accessible object.
                 """
-        interfaces = property(fget=get_interfaces, doc=_interfacesDoc)
+        interfaces = property(fget=_get_interfaces, doc=_interfacesDoc)
 
 #END----------------------------------------------------------------------------
diff --git a/pyatspi/cache.py b/pyatspi/cache.py
index c8b09ab..7c07cf9 100644
--- a/pyatspi/cache.py
+++ b/pyatspi/cache.py
@@ -22,86 +22,18 @@ from interfaces import *
 from busutils import AccessibilityBus
 
 __all__ = [
-           "ApplicationCache",
            "AccessibleCache"
           ]
 
-#------------------------------------------------------------------------------
-
-class ApplicationCache(object):
-        """
-        Keeps a store of the caches for all accessible applications.
-        Updates as new applications are added or removed.
-
-        @connection: D-Bus connection used to access applications.
-        """
- 
-        ATSPI_EVENT_OBJECT_INTERFACE = "org.freedesktop.atspi.Event.Object"
-
-        def __init__(self):
-                self._connection = AccessibilityBus ()
-
-                self._application_list = []
-                self._application_cache = {}
-
-                obj = self._connection.get_object(ATSPI_REGISTRY_NAME, ATSPI_ROOT_PATH)
-                self._desktop = dbus.Interface(obj, ATSPI_ACCESSIBLE)
-                apps = self._desktop.GetChildren()
-
-                self._connection.add_signal_receiver(self._children_changed_handler,
-						     bus_name=ATSPI_REGISTRY_NAME,
-						     path=ATSPI_ROOT_PATH,
-                                                     dbus_interface=self.ATSPI_EVENT_OBJECT_INTERFACE,
-                                                     signal_name="children_changed",
-						     member_keyword="member",
-						     sender_keyword="sender",
-						     path_keyword="path")
-
-
-
-		self._application_list.extend(apps)
-                        
-                for bus_name, object_path in self._application_list:
-                                self._application_cache[bus_name] = AccessibleCache(bus_name, object_path)
-
-        def __call__ (self, app_name, acc_path): 
-                """
-                Returns the cache tuple for the given application and accessible
-                object path. Throws an IndexError if the cache data is not found.
-                """
-                return self._application_cache[app_name][acc_path]
-
-	def __getitem__ (self, key):
-		try:
-			name, path = key
-			return self._application_cache[name][key]
-		except Exception:
-			raise KeyError ()
-
-        def __contains__ (self, key):
-                try:
-                        name, path = key
-                        return key in self._application_cache[app_name]
-                except Exception:
-                        return False
-
-	def _children_changed_handler (self, app, minor, detail1, detail2, any_data,
-				             sender=None, member=None, path=None):
-		if minor == "add":
-			bus_name, object_path = any_data
-                        self._application_list.append(bus_name)
-                        self._application_cache[bus_name] = AccessibleCache(bus_name)
-		elif minor == "remove":
-			bus_name, object_path = any_data
-                        self._application_list.remove(bus_name)
-                        del(self._application_cache[bus_name])
-
+_ATSPI_CACHE_PATH = '/org/at_spi/cache'
+_ATSPI_CACHE_INTERFACE = 'org.freedesktop.atspi.Cache'
+_ATSPI_EVENT_OBJECT_INTERFACE = "org.freedesktop.atspi.Event.Object"
 
 #------------------------------------------------------------------------------
 
 class _CacheData(object):
         __slots__ = [
-                        'path',
+                        'reference',
                         'application',
                         'parent',
                         'interfaces',
@@ -116,7 +48,7 @@ class _CacheData(object):
                 self._update(data)
 
         def __str__(self):
-                return (str(self.path) + '\n' +
+                return (str(self.reference) + '\n' +
                         str(self.application) + '\n' +
                         str(self.parent) + '\n' +
                         str(self.children) + '\n' +
@@ -127,7 +59,7 @@ class _CacheData(object):
                         str(self.state))
 
         def _update(self, data):
-                (self.path,
+                (self.reference,
                  self.application,
                  self.parent,
                  self.children,
@@ -139,106 +71,121 @@ class _CacheData(object):
 
 #------------------------------------------------------------------------------
 
-def _list_items_added_removed (l1, l2):
+class DesktopCacheManager (object):
         """
-        Returns a tuple (boolean, boolean).
-        The first value indicates if, when
-        moving from l1 to l2, any items have been added.
-        The second value indicates whether any items have
-        been removed.
+        Responsible for keeping track of applications as they are added or removed
+        from the desktop object.
         """
-        l1notl2 = [item for item in l1 if item not in l2]
-        l2notl1 = [item for item in l2 if item not in l1]
-        return ((len(l1notl2) > 0), (len(l2notl1) > 0))
+ 
+        def __init__(self, cache):
+                bus = AccessibilityBus ()
+
+                self._cache = cache
+                self._application_list = {}
+
+                bus.add_signal_receiver(self._children_changed_handler,
+                                        bus_name=ATSPI_REGISTRY_NAME,
+                                        path=ATSPI_ROOT_PATH,
+                                        dbus_interface=_ATSPI_EVENT_OBJECT_INTERFACE,
+                                        signal_name="ChildrenChanged",
+                                        member_keyword="member",
+                                        sender_keyword="sender",
+                                        path_keyword="path")
+
+                obj     = bus.get_object(ATSPI_REGISTRY_NAME, ATSPI_ROOT_PATH)
+                desktop = dbus.Interface(obj, ATSPI_ACCESSIBLE)
+                apps    = desktop.GetChildren()
+
+                for bus_name, object_path in apps:
+                                self._application_list[bus_name] = ApplicationCacheManager (cache, bus_name)
+
+	def _children_changed_handler (self, 
+                                       app, minor, detail1, detail2, any_data,
+				       sender=None, member=None, path=None):
+		if minor == "add":
+                        bus_name, object_path = any_data
+                        self._application_list[bus_name] = ApplicationCacheManager(cache, bus_name)
+		elif minor == "remove":
+                        bus_name, object_path = any_data
+                        self._application_list[bus_name].remove_all()
+                        del(self._application_list[bus_name])
 
 #------------------------------------------------------------------------------
 
-class AccessibleCache(object):
+class ApplicationCacheManager (object):
         """
-        There is one accessible cache per application.
-        For each application the accessible cache stores
-        data on every accessible object within the app.
-
-        connection - DBus connection.
-        busName    - Name of DBus connection where cache interface resides.
+        The application cache manager is responsible for keeping the cache up to date
+        with cache items from the given application.
         """
 
-        _PATH = '/org/at_spi/cache'
-        _INTERFACE = 'org.freedesktop.atspi.Cache'
-        _GET_METHOD = 'GetItems'
-
-        _ATSPI_EVENT_OBJECT_INTERFACE = "org.freedesktop.atspi.Event.Object"
-
-        _CACHE_PATH = '/org/at_spi/cache'
-        _CACHE_INTERFACE = 'org.freedesktop.atspi.Cache'
 
-        def __init__(self, bus_name, object_path):
+        def __init__(self, cache, bus_name):
                 """
                 Creates a cache.
 
                 connection - DBus connection.
                 busName    - Name of DBus connection where cache interface resides.
                 """
-                self._connection = AccessibilityBus()
-                self._bus_name = bus_name
-		self._object_path = object_path
-
-                self._objects = {}
-
-                obj = self._connection.get_object (bus_name, self._CACHE_PATH)
-                cache = dbus.Interface (obj, self._CACHE_INTERFACE)
-                self._update_objects(cache.GetItems())
-
-                self._connection.add_signal_receiver(self._property_change_handler,
-                                                     dbus_interface=self._ATSPI_EVENT_OBJECT_INTERFACE,
-                                                     signal_name="property_change",
-						     member_keyword="member",
-						     sender_keyword="sender",
-						     path_keyword="path")
-                self._connection.add_signal_receiver(self._children_changed_handler,
-                                                     dbus_interface=self._ATSPI_EVENT_OBJECT_INTERFACE,
-                                                     signal_name="children_changed",
-						     member_keyword="member",
-						     sender_keyword="sender",
-						     path_keyword="path")
-
-        def __getitem__(self, key):
-                try:
-                        name, path = key
-                        if name != self_bus_name:
-                                raise KeyError ()
-                        return self._objects[path]
-                except Exception:
-                        raise KeyError ()
-
-        def __contains__(self, key):
-                try:
-                        name, path = key
-                        if name != self_bus_name:
-                                return False
-                        return path in self._objects
-                except Exception:
-                        return False
-
-        def _update_object (self, data):
-                #First element is the object path.
-                path = data[0]
-                self._objects[path] = _CacheData (data)
-
-        def _update_objects (self, objects):
+                bus = AccessibilityBus()
+
+                self._cache = cache
+		self._bus_name = bus_name
+
+                cache_obj = bus.get_object (bus_name, _ATSPI_CACHE_PATH)
+                cache_itf = dbus.Interface (cache_obj, _ATSPI_CACHE_INTERFACE)
+                self._add_objects(cache_itf.GetItems())
+
+                self._property_change =  \
+                        bus.add_signal_receiver(self._property_change_handler,
+				                bus_name=self._bus_name,
+                                                dbus_interface=_ATSPI_EVENT_OBJECT_INTERFACE,
+                                                signal_name="PropertyChange",
+                                                member_keyword="member",
+                                                sender_keyword="sender",
+                                                path_keyword="path")
+
+                self._children_changed = \
+                        bus.add_signal_receiver(self._children_changed_handler,
+                                                bus_name=self._bus_name,
+                                                dbus_interface=_ATSPI_EVENT_OBJECT_INTERFACE,
+                                                signal_name="ChildrenChanged",
+                                                member_keyword="member",
+                                                sender_keyword="sender",
+                                                path_keyword="path")
+
+		self._cache_add = \
+                        bus.add_signal_receiver(self._add_object,
+                                                bus_name=self._bus_name,
+                                                path=_ATSPI_CACHE_PATH,
+                                                dbus_interface=_ATSPI_CACHE_INTERFACE,
+                                                signal_name="AddAccessible")
+
+		self._cache_remove = \
+                        bus.add_signal_receiver(self._remove_object,
+                                                bus_name=self._bus_name,
+                                                path=_ATSPI_CACHE_PATH,
+                                                dbus_interface=_ATSPI_CACHE_INTERFACE,
+                                                signal_name="RemoveAccessible")
+
+
+        def _add_object (self, data):
+                #First element is the object reference
+                bus_name, object_path = data[0]
+                self._cache[(bus_name, object_path)] = _CacheData (data)
+
+        def _remove_object(self, reference):
+		bus_name, object_path = reference
+                del(self._cache[(bus_name, object_path)])
+
+        def _add_objects (self, objects):
                 for data in objects:
-                        self._update_object (data)
-
-        def _remove_object(self, path):
-                try:
-                        del(self._objects[path])
-                except KeyError:
-                        pass
-
-	def _property_change_handler (self, app, minor, detail1, detail2, any_data,
-				            sender=None, member=None, path=None):
-                if (sender, path) in self:
-			item = self[(sender, path)]
+                        self._add_object (data)
+
+	def _property_change_handler (self,
+                                      app, minor, detail1, detail2, any_data,
+				      sender=None, member=None, path=None):
+                if (sender, path) in self._cache:
+			item = self._cache[(sender, path)]
 			if minor == "accessible-name":
 				item.name = any_data
 			elif minor == "accessible-description":
@@ -246,13 +193,34 @@ class AccessibleCache(object):
 			elif minor == "accessible-parent":
 				item.parent = any_data
 
-	def _children_changed_handler (self, app, minor, detail1, detail2, any_data,
-				             sender=None, member=None, path=None):
-		if (sender, path) in self:
-			item = self[(sender, path)]
+	def _children_changed_handler (self,
+                                       app, minor, detail1, detail2, any_data,
+				       sender=None, member=None, path=None):
+		if (sender, path) in self._cache:
+			item = self._cache[(sender, path)]
 			if minor == "add":
 				item.children.insert (detail1, any_data)
 			elif minor == "remove":
-				item.remove (detail1 + 1)
+				del (item.children[detail1])
+
+        def remove_all (self):
+                for bus_name, object_path in self._cache.keys():
+                        if bus_name == self._bus_name:
+                                del(self._cache[(self._bus_name, object_path)])
+
+#------------------------------------------------------------------------------
+
+class AccessibleCache (dict):
+
+	def __init__ (self, bus_name=None):
+		dict.__init__ (self)
+
+                if bus_name:
+                        self._manager = ApplicationCacheManager (self, bus_name) 
+                else:
+                        self._manager = DesktopCacheManager (self)
+
+        def __call__ (self, bus_name, object_path):
+                return self[(bus_name, object_path)]
 
 #END----------------------------------------------------------------------------
diff --git a/pyatspi/collection.py b/pyatspi/collection.py
index 0a4efff..c502115 100644
--- a/pyatspi/collection.py
+++ b/pyatspi/collection.py
@@ -102,7 +102,7 @@ class Collection(Accessible):
                         (name, path) = ret[i]
                         if (name == ""):
                                 name = self._app_name
-                        ret[i] = self.acc_factory (name, path, ATSPI_ACCESSIBLE)
+                        ret[i] = self._acc_factory (name, path, ATSPI_ACCESSIBLE)
                 return ret;
 
         def getMatches(self, rule, sortby, count, traverse):
diff --git a/pyatspi/component.py b/pyatspi/component.py
index 7df6b05..a833956 100644
--- a/pyatspi/component.py
+++ b/pyatspi/component.py
@@ -103,7 +103,7 @@ class Component(Accessible):
                 (name, path) = func(x, y, UInt32(coord_type))
                 if (name == ""):
                         name = self._app_name
-                return self.acc_factory (name, path, interfaces.ATSPI_ACCESSIBLE)
+                return self._acc_factory (name, path, interfaces.ATSPI_ACCESSIBLE)
 
         def getAlpha(self):
                 """
diff --git a/pyatspi/hyperlink.py b/pyatspi/hyperlink.py
index 48b59b4..2554198 100644
--- a/pyatspi/hyperlink.py
+++ b/pyatspi/hyperlink.py
@@ -50,7 +50,7 @@ class Hyperlink(Accessible):
                 ith anchor can be accessed.
                 """
                 func = self.get_dbus_method("getObject", dbus_interface=ATSPI_HYPERLINK)
-                return self.acc_factory (self._app_name, func(index), ATSPI_ACCESSIBLE)
+                return self._acc_factory (self._app_name, func(index), ATSPI_ACCESSIBLE)
 
         def getURI(self, index):
                 """
diff --git a/pyatspi/hypertext.py b/pyatspi/hypertext.py
index ace75c5..75b1013 100644
--- a/pyatspi/hypertext.py
+++ b/pyatspi/hypertext.py
@@ -39,7 +39,7 @@ class Hypertext(Accessible):
                 @return the Hyperlink in this Hypertext object.
                 """
                 func = self.get_dbus_method("getLink", dbus_interface=ATSPI_HYPERTEXT)
-                return self.acc_factory (self._app_name, func(index), interfaces.ATSPI_HYPERLINK)
+                return self._acc_factory (self._app_name, func(index), interfaces.ATSPI_HYPERLINK)
 
         def getLinkIndex(self, character_index):
                 """
diff --git a/pyatspi/registry.py b/pyatspi/registry.py
index e166fb9..6a437fc 100644
--- a/pyatspi/registry.py
+++ b/pyatspi/registry.py
@@ -28,7 +28,7 @@ from factory import AccessibleFactory
 from appevent import _ApplicationEventRegister, _NullApplicationEventRegister
 from deviceevent import _DeviceEventRegister, _NullDeviceEventRegister
 from busutils import AccessibilityBus
-from cache import *
+from cache import AccessibleCache
 
 from deviceevent import KEY_PRESSED_EVENT as _KEY_PRESSED_EVENT
 from deviceevent import KEY_RELEASED_EVENT as _KEY_RELEASED_EVENT
@@ -115,39 +115,33 @@ class Registry(object):
                 @param app_name: D-Bus name of the application to connect to when not using the registry daemon.
                 """
 
-                _connection = AccessibilityBus ()
-                _bus_object = _connection.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
 
                 # Set up the cache
 		cache = None
-
                 if main_loop_type == MAIN_LOOP_GLIB:
-                        if app_name:
-                                cache = AccessibleCache(app_name, _ATSPI_ROOT_PATH)
-                        else:
-                                cache = ApplicationCache()
+                                cache = AccessibleCache (app_name)
 
 		factory = AccessibleFactory(cache)
 
                 # Set up the device event controllers
+                _connection = AccessibilityBus ()
+                _bus_object = _connection.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
+
                 if app_name:
-                        devreg = _NullDeviceEventRegister()
-                        appreg = _NullApplicationEventRegister()
+                        self.device_event_register = _NullDeviceEventRegister()
+                        seld.app_event_register    = _NullApplicationEventRegister()
+
 			name = _bus_object.GetNameOwner (app_name)
-                        desktop = factory (name, _ATSPI_ROOT_PATH, _ATSPI_DESKTOP)
+                        self.desktop = factory (name, _ATSPI_ROOT_PATH, _ATSPI_DESKTOP)
                 else:
-                        devreg = _DeviceEventRegister()
-                        appreg = _ApplicationEventRegister(factory)
+                        self.device_event_register = _DeviceEventRegister()
+                        self.app_event_register    = _ApplicationEventRegister(factory)
+
 			name = _bus_object.GetNameOwner (_ATSPI_REGISTRY_NAME)
-                        desktop = factory (name, _ATSPI_ROOT_PATH, _ATSPI_DESKTOP)
+                        self.desktop = factory (name, _ATSPI_ROOT_PATH, _ATSPI_DESKTOP)
 
-                # Create the registry object
                 self.has_implementations = True
 
-                self.device_event_register = devreg
-                self.app_event_register = appreg
-                self.desktop = desktop
-
         def _set_default_registry (self):
                 self._set_registry (MAIN_LOOP_GLIB)
 
diff --git a/pyatspi/selection.py b/pyatspi/selection.py
index 1ec8cac..ef8a25f 100644
--- a/pyatspi/selection.py
+++ b/pyatspi/selection.py
@@ -85,7 +85,7 @@ class Selection(Accessible):
                 (name, path) = func (index)
                 if (name == ""):
                         name = self._app_name
-                return self.acc_factory (name, path, ATSPI_ACCESSIBLE)
+                return self._acc_factory (name, path, ATSPI_ACCESSIBLE)
 
         def isChildSelected(self, index):
                 """
diff --git a/pyatspi/table.py b/pyatspi/table.py
index d45e2eb..01fbf82 100644
--- a/pyatspi/table.py
+++ b/pyatspi/table.py
@@ -75,7 +75,7 @@ class Table(Accessible):
                 (name, path) = func(row, column)
                 if (name == ""):
                         name = self._app_name
-                return self.acc_factory (name, path, ATSPI_ACCESSIBLE)
+                return self._acc_factory (name, path, ATSPI_ACCESSIBLE)
 
         def getColumnAtIndex(self, index):
                 """
@@ -127,7 +127,7 @@ class Table(Accessible):
                 if available.
                 """
                 func = self.get_dbus_method("GetColumnHeader", dbus_interface=ATSPI_TABLE)
-                return self.acc_factory (self._app_name, func(index), ATSPI_ACCESSIBLE)
+                return self._acc_factory (self._app_name, func(index), ATSPI_ACCESSIBLE)
 
         def getIndexAt(self, row, column):
                 """
@@ -234,7 +234,7 @@ class Table(Accessible):
 		(name, path) = func (row)
 		if (name == ""):
 			name = self._app_name
-                return self.acc_factory (name, path, ATSPI_ACCESSIBLE)
+                return self._acc_factory (name, path, ATSPI_ACCESSIBLE)
 
         def getSelectedColumns(self):
                 """
@@ -315,7 +315,7 @@ class Table(Accessible):
                 (name, path) = self._pgetter(ATSPI_TABLE, "Caption")
                 if (name == ""):
                         name = self._app_name
-                return self.acc_factory (name, path, ATSPI_ACCESSIBLE)
+                return self._acc_factory (name, path, ATSPI_ACCESSIBLE)
         _captionDoc = \
                 """
                 An Accessible which represents of a caption for a Table.
@@ -365,7 +365,7 @@ class Table(Accessible):
                 (name, path) = self._pgetter(ATSPI_TABLE, "Summary")
                 if (name == ""):
                         name = self._app_name
-                return self.acc_factory (name, path, ATSPI_ACCESSIBLE)
+                return self._acc_factory (name, path, ATSPI_ACCESSIBLE)
         _summaryDoc = \
                 """
                 An accessible object which summarizes the contents of a Table.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]