Sunday, 11 August 2013

PyQt4 and QtDBus: Signals don't arrive?

PyQt4 and QtDBus: Signals don't arrive?

I am trying to connect to a DBus signal using PyQt4.QtDBus with Python3.
My aim is to be notified when a disc is inserted into a CDROM drive.
According to PyQt4's doc, the slot should receive a single argument of
type QDBusMessage. Therefore I try the following:
from PyQt4.QtDBus import *
from PyQt4.QtCore import *
import sys
class Test(QObject):
@pyqtSlot(QDBusMessage)
def slot(self, message):
print("yes")
if __name__ == "__main__":
app = QCoreApplication(sys.argv)
test = Test()
sysbus = QDBusConnection.systemBus()
ans = sysbus.connect("org.freedesktop.UDisks2",
"/org/freedesktop/UDisks2",
"org.freedesktop.DBus.Properties",
"PropertiesChanged", test.slot)
print(ans)
app.exec_()
This prints True so the connection should be okay. However if I insert a
CD nothing happens. When I connect to the same signal in qdbusviewer, it
is correctly received. Am I missing anything here? DBus seems to work in
principle, because e.g. if I add
print(QDBusInterface("org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus", sysbus).call("GetId").arguments())
to the above then I correctly get an ID printed.

No comments:

Post a Comment