1 #Copyright (C) 2008 Codethink Ltd
3 #This library is free software; you can redistribute it and/or
4 #modify it under the terms of the GNU Lesser General Public
5 #License version 2 as published by the Free Software Foundation.
7 #This program is distributed in the hope that it will be useful,
8 #but WITHOUT ANY WARRANTY; without even the implied warranty of
9 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 #GNU General Public License for more details.
11 #You should have received a copy of the GNU Lesser General Public License
12 #along with this program; if not, write to the Free Software
13 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 from base import BaseProxy, Enum
17 from factory import create_accessible, add_accessible_class
18 from stateset import StateSet, _marshal_state_set
19 from relation import _marshal_relation_set
23 "LOCALE_TYPE_COLLATE",
25 "LOCALE_TYPE_MESSAGES",
26 "LOCALE_TYPE_MONETARY",
27 "LOCALE_TYPE_NUMERIC",
33 #------------------------------------------------------------------------------
35 class LOCALE_TYPE(Enum):
37 0:'LOCALE_TYPE_MESSAGES',
38 1:'LOCALE_TYPE_COLLATE',
39 2:'LOCALE_TYPE_CTYPE',
40 3:'LOCALE_TYPE_MONETARY',
41 4:'LOCALE_TYPE_NUMERIC',
45 LOCALE_TYPE_COLLATE = LOCALE_TYPE(1)
46 LOCALE_TYPE_CTYPE = LOCALE_TYPE(2)
47 LOCALE_TYPE_MESSAGES = LOCALE_TYPE(0)
48 LOCALE_TYPE_MONETARY = LOCALE_TYPE(3)
49 LOCALE_TYPE_NUMERIC = LOCALE_TYPE(4)
50 LOCALE_TYPE_TIME = LOCALE_TYPE(5)
52 #------------------------------------------------------------------------------
54 class BoundingBox(list):
55 def __new__(cls, x, y, width, height):
56 list.__new__(cls, (x, y, width, height))
57 def __init__(self, x, y, width, height):
58 list.__init__(self, (x, y, width, height))
62 def _set_x(self, val):
64 x = property(fget=_get_x, fset=_set_x)
67 def _set_y(self, val):
69 y = property(fget=_get_y, fset=_set_y)
72 def _set_width(self, val):
74 width = property(fget=_get_width, fset=_set_width)
75 def _get_height(self):
77 def _set_height(self, val):
79 height = property(fget=_get_height, fset=_set_height)
81 #------------------------------------------------------------------------------
83 class Accessible(BaseProxy):
85 The base interface which is implemented by all accessible objects.
86 All objects support interfaces for querying their contained
87 'children' and position in the accessible-object hierarchy,
88 whether or not they actually have children.
91 def getApplication(self):
93 Get the containing Application for this object.
94 @return the Application instance to which this object belongs.
96 application_root = self._cache[self._app_name]._get_root()
97 #TODO Set the desktop object as the parent of this.
98 return create_accessible(self._cache,
101 interfaces.ATSPI_APPLICATION,
102 connection=self._cache._connection)
104 def getAttributes(self):
106 Get a list of properties applied to this object as a whole, as
107 an AttributeSet consisting of name-value pairs. As such these
108 attributes may be considered weakly-typed properties or annotations,
109 as distinct from the strongly-typed interface instance data declared
110 using the IDL "attribute" keyword.
111 Not all objects have explicit "name-value pair" AttributeSet
113 Attribute names and values may have any UTF-8 string value, however
114 where possible, in order to facilitate consistent use and exposure
115 of "attribute" properties by applications and AT clients, attribute
116 names and values should chosen from a publicly-specified namespace
118 Where possible, the names and values in the name-value pairs
119 should be chosen from well-established attribute namespaces using
120 standard semantics. For example, attributes of Accessible objects
121 corresponding to XHTML content elements should correspond to
122 attribute names and values specified in the w3c XHTML specification,
123 at http://www.w3.org/TR/xhtml2, where such values are not already
124 exposed via a more strongly-typed aspect of the AT-SPI API. Metadata
125 names and values should be chosen from the 'Dublin Core' Metadata
126 namespace using Dublin Core semantics: http://dublincore.org/dcregistry/
127 Similarly, relevant structural metadata should be exposed using
128 attribute names and values chosen from the CSS2 and WICD specification:
129 http://www.w3.org/TR/1998/REC-CSS2-19980512 WICD (http://www.w3.org/TR/2005/WD-WICD-20051121/).
131 @return : An AttributeSet encapsulating any "attribute values"
132 currently defined for the object. An attribute set is a list of strings
133 with each string comprising an name-value pair format 'name:value'.
135 func = self.get_dbus_method("getAttributes")
138 def getChildAtIndex(self, index):
140 Get the accessible child of this object at index.
142 an in parameter indicating which child is requested (zero-indexed).
143 @return : the 'nth' Accessible child of this object.
145 path = self.cached_data.children[index]
146 return create_accessible(self._cache,
149 interfaces.ATSPI_ACCESSIBLE,
150 connection=self._cache._connection)
152 def getIndexInParent(self):
154 Get the index of this object in its parent's child list.
155 @return : a long integer indicating this object's index in the
158 for i in range(0, self.parent.childCount):
159 child = self.parent.getChildAtIndex(i)
160 if self.isEqual(child):
162 raise AccessibleObjectNoLongerExists("Child not found within parent")
164 def getLocalizedRoleName(self):
166 Get a string indicating the type of UI role played by this object,
167 translated to the current locale.
168 @return : a UTF-8 string indicating the type of UI role played
171 func = self.get_dbus_method("getLocalizedRoleName")
174 def getRelationSet(self):
176 Get a set defining this object's relationship to other accessible
178 @return : a RelationSet defining this object's relationships.
180 func = self.get_dbus_method("getRelationSet")
181 relation_set = func()
182 return _marshal_relation_set(self._cache, self._dbus_object, self._app_name, relation_set)
186 Get the Role indicating the type of UI role played by this object.
187 @return : a Role indicating the type of UI role played by this
190 return self.cached_data.role
192 def getRoleName(self):
194 Get a string indicating the type of UI role played by this object.
195 @return : a UTF-8 string indicating the type of UI role played
198 func = self.get_dbus_method("getRoleName")
203 Get the current state of the object as a StateSet.
204 @return : a StateSet encapsulating the currently true states
207 func = self.get_dbus_method("getState")
209 return _marshal_state_set(bitfield)
211 def isEqual(self, accessible):
213 Determine whether an Accessible refers to the same object as
214 another. This method should be used rather than brute-force comparison
215 of object references (i.e. "by-value" comparison), as two object
216 references may have different apparent values yet refer to the
219 an Accessible object reference to compare to
220 @return : a boolean indicating whether the two object references
221 point to the same object.
223 return (self._app_name == accessible._app_name) and \
224 (self._acc_path == accessible._acc_path)
226 def get_childCount(self):
227 return len(self.cached_data.children)
230 childCount: the number of children contained by this object.
232 childCount = property(fget=get_childCount, doc=_childCountDoc)
234 def get_description(self):
235 return self.cached_data.description
238 a string describing the object in more detail than name.
240 description = property(fget=get_description, doc=_descriptionDoc)
243 return self.cached_data.name
246 a (short) string representing the object's name.
248 name = property(fget=get_name, doc=_nameDoc)
250 def get_parent(self):
254 return create_accessible(self._cache,
256 self.cached_data.parent,
257 interfaces.ATSPI_ACCESSIBLE,
258 connection=self._cache._connection)
262 an Accessible object which is this object's containing object.
264 parent = property(fget=get_parent, doc=_parentDoc)
266 # Register the Accessible class with the accessible factory.
267 add_accessible_class(interfaces.ATSPI_ACCESSIBLE, Accessible)
269 #END----------------------------------------------------------------------------