So, as a follow up to the PyQt/python-dbus issue connecting to both the session and system buses, should it be possible to place each messsge loop (Glib and PyQt) in a separate thread? Here's my naive attempt at this (that doesn't work). I guess I don't understand enough about the message loops to know whether this is completely misguided or not...
<br><br>Thanks,<br><br>Don<br><br><br>----------------------------------------<br>#! /usr/bin/env python<br><br>import sys, threading<br>import Queue<br><br>import dbus<br>import dbus.service<br>from dbus.mainloop.glib import DBusGMainLoop
<br>from gobject import MainLoop<br><br>from PyQt4 import QtGui, QtCore<br>from PyQt4.QtCore import Qt<br><br><br> <br>class Test(dbus.service.Object):<br> def __init__(self,update_queue, name, object_path):<br>
dbus.service.Object.__init__(self, name, object_path)<br> self.update_queue = update_queue<br> <br> @dbus.service.method('com.hplip.StatusService')<br> def EchoString(self, s):<br> return s
<br> <br><br>class DBusThread(threading.Thread):<br> def __init__(self, update_queue):<br> threading.Thread.__init__(self)<br> self.update_queue = update_queue<br> <br> def run(self):<br> dbus_loop = DBusGMainLoop(set_as_default=False)
<br><br> self.system_bus = dbus.SystemBus(mainloop=dbus_loop)<br> self.session_bus = dbus.SessionBus(mainloop=dbus_loop)<br> <br> self.system_bus.add_signal_receiver(self.handle_system_signal, sender_keyword='sender',
<br> destination_keyword='dest', interface_keyword='interface', <br> member_keyword='member', path_keyword='path')<br> <br> self.session_name = dbus.service.BusName
("com.hplip.StatusService", self.session_bus)<br> self.test_object = Test(self.update_queue, self.session_name, "/com/hplip/StatusService/Test")<br> <br> print "Running dbus loop..."
<br> MainLoop().run()<br> print "dbus loop exit."<br><br> <br> def handle_system_signal(*args,**kwds):<br> print args<br> print kwds<br> <br> <br>def main(args):
<br> app = QtGui.QApplication(sys.argv)<br><br> tray_icon = QtGui.QSystemTrayIcon()<br> icon = QtGui.QIcon("HPmenu.png") <br> tray_icon.setIcon(icon)<br> menu = QtGui.QMenu()<br> menu.addAction
("&Quit", quit, Qt.CTRL + Qt.Key_Q)<br> tray_icon.setContextMenu(menu)<br><br> tray_icon.show()<br><br> update_queue = Queue.Queue() # unfinished <br><br> dbus_thread = DBusThread(update_queue)<br>
dbus_thread.start()<br><br> print "Running Qt mainloop..."<br> app.exec_()<br> print "qt loop exit"<br><br><br>if __name__ == '__main__':<br> sys.exit(main(sys.argv))<br>