[PyQt] pyqt4topyqt5 a helper for the conversion PyQt4 to PyQt5
Vincent Vande Vyvre
vincent.vandevyvre at swing.be
Tue Jul 23 09:24:36 BST 2013
Le 22/07/2013 20:46, Baz Walter a écrit :
> Thanks for posting this. I had thought of doing something similar
> myself, but didn't find the time.
>
> I haven't really tested your script much, but I found a couple of
> problems. The 'call_re' and 'slots_re' regexps only allow for
> double-quoted strings, so any single-quoted signals/slots will get the
> "Ambiguous syntax" message.
Fixed in the last revision.
>
> Also, your script needs to allow for overloads of signals with default
> arguments like "clicked(bool = 0)". This is a very common source of
> bugs when converting from old-style signals - there's even an example
> of it in your own README!:
>
> < self.connect(ui.right, SIGNAL("clicked()"), lambda angle=90:
> self.rotate(angle))
> > ui.right.clicked.connect(lambda angle=90: self.rotate(angle))
>
> The old-style signal will pass no arguments to its handler, but the
> new-style signal will pass "False" by default (even if the button is
> not checkable). To avoid this issue, you must explicitly select the
> "no argument" overload with an empty tuple:
>
> ui.right.clicked[()].connect(lambda angle=90: self.rotate(angle))
>
> I think there may be a few other signals that have similar issues
> (QAction.triggered is one that immediately springs to mind). The PyQt4
> class reference has details about the default overloads for new-style
> signals, e.g:
>
> http://pyqt.sourceforge.net/Docs/PyQt4/qabstractbutton.html#clicked
> http://pyqt.sourceforge.net/Docs/PyQt4/qaction.html#triggered
>
> so you could try grepping that to find the others.
>
I know some signal send an unexpected boolean but I've never seen a
problem about that.
In all my own codes, for a signal, say:
button.clicked.connect(self.foo)
You can have the callable:
def foo(self, arg)
or:
def foo(self)
without raise any error.
Thank's for your feedback
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
More information about the PyQt
mailing list