[pyatspi2/gi: 1/3] Initial commit of pygi-based code
- From: Mike Gorse <mgorse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pyatspi2/gi: 1/3] Initial commit of pygi-based code
- Date: Wed, 24 Nov 2010 19:41:10 +0000 (UTC)
commit 5a7636e49f457869c57beaf63eec25077f0057b0
Author: Mike Gorse <mgorse novell com>
Date: Wed Nov 24 04:21:14 2010 -0500
Initial commit of pygi-based code
configure.ac | 2 +-
pyatspi/Accessibility.py | 192 ++++++++-
pyatspi/Makefile.am | 13 +-
pyatspi/__init__.py | 19 +-
pyatspi/action.py | 107 -----
pyatspi/cache.py | 17 -
pyatspi/component.py | 186 ---------
pyatspi/constants.py | 2 -
pyatspi/document.py | 70 ----
pyatspi/editabletext.py | 120 ------
pyatspi/factory.py | 13 +-
pyatspi/hyperlink.py | 107 -----
pyatspi/hypertext.py | 69 ----
pyatspi/image.py | 105 -----
pyatspi/registry.py | 309 ++++++---------
pyatspi/selection.py | 135 -------
pyatspi/state.py | 119 +------
pyatspi/table.py | 380 ------------------
pyatspi/text.py | 575 ---------------------------
pyatspi/utils.py | 8 +-
pyatspi/value.py | 70 ----
tests/pyatspi/runtests.sh | 3 +-
tests/pyatspi/{testrunner => testrunner.in} | 2 +-
23 files changed, 308 insertions(+), 2315 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 30cc5f5..00d200e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,7 +32,6 @@ AM_CONDITIONAL(ENABLE_TESTING, test x$enable_tests == xyes)
if test "$enable_tests" = "yes"; then
AM_CHECK_PYMOD(dbus, , , [AC_MSG_ERROR(Could not find python module: dbus)])
-AM_CHECK_PYMOD(xlib,,,[AC_MSG_ERROR(Could not find python module: xlib)])
PKG_CHECK_MODULES(DBUS, [dbus-1 >= 1.0])
AC_SUBST(DBUS_LIBS)
@@ -86,6 +85,7 @@ AC_CONFIG_FILES([Makefile
tests/dummyatk/Makefile
tests/data/Makefile
tests/pyatspi/Makefile
+ tests/pyatspi/testrunner
tests/pyatspi/pasytest/Makefile
tests/apps/Makefile
pyatspi/Makefile
diff --git a/pyatspi/Accessibility.py b/pyatspi/Accessibility.py
index ae049d3..343cf86 100644
--- a/pyatspi/Accessibility.py
+++ b/pyatspi/Accessibility.py
@@ -12,29 +12,181 @@
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+from gi.repository import Atspi
+
from registry import *
Registry = Registry()
from constants import *
-from utils import *
-
-from deviceevent import *
-from appevent import *
-
-from accessible import *
-from action import *
-from application import *
-from collection import *
-from component import *
-from document import *
-from editabletext import *
-from hyperlink import *
-from hypertext import *
-from image import *
-from relation import *
from role import *
-from selection import *
from state import *
-from table import *
-from text import *
-from value import *
+from utils import *
+
+def Accessible_getitem(self, i):
+ if i < 0 or i >= self.get_child_count():
+ raise IndexError
+ return self.get_child_at_index(i)
+
+def pointToList(point):
+ return (point.x, point.y)
+
+def rectToList(rect):
+ return (rect.x, rect.y, rect.width, rect.height)
+
+def textAttrToList(ta):
+ return (ta.start_offset, ta.end_offset, ta.text)
+
+def rangeToList(r):
+ return (r.start_offset, r.end_offset, r.text)
+
+def textRangeToList(r):
+ return (r.start_offset, r.end_offset, r.text)
+
+### Accessible ###
+Atspi.Accessible.getChildAtIndex = Atspi.Accessible.get_child_at_index
+Atspi.Accessible.getAttributes = Atspi.Accessible.get_attributes_as_array
+Atspi.Accessible.getApplication = Atspi.Accessible.get_host_application
+Atspi.Accessible.__getitem__ = Accessible_getitem
+Atspi.Accessible.__len__ = Atspi.Accessible.get_child_count
+Atspi.Accessible.__nonzero__ = lambda x: True
+Atspi.Accessible.name = property(fget=Atspi.Accessible.get_name)
+Atspi.Accessible.getRole = Atspi.Accessible.get_role
+
+### action ###
+Atspi.Accessible.queryAction = Atspi.Accessible.get_action
+Atspi.Action.doAction = Atspi.Action.do_action
+Atspi.Action.getDescription = Atspi.Action.get_description
+Atspi.Action.getKeyBinding = Atspi.Action.get_key_binding
+Atspi.Action.getName = Atspi.Action.get_name
+Atspi.Action.get_nActions = Atspi.Action.get_n_actions
+
+### collection ###
+Atspi.Accessible.queryCollection = Atspi.Accessible.get_collection
+Atspi.Collection.isAncesterOf = Atspi.Collection.is_ancestor_of
+Atspi.Collection.createMatchRule = lambda x, s, smt, a, amt, r, rmt, inv: Atspi.MatchRule.new (s, smt, a, amt, i, imt, r, rmt, inv)
+Atspi.Collection.getMatches = Atspi.Collection.get_matches
+Atspi.Collection.getMatchesFrom = Atspi.Collection.get_matches_from
+Atspi.Collection.getMatchesTo = Atspi.Collection.get_matches_to
+Atspi.Collection.getActiveDescendant = Atspi.Collection.get_active_descendant
+
+### component ###
+Atspi.Accessible.queryComponent = Atspi.Accessible.get_component
+Atspi.Component.getAccessibleAtPoint = Atspi.Component.get_accessible_at_point
+Atspi.Component.getAlpha = Atspi.Component.get_alpha
+Atspi.Component.getExtents = lambda x,c: rectToList(Atspi.Component.get_extents(x,c))
+Atspi.Component.getLayer = Atspi.Component.get_layer
+Atspi.Component.getMDIZOrder = Atspi.Component.get_mdi_z_order
+Atspi.Component.getPosition = lambda x,p: pointToList(Atspi.Component.get_position(x,p))
+Atspi.Component.getSize = lambda x: pointToList(Atspi.Component.get_size(x))
+Atspi.Component.grabFocus = Atspi.Component.grab_focus
+
+### document ###
+Atspi.Accessible.queryDocument = Atspi.Accessible.get_document
+Atspi.Document.getAttributevalue = Atspi.Document.get_attribute_value
+Atspi.Document.getAttributes = lambda x: [key + ":" + value for key, value in Atspi.Document.get_attributes (x)]
+Atspi.Document.getLocale = Atspi.Document.get_locale
+
+### editable text ###
+Atspi.Accessible.queryEditableText = Atspi.Accessible.get_editable_text
+Atspi.EditableText.copyText = Atspi.EditableText.copy_text
+Atspi.EditableText.cutText = Atspi.EditableText.cut_text
+Atspi.EditableText.deleteText = Atspi.EditableText.delete_text
+Atspi.EditableText.insertText = Atspi.EditableText.insert_text
+Atspi.EditableText.pasteText = Atspi.EditableText.paste_text
+Atspi.EditableText.setTextContents = Atspi.EditableText.set_text_contents
+
+### hyperlink ###
+Atspi.Hyperlink.getObject = Atspi.Hyperlink.get_object
+Atspi.Hyperlink.getURI = Atspi.Hyperlink.get_uri
+Atspi.Hyperlink.isValid = Atspi.Hyperlink.is_valid
+Atspi.Hyperlink.get_endIndex = Atspi.Hyperlink.get_end_index
+Atspi.Hyperlink.get_nAnchors = Atspi.Hyperlink.get_n_anchors
+Atspi.Hyperlink.get_startIndex = Atspi.Hyperlink.get_start_index
+
+### hypertext ###
+Atspi.Accessible.queryHypertet = Atspi.Accessible.get_hypertext
+Atspi.Hypertext.getLink = Atspi.Hypertext.get_link
+Atspi.Hypertext.getLinkIndex = Atspi.Hypertext.get_link_index
+Atspi.Hypertext.getNLinks = Atspi.Hypertext.get_n_links
+
+### image ###
+Atspi.Accessible.queryImage = Atspi.Accessible.get_image
+Atspi.Image.getImageExtents = lambda x,c: rectToList(Atspi.Image.get_image_extents(x,c))
+Atspi.Image.getImagePosition = lambda x,p: pointToList(Atspi.Image.get_image_position(x,p))
+Atspi.Image.getImageSize = lambda x: pointToList(Atspi.Image.get_image_size(x))
+Atspi.Image.get_imageDescription = Atspi.Image.get_image_description
+Atspi.Image.get_imageLocale = Atspi.Image.get_image_locale
+
+### selection ###
+Atspi.Accessible.querySelection = Atspi.Accessible.get_selection
+Atspi.Selection.clearSelectio = Atspi.Selection.clear_selection
+Atspi.Selection.deselectChild = Atspi.Selection.deselect_child
+Atspi.Selection.deselectSelectedChild = Atspi.Selection.deselect_selected_child
+Atspi.Selection.getSelectedChild = Atspi.Selection.get_selected_child
+Atspi.Selection.isChildSelected = Atspi.Selection.is_child_selected
+Atspi.Selection.selectAll = Atspi.Selection.select_all
+Atspi.Selection.selectChild = Atspi.Selection.select_child
+Atspi.Selection.get_nSelectedChildren = Atspi.Selection.get_n_selected_children
+
+### table ###
+Atspi.Accessible.queryTable = Atspi.Accessible.get_table
+Atspi.Table.addColumnSelection = Atspi.Table.add_column_selection
+Atspi.Table.addRowSelection = Atspi.Table.add_row_selection
+Atspi.Table.getAccessibleAt = Atspi.Table.get_accessible_at
+Atspi.Table.getColumnAtIndex = Atspi.Table.get_column_at_index
+Atspi.Table.getColumnDescription = Atspi.Table.get_column_description
+Atspi.Table.getColumnExtentAt = Atspi.Table.get_column_extent_at
+Atspi.Table.getColumnHeader = Atspi.Table.get_column_header
+Atspi.Table.getIndexAt = Atspi.Table.get_index_at
+Atspi.Table.getRowAtIndex = Atspi.Table.get_row_at_index
+Atspi.Table.getRowColumnExtents = Atspi.Table.get_row_column_extents_at_index
+Atspi.Table.getRowDescription = Atspi.Table.get_row_description
+Atspi.Table.getRowExtentAt = Atspi.Table.get_row_extent_at
+Atspi.Table.getRowHeader = Atspi.Table.get_row_header
+Atspi.Table.getSelectedColumns = Atspi.Table.get_selected_columns
+Atspi.Table.getSelectedRows = Atspi.Table.get_selected_rows
+Atspi.Table.isColumnSelected = Atspi.Table.is_column_selected
+Atspi.Table.isRowSelected = Atspi.Table.is_row_selected
+Atspi.Table.isSelected = Atspi.Table.is_selected
+Atspi.Table.removeColumnSelection = Atspi.Table.remove_column_selection
+Atspi.Table.removeRowSelection = Atspi.Table.remove_row_selection
+Atspi.Table.get_nColumns = Atspi.Table.get_n_columns
+Atspi.Table.get_nRows = Atspi.Table.get_n_rows
+Atspi.Table.get_nSelectedColumns = Atspi.Table.get_n_selected_columns
+Atspi.Table.get_nSelectedRows = Atspi.Table.get_n_selected_rows
+
+### text ###
+Atspi.Accessible.queryText = Atspi.Accessible.get_text
+Atspi.Text.addSelection = Atspi.Text.add_selection
+Atspi.Text.getAttributeRun = lambda x,o,i: textAttrToList (Atspi.Text.get_attribute_run (x,o,i))
+Atspi.Text.getAttributevalue = Atspi.Text.get_attribute_value
+Atspi.Text.getAttributes = lambda x,o: textAttrToList (Atspi.Text.get_attributes (x, o))
+Atspi.Text.getBoundedRanges = Atspi.Text.get_bounded_ranges
+Atspi.Text.getcharacterAtOffset = Atspi.Text.get_character_at_offset
+Atspi.Text.getCharacterExtents = lambda x,c: rectToist(Atspi.Text.get_character_extents(x,c))
+Atspi.Text.getDefaultAttributeSet = lambda x: [key + ":" + value for key, value in Atspi.Text.get_default_attribute_set (x)]
+Atspi.Text.getDefaultAttributes = lambda x: [key + ":" + value for key, value in Atspi.Text.get_default_attributes (x)]
+Atspi.Text.getNSelections = Atspi.Text.get_n_selections
+Atspi.Text.getOffsetAtPoint = Atspi.Text.get_offset_at_point
+Atspi.Text.getRangeExtents = lambda x,c: rectToist(Atspi.Text.get_range_extents(x,c))
+Atspi.Text.getSelection = lambda x,n: rangeToList (Atspi.Text.get_selection (x,n))
+Atspi.Text.getText = Atspi.Text.get_text
+Atspi.Text.getTextAfterOfset = lambda x,o: textRangeToList(Atspi.Text.get_text_after_offset (x,o))
+Atspi.Text.getTextAtOfset = lambda x,o: textRangeToList(Atspi.Text.get_text_at_offset (x,o))
+Atspi.Text.getTextBeforeOfset = lambda x,o: textRangeToList(Atspi.Text.get_text_before_offset (x,o))
+Atspi.Text.removeSelection = Atspi.Text.remove_selection
+Atspi.Text.setCaretOffset = Atspi.Text.set_caret_offset
+Atspi.Text.setSelection = Atspi.Text.set_selection
+Atspi.Text.get_caretOffset = Atspi.Text.get_caret_offset
+Atspi.Text.get_characterCount = Atspi.Text.get_character_count
+
+### value ###
+Atspi.Accessible.queryValue = Atspi.Accessible.get_value
+Atspi.Value.get_currentValue = Atspi.Value.get_current_value
+Atspi.Value.set_currentValue = Atspi.Value.set_current_value
+Atspi.Value.get_maximumValue = Atspi.Value.get_maximum_value
+Atspi.Value.get_minimumIncrement = Atspi.Value.get_minimum_increment
+Atspi.Value.get_minimumValue = Atspi.Value.get_minimum_value
+
+### event ###
+Atspi.Event.host_application = lambda x: x.source.host_application
diff --git a/pyatspi/Makefile.am b/pyatspi/Makefile.am
index f7fe275..b303d68 100644
--- a/pyatspi/Makefile.am
+++ b/pyatspi/Makefile.am
@@ -12,28 +12,17 @@ pyatspi_PYTHON = \
appevent.py \
application.py \
cache.py \
- collection.py \
- component.py \
constants.py \
deviceevent.py \
- document.py \
- editabletext.py \
enum.py \
exceptions.py \
factory.py \
- hyperlink.py \
- hypertext.py \
- image.py \
__init__.py \
interfaces.py \
registry.py \
relation.py \
role.py \
- selection.py \
state.py \
- table.py \
- text.py \
- utils.py \
- value.py
+ utils.py
CLEANFILES = *.pyc
diff --git a/pyatspi/__init__.py b/pyatspi/__init__.py
index 896251c..cad1bb1 100644
--- a/pyatspi/__init__.py
+++ b/pyatspi/__init__.py
@@ -1,4 +1,4 @@
-#Copyright (C) 2008 Codethink Ltd
+#Copyright (C) 210 Novell, Inc.
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
@@ -38,19 +38,8 @@ if useCorba:
else:
__version__ = (1, 9, 0)
- import constants
- from Accessibility import *
+# TODO: Look at pyatspi2 __init__.py; recreate namespace pollution, etc.
- from dbus.mainloop.glib import DBusGMainLoop
- DBusGMainLoop (set_as_default=True)
- del DBusGMainLoop
+from gi.repository import Atspi
- #This is a re-creation of the namespace pollution implemented
- #by PyORBit.
- import Accessibility
- sys.modules['Accessibility'] = Accessibility
-
- import appevent as event
-
-del sys
-del useCorba
+from Accessibility import *
diff --git a/pyatspi/cache.py b/pyatspi/cache.py
index 3bfb0f7..9052ada 100644
--- a/pyatspi/cache.py
+++ b/pyatspi/cache.py
@@ -219,12 +219,6 @@ class DesktopCacheManager (object):
app = self._application_list[data[0]]
app._remove_object(data)
- def getBusAddress(self, bus_name):
- try:
- return self._application_list[bus_name].busAddress
- except KeyError:
- return None
-
class ApplicationCacheManager (object):
"""
The application cache manager is responsible for keeping the cache up to date
@@ -245,15 +239,6 @@ class ApplicationCacheManager (object):
self._cache = cache
self._bus_name = bus_name
- try:
- app_obj = bus.get_object (bus_name, ATSPI_ROOT_PATH, introspect=False)
- app_itf = dbus.Interface (app_obj, ATSPI_APPLICATION)
- self.busAddress = app_itf.GetApplicationBusAddress()
- if self.busAddress == "":
- self.busAddress = None
- except:
- self.busAddress = None
-
cache_obj = bus.get_object (bus_name, _ATSPI_CACHE_PATH, introspect=False)
cache_itf = dbus.Interface (cache_obj, _ATSPI_CACHE_INTERFACE)
try:
@@ -370,6 +355,4 @@ class AccessibleCache (dict):
def __call__ (self, bus_name, object_path):
return self[(bus_name, object_path)]
- def getBusAddress(self, bus_name):
- return self._manager.getBusAddress(bus_name)
#END----------------------------------------------------------------------------
diff --git a/pyatspi/constants.py b/pyatspi/constants.py
index 7b53230..c5e14e4 100644
--- a/pyatspi/constants.py
+++ b/pyatspi/constants.py
@@ -143,5 +143,3 @@ EVENT_TREE = {
'focus' :
['focus:']
}
-
-from Accessibility import *
diff --git a/pyatspi/factory.py b/pyatspi/factory.py
index 8181028..e53d153 100644
--- a/pyatspi/factory.py
+++ b/pyatspi/factory.py
@@ -75,13 +75,14 @@ class AccessibleFactory (object):
return None
if dbus_object == None:
- busAddress = self._cache.getBusAddress (name)
- if busAddress is not None:
- busAddress = str(busAddress)
+ 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)
- else:
- bus = self._connection
- dbus_object = bus.get_object (name, path, introspect=False)
+ 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)
diff --git a/pyatspi/registry.py b/pyatspi/registry.py
index 6f5bb11..d4b034d 100644
--- a/pyatspi/registry.py
+++ b/pyatspi/registry.py
@@ -1,3 +1,4 @@
+#Copyright (C) 2010 Novell, Inc.
#Copyright (C) 2008 Codethink Ltd
#copyright: Copyright (c) 2005, 2007 IBM Corporation
@@ -21,33 +22,16 @@
#------------------------------------------------------------------------------
-import dbus
-import os as _os
-import Queue
-import threading
-import time
-import traceback
-
-from busutils import *
-
-from factory import AccessibleFactory
-from appevent import _ApplicationEventRegister, _NullApplicationEventRegister
-from deviceevent import _DeviceEventRegister, _NullDeviceEventRegister
-from cache import AccessibleCache
-
-from deviceevent import KEY_PRESSED_EVENT as _KEY_PRESSED_EVENT
-from deviceevent import KEY_RELEASED_EVENT as _KEY_RELEASED_EVENT
-
-from interfaces import ATSPI_REGISTRY_NAME as _ATSPI_REGISTRY_NAME
-from interfaces import ATSPI_ROOT_PATH as _ATSPI_ROOT_PATH
-from interfaces import ATSPI_DESKTOP as _ATSPI_DESKTOP
-
__all__ = ["Registry",
"MAIN_LOOP_GLIB",
"MAIN_LOOP_NONE",
"set_default_registry"]
+import os as _os
import gobject
+from gi.repository import Atspi
+from gi.repository import GObject
+import time
#------------------------------------------------------------------------------
@@ -67,17 +51,17 @@ class Registry(object):
reference to the Accessibility.Registry singleton. Doing so is harmless and
has no point.
- @ivar async: Should event dispatch to local listeners be decoupled from event
+ @@ivar async: Should event dispatch to local listeners be decoupled from event
receiving from the registry?
- @type async: boolean
- @ivar reg: Reference to the real, wrapped registry object
- @type reg: Accessibility.Registry
- @ivar dev: Reference to the device controller
- @type dev: Accessibility.DeviceEventController
- @ivar clients: Map of event names to client listeners
- @type clients: dictionary
- @ivar observers: Map of event names to AT-SPI L{_Observer} objects
- @type observers: dictionary
+ @@type async: boolean
+ @@ivar reg: Reference to the real, wrapped registry object
+ @@type reg: Accessibility.Registry
+ @@ivar dev: Reference to the device controller
+ @@type dev: Accessibility.DeviceEventController
+ @@ivar clients: Map of event names to client listeners
+ @@type clients: dictionary
+ @@ivar observers: Map of event names to AT-SPI L{_Observer} objects
+ @@type observers: dictionary
"""
__shared_state = {}
@@ -100,8 +84,8 @@ class Registry(object):
def __call__(self):
"""
- @return: This instance of the registry
- @rtype: L{Registry}
+ @@return: This instance of the registry
+ @@rtype: L{Registry}
"""
return self
@@ -116,48 +100,24 @@ class Registry(object):
This function should be called before pyatspi is used if you
wish to change these defaults.
- @param main_loop_type: 'GLib', 'None' or 'Qt'. If 'None' is selected then caching
+ @@param main_loop_type: 'GLib', 'None' or 'Qt'. If 'None' is selected then caching
is disabled.
- @param use_registry: Whether to connect to a registry daemon for device events.
+ @@param use_registry: Whether to connect to a registry daemon for device events.
Without this the application to connect to must be declared in the
app_name parameter.
- @param app_name: D-Bus name of the application to connect to when not using the registry daemon.
+ @@param app_name: D-Bus name of the application to connect to when not using the registry daemon.
"""
- self.queue = Queue.Queue()
-
- _os.environ["AT_SPI_CLIENT"] = "1"
-
- # Set up the cache
- cache = None
- if main_loop_type == MAIN_LOOP_GLIB:
- cache = AccessibleCache (app_name)
-
- factory = AccessibleFactory(cache)
-
self.has_implementations = True
- # Set up the device event controllers
- _connection = SyncAccessibilityBus (self)
- _bus_object = _connection.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
-
- if app_name:
- self.device_event_register = _NullDeviceEventRegister()
- self.app_event_register = _NullApplicationEventRegister()
-
- name = _bus_object.GetNameOwner (app_name)
- self.desktop = factory (name, _ATSPI_ROOT_PATH, _ATSPI_DESKTOP)
- else:
- self.device_event_register = _DeviceEventRegister()
- self.app_event_register = _ApplicationEventRegister(factory)
-
- name = _bus_object.GetNameOwner (_ATSPI_REGISTRY_NAME)
- self.desktop = factory (name, _ATSPI_ROOT_PATH, _ATSPI_DESKTOP)
+ # TODO: Move to libatspi
+ _os.environ["AT_SPI_CLIENT"] = "1"
self.async = False # not fully supported yet
self.started = False
+ self.event_listeners = dict()
def _set_default_registry (self):
self._set_registry (MAIN_LOOP_GLIB)
@@ -166,31 +126,22 @@ class Registry(object):
"""
Enter the main loop to start receiving and dispatching events.
- @param async: Should event dispatch be asynchronous (decoupled) from
+ @@param async: Should event dispatch be asynchronous (decoupled) from
event receiving from the AT-SPI registry?
- @type async: boolean
- @param gil: Add an idle callback which releases the Python GIL for a few
+ @@type async: boolean
+ @@param gil: Add an idle callback which releases the Python GIL for a few
milliseconds to allow other threads to run? Necessary if other threads
will be used in this process.
- Note - No Longer used.
- @type gil: boolean
+ @@type gil: boolean
"""
if not self.has_implementations:
self._set_default_registry ()
- self.acquireLock()
- self.thread = threading.currentThread()
self.started = True
- def idleReleaseLock():
- self.releaseLock()
- return False
-
- gobject.idle_add(idleReleaseLock)
-
if gil:
def releaseGIL():
try:
- time.sleep(1e-5)
+ time.sleep(1e-2)
except KeyboardInterrupt, e:
# store the exception for later
releaseGIL.keyboard_exception = e
@@ -198,19 +149,16 @@ class Registry(object):
return True
# make room for an exception if one occurs during the
releaseGIL.keyboard_exception = None
- i = gobject.idle_add(releaseGIL)
-
- self.main_loop.run()
- self.started = False
- gobject.source_remove(i)
+ i = GObject.idle_add(releaseGIL)
+ Atspi.event_main()
+ GObject.source_remove(i)
if releaseGIL.keyboard_exception is not None:
# raise an keyboard exception we may have gotten earlier
raise releaseGIL.keyboard_exception
else:
- try:
- self.main_loop.run()
- except KeyboardInterrupt:
- pass
+ atspi.event_main()
+
+ self.started = False
def stop(self, *args):
"""
@@ -218,17 +166,14 @@ class Registry(object):
"""
if not self.has_implementations:
self._set_default_registry ()
- def main_quit():
- self.main_loop.quit()
- return False
- gobject.idle_add(main_quit)
+ Atspi.event_quit()
def getDesktopCount(self):
"""
Gets the number of available desktops.
- @return: Number of desktops
- @rtype: integer
+ @@return: Number of desktops
+ @@rtype: integer
"""
return 1
@@ -236,14 +181,14 @@ class Registry(object):
"""
Gets a reference to the i-th desktop.
- @param i: Which desktop to get
- @type i: integer
- @return: Desktop reference
- @rtype: Accessibility.Desktop
+ @@param i: Which desktop to get
+ @@type i: integer
+ @@return: Desktop reference
+ @@rtype: Accessibility.Desktop
"""
if not self.has_implementations:
self._set_default_registry ()
- return self.desktop
+ return Atspi.get_desktop(i)
def registerEventListener(self, client, *names):
"""
@@ -260,14 +205,19 @@ class Registry(object):
To ensure the client is properly garbage collected, call
L{deregisterEventListener}.
- @param client: Callable to be invoked when the event occurs
- @type client: callable
- @param names: List of full or partial event names
- @type names: list of string
+ @@param client: Callable to be invoked when the event occurs
+ @@type client: callable
+ @@param names: List of full or partial event names
+ @@type names: list of string
"""
if not self.has_implementations:
self._set_default_registry ()
- self.app_event_register.registerEventListener (client, *names)
+ try:
+ listener = self.event_listeners[client]
+ except:
+ listener = self.event_listeners[client] = Atspi.EventListener.new_simple(client)
+ for name in names:
+ Atspi.EventListener.register (listener, name)
def deregisterEventListener(self, client, *names):
"""
@@ -278,20 +228,29 @@ class Registry(object):
This method must be called to ensure a client registered by
L{registerEventListener} is properly garbage collected.
- @param client: Client callback to remove
- @type client: callable
- @param names: List of full or partial event names
- @type names: list of string
- @return: Were event names specified for which the given client was not
+ @@param client: Client callback to remove
+ @@type client: callable
+ @@param names: List of full or partial event names
+ @@type names: list of string
+ @@return: Were event names specified for which the given client was not
registered?
- @rtype: boolean
+ @@rtype: boolean
"""
if not self.has_implementations:
self._set_default_registry ()
- self.app_event_register.deregisterEventListener (client, *names)
+ try:
+ listener = self.event_listeners[client]
+ except:
+ return
+ for name in names:
+ Atspi.EventListener.deregister(listener, name)
# -------------------------------------------------------------------------------
+ # TODO: Remove this hack
+ _KEY_PRESSED_EVENT=1
+ _KEY_RELEASED_EVENT=2
+
def registerKeystrokeListener(self,
client,
key_set=[],
@@ -303,40 +262,40 @@ class Registry(object):
"""
Registers a listener for key stroke events.
- @param client: Callable to be invoked when the event occurs
- @type client: callable
- @param key_set: Set of hardware key codes to stop monitoring. Leave empty
+ @@param client: Callable to be invoked when the event occurs
+ @@type client: callable
+ @@param key_set: Set of hardware key codes to stop monitoring. Leave empty
to indicate all keys.
- @type key_set: list of integer
- @param mask: When the mask is None, the codes in the key_set will be
+ @@type key_set: list of integer
+ @@param mask: When the mask is None, the codes in the key_set will be
monitored only when no modifier is held. When the mask is an
integer, keys in the key_set will be monitored only when the modifiers in
the mask are held. When the mask is an iterable over more than one
integer, keys in the key_set will be monitored when any of the modifier
combinations in the set are held.
- @type mask: integer, iterable, None
- @param kind: Kind of events to watch, KEY_PRESSED_EVENT or
+ @@type mask: integer, iterable, None
+ @@param kind: Kind of events to watch, KEY_PRESSED_EVENT or
KEY_RELEASED_EVENT.
- @type kind: list
- @param synchronous: Should the callback notification be synchronous, giving
+ @@type kind: list
+ @@param synchronous: Should the callback notification be synchronous, giving
the client the chance to consume the event?
- @type synchronous: boolean
- @param preemptive: Should the callback be allowed to preempt / consume the
+ @@type synchronous: boolean
+ @@param preemptive: Should the callback be allowed to preempt / consume the
event?
- @type preemptive: boolean
- @param global_: Should callback occur even if an application not supporting
+ @@type preemptive: boolean
+ @@param global_: Should callback occur even if an application not supporting
AT-SPI is in the foreground? (requires xevie)
- @type global_: boolean
+ @@type global_: boolean
"""
if not self.has_implementations:
self._set_default_registry ()
- self.device_event_register.registerKeystrokeListener (client,
- key_set,
- mask,
- kind,
- synchronous,
- preemptive,
- global_)
+ Atspi.register_keystroke_listener(client,
+ key_set,
+ mask,
+ kind,
+ synchronous,
+ preemptive,
+ global_)
def deregisterKeystrokeListener(self,
client,
@@ -346,50 +305,28 @@ class Registry(object):
"""
Deregisters a listener for key stroke events.
- @param client: Callable to be invoked when the event occurs
- @type client: callable
- @param key_set: Set of hardware key codes to stop monitoring. Leave empty
+ @@param client: Callable to be invoked when the event occurs
+ @@type client: callable
+ @@param key_set: Set of hardware key codes to stop monitoring. Leave empty
to indicate all keys.
- @type key_set: list of integer
- @param mask: When the mask is None, the codes in the key_set will be
+ @@type key_set: list of integer
+ @@param mask: When the mask is None, the codes in the key_set will be
monitored only when no modifier is held. When the mask is an
integer, keys in the key_set will be monitored only when the modifiers in
the mask are held. When the mask is an iterable over more than one
integer, keys in the key_set will be monitored when any of the modifier
combinations in the set are held.
- @type mask: integer, iterable, None
- @param kind: Kind of events to stop watching, KEY_PRESSED_EVENT or
+ @@type mask: integer, iterable, None
+ @@param kind: Kind of events to stop watching, KEY_PRESSED_EVENT or
KEY_RELEASED_EVENT.
- @type kind: list
- @raise KeyError: When the client isn't already registered for events
+ @@type kind: list
+ @@raise KeyError: When the client isn't already registered for events
"""
if not self.has_implementations:
self._set_default_registry ()
- self.device_event_register.deregisterKeystrokeListener (client, key_set, mask, kind)
-
- # -------------------------------------------------------------------------------
-
- def enqueueEvent (self, handler, event):
- """
- Queue an event for later delivery.
- """
- self.queue.put((handler, event))
-
- def pumpQueuedEvents (self):
- """
- Dispatch events that have been queued.
- """
- while (not(self.queue.empty())):
- (handler, event) = self.queue.get()
- handler(event)
-
- def flushEvents (self):
- """
- Empty the event queue.
- """
- self.queue = Queue.QUeue()
+ Atspi.deregister_keystroke_listener (client, key_set, mask, kind)
- # -------------------------------------------------------------------------------
+ # TODO: enqueueEvent, etc?
def generateKeyboardEvent(self, keycode, keysym, kind):
"""
@@ -398,16 +335,16 @@ class Registry(object):
required and should be one of the KEY_PRESS, KEY_RELEASE, KEY_PRESSRELEASE,
KEY_SYM, or KEY_STRING.
- @param keycode: Hardware keycode or None
- @type keycode: integer
- @param keysym: Symbolic key string or None
- @type keysym: string
- @param kind: Kind of event to synthesize
- @type kind: integer
+ @@param keycode: Hardware keycode or None
+ @@type keycode: integer
+ @@param keysym: Symbolic key string or None
+ @@type keysym: string
+ @@param kind: Kind of event to synthesize
+ @@type kind: integer
"""
if not self.has_implementations:
self._set_default_registry ()
- self.device_event_register.generateKeyboardEvent (keycode, keysym, kind)
+ Atspi.generate_keyboard_event (keycode, keysym, kind)
def generateMouseEvent(self, x, y, name):
"""
@@ -416,34 +353,16 @@ class Registry(object):
(button 1 press), MOUSE_REL (relative motion), MOUSE_B3D (butten 3
double-click).
- @param x: Horizontal coordinate, usually left-hand oriented
- @type x: integer
- @param y: Vertical coordinate, usually left-hand oriented
- @type y: integer
- @param name: Name of the event to generate
- @type name: string
+ @@param x: Horizontal coordinate, usually left-hand oriented
+ @@type x: integer
+ @@param y: Vertical coordinate, usually left-hand oriented
+ @@type y: integer
+ @@param name: Name of the event to generate
+ @@type name: string
"""
if not self.has_implementations:
self._set_default_registry ()
- self.device_event_register.generateMouseEvent (x, y, name)
-
- def acquireLock(self):
- """
- Acquire a lock, creating the registry irst if needed.
- """
- try:
- self.lock.acquire()
- except AttributeError:
- self.lock = threading.RLock()
- self.lock.acquire()
-
- def releaseLock(self):
- """
- Release the lock
- """
- self.lock.release()
-
-#------------------------------------------------------------------------------
+ Atspi.generate_mouse_event (x, y, name)
def set_default_registry (main_loop, app_name=None):
registry = Registry ()
diff --git a/pyatspi/state.py b/pyatspi/state.py
index e6b4ed4..cc7ef98 100644
--- a/pyatspi/state.py
+++ b/pyatspi/state.py
@@ -19,6 +19,7 @@
#authors: Peter Parente, Mark Doffman
+from gi.repository import Atspi
from enum import Enum as _Enum
#------------------------------------------------------------------------------
@@ -156,120 +157,4 @@ def _marshal_state_set(bitfield):
#------------------------------------------------------------------------------
-class StateSet(object):
- """
- The StateSet object implements a wrapper around a
- bitmap of Accessible states.
-
- The StateSet object is the instantaneous state of
- the Accessible object and is not updated with its
- container Accessible. This behaviour is different
- to the CORBA version of AT-SPI
- """
- def __init__(self, *states):
- """
- Initializes the state set with the given states.
-
- @param states: States to add immediately
- @type states: list
- """
- self.states = set()
- map(self.add, states)
-
- def contains(self, state):
- """
- Checks if this StateSet contains the given state.
-
- @param state: State to check
- @type state: Accessibility.StateType
- @return: True if the set contains the given state
- @rtype: boolean
- """
- return state in self.states
-
- def add(self, *states):
- """
- Adds states to this set.
-
- @param states: State(s) to add
- @type states: Accessibility.StateType
- """
- for state in states:
- self.states.add(state)
-
- def remove(self, state):
- """
- Removes states from this set.
-
- @param states: State(s) to remove
- @type states: Accessibility.StateType
- """
- self.states.remove(state)
-
- def equals(self, state_set):
- """
- Checks if this StateSet contains exactly the same members as the given
- StateSet.
-
- @param state_set: Another set
- @type state_set: Accessibility.StateSet
- @return: Are the sets equivalent in terms of their contents?
- @rtype: boolean
- """
- return set(state_set.getStates()) == self.states
-
- def compare(self, state_set):
- """
- Finds the symmetric difference between this state set andthe one provided,
- and returns it as a new StateSet.
-
- @note: This does not use L{_StateSetImpl.compare} which cannot be
- implemented at this time
- @param state_set: Set to compare against
- @type state_set: Accessibility.StateSet
- @return: Proxy for the new set
- @rtype: L{StateSet}
- """
- a = set(self.getStates())
- b = set(state_set.getStates())
- diff = a.symmetric_difference(b)
- return StateSet(*diff)
-
- def isEmpty(self):
- """
- Checks if this StateSet is empty.
-
- @return: Is it empty?
- @rtype: boolean
- """
- return len(self.states) == 0
-
- def getStates(self):
- """
- Gets the sequence of all states in this set.
-
- @return: List of states
- @rtype: list
- """
- return list(self.states)
-
- def raw(self):
- """
- Gets the sequence of all states in this set as a pair of
- 32-bit flags, suitable for transmitting via dbus..
-
- @return: List of two 32-bit flags representing the states
- @rtype: list
- """
- lower = upper = 0
- for i in range (0, 32):
- if (self.contains(i)):
- lower |= (1 << i)
- for i in range (32, 64):
- if (self.contains(i)):
- upper |= (1 << (i - 32))
- return [lower, upper]
-
- def unref(self):
- pass
-#END----------------------------------------------------------------------------
+StateSet = Atspi.StateSet
diff --git a/pyatspi/utils.py b/pyatspi/utils.py
index 199ae32..88731c1 100644
--- a/pyatspi/utils.py
+++ b/pyatspi/utils.py
@@ -19,11 +19,11 @@
#authors: Peter Parente, Mark Doffman
-import relation
-import state
+#import relation
+#import state
import registry
-from deviceevent import *
+#from deviceevent import *
__all__ = [
"setCacheLevel",
@@ -36,7 +36,7 @@ __all__ = [
"stringToConst",
"stateToString",
"relationToString",
- "allModifiers",
+ #"allModifiers",
"findDescendant",
"findAllDescendants",
"findAncestor",
diff --git a/tests/pyatspi/runtests.sh b/tests/pyatspi/runtests.sh
index 18429d2..a8bff43 100755
--- a/tests/pyatspi/runtests.sh
+++ b/tests/pyatspi/runtests.sh
@@ -7,7 +7,8 @@ export TEST_APPLICATION=$top_builddir/tests/apps/test-application
run()
{
- $PYTHON $top_srcdir/tests/pyatspi/testrunner -l $1 -m $2 -n $3
+ chmod a+x $top_srcdir/tests/pyatspi/testrunner
+ $top_srcdir/tests/pyatspi/testrunner -l $1 -m $2 -n $3
result=$?
if [ $result -ne 0 ]; then
ret=$result
diff --git a/tests/pyatspi/testrunner b/tests/pyatspi/testrunner.in
similarity index 99%
rename from tests/pyatspi/testrunner
rename to tests/pyatspi/testrunner.in
index 6ff15c5..e6dd9b2 100755
--- a/tests/pyatspi/testrunner
+++ b/tests/pyatspi/testrunner.in
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#! PYTHON@
import gobject
import dbus
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]