1 #Copyright (C) 2008 Codethink Ltd
2 #copyright: Copyright (c) 2005, 2007 IBM Corporation
4 #This library is free software; you can redistribute it and/or
5 #modify it under the terms of the GNU Lesser General Public
6 #License version 2 as published by the Free Software Foundation.
8 #This program is distributed in the hope that it will be useful,
9 #but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 #GNU General Public License for more details.
12 #You should have received a copy of the GNU Lesser General Public License
13 #along with this program; if not, write to the Free Software
14 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 #Portions of this code originally licensed and copyright (c) 2005, 2007
17 #IBM Corporation under the BSD license, available at
18 #U{http://www.opensource.org/licenses/bsd-license.php}
20 #authors: Peter Parente, Mark Doffman
24 from dbus.mainloop.glib import DBusGMainLoop
25 DBusGMainLoop(set_as_default=True)
27 from test import TestApplicationCache
28 from desktop import Desktop
30 class Registry(object):
32 Wraps the Accessibility.Registry to provide more Pythonic registration for
35 This object should be treated as a singleton, but such treatment is not
36 enforced. You can construct another instance of this object and give it a
37 reference to the Accessibility.Registry singleton. Doing so is harmless and
40 @ivar async: Should event dispatch to local listeners be decoupled from event
41 receiving from the registry?
43 @ivar reg: Reference to the real, wrapped registry object
44 @type reg: Accessibility.Registry
45 @ivar dev: Reference to the device controller
46 @type dev: Accessibility.DeviceEventController
47 @ivar queue: Queue of events awaiting local dispatch
48 @type queue: Queue.Queue
49 @ivar clients: Map of event names to client listeners
50 @type clients: dictionary
51 @ivar observers: Map of event names to AT-SPI L{_Observer} objects
52 @type observers: dictionary
55 _REGISTRY_NAME = 'org.freedesktop.atspi.Registry'
57 def __init__(self, app_name=None):
59 Stores a reference to the AT-SPI registry. Gets and stores a reference
60 to the DeviceEventController.
62 @param reg: Reference to the AT-SPI registry daemon
63 @type reg: Accessibility.Registry
65 self._bus = dbus.SessionBus()
67 self._app_name = app_name
68 self._cache = TestApplicationCache(self._bus, app_name)
72 @return: This instance of the registry
77 def start(self, async=False, gil=True):
79 Enter the main loop to start receiving and dispatching events.
81 @param async: Should event dispatch be asynchronous (decoupled) from
82 event receiving from the AT-SPI registry?
84 @param gil: Add an idle callback which releases the Python GIL for a few
85 milliseconds to allow other threads to run? Necessary if other threads
86 will be used in this process.
87 Note - No Longer used.
90 self._loop = gobject.MainLoop()
93 def stop(self, *args):
94 """Quits the main loop."""
98 def getDesktopCount(self):
100 Gets the number of available desktops.
102 @return: Number of desktops
107 def getDesktop(self, i):
109 Gets a reference to the i-th desktop.
111 @param i: Which desktop to get
113 @return: Desktop reference
114 @rtype: Accessibility.Desktop
116 return Desktop(self._cache)