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.
15 from weakref import ref
17 from dbus.proxies import Interface, ProxyObject
18 from dbus.exceptions import *
20 from factory import interfaceFactory
22 class AccessibleObjectNoLongerExists(Exception):
25 #------------------------------------------------------------------------------
29 return self._enum_lookup(int(self))
31 #------------------------------------------------------------------------------
33 class BaseProxyMeta(type):
37 queryable_interfaces = {
38 'Accessible':ATSPI_ACCESSIBLE,
39 'Action':ATSPI_ACTION,
40 'Application':ATSPI_APPLICATION,
41 'Collection':ATSPI_COLLECTION,
42 'Component':ATSPI_COMPONENT,
43 'Desktop':ATSPI_DESKTOP,
44 'Document':ATSPI_DOCUMENT,
45 'EditableText':ATSPI_EDITABLE_TEXT,
46 'Hypertext':ATSPI_HYPERTEXT,
47 'Hyperlink':ATSPI_HYPERLINK,
49 'Selection':ATSPI_SELECTION,
50 'StreamableContent':ATSPI_STREAMABLE_CONTENT,
56 for interface in queryable_interfaces.keys():
57 name = 'query%s' % interface
58 def new_query(self, object):
59 return self.queryInterface(object, queryable_interfaces[interface])
60 setattr(cls, name, new_query)
62 #------------------------------------------------------------------------------
64 class BaseProxy(Interface):
66 A D-Bus proxy for a remote object that implements one or more of the AT-SPI
67 Accessibility interfaces.
70 __metaclass__ = BaseProxyMeta
72 def __init__(self, busobject, cache, app, path, interface):
74 Create a D-Bus Proxy for an ATSPI interface.
76 busobject - The D-Bus proxy object this interface uses for D-Bus calls.
77 cache - The accessible cache that this object is owned by.
78 path - The object path of the remote object.
79 app - The bus name of the application this object belongs to.
80 interface - The name of the ATSPI interface that this proxy implements.
82 Interface.__init__(self, busobject, interface)
89 self._pgetter = self.get_dbus_method("Get", dbus_interface="org.freedesktop.DBus.Properties")
90 self._psetter = self.get_dbus_method("Set", dbus_interface="org.freedesktop.DBus.Properties")
92 def __getattr__(self, *args, **kwargs):
94 The __getattr__ function must return the D-Bus method wrapped in a
95 method to translate exceptions.
97 # Need to throw an AccessibleObjectNoLongerExists exception
98 # on D-Bus error of the same type.
100 return Interface.__getattr__(self, *args, **kwargs)
101 except UnknownMethodException, e:
102 raise NotImplementedError(e)
103 except DBusException, e:
109 data = self._cache._objects[self._path]
111 raise AccessibleObjectNoLongerExists, 'Cache data cannot be found for path %s' % (self._path,)
115 def interfaces(self):
116 return self._data.interfaces
118 def queryInterface(self, interface):
119 if interface in self._data.interfaces:
120 return interfaceFactory(self._obj, self._cache, self._app, self._path, interface)
122 raise NotImplementedError(
123 "%s not supported by accessible object at path %s"
124 % (interface, self.path))
126 #END----------------------------------------------------------------------------