[PyQt] How to process QDBusPendingCallWatcher results?
Evade Flow
evadeflow at gmail.com
Mon Aug 13 04:31:54 BST 2012
I'm working on an app that needs to invoke methods in
various D-Bus services asynchronously, so I wrote this small program to
test the basic machinery:
from PyQt4 import QtCore, QtDBus
class DeviceInterface(QtDBus.QDBusAbstractInterface):
def __init__(self, service, path, connection, parent=None):
super().__init__(service, path,
'org.freedesktop.UDisks.Device',
connection, parent)
@QtCore.pyqtSlot(QtDBus.QDBusArgument)
def callFinishedSlot(self, arg):
print("Got result:", arg)
if __name__ == '__main__':
import sys
app = QtCore.QCoreApplication(sys.argv)
dev = DeviceInterface('org.freedesktop.UDisks.Device',
'/org/freedesktop/UDisks/Device/sda1',
QtDBus.QDBusConnection.systemBus(), app)
async = dev.asyncCall("FilesystemListOpenFiles");
watcher = QtDBus.QDBusPendingCallWatcher(async, dev)
watcher.finished.connect(dev.callFinishedSlot)
sys.exit(app.exec_())
It seems to work(?) Anyway, it prints:
Got result: <PyQt4.QtDBus.QDBusPendingCallWatcher object at 0xb740c77c>
The trouble is, I can't figure out how to get results out of the
QDBusPendingCallWatcher object. The C++ code I adapted the above
example from does this:
void MyClass.callFinishedSlot(QDBusPendingCallWatcher *call)
{
QDBusPendingReply<QString, QByteArray> reply = *call;
if (reply.isError()) {
showError();
} else {
QString text = reply.argumentAt<0>();
QByteArray data = reply.argumentAt<1>();
showReply(text, data);
}
call->deleteLater();
}
Can anyone suggest how I might convert the C++ slot syntax to something
that will work with PyQt? Thanks!
More information about the PyQt
mailing list