Hello,<br><br>I'm playing around with a little test dbus/PyQt4 python script, and have run into an issue... I am trying to accomplish two things in this script: 1) receive signals from the system bus, and 2) export a callable object on the session bus. When I run my little test script, only the last of these 2 things that I setup work.
<br><br>Scenario #1: Setup session bus first, and system bus second. In this scenario, the system bus handler get signals, the session bus exports the object, but a viewer like qdbusviewer hangs when it tries to open the path to the object. It seems that the call to
dbus.SystemBus() "kills" the session bus setup (and if I remove the add_signal_receiver() call, and leave just the system_bus = dbus.SystemBus() call, it still fails).<br><br>session_bus = dbus.SessionBus()<br>name =
dbus.service.BusName("com.hplip.StatusService", session_bus)<br>test = Test(name, "/com/hplip/StatusService/Test")<br><br>system_bus = dbus.SystemBus()<br><br># processes of non-privledged users can rec. signals from the system bus
<br>system_bus.add_signal_receiver(handle_signal, sender_keyword='sender', <br> destination_keyword='dest', interface_keyword='interface', <br> member_keyword='member', path_keyword='path')
<br> <br><br>Scenario #2: Setup system bus first, and the session bus second. In this scenario, the object exported on the session bus is callable (I can successfully call the Echo method in qdbusviewer), but the signals from the system bus no longer function. It seems that the call to
dbus.SessionBus() "kills" the system bus setup (and if I remove the next 2 lines and leave just the session_bus = dbus.SessionBus() line, it still fails).<br><br>system_bus = dbus.SystemBus()<br>
<br>
# processes of non-privledged users can rec. signals from the system bus<br>
system_bus.add_signal_receiver(handle_signal, sender_keyword='sender', <br>
destination_keyword='dest', interface_keyword='interface', <br>
member_keyword='member', path_keyword='path')<br>
<br>session_bus = dbus.SessionBus()<br>
name = dbus.service.BusName("com.hplip.StatusService", session_bus)<br>
test = Test(name, "/com/hplip/StatusService/Test")<br><br>The complete script is here (in scenario #1 order):<br><br>#! /usr/bin/env python<br><br>import dbus<br>import dbus.service<br>import dbus.mainloop.qt<br>
from PyQt4 import QtGui, QtCore<br>from PyQt4.QtCore import Qt<br>import sys<br><br><br>def handle_signal(*args, **kwds):<br> print "Signal!"<br> print kwds<br> print<br> tray_icon.showMessage("HPLIP Status",
QtCore.QString("Received message from %1").arg(kwds['sender']))<br><br> <br>def quit():<br> app.quit()<br> <br>class Test(dbus.service.Object):<br> def __init__(self, name, object_path):<br>
dbus.service.Object.__init__(self, name, object_path)<br> <br> @dbus.service.method('com.hplip.StatusService')<br> def EchoString(self, s):<br> return s<br> <br><br>app = QtGui.QApplication
(sys.argv)<br>dbus.mainloop.qt.DBusQtMainLoop(set_as_default=True)<br><br><br>session_bus = dbus.SessionBus()<br>name = dbus.service.BusName("com.hplip.StatusService", session_bus)<br>test = Test(name, "/com/hplip/StatusService/Test")
<br><br><br>system_bus = dbus.SystemBus()<br><br># processes of non-privledged users can call methods on the system bus<br>proxy = system_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')<br>
print proxy.GetId()<br><br><br># processes of non-privledged users can rec. signals from the system bus<br>system_bus.add_signal_receiver(handle_signal, sender_keyword='sender', <br> destination_keyword='dest', interface_keyword='interface',
<br> member_keyword='member', path_keyword='path')<br> <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>app.exec_()<br><br><br><br>I don't know if there is something wrong in my code, if there is a bug in dbus or the qt dbus mainloop, or I am making some other sort of rookie mistake. It does say in the python-dbus docs that: "Of course, you can connect to both [system and session buses] in the same application.", so I am pretty sure it is possible.
<br><br>Thanks for the help,<br><br>Don<br><br><br><br>
<br>