[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Passsing Unsigned Int to DBus
From: Bo_Møller_Petersen <kemibo () gmail ! com>
Date: 2019-02-11 16:38:58
Message-ID: CAGe7pNh3TdHE-8FUkn11K945nshUs_=8YU1pHvuj4rWXw-On8g () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
I was looking af http://pyqt.sourceforge.net/Docs/PyQt5/pyqt_qvariant.html
and got the impression that QVariant was not available when using python 3.
Anyway using you code I get the following error:
QDBusMarshaller: cannot add a null QDBusVariant
QDBusConnection: error: could not send message to service
"org.kde.Solid.PowerManagement.PolicyAgent" path
"/org/kde/Solid/PowerManagement/PolicyAgent" interface
"org.kde.Solid.PowerManagement.PolicyAgent" member "AddInhibition":
Marshalling failed: Variant containing QVariant::Invalid passed in arguments
I must admit i'm a bit lost on where the QVariant picked up the
QVariant::Invalid. Any pointer on where to look?
Bo
On Sun, Feb 10, 2019 at 7:19 PM Phil Thompson <phil@riverbankcomputing.com>
wrote:
> On 10 Feb 2019, at 5:55 pm, Bo Møller Petersen <kemibo@gmail.com> wrote:
> >
> > I'm trying to use PyQt5's DBus module to interact with the KDE
> PowerManagerAgent on a linux system. When calling the AddInhibition method
> I need to send the first paramter as an uint32 (Unsigned int), but the code
> sends the value as a singed int.
> >
> > The code is written using Python 3 and using Pyqt5
> >
> > class PowerChangeInhibitor:
> > def __init__(self):
> > self.dBusService = 'org.kde.Solid.PowerManagement.PolicyAgent'
> > self.dBusPath = '/org/kde/Solid/PowerManagement/PolicyAgent'
> > self.dBusInterface = 'org.kde.Solid.PowerManagement.PolicyAgent'
> > self.cookies = []
> >
> > def ActivateInhibition(self, interruptSession, changeProfile,
> changeScreenSettings,who, reason):
> >
> >
> > self.dBus = QtDBus.QDBusConnection.sessionBus()
> > if interruptSession:
> > #dBusInterface = QtDBus.QDBusInterface(self.dBusService,
> self.dBusPath,'' , self.dBus)
> > #reply = dBusInterface.call('AddInhibition',1,who,reason)
> >
> > msg = QtDBus.QDBusMessage.createMethodCall(self.dBusService,
> self.dBusPath,self.dBusInterface,'AddInhibition')
> >
> > #unsignedValue = 1
> # writes 1 but typed as int32
> > #unsignedValue = ctypes.c_uint(1)
> # Type not registered
> > #unsignedValue = struct.unpack_from("I", struct.pack("i",
> 1)) # Type not registered
> > #unsignedValue = QtCore.QByteArray(b'0x01')[0]
> # Type not registered
> > #unsignedValue = bytes(1)
> # Type not registered
> > #unsignedValue = QtDBus.QDBusVariant(1)
> # array of bytes "0x01"
> > #unsignedValue = QtDBus.QDBusVariant(1)[0]
> # QDBusVariant does not support indexing
> > #unsignedValue =
> QtDBus.QDBusVariant().setVariant(ctypes.c_uint(1)) # Variant contained
> QVariantInvalid
> > unsignedValue = QtDBus.QDBusVariant(ctypes.c_uint(1))
> # Type not registered
> >
> > msg << unsignedValue << who << reason
> > reply = QtDBus.QDBusReply(self.dBus.call(msg))
> > if reply.isValid():
> > self.cookies.append(reply.value())
> >
> >
> > I have commented out previous attempts with their results on the right.
> Using dbus-monitor I can see that the part where i'm struggeling is getting
> QDBusInterface to emit the desired UNIT32 type info.
> >
> > Any pointers on how I pass an unsigned int as an argument to my
> QDBusMessage ?
>
> Use QVariant.convert()...
>
> qvar = QVariant(ctypes.c_uint(1))
> qvar.convert(QVariant.UInt)
> unsignedValue = QtDBus.QDBusVariant(qvar)
>
> Phil
[Attachment #5 (text/html)]
<div dir="ltr"><div dir="ltr"><div dir="ltr">I was looking af <a \
href="http://pyqt.sourceforge.net/Docs/PyQt5/pyqt_qvariant.html">http://pyqt.sourceforge.net/Docs/PyQt5/pyqt_qvariant.html</a> \
and got the impression that QVariant was not available when using python 3.</div><div \
dir="ltr"><br></div><div>Anyway using you code I get the following \
error:</div><div><font size="1"><span \
style="font-family:monospace,monospace">QDBusMarshaller: cannot add a null \
QDBusVariant<br>QDBusConnection: error: could not send message to service \
"org.kde.Solid.PowerManagement.PolicyAgent" path \
"/org/kde/Solid/PowerManagement/PolicyAgent" interface \
"org.kde.Solid.PowerManagement.PolicyAgent" member \
"AddInhibition": Marshalling failed: Variant containing QVariant::Invalid \
passed in arguments</span></font><br></div><div><br></div><div><font size="2">I must \
admit i'm a bit lost on where the QVariant picked up the QVariant::Invalid. Any \
pointer on where to look?</font></div><div><font size="1"><span \
style="font-family:monospace,monospace"><br></span></font></div><div><font \
size="1"><span style="font-family:monospace,monospace">Bo<br></span></font></div><div><font \
size="1"><span style="font-family:monospace,monospace"><br></span></font></div><div><br></div></div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Feb 10, 2019 at 7:19 PM \
Phil Thompson <<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>> \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 10 Feb 2019, at \
5:55 pm, Bo Møller Petersen <<a href="mailto:kemibo@gmail.com" \
target="_blank">kemibo@gmail.com</a>> wrote:<br> > <br>
> I'm trying to use PyQt5's DBus module to interact with the KDE \
PowerManagerAgent on a linux system. When calling the AddInhibition method I need to \
send the first paramter as an uint32 (Unsigned int), but the code sends the value as \
a singed int.<br> > <br>
> The code is written using Python 3 and using Pyqt5<br>
> <br>
> class PowerChangeInhibitor:<br>
> def __init__(self):<br>
> self.dBusService = \
'org.kde.Solid.PowerManagement.PolicyAgent'<br> > \
self.dBusPath = '/org/kde/Solid/PowerManagement/PolicyAgent'<br> > \
self.dBusInterface = 'org.kde.Solid.PowerManagement.PolicyAgent'<br> > \
self.cookies = []<br> > <br>
> def ActivateInhibition(self, interruptSession, changeProfile, \
changeScreenSettings,who, reason):<br> > <br>
> <br>
> self.dBus = QtDBus.QDBusConnection.sessionBus()<br>
> if interruptSession:<br>
> #dBusInterface = QtDBus.QDBusInterface(self.dBusService, \
self.dBusPath,'' , self.dBus) <br> > #reply = \
dBusInterface.call('AddInhibition',1,who,reason)<br> > \
<br> > msg = \
QtDBus.QDBusMessage.createMethodCall(self.dBusService, \
self.dBusPath,self.dBusInterface,'AddInhibition')<br> > <br>
> #unsignedValue = 1 \
# writes 1 but typed as int32<br> > #unsignedValue = \
ctypes.c_uint(1) # Type not \
registered <br> > #unsignedValue = \
struct.unpack_from("I", struct.pack("i", 1)) # Type \
not registered<br> > #unsignedValue = \
QtCore.QByteArray(b'0x01')[0] # Type not \
registered <br> > #unsignedValue = bytes(1) \
# Type not registered<br> > #unsignedValue = \
QtDBus.QDBusVariant(1) # array of bytes \
"0x01"<br> > #unsignedValue = \
QtDBus.QDBusVariant(1)[0] # QDBusVariant does \
not support indexing<br> > #unsignedValue = \
QtDBus.QDBusVariant().setVariant(ctypes.c_uint(1)) # Variant contained \
QVariantInvalid<br> > unsignedValue = \
QtDBus.QDBusVariant(ctypes.c_uint(1)) # Type not \
registered<br> > <br>
> msg << unsignedValue << who << reason<br>
> reply = QtDBus.QDBusReply(self.dBus.call(msg))<br>
> if reply.isValid():<br>
> self.cookies.append(reply.value())<br>
> <br>
> <br>
> I have commented out previous attempts with their results on the right. Using \
dbus-monitor I can see that the part where i'm struggeling is getting \
QDBusInterface to emit the desired UNIT32 type info.<br> > <br>
> Any pointers on how I pass an unsigned int as an argument to my QDBusMessage \
?<br> <br>
Use QVariant.convert()...<br>
<br>
qvar = QVariant(ctypes.c_uint(1))<br>
qvar.convert(QVariant.UInt)<br>
unsignedValue = QtDBus.QDBusVariant(qvar)<br>
<br>
Phil</blockquote></div>
[Attachment #6 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic