[PyQt] How to process QDBusPendingCallWatcher results?
Phil Thompson
phil at riverbankcomputing.com
Mon Aug 13 09:43:53 BST 2012
On Sun, 12 Aug 2012 23:31:54 -0400, Evade Flow <evadeflow at gmail.com>
wrote:
> 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!
Try this...
def callFinishedSlot(self, call):
reply = QtDBus.QPyDBusPendingReply(call)
if reply.isError():
self.showError()
else:
text = reply.argumentAt(0)
data = reply.argumentAt(1)
...etc.
Phil
More information about the PyQt
mailing list