[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 \
&quot;org.kde.Solid.PowerManagement.PolicyAgent&quot; path \
&quot;/org/kde/Solid/PowerManagement/PolicyAgent&quot; interface \
&quot;org.kde.Solid.PowerManagement.PolicyAgent&quot; member \
&quot;AddInhibition&quot;: Marshalling failed: Variant containing QVariant::Invalid \
passed in arguments</span></font><br></div><div><br></div><div><font size="2">I must \
admit i&#39;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 &lt;<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>&gt; \
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 &lt;<a href="mailto:kemibo@gmail.com" \
target="_blank">kemibo@gmail.com</a>&gt; wrote:<br> &gt; <br>
&gt; I&#39;m trying to use PyQt5&#39;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> &gt; <br>
&gt; The code is written using Python 3 and using Pyqt5<br>
&gt; <br>
&gt; class PowerChangeInhibitor:<br>
&gt;        def __init__(self):<br>
&gt;              self.dBusService = \
&#39;org.kde.Solid.PowerManagement.PolicyAgent&#39;<br> &gt;              \
self.dBusPath = &#39;/org/kde/Solid/PowerManagement/PolicyAgent&#39;<br> &gt;         \
self.dBusInterface = &#39;org.kde.Solid.PowerManagement.PolicyAgent&#39;<br> &gt;     \
self.cookies = []<br> &gt;              <br>
&gt;        def ActivateInhibition(self, interruptSession, changeProfile, \
changeScreenSettings,who, reason):<br> &gt; <br>
&gt;              <br>
&gt;              self.dBus = QtDBus.QDBusConnection.sessionBus()<br>
&gt;              if interruptSession:<br>
&gt;                    #dBusInterface = QtDBus.QDBusInterface(self.dBusService, \
self.dBusPath,&#39;&#39; , self.dBus) <br> &gt;                    #reply = \
dBusInterface.call(&#39;AddInhibition&#39;,1,who,reason)<br> &gt;                    \
<br> &gt;                    msg = \
QtDBus.QDBusMessage.createMethodCall(self.dBusService, \
self.dBusPath,self.dBusInterface,&#39;AddInhibition&#39;)<br> &gt;   <br>
&gt;                    #unsignedValue = 1                                            \
# writes 1 but typed as int32<br> &gt;                    #unsignedValue = \
ctypes.c_uint(1)                                                      # Type not \
registered <br> &gt;                    #unsignedValue = \
struct.unpack_from(&quot;I&quot;, struct.pack(&quot;i&quot;, 1))            # Type \
not registered<br> &gt;                    #unsignedValue = \
QtCore.QByteArray(b&#39;0x01&#39;)[0]                                   # Type not \
registered <br> &gt;                    #unsignedValue =   bytes(1)                   \
# Type not registered<br> &gt;                    #unsignedValue = \
QtDBus.QDBusVariant(1)                                             # array of bytes \
&quot;0x01&quot;<br> &gt;                    #unsignedValue = \
QtDBus.QDBusVariant(1)[0]                                         # QDBusVariant does \
not support indexing<br> &gt;                    #unsignedValue = \
QtDBus.QDBusVariant().setVariant(ctypes.c_uint(1))   # Variant contained \
QVariantInvalid<br> &gt;                    unsignedValue =   \
QtDBus.QDBusVariant(ctypes.c_uint(1))                        # Type not \
registered<br> &gt; <br>
&gt;                    msg &lt;&lt; unsignedValue &lt;&lt; who &lt;&lt; reason<br>
&gt;                    reply = QtDBus.QDBusReply(self.dBus.call(msg))<br>
&gt;                    if reply.isValid():<br>
&gt;                          self.cookies.append(reply.value())<br>
&gt; <br>
&gt;     <br>
&gt; I have commented out previous attempts with their results on the right. Using \
dbus-monitor I can see that the part where i&#39;m struggeling is getting \
QDBusInterface to emit the desired UNIT32 type info.<br> &gt; <br>
&gt; 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