b6676d2eb132e3f11244227383a68414170c8a5a
[platform/core/uifw/at-spi2-atk.git] / pyatspi / applicationcache.py
1 #Copyright (C) 2008 Codethink Ltd
2
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.
6
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.
14
15 from accessiblecache import AccessibleCache
16 from desktop import Desktop
17 from factory import accessible_factory
18
19 import interfaces
20
21 __all__ = [
22
23            "TestApplicationCache",
24           ]
25
26 #------------------------------------------------------------------------------
27
28 class TestApplicationCache(object):
29         """
30         Test application store, accesses a single application.
31
32         The store object acts as a central class for creating accessible objects.
33         It interfaces with the ATSPI registry to keep account of all accessible
34         applications. It contains the accessible cache objects from each application.
35
36         @registry:   Each accessible cache object must have a reference to the registry
37                      object to send update events.
38
39         @connection: D-Bus connection used to access applications.
40
41         @bus_name:   The test store only accesses one accessible application, this is its
42                      D-Bus path.
43         """
44
45         def __init__(self, registry, connection, bus_name):
46                 self._connection = connection
47
48                 self.application_list = [bus_name]
49                 self.application_cache = {bus_name:AccessibleCache(registry, connection, bus_name)}
50
51         def get_cache_data(self, app_name, acc_path):
52                 """
53                 Returns the cache tuple for the given application and accessible
54                 object path. Throws an IndexError if the cache data is not found.
55                 """
56                 return self.application_cache[app_name][acc_path]
57
58         def create_application(self, app_name):
59                 """
60                 Creates an accessible object for the root of the application
61                 available at the given D-Bus name.
62                 """
63                 cls = accessible_factory.get_accessible_class(interfaces.ATSPI_APPLICATION)
64                 return cls(app_name, self.application_cache[app_name].root, self, interfaces.ATSPI_APPLICATION)
65
66         def create_accessible(self, app_name, acc_path, interface, dbus_object=None):
67                 """
68                 Creates an accessible object.
69
70                 @app_name: D-Bus name of the application where the accessible object resides.
71
72                 @acc_path: D-Bus path of the object within the application.
73
74                 @interface: D-Bus interface of the requested object. A different accessible object
75                             class will be created depending on this. Making the function much like 
76                             an accessible object factory.
77
78                 @dbus_object: If a D-Bus object already exists for the accessible object it can be
79                               provided here so that another one is not created.
80                 """
81                 # An acc_path of '/' implies the desktop object, whatever the app_name.
82                 if acc_path == '/':
83                         return Desktop(self)
84                 else:
85                         cls = accessible_factory.get_accessible_class(interface)
86                         return cls(app_name, acc_path, self, interface, dbus_object=dbus_object)
87
88         @property
89         def connection(self):
90                 """
91                 D-Bus connection used by the store.
92                 """
93                 return self._connection
94
95 #END----------------------------------------------------------------------------