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, updates):
73 update, remove = updates
74 self._remove_objects(update)
75 self._update_objects(remove)
77 def _update_objects(self, objects):
79 #First element is the object path.
81 if path in self._objects:
82 cachedata = self._objects[path]
83 cachedata.update(data)
85 self._objects[path] = _CacheData(data)
87 def _remove_objects(self, paths):
89 del(self._objects[path])
92 #------------------------------------------------------------------------------
94 class AccessibleCache(_BaseCache):
96 There is one accessible cache per application.
97 For each application the accessible cache stores
98 data on every accessible object within the app.
100 It also acts as the factory for creating client
101 side proxies for these accessible objects.
103 connection - DBus connection.
104 busName - Name of DBus connection where cache interface resides.
107 _PATH = '/org/freedesktop/atspi/tree'
108 _INTERFACE = 'org.freedesktop.atspi.Tree'
109 _GET_METHOD = 'getTree'
110 _UPDATE_SIGNAL = 'updateTree'
112 def __init__(self, connection, bus_name):
113 _BaseCache.__init__(self, connection, bus_name)
115 obj = connection.get_object(self._bus_name, self._PATH, introspect=False)
116 itf = _dbus.Interface(obj, self._INTERFACE)
118 self._root = itf.getRoot()
123 root = property(fget=_get_root)
125 #END---------------------------------------------------------------------------