[pyatspi2] Only use cache if registry.start has been called



commit 8804769e68e45e64961897e8ec508b28bce9be96
Author: Mike Gorse <mgorse novell com>
Date:   Wed May 19 20:40:55 2010 -0400

    Only use cache if registry.start has been called
    
    If registry.start() hasn't been called, then presume we have no main loop
    and do not use the cache, so that, ie, a script that simply sleeps will
    have valid information.  For compatibility with at-spi-corba.
    Also, catch dbus exceptions when calling GetItems.

 pyatspi/accessible.py |    2 ++
 pyatspi/cache.py      |    5 ++++-
 pyatspi/registry.py   |    2 ++
 3 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/pyatspi/accessible.py b/pyatspi/accessible.py
index b2b0e4e..2a04fde 100644
--- a/pyatspi/accessible.py
+++ b/pyatspi/accessible.py
@@ -263,6 +263,8 @@ class Accessible(BaseProxy):
 
         @property
 	def cached (self):
+                if not(registry.Registry().started):
+                        return False
                 if self._cache is not None:
 		        return (self.app_name, self.acc_path) in self._cache
                 else:
diff --git a/pyatspi/cache.py b/pyatspi/cache.py
index e25d9d9..b40ec74 100644
--- a/pyatspi/cache.py
+++ b/pyatspi/cache.py
@@ -170,7 +170,10 @@ class ApplicationCacheManager (object):
 
                 cache_obj = bus.get_object (bus_name, _ATSPI_CACHE_PATH, introspect=False)
                 cache_itf = dbus.Interface (cache_obj, _ATSPI_CACHE_INTERFACE)
-                self._add_objects(cache_itf.GetItems())
+                try:
+                        self._add_objects(cache_itf.GetItems())
+                except dbus.exceptions.DBusException:
+                        pass
 
                 self._property_change =  \
                         bus.add_signal_receiver(self._property_change_handler,
diff --git a/pyatspi/registry.py b/pyatspi/registry.py
index 7e80e80..4f58307 100644
--- a/pyatspi/registry.py
+++ b/pyatspi/registry.py
@@ -154,6 +154,7 @@ class Registry(object):
 
 		self.async = False	# not fully supported yet
                 self.has_implementations = True
+                self.started = False
 
         def _set_default_registry (self):
                 self._set_registry (MAIN_LOOP_GLIB)
@@ -173,6 +174,7 @@ class Registry(object):
                 """
                 if not self.has_implementations:
                         self._set_default_registry ()
+                self.started = True
                 try:
                         self.main_loop.run()
                 except KeyboardInterrupt:



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