[pyatspi2] Notify registry of event registrations and use to start polling of mouse



commit 7a22150cdf6791cb4e412ca7a65fef91fa75dac5
Author: Mike Gorse <mgorse novell com>
Date:   Mon Aug 9 12:15:19 2010 -0400

    Notify registry of event registrations and use to start polling of mouse
    
    FDO#29427; listening for mouse:abs events now works.
    This is also the first step in moving towards only emitting events when
    a client is listening.

 pyatspi/appevent.py     |   14 ++++++++++++++
 pyatspi/busutils/bus.py |   42 ++++++++++++++++++++++++++++--------------
 pyatspi/factory.py      |    9 ++++++++-
 3 files changed, 50 insertions(+), 15 deletions(-)
---
diff --git a/pyatspi/appevent.py b/pyatspi/appevent.py
index eb6c2d0..58dd52f 100644
--- a/pyatspi/appevent.py
+++ b/pyatspi/appevent.py
@@ -15,8 +15,10 @@
 import string
 import gobject
 import interfaces
+from interfaces import ATSPI_REGISTRY_NAME, ATSPI_ROOT_PATH
 from accessible import BoundingBox
 from exceptions import *
+import dbus as _dbus
 
 from factory import AccessibleFactory
 from busutils import *
@@ -334,6 +336,12 @@ class _ApplicationEventRegister (object):
                         if duplicate == False:
                                 registered.append((new_type.name,
                                                    event_type_to_signal_reciever(self._bus, self._factory, client, new_type)))
+                                self._bus.call_async(ATSPI_REGISTRY_NAME,
+                                                     ATSPI_ROOT_PATH,
+                                                     interfaces.ATSPI_APPLICATION,
+                                                     'RegisterEventListener',
+                                                     's', (name,), None, None)
+
                                 self.removeEvents (client, True, name)
 
         def deregisterEventListener(self, client, *names):
@@ -358,6 +366,12 @@ class _ApplicationEventRegister (object):
 
                                 if remove_type.is_subtype(registered_type, excludeSelf):
                                         signal_match.remove()
+                                        self._bus.call_async(ATSPI_REGISTRY_NAME,
+                                                             ATSPI_ROOT_PATH,
+                                                             interfaces.ATSPI_APPLICATION,
+                                                             'DeregisterEventListener',
+                                                             's', (type_name,),
+                                                             None, None)
                                         del(registered[i])
                                 else:
                                         missing = True
diff --git a/pyatspi/busutils/bus.py b/pyatspi/busutils/bus.py
index 00652f7..d0ee289 100644
--- a/pyatspi/busutils/bus.py
+++ b/pyatspi/busutils/bus.py
@@ -111,22 +111,36 @@ class AsyncAccessibilityBus (_AccessibilityBus):
         D-Bus calls are made asyncronously.
 	"""
 
-	_shared_instance = None
+	_shared_instances = dict()
 	
-	def __new__ (cls, registry):
-		if AsyncAccessibilityBus._shared_instance:
-			return AsyncAccessibilityBus._shared_instance
-		else:
-			try:
-				AsyncAccessibilityBus._shared_instance = \
-                                        _AccessibilityBus.__new__ (cls, _get_accessibility_bus_address(), None)
-			except Exception:
-				AsyncAccessibilityBus._shared_instance = \
-                                        _AccessibilityBus.__new__ (cls, _bus.BusConnection.TYPE_SESSION, None)
+	def __new__ (cls, registry, address = None):
+		try:
+			return AsyncAccessibilityBus._shared_instances[address]
+		except:
+                        pass
+
+                realAddress = address
+                if realAddress is None:
+                        try:
+                                realAddress = _get_accessibility_bus_address()
+                        except:
+                                realAddress = _bus.BusConnection.TYPE_SESSION
+
+                try:
+                        AsyncAccessibilityBus._shared_instances[address] = \
+                                _AccessibilityBus.__new__ (cls, realAddress, None)
+                except:
+                        AsyncAccessibilityBus._shared_instances[address] = \
+                                _AccessibilityBus.__new__ (cls, _bus.BusConnection.TYPE_SESSION, None)
 			
-			return AsyncAccessibilityBus._shared_instance
-
-	def __init__ (self, registry):
+                return AsyncAccessibilityBus._shared_instances[address]
+
+	def __init__ (self, registry, address = None):
+                if address is None:
+                        try:
+                                address = _get_accessibility_bus_address()
+                        except:
+                                address = _bus.BusConnection.TYPE_SESSION
 		try:
 			_AccessibilityBus.__init__ (self, _get_accessibility_bus_address(), None)
 		except Exception:
diff --git a/pyatspi/factory.py b/pyatspi/factory.py
index 1a4d783..e53d153 100644
--- a/pyatspi/factory.py
+++ b/pyatspi/factory.py
@@ -75,7 +75,14 @@ class AccessibleFactory (object):
 			return None
 
                 if dbus_object == None:
-                        dbus_object = self._connection.get_object (name, path, introspect=False)
+                        try:
+                                app_obj = bus.get_object (name, ATSPI_ROOT_PATH, introspect=False)
+                                app_itf = dbus.Interface (cache_obj, _ATSPI_APPLICATIONCACHE_INTERFACE)
+                                busAddress = app_itf.GetApplicationBusAddress()
+                                bus = AsyncAccessibilityBus(registry.Registry(), busAddress)
+                                dbus_object = bus.get_object (name, path, introspect=False)
+                        except:
+                                dbus_object = self._connection.get_object (name, path, introspect=False)
         
                 return self._interfaces[itf] (self._cache, self, name, path, dbus_object)
 



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