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 proxy
17 from dbus.proxies import Interface, ProxyObject
18 from dbus.exceptions import *
20 class AccessibleObjectNoLongerExists(Exception):
23 #------------------------------------------------------------------------------
27 return self._enum_lookup(int(self))
29 #------------------------------------------------------------------------------
31 class BaseProxy(Interface):
33 The base D-Bus proxy for a remote object that implements one or more
34 of the AT-SPI interfaces.
36 This class must be further specialised as the cache stores are different
37 for Desktop objects and other Accessible objects.
40 def __new__(cls, *args, **kwargs):
41 Interface.__new__(cls, *args, **kwargs)
43 queryable_interfaces = {
44 'Accessible':ATSPI_ACCESSIBLE,
45 'Action':ATSPI_ACTION,
46 'Application':ATSPI_APPLICATION,
47 'Collection':ATSPI_COLLECTION,
48 'Component':ATSPI_COMPONENT,
49 'Desktop':ATSPI_DESKTOP,
50 'Document':ATSPI_DOCUMENT,
51 'EditableText':ATSPI_EDITABLE_TEXT,
52 'Hypertext':ATSPI_HYPERTEXT,
53 'Hyperlink':ATSPI_HYPERLINK,
55 'Selection':ATSPI_SELECTION,
56 'StreamableContent':ATSPI_STREAMABLE_CONTENT,
62 for interface in queryable_interfaces.keys():
63 name = 'query%s' % interface
64 def new_query(self, object):
65 return self.queryInterface(object, queryable_interfaces[interface])
66 setattr(cls, name, new_query)
68 def __init__(self, obj, cache, path, interface):
70 Create a D-Bus Proxy for an ATSPI interface.
72 obj - The D-Bus proxy object this interface uses for D-Bus calls.
73 cache - Cache storing data for this object.
74 path - The object path of the remote object.
75 interface - The name of the ATSPI interface that this proxy implements.
77 Interface.__init__(self, obj, interface)
79 self._cobj = ref(cache)
82 self._pgetter = self.get_dbus_method("Get", dbus_interface="org.freedesktop.DBus.Properties")
83 self._psetter = self.get_dbus_method("Set", dbus_interface="org.freedesktop.DBus.Properties")
85 def __getattr__(self, *args, **kwargs):
87 The __getattr__ function must return the D-Bus method wrapped in a
88 method to translate exceptions.
90 # Need to throw an AccessibleObjectNoLongerExists exception
91 # on D-Bus error of the same type.
93 return Interface.__getattr__(self, *args, **kwargs)
94 except UnknownMethodException, e:
95 raise NotImplementedError(e)
96 except DBusException, e:
103 raise AccessibleObjectNoLongerExits("Application has been removed")
108 data = self._cache._objects[self._path]
110 raise AccessibleObjectNoLongerExists, 'Cache data cannot be found for path %s' % (self._path,)
114 def interfaces(self):
115 return self._data.interfaces
117 def queryInterface(self, interface):
118 if interface in self._data.interfaces:
119 return self._cache.proxyFactory(self._path, interface, dbus_obj=self._obj)
121 raise NotImplementedError(
122 "%s not supported by accessible object at path %s"
123 % (interface, self.path))
125 #END----------------------------------------------------------------------------