[pyatspi2] Properly fix sub-fields of event types
- From: Mike Gorse <mgorse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pyatspi2] Properly fix sub-fields of event types
- Date: Wed, 29 Dec 2010 17:01:25 +0000 (UTC)
commit 07451e76faae5cc8cd7e4538cfc11a548745d50d
Author: Mike Gorse <mgorse novell com>
Date: Wed Dec 29 12:03:06 2010 -0500
Properly fix sub-fields of event types
An event type should inherit from str, so all string functions are accessible.
pyatspi/Accessibility.py | 6 +
pyatspi/appevent.py | 304 ----------------------------------------------
2 files changed, 6 insertions(+), 304 deletions(-)
---
diff --git a/pyatspi/Accessibility.py b/pyatspi/Accessibility.py
index 787871f..cb3d314 100644
--- a/pyatspi/Accessibility.py
+++ b/pyatspi/Accessibility.py
@@ -23,6 +23,7 @@ from state import *
from text import *
from document import *
from utils import *
+from appevent import *
def Accessible_getitem(self, i):
len=self.get_child_count()
@@ -87,6 +88,9 @@ def getInterface(func, obj):
def hashToAttributeList(h):
return [x + ":" + h[x] for x in h.keys()]
+def getEventType(event):
+ return EventType(event.rawType)
+
### Accessible ###
Accessible = Atspi.Accessible
Atspi.Accessible.getChildAtIndex = Atspi.Accessible.get_child_at_index
@@ -267,6 +271,8 @@ Atspi.Value.minimumValue = property(fget=Atspi.Value.get_minimum_value)
### event ###
Atspi.Event.host_application = property(fget=lambda x: x.source.get_application())
+Atspi.Event.rawType = Atspi.Event.type
+Atspi.Event.type = property(fget=getEventType)
### RelationSet ###
Atspi.Relation.getRelationType = Atspi.Relation.get_relation_type
diff --git a/pyatspi/appevent.py b/pyatspi/appevent.py
index 8395982..b50eed8 100644
--- a/pyatspi/appevent.py
+++ b/pyatspi/appevent.py
@@ -13,24 +13,6 @@
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import string
-import gobject
-import interfaces
-from interfaces import ATSPI_REGISTRY_NAME, ATSPI_ROOT_PATH
-from interfaces import ATSPI_REGISTRY_PATH, ATSPI_REGISTRY_INTERFACE
-from accessible import BoundingBox
-from exceptions import *
-import dbus as _dbus
-
-from factory import AccessibleFactory
-from busutils import *
-import registry
-
-__all__ = [
- "Event",
- "EventType",
- ]
-
-#------------------------------------------------------------------------------
class _ELessList(list):
def __getitem__(self, index):
@@ -107,289 +89,3 @@ class EventType(str):
@property
def value(self):
return str(self)
-
-#------------------------------------------------------------------------------
-
-_interface_to_klass = {
- "org.a11y.atspi.Event.Object":"object",
- "org.a11y.atspi.Event.Window":"window",
- "org.a11y.atspi.Event.Mouse":"mouse",
- "org.a11y.atspi.Event.Keyboard":"keyboard",
- "org.a11y.atspi.Event.Terminal":"terminal",
- "org.a11y.atspi.Event.Document":"document",
- "org.a11y.atspi.Event.Focus":"focus",
- }
-
-_klass_to_interface = {
- "object":"org.a11y.atspi.Event.Object",
- "window":"org.a11y.atspi.Event.Window",
- "mouse":"org.a11y.atspi.Event.Mouse",
- "keyboard":"org.a11y.atspi.Event.Keyboard",
- "terminal":"org.a11y.atspi.Event.Terminal",
- "document":"org.a11y.atspi.Event.Document",
- "focus":"org.a11y.atspi.Event.Focus",
- }
-
-#------------------------------------------------------------------------------
-
-def _major_to_signal_name (name):
- def capitalize (s):
- return s[0].upper() + s[1:]
-
- return ''.join ([capitalize (p) for p in name.split('-')])
-
-def _signal_name_to_major (name):
- def dashize (s):
- if s.isupper():
- return '-' + s.lower()
- return s
-
- return ''.join ([name[0].lower(),] + [dashize (c) for c in name[1:]])
-
-#------------------------------------------------------------------------------
-
-def signal_spec_to_event_type (interface, name, minor):
- """
- Converts an AT-SPI D-Bus signal specification into a Corba AT-SPI
- event type.
- """
- klass = _interface_to_klass[interface]
- major = _signal_name_to_major (name)
-
- if klass == "focus":
- return EventType ("focus:")
-
- event_string = klass + ':' + major
- if minor:
- event_string += ":" + minor
- return EventType (event_string)
-
-def event_type_to_signal_reciever(bus, factory, event_handler, event_type):
- """
- Converts a Corba AT-SPI event type to the correct D-Bus AT-SPI signal
- reciever.
- """
- kwargs = {
- 'sender_keyword':'sender',
- 'interface_keyword':'interface',
- 'member_keyword':'member',
- 'path_keyword':'path',
- }
- if event_type.klass:
- kwargs['dbus_interface'] = _klass_to_interface[event_type.klass]
- if event_type.major:
- kwargs['signal_name'] = _major_to_signal_name (event_type.major)
- if event_type.minor:
- kwargs['arg0'] = event_type.minor
-
- def handler_wrapper(minor,
- detail1,
- detail2,
- any_data,
- source_application,
- sender=None,
- interface=None,
- member=None,
- path=None):
-
- # Convert the event type
- type = signal_spec_to_event_type (interface, member, minor)
-
- # Marshal the 'any_data' to correct class / structure
- if type.is_subtype (EventType ("object:bounds-changed")):
- any_data = BoundingBox(*any_data)
- elif (type.is_subtype (EventType ("object:children-changed")) or
- type.is_subtype (EventType ("object:property-change:accessible-parent")) or
- type.is_subtype (EventType ("object:active-descendant-changed"))):
- data_name, data_path = any_data;
- any_data = factory (data_name, data_path, interfaces.ATSPI_ACCESSIBLE)
-
- # Create the source application
- source_app_name, source_app_path = source_application
- source_application = factory (source_app_name, source_app_path, interfaces.ATSPI_APPLICATION)
-
- # Create the source
- source_name = sender
- source_path = path
- if (path == interfaces.ATSPI_ROOT_PATH):
- source_itf = interfaces.ATSPI_APPLICATION
- else:
- source_itf = interfaces.ATSPI_ACCESSIBLE
- source = factory (source_name, source_path, source_itf)
-
- event = Event (type,
- detail1,
- detail2,
- any_data,
- source_application,
- source)
- depth = gobject.main_depth()
- r = registry.Registry()
- if (r.async):
- r.enqueueEvent(event_handler, event)
- else:
- return event_handler(event)
-
- return bus.add_signal_receiver(handler_wrapper, **kwargs)
-
-#------------------------------------------------------------------------------
-
-class Event(object):
- """
- Wraps an AT-SPI event with a more Pythonic interface managing exceptions,
- the differences in any_data across versions, and the reference counting of
- accessibles provided with the event.
-
- @note: All unmarked attributes of this class should be considered public
- readable and writable as the class is acting as a record object.
-
- @ivar type: The type of the AT-SPI event
- @type type: L{EventType}
- @ivar detail1: First AT-SPI event parameter
- @type detail1: integer
- @ivar detail2: Second AT-SPI event parameter
- @type detail2: integer
- @ivar any_data: Extra AT-SPI data payload
- @type any_data: object
- @ivar host_application: Application owning the event source
- @type host_application: Tuple (Name, Path)
- @ivar source: Source of the event
- @type source: Accessibility.Accessible
- """
- def __init__(self,
- type_slash_event=None,
- detail1=None,
- detail2=None,
- any_data=None,
- host_application=None,
- source=None):
-
- if detail1 == None:
- #This alternative init is provided for compatibility with the old API.
- #The old API apparently allowed the event to be delivered as a class with
- #named parameters. (Something like a copy constructor)
- #Old API used in orca - focus_tracking_presenter.py line 1106
- event = type_slash_event
-
- self.type = event.type
- self.detail1 = event.detail1
- self.detail2 = event.detail2
- self.any_data = event.any_data
- self.source = event.source
- self.application = event.source
- else:
- type = type_slash_event
-
- self.type = type
- self.detail1 = detail1
- self.detail2 = detail2
- self.any_data = any_data
- self.source = source
- self.host_application = host_application
-
- @property
- def source_name(self):
- return self.source.name
-
- @property
- def source_role(self):
- return self.source.getRole()
-
- def __str__(self):
- """
- Builds a human readable representation of the event including event type,
- parameters, and source info.
-
- @return: Event description
- @rtype: string
- """
- return '%s(%s, %s, %s)\n\tsource: %s\n\thost_application: %s' % \
- (self.type, self.detail1, self.detail2, self.any_data,
- self.source, self.host_application)
-
-#------------------------------------------------------------------------------
-
-class _ApplicationEventRegister (object):
-
- def __init__ (self, factory):
- self._bus = AsyncAccessibilityBus (registry.Registry())
- self._factory = factory
-
- self._event_listeners = {}
-
- def registerEventListener (self, client, *names):
- try:
- registered = self._event_listeners[client]
- except KeyError:
- registered = []
- self._event_listeners[client] = registered
-
- for name in names:
- duplicate = False
- new_type = EventType(name)
- 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._bus.call_async(ATSPI_REGISTRY_NAME,
- ATSPI_REGISTRY_PATH,
- ATSPI_REGISTRY_INTERFACE,
- 'RegisterEvent',
- 's', (name,), None, None)
-
- 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:
- # Presumably if were trying to deregister a client with
- # no names then the return type is always true.
- return True
-
- missing = False
-
- for name in names:
- remove_type = EventType(name)
- copy = registered[:]
- for i in range (0, len(copy)):
- type_name, signal_match = copy[i]
- registered_type = EventType(type_name)
-
- if remove_type.is_subtype(registered_type, excludeSelf):
- signal_match.remove()
- self._bus.call_async(ATSPI_REGISTRY_NAME,
- ATSPI_REGISTRY_PATH,
- ATSPI_REGISTRY_INTERFACE,
- 'DeregisterEvent',
- 's', (type_name,),
- None, None)
- del(registered[i])
- else:
- missing = True
-
- if registered == []:
- del(self._event_listeners[client])
-
- return missing
-
-#------------------------------------------------------------------------------
-
-class _NullApplicationEventRegister (object):
-
- def registerEventListener(self, client, *names):
- pass
-
- def deregisterEventListener(self, client, *names):
- return FALSE
-
-#END----------------------------------------------------------------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]