From 22d91431a33da3a4dbe06bb322fafafe23feb347 Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Thu, 23 Apr 2009 09:54:30 +0100 Subject: [PATCH] 2009-04-22 Mark Doffman Add a cache in each accessible object for the relation set. Add a client side implementation of getRoleName. --- pyatspi/accessible.py | 20 ++++++++--- pyatspi/base.py | 12 +++++++ pyatspi/constants.py | 2 +- pyatspi/desktop.py | 3 ++ pyatspi/role.py | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 5 deletions(-) diff --git a/pyatspi/accessible.py b/pyatspi/accessible.py index ab590bf..8055e00 100644 --- a/pyatspi/accessible.py +++ b/pyatspi/accessible.py @@ -17,7 +17,7 @@ from base import BaseProxy, Enum from factory import accessible_factory from state import StateSet, _marshal_state_set from relation import _marshal_relation_set -from role import Role +from role import Role, ROLE_NAMES __all__ = [ "LOCALE_TYPE", @@ -92,6 +92,8 @@ class Accessible(BaseProxy): whether or not they actually have children. """ + _relation_set = None + def __nonzero__(self): return True @@ -182,9 +184,13 @@ class Accessible(BaseProxy): objects. @return : a RelationSet defining this object's relationships. """ - func = self.get_dbus_method("getRelationSet", dbus_interface=ATSPI_ACCESSIBLE) - relation_set = func() - return _marshal_relation_set(self._cache, self._app_name, relation_set) + if self._relation_set: + return self._relation_set + else: + func = self.get_dbus_method("getRelationSet", dbus_interface=ATSPI_ACCESSIBLE) + relation_set = func() + self._relation_set = _marshal_relation_set(self._cache, self._app_name, relation_set) + return self._relation_set def getRole(self): """ @@ -200,8 +206,11 @@ class Accessible(BaseProxy): @return : a UTF-8 string indicating the type of UI role played by this object. """ + """ func = self.get_dbus_method("getRoleName", dbus_interface=ATSPI_ACCESSIBLE) return func() + """ + return ROLE_NAMES[self.cached_data.role] def getState(self): """ @@ -264,6 +273,9 @@ class Accessible(BaseProxy): """ parent = property(fget=get_parent, doc=_parentDoc) + def flushCache(self): + self._relation_set = None + # Register the accessible class with the factory. accessible_factory.register_accessible_class(ATSPI_ACCESSIBLE, Accessible) diff --git a/pyatspi/base.py b/pyatspi/base.py index 9a675d5..607cf2f 100644 --- a/pyatspi/base.py +++ b/pyatspi/base.py @@ -46,6 +46,15 @@ class Enum(dbus.UInt32): def __str__(self): return self._enum_lookup[int(self)] + def __eq__(self, other): + if int(self) == int(other): + return True + else: + return False + + def __hash__(self): + return int(self) + #------------------------------------------------------------------------------ @@ -186,4 +195,7 @@ class BaseProxy(object): "%s not supported by accessible object at path %s" % (interface, self._acc_path)) + def flushCache(self): + pass + #END---------------------------------------------------------------------------- diff --git a/pyatspi/constants.py b/pyatspi/constants.py index eab731c..b6c694a 100644 --- a/pyatspi/constants.py +++ b/pyatspi/constants.py @@ -45,7 +45,7 @@ CACHE_EVENTS = ['object:property-change:accessible-name', 'object:property-change:accessible-role', 'object:property-change:accessible-parent'] -CACHE_PROPERTIES = "" +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 diff --git a/pyatspi/desktop.py b/pyatspi/desktop.py index 3f5aac7..2fcf0dc 100644 --- a/pyatspi/desktop.py +++ b/pyatspi/desktop.py @@ -358,4 +358,7 @@ class Desktop(object): "%s not supported by accessible object at path %s" % (interface, self._acc_path)) + def flushCache(self): + pass + #END---------------------------------------------------------------------------- diff --git a/pyatspi/role.py b/pyatspi/role.py index b4fe24f..a7dac27 100644 --- a/pyatspi/role.py +++ b/pyatspi/role.py @@ -203,4 +203,95 @@ ROLE_UNKNOWN = Role(67) ROLE_VIEWPORT = Role(68) ROLE_WINDOW = Role(69) +ROLE_NAMES = { + ROLE_INVALID:'invalid', + ROLE_ACCELERATOR_LABEL:'accelerator label', + ROLE_ALERT:'alert', + ROLE_ANIMATION:'animation', + ROLE_ARROW:'arrow', + ROLE_CALENDAR:'calendar', + ROLE_CANVAS:'canvas', + ROLE_CHECK_BOX:'check box', + ROLE_CHECK_MENU_ITEM:'check menu item', + ROLE_COLOR_CHOOSER:'color chooser', + ROLE_COLUMN_HEADER:'column header', + ROLE_COMBO_BOX:'combo box', + ROLE_DATE_EDITOR:'dateeditor', + ROLE_DESKTOP_ICON:'desktop icon', + ROLE_DESKTOP_FRAME:'desktop frame', + ROLE_DIAL:'dial', + ROLE_DIALOG:'dialog', + ROLE_DIRECTORY_PANE:'directory pane', + ROLE_DRAWING_AREA:'drawing area', + ROLE_FILE_CHOOSER:'file chooser', + ROLE_FILLER:'filler', + ROLE_FONT_CHOOSER:'font chooser', + ROLE_FRAME:'frame', + ROLE_GLASS_PANE:'glass pane', + ROLE_HTML_CONTAINER:'html container', + ROLE_ICON:'icon', + ROLE_IMAGE:'image', + ROLE_INTERNAL_FRAME:'internal frame', + ROLE_LABEL:'label', + ROLE_LAYERED_PANE:'layered pane', + ROLE_LIST:'list', + ROLE_LIST_ITEM:'list item', + ROLE_MENU:'menu', + ROLE_MENU_BAR:'menu bar', + ROLE_MENU_ITEM:'menu item', + ROLE_OPTION_PANE:'option pane', + ROLE_PAGE_TAB:'page tab', + ROLE_PAGE_TAB_LIST:'page tab list', + ROLE_PANEL:'panel', + ROLE_PASSWORD_TEXT:'password text', + ROLE_POPUP_MENU:'popup menu', + ROLE_PROGRESS_BAR:'progress bar', + ROLE_PUSH_BUTTON:'push button', + ROLE_RADIO_BUTTON:'radio button', + ROLE_RADIO_MENU_ITEM:'radio menu item', + ROLE_ROOT_PANE:'root pane', + ROLE_ROW_HEADER:'row header', + ROLE_SCROLL_BAR:'scroll bar', + ROLE_SCROLL_PANE:'scroll pane', + ROLE_SEPARATOR:'separator', + ROLE_SLIDER:'slider', + ROLE_SPLIT_PANE:'split pane', + ROLE_SPIN_BUTTON:'spin button', + ROLE_STATUS_BAR:'status bar', + ROLE_TABLE:'table', + ROLE_TABLE_CELL:'table cell', + ROLE_TABLE_COLUMN_HEADER:'table column header', + ROLE_TABLE_ROW_HEADER:'table row header', + ROLE_TEAROFF_MENU_ITEM:'tear off menu item', + ROLE_TERMINAL:'terminal', + ROLE_TEXT:'text', + ROLE_TOGGLE_BUTTON:'toggle button', + ROLE_TOOL_BAR:'tool bar', + ROLE_TOOL_TIP:'tool tip', + ROLE_TREE:'tree', + ROLE_TREE_TABLE:'tree table', + ROLE_UNKNOWN:'unknown', + ROLE_VIEWPORT:'viewport', + ROLE_WINDOW:'window', + ROLE_HEADER:'header', + ROLE_FOOTER:'footer', + ROLE_PARAGRAPH:'paragraph', + ROLE_RULER:'ruler', + ROLE_APPLICATION:'application', + ROLE_AUTOCOMPLETE:'autocomplete', + ROLE_EDITBAR:'edit bar', + ROLE_EMBEDDED:'embedded component', + ROLE_ENTRY:'entry', + ROLE_CHART:'chart', + ROLE_CAPTION:'caption', + ROLE_DOCUMENT_FRAME:'document frame', + ROLE_HEADING:'heading', + ROLE_PAGE:'page', + ROLE_SECTION:'section', + ROLE_REDUNDANT_OBJECT:'redundant object', + ROLE_FORM:'form', + ROLE_LINK:'link', + ROLE_INPUT_METHOD_WINDOW:'input method window', +} + #END---------------------------------------------------------------------------- -- 2.7.4