[PyQt] How to process QDBusPendingCallWatcher results?

Evade Flow evadeflow at gmail.com
Mon Aug 13 16:46:19 BST 2012


I noticed that, too, and was a little surprised it worked anyway. But
shouldn't it be:

    @QtCore.pyqtSlot(QtDBus.QDBusPendingCallWatcher)
    def callFinishedSlot(self, call):

When I remove it completely, I get:

    TypeError: callFinishedSlot() takes exactly 2 arguments (1 given)



On Mon, Aug 13, 2012 at 11:33 AM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Mon, 13 Aug 2012 11:13:36 -0400, Evade Flow <evadeflow at gmail.com>
> wrote:
>>> Sorry, my mistake - QDBusPendingReply, not QPyDBusPendingReply...
>>
>> Ah, okay---yeah, that works great, thanks! I had a couple minor typos in
>> my example. Appending a complete, working version below, in case it's
>> helpful to someone else (possibly a future version of me! :-}) It should
>> work on most current Linux distributions, though you might need to
>> replace 'sda1' with a different partition name...
>>
>> ----------
>>
>> 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, call):
>>         reply = QtDBus.QDBusPendingReply(call)
>>         if reply.isError():
>>             print(reply.error().message())
>>         else:
>>             print("  PID        UID     COMMAND")
>>             print("-------    -------
>>             ------------------------------------")
>>             for pid, uid, cmd in reply.argumentAt(0):
>>                 print("{0:>7d}    {1:>7d}   {2}".format(pid, uid, cmd))
>>
>> if __name__ == '__main__':
>>     import sys
>>     app = QtCore.QCoreApplication(sys.argv)
>>
>>     dev = DeviceInterface('org.freedesktop.UDisks',
>>                           '/org/freedesktop/UDisks/devices/sda1',
>>                           QtDBus.QDBusConnection.systemBus(), app)
>>
>>     async = dev.asyncCall("FilesystemListOpenFiles");
>>     watcher = QtDBus.QDBusPendingCallWatcher(async, dev)
>>     watcher.finished.connect(dev.callFinishedSlot)
>>     sys.exit(app.exec_())
>
> Actually there is still a bug. Change the call to pyqtSlot() to...
>
>     @QtCore.pyqtSlot(QtDBus.QDBusPendingCall)
>
> ...or just remove it completely.
>
> Phil


More information about the PyQt mailing list