[PyQt] How to process QDBusPendingCallWatcher results?
Evade Flow
evadeflow at gmail.com
Mon Aug 13 16:13:36 BST 2012
> 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_())
On Mon, Aug 13, 2012 at 10:00 AM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Mon, 13 Aug 2012 09:41:44 -0400, Evade Flow <evadeflow at gmail.com>
> wrote:
>>> 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?)
>
> Sorry, my mistake - QDBusPendingReply, not QPyDBusPendingReply. (The
> latter is the internal C++ class but it's exposed as the former.)
>
> Phil
More information about the PyQt
mailing list