Merge branch 'master' of ssh://git.codethink.co.uk/git/atspi-dbus
[platform/core/uifw/at-spi2-atk.git] / pyatspi / factory.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 #------------------------------------------------------------------------------
16
17 class AccessibleFactory(object):
18         __accessible_interfaces = {}
19
20         def create_accessible(self, cache, app_name, acc_path, interface, dbus_object=None, connection=None, parent=None):
21                 class_ = self.__accessible_interfaces[interface]
22                 return class_(cache,
23                               app_name,
24                               acc_path,
25                               interface,
26                               dbus_object=dbus_object,
27                               connection=connection,
28                               parent=parent)
29
30         def add_accessible_class(self, name, cls):
31                 self.__accessible_interfaces[name] = cls
32
33 _factory = AccessibleFactory()
34
35 def create_accessible(cache, app_name, acc_path, interface, dbus_object=None, connection=None, parent=None):
36         """
37         Used to create different python classes for each of the accessible interfaces.
38
39         The decision on which class to create is based on the name of the
40         accessible interface.
41
42         cache - ApplicationCache, where the cached data for the accessible can be obtained.
43         app_name - D-Bus bus name of the application this accessible belongs to.
44         acc_path - D-Bus object path of the server side accessible object.
45         interface - D-Bus interface of the object. Used to decide which accessible class to instanciate.
46         dbus_object(kwarg) - The D-Bus proxy object used by the accessible for D-Bus method calls.
47         connection(kwarg) - Client side D-Bus connection, provided if no D-Bus proxy is available.
48         """
49         return _factory.create_accessible(cache,
50                                           app_name,
51                                           acc_path,
52                                           interface,
53                                           dbus_object=dbus_object,
54                                           connection=connection,
55                                           parent=parent)
56
57 def add_accessible_class(name, cls):
58         _factory.add_accessible_class(name, cls)
59
60 #END----------------------------------------------------------------------------