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 dbus.proxies import Interface
17 from dbus.exceptions import *
20 from factory import create_accessible
23 "AccessibleObjectNoLongerExists",
28 class AccessibleObjectNoLongerExists(Exception):
31 #------------------------------------------------------------------------------
35 return self._enum_lookup(int(self))
37 #------------------------------------------------------------------------------
40 class BaseProxyMeta(type):
41 def __init__(cls, *args, **kwargs):
42 type.__init__(cls, *args, **kwargs)
44 queryable_interfaces = {
45 'Accessible':interfaces.ATSPI_ACCESSIBLE,
46 'Action':interfaces.ATSPI_ACTION,
47 'Application':interfaces.ATSPI_APPLICATION,
48 'Collection':interfaces.ATSPI_COLLECTION,
49 'Component':interfaces.ATSPI_COMPONENT,
50 'Desktop':interfaces.ATSPI_DESKTOP,
51 'Document':interfaces.ATSPI_DOCUMENT,
52 'EditableText':interfaces.ATSPI_EDITABLE_TEXT,
53 'Hypertext':interfaces.ATSPI_HYPERTEXT,
54 'Hyperlink':interfaces.ATSPI_HYPERLINK,
55 'Image':interfaces.ATSPI_IMAGE,
56 'Selection':interfaces.ATSPI_SELECTION,
57 'StreamableContent':interfaces.ATSPI_STREAMABLE_CONTENT,
58 'Table':interfaces.ATSPI_TABLE,
59 'Text':interfaces.ATSPI_TEXT,
60 'Value':interfaces.ATSPI_VALUE,
63 for interface in queryable_interfaces.keys():
64 name = 'query%s' % interface
65 def new_query(self, object):
66 return self.queryInterface(object, queryable_interfaces[interface])
67 setattr(cls, name, new_query)
69 #------------------------------------------------------------------------------
71 class BaseProxy(Interface):
73 The base D-Bus proxy for a remote object that implements one or more
74 of the AT-SPI interfaces.
77 __metaclass__ = BaseProxyMeta
79 def __init__(self, cache, app_name, acc_path, interface, dbus_object=None, connection=None, parent=None):
81 Create a D-Bus Proxy for an ATSPI interface.
83 cache - ApplicationCache, where the cached data for the accessible can be obtained.
84 app_name - D-Bus bus name of the application this accessible belongs to.
85 acc_path - D-Bus object path of the server side accessible object.
86 parent - Parent accessible.
87 interface - D-Bus interface of the object. Used to decide which accessible class to instanciate.
88 dbus_object(kwarg) - The D-Bus proxy object used by the accessible for D-Bus method calls.
91 self._app_name = app_name
92 self._acc_path = acc_path
96 dbus_object = connection.get_object(self._app_name, self._acc_path, introspect=False)
97 self._dbus_object = dbus_object
99 Interface.__init__(self, self._dbus_object, interface)
101 self._pgetter = self.get_dbus_method("Get", dbus_interface="org.freedesktop.DBus.Properties")
102 self._psetter = self.get_dbus_method("Set", dbus_interface="org.freedesktop.DBus.Properties")
104 def get_dbus_method(self, *args, **kwargs):
105 method = Interface.get_dbus_method(self, *args, **kwargs)
107 def dbus_method_func(*args, **kwargs):
108 # TODO Need to throw an AccessibleObjectNoLongerExists exception
109 # on D-Bus error of the same type.
111 return method(*args, **kwargs)
112 except UnknownMethodException, e:
113 raise NotImplementedError(e)
114 except DBusException, e:
117 return dbus_method_func
120 def cached_data(self):
122 return self._cache[self._app_name][self._acc_path]
124 raise AccessibleObjectNoLongerExists, \
125 'Cache data cannot be found for path %s in app %s' % (self._acc_path, self._app_name)
128 def interfaces(self):
129 return self._data.interfaces
131 def queryInterface(self, interface):
133 Gets a different accessible interface for this object
134 or raises a NotImplemented error if the given interface
137 if interface in self._data.interfaces:
138 return create_accessible(self._cache,
143 dbus_object=self._dbus_object)
145 raise NotImplementedError(
146 "%s not supported by accessible object at path %s"
147 % (interface, self.path))
149 #END----------------------------------------------------------------------------