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.
17 #------------------------------------------------------------------------------
19 class _CacheData(object):
29 def __init__(self, data):
32 def update(self, data):
33 #Don't cache the path here, used as lookup in cache object dict.
40 self.description) = data
42 #------------------------------------------------------------------------------
44 class _BaseCache(object):
46 def __init__(self, connection, bus_name):
50 connection - DBus connection.
51 busName - Name of DBus connection where cache interface resides.
53 self._connection = connection
54 self._bus_name = bus_name
56 obj = connection.get_object(bus_name, self._PATH, introspect=False)
57 itf = _dbus.Interface(obj, self._INTERFACE)
61 get_method = itf.get_dbus_method(self._GET_METHOD)
62 self._update_objects(get_method())
64 self._signalMatch = itf.connect_to_signal(self._UPDATE_SIGNAL, self._update_handler)
66 def __getitem__(self, key):
67 return self._objects[key]
69 def __contains__(self, key):
70 return key in self._objects
72 def _update_handler(self, update, remove):
73 self._remove_objects(remove)
74 self._update_objects(update)
76 def _update_objects(self, objects):
78 #First element is the object path.
80 if path in self._objects:
81 cachedata = self._objects[path]
82 cachedata.update(data)
84 self._objects[path] = _CacheData(data)
86 def _remove_objects(self, paths):
88 del(self._objects[path])
91 #------------------------------------------------------------------------------
93 class AccessibleCache(_BaseCache):
95 There is one accessible cache per application.
96 For each application the accessible cache stores
97 data on every accessible object within the app.
99 It also acts as the factory for creating client
100 side proxies for these accessible objects.
102 connection - DBus connection.
103 busName - Name of DBus connection where cache interface resides.
106 _PATH = '/org/freedesktop/atspi/tree'
107 _INTERFACE = 'org.freedesktop.atspi.Tree'
108 _GET_METHOD = 'getTree'
109 _UPDATE_SIGNAL = 'updateTree'
111 def __init__(self, connection, bus_name):
112 _BaseCache.__init__(self, connection, bus_name)
114 obj = connection.get_object(self._bus_name, self._PATH, introspect=False)
115 itf = _dbus.Interface(obj, self._INTERFACE)
117 self._root = itf.getRoot()
122 root = property(fget=_get_root)
125 #END---------------------------------------------------------------------------