[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QPoint not automatically cast to QPointF
From:       Shriramana Sharma <samjnaa () gmail ! com>
Date:       2012-09-20 11:31:46
Message-ID: CAH-HCWUL2nJ3631e5FJJS+hDT=tMB8L2itk4EchsK8ZNi5mMZA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi. Thanks for your reply. What you have to do in SIP, is it of the nature
of a workaround to Python's inability to do the conversion automatically?
Or Python is able to do the conversion automatically and SIP just needs to
present the classes in a proper manner as required by Python?

Sent from my Android phone
On Sep 20, 2012 2:19 PM, "Phil Thompson" <phil@riverbankcomputing.com>
wrote:

> On Thu, 20 Sep 2012 07:34:10 +0530, Shriramana Sharma <samjnaa@gmail.com>
> wrote:
> > In my recent work with Beziers I ran across this. A QPoint is *not*
> > automatically converted into a QPointF in Python/PyQt while it *is*
> > converted in C++:
> >
> > The following C++ code compiles fine:
> >
> > # include <QtCore/QPoint>
> > # include <QtGui/QPainterPath>
> > int main ( void ) {
> >       QPainterPath p ;
> >       QPoint p1 ( 100, 150 ), c1 ( 166, 250 ), c2 ( 234, 250 ), p2 (
> 300, 150
> )
> >       ;
> >       p . moveTo ( p1 ) ;
> >       p . cubicTo ( c1, c2, p2 ) ;
> > }
> >
> > whereas its Python/PyQt equivalent:
> >
> > #! /usr/bin/env python3
> > from PyQt4 . QtCore import QPoint
> > from PyQt4 . QtGui import QPainterPath
> > p = QPainterPath ()
> > p1 = QPoint ( 100, 150 )
> > c1 = QPoint ( 166, 250 )
> > c2 = QPoint ( 234, 250 )
> > p2 = QPoint ( 300, 150 )
> > p . moveTo ( p1 )
> > p . cubicTo ( c1, c2, p2 )
> >
> > produces the following:
> >
> > Traceback (most recent call last):
> >   File "./qpoint-test.py", line 11, in <module>
> >     p . moveTo ( p1 )
> > TypeError: arguments did not match any overloaded call:
> >   QPainterPath.moveTo(QPointF): argument 1 has unexpected type 'QPoint'
> >   QPainterPath.moveTo(float, float): argument 1 has unexpected type
> >   'QPoint'
> >
> > But QPointF in PyQt *does* provide a constructor from QPoint, so is
> > this the limitation of Python that it does not automatically check
> > whether it can convert one type to another to satisfy a function's
> > call signature? (Or is there some other fault in my PyQt code?)
> >
> > I realize I could always convert it manually using QPointF(p1) etc but
> > the assumption seems natural that an integer-precision numeric object
> > should be accepted where a float-precision can...
>
> It requires a change to SIP to handle this automatically which is on the
> TODO list but I haven't got round to it yet.
>
> Phil
>

[Attachment #5 (text/html)]

<p>Hi. Thanks for your reply. What you have to do in SIP, is it of the nature of a \
workaround to Python&#39;s inability to do the conversion automatically? Or Python is \
able to do the conversion automatically and SIP just needs to present the classes in \
a proper manner as required by Python?</p>

<p>Sent from my Android phone</p>
<div class="gmail_quote">On Sep 20, 2012 2:19 PM, &quot;Phil Thompson&quot; &lt;<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>&gt; \
wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"> On Thu, 20 Sep 2012 07:34:10 \
+0530, Shriramana Sharma &lt;<a \
href="mailto:samjnaa@gmail.com">samjnaa@gmail.com</a>&gt;<br> wrote:<br>
&gt; In my recent work with Beziers I ran across this. A QPoint is *not*<br>
&gt; automatically converted into a QPointF in Python/PyQt while it *is*<br>
&gt; converted in C++:<br>
&gt;<br>
&gt; The following C++ code compiles fine:<br>
&gt;<br>
&gt; # include &lt;QtCore/QPoint&gt;<br>
&gt; # include &lt;QtGui/QPainterPath&gt;<br>
&gt; int main ( void ) {<br>
&gt;       QPainterPath p ;<br>
&gt;       QPoint p1 ( 100, 150 ), c1 ( 166, 250 ), c2 ( 234, 250 ), p2 ( 300, \
150<br> )<br>
&gt;       ;<br>
&gt;       p . moveTo ( p1 ) ;<br>
&gt;       p . cubicTo ( c1, c2, p2 ) ;<br>
&gt; }<br>
&gt;<br>
&gt; whereas its Python/PyQt equivalent:<br>
&gt;<br>
&gt; #! /usr/bin/env python3<br>
&gt; from PyQt4 . QtCore import QPoint<br>
&gt; from PyQt4 . QtGui import QPainterPath<br>
&gt; p = QPainterPath ()<br>
&gt; p1 = QPoint ( 100, 150 )<br>
&gt; c1 = QPoint ( 166, 250 )<br>
&gt; c2 = QPoint ( 234, 250 )<br>
&gt; p2 = QPoint ( 300, 150 )<br>
&gt; p . moveTo ( p1 )<br>
&gt; p . cubicTo ( c1, c2, p2 )<br>
&gt;<br>
&gt; produces the following:<br>
&gt;<br>
&gt; Traceback (most recent call last):<br>
&gt;   File &quot;./qpoint-test.py&quot;, line 11, in &lt;module&gt;<br>
&gt;     p . moveTo ( p1 )<br>
&gt; TypeError: arguments did not match any overloaded call:<br>
&gt;   QPainterPath.moveTo(QPointF): argument 1 has unexpected type \
&#39;QPoint&#39;<br> &gt;   QPainterPath.moveTo(float, float): argument 1 has \
unexpected type<br> &gt;   &#39;QPoint&#39;<br>
&gt;<br>
&gt; But QPointF in PyQt *does* provide a constructor from QPoint, so is<br>
&gt; this the limitation of Python that it does not automatically check<br>
&gt; whether it can convert one type to another to satisfy a function&#39;s<br>
&gt; call signature? (Or is there some other fault in my PyQt code?)<br>
&gt;<br>
&gt; I realize I could always convert it manually using QPointF(p1) etc but<br>
&gt; the assumption seems natural that an integer-precision numeric object<br>
&gt; should be accepted where a float-precision can...<br>
<br>
It requires a change to SIP to handle this automatically which is on the<br>
TODO list but I haven&#39;t got round to it yet.<br>
<br>
Phil<br>
</blockquote></div>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://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