[orca] Fix D-Bus interaction with gsmag.



commit ddd1c29c2f9c519e00c72728fcc922a7ed7fb087
Author: Willie Walker <william walker sun com>
Date:   Fri Nov 13 09:39:03 2009 -0500

    Fix D-Bus interaction with gsmag.
    
    The main problem was that we needed to ensure the DBus mainloop was set to
    dbus.mainloop.glib.DBusGMainLoop. Otherwise, we'd end up getting a major
    suckmo error: RuntimeError: To make asynchronous calls, receive signals or
    export objects, D-Bus connections must be attached to a main loop by passing
    mainloop=... to the constructor or calling dbus.set_default_main_loop(...)

 src/orca/dbusserver.py |   26 ++++++++++++++++++++------
 src/orca/orca.py       |   17 ++++++++++++-----
 2 files changed, 32 insertions(+), 11 deletions(-)
---
diff --git a/src/orca/dbusserver.py b/src/orca/dbusserver.py
index f6a322c..18f6085 100644
--- a/src/orca/dbusserver.py
+++ b/src/orca/dbusserver.py
@@ -27,7 +27,6 @@ __license__   = "LGPL"
 
 import dbus
 import dbus.service
-import dbus.mainloop.glib
 
 import debug
 import settings
@@ -40,6 +39,10 @@ loggingStreamHandlers = {}
 # pylint: disable-msg=R0923
 # Server: Interface not implemented
 
+bus = None
+name = None
+obj = None
+
 class Server(dbus.service.Object):
 
     def __init__(self, object_path, bus_name):
@@ -138,25 +141,36 @@ class Server(dbus.service.Object):
             stringIO = StringIO.StringIO()
         return result
 
-obj = None
-
 def init():
     """Sets up the Orca DBus service.  This will only take effect once
     the Orca main loop starts."""
 
+    global bus
+    global name
     global obj
 
-    if obj:
+    if obj or bus or name:
         return
 
     try:
-        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
         bus = dbus.SessionBus()
-        name = dbus.service.BusName('org.gnome.Orca', bus=bus)
+        name = dbus.service.BusName('org.gnome.Orca',
+                                    bus=bus,
+                                    allow_replacement=False,
+                                    replace_existing=False)
         obj = Server('/', name)
     except:
         debug.println(debug.LEVEL_WARNING,
                       "dbusserver.py: Could not initialize DBus server")
+        debug.printException(debug.LEVEL_WARNING)
 
 def shutdown():
     pass
+
+def main():
+    import pyatspi
+    init()
+    pyatspi.Registry.start()
+
+if __name__ == "__main__":
+    main()
diff --git a/src/orca/orca.py b/src/orca/orca.py
index 62539e7..905abd8 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -61,19 +61,26 @@ import signal
 import time
 import unicodedata
 
+import settings
+if settings.useDBus:
+    import dbus.mainloop.glib
+    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+    import dbusserver
+    try:
+        import gsmag as mag
+    except:
+        import mag
+else:
+    import mag
+
 import pyatspi
 import braille
 import debug
 import httpserver
 import keynames
 import keybindings
-try:
-    import gsmag as mag
-except:
-    import mag
 import orca_state
 import platform
-import settings
 import speech
 
 from input_event import BrailleEvent



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]