[pyatspi2] Have event registrations supercede those of their subtypes
- From: Mike Gorse <mgorse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pyatspi2] Have event registrations supercede those of their subtypes
- Date: Thu, 5 Aug 2010 00:16:03 +0000 (UTC)
commit a470ce419d12c135f7cb669f83ff5c6ac3aa6500
Author: Mike Gorse <mgorse novell com>
Date: Wed Aug 4 20:03:23 2010 -0400
Have event registrations supercede those of their subtypes
Ignore registrations for event names that are encompassed by other names.
Ie, if a client registers "object", "object:property-change", and
"object:property-change::accessible-name," and an
object:property-change::accessible-name event is receied, invoke the event
handler once, not three times. This should fix compatibility with applications
that register events using pyatspi.EVENT_TREE (ie, accerciser/strongwind).
pyatspi/appevent.py | 24 ++++++++++++++++++++----
pyatspi/constants.py | 9 ++++++---
2 files changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/pyatspi/appevent.py b/pyatspi/appevent.py
index 304c585..eb6c2d0 100644
--- a/pyatspi/appevent.py
+++ b/pyatspi/appevent.py
@@ -79,7 +79,7 @@ class EventType(str):
self.minor = self._separated[2]
self.detail = self._separated[3]
- def is_subtype(self, event_type):
+ def is_subtype(self, event_type, excludeSelf = False):
"""
Determines if the passed event type is a subtype
of this event.
@@ -92,6 +92,9 @@ class EventType(str):
else:
if event_type.minor and event_type.minor != self.minor:
return False
+ if (excludeSelf and event_type.klass == self.klass
+ and event_type.major == self.major and event_type.minor == self.minor):
+ return False
return True
@property
@@ -319,11 +322,24 @@ class _ApplicationEventRegister (object):
self._event_listeners[client] = registered
for name in names:
+ duplicate = False
new_type = EventType(name)
- registered.append((new_type.name,
- event_type_to_signal_reciever(self._bus, self._factory, client, new_type)))
+ copy = registered[:]
+ for i in range (0, len(copy)):
+ type_name, signal_match = copy[i]
+ registered_type = EventType(type_name)
+
+ if new_type.is_subtype(registered_type):
+ duplicate = True
+ if duplicate == False:
+ registered.append((new_type.name,
+ event_type_to_signal_reciever(self._bus, self._factory, client, new_type)))
+ self.removeEvents (client, True, name)
def deregisterEventListener(self, client, *names):
+ return self.removeEvents (client, False, *names)
+
+ def removeEvents (self, client, excludeSelf, *names):
try:
registered = self._event_listeners[client]
except KeyError:
@@ -340,7 +356,7 @@ class _ApplicationEventRegister (object):
type_name, signal_match = copy[i]
registered_type = EventType(type_name)
- if remove_type.is_subtype(registered_type):
+ if remove_type.is_subtype(registered_type, excludeSelf):
signal_match.remove()
del(registered[i])
else:
diff --git a/pyatspi/constants.py b/pyatspi/constants.py
index b6c694a..7b53230 100644
--- a/pyatspi/constants.py
+++ b/pyatspi/constants.py
@@ -47,9 +47,12 @@ CACHE_EVENTS = ['object:property-change:accessible-name',
CACHE_PROPERTIES = ''
-# Dictionary used to correct the bug of not being able to register for all the
-# subevents given only an AT-SPI event class (i.e. first part of the event
-# name) keys are event names having subevents and values are the subevents
+# This was placed into at-spi-corba because it apparently had a bug where
+# one could not register for all the subevents of an event given only an
+# AT-SPI event class (ie, first part of the event name). Pyatspi2 does not
+# have this issue, but will leave the tree as-is for now, and some programs
+# pass it to registerEventListener, so the constant needs to stay.
+# Keys are event names having subevents and values are the subevents
# under the key event; handlers *can* be registered for events not in this tree
EVENT_TREE = {
'terminal':
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]