[PyQt] How to process QDBusPendingCallWatcher results?
Evade Flow
evadeflow at gmail.com
Mon Aug 13 14:41:44 BST 2012
> Try this...
>
> def callFinishedSlot(self, call):
> reply = QtDBus.QPyDBusPendingReply(call)
Thanks, Phil. It doesn't work for me yet, I'm getting:
>>> call
<PyQt4.QtDBus.QDBusPendingCallWatcher object at 0x9e9538c>
>>> reply = QtDBus.QPyDBusPendingReply(call)
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
builtins.AttributeError: 'module' object has no attribute 'QPyDBusPendingReply'
I'm now looking through the build setup to see whether there's some
config setting I missed that is keeping the qpy stuff from getting
built. Any suggestions? (I built from the PyQt4.9.4 release tarball; do
I need to use a development snapshot instead?)
On Mon, Aug 13, 2012 at 4:43 AM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> 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