[PyQt] pyqt4topyqt5 a helper for the conversion PyQt4 to PyQt5
Vincent Vande Vyvre
vincent.vandevyvre at swing.be
Wed Jul 24 07:50:26 BST 2013
Le 23/07/2013 18:01, Baz Walter a écrit :
> On 23/07/13 09:24, Vincent Vande Vyvre wrote:
>> 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.
>
> You've completely missed the point :)
>
> If you look carefully at what I posted you will see that there is a
> real problem. To spell it out using the example from your README:
>
> ui.right.clicked.connect(lambda angle=90: self.rotate(angle))
>
> The signal will pass 'False' by default, so the 'angle' argument of
> the handler will be effectively set to '0' every time the button is
> clicked, rather than the '90' that was intended.
>
> This is different from the old-style signal:
>
> self.connect(ui.right, SIGNAL("clicked()"), lambda angle=90:
> self.rotate(angle))
>
> where the default is to pass nothing, meaning that the 'angle'
> argument will remain as the intended '90'.
>
> The examples you give above don't suffer from this problem, because
> they don't have *default arguments*. The problem case is this:
>
> def foo(self, arg=25)
>
> Personally, I always use the 'clicked[()]' form when connecting up
> these kinds of signals, because it's so easy to add a default argument
> to a handler at a later stage and forget about the overloads of the
> signal that pass a default value.
>
> (Yeah, I know that '[()]' looks ugly - but the potential for bugs is
> far uglier).
>
Oops, I was not thinking for the case of the argument.
Anyway, I must rewrite this part of code because I see (with the help of
nullege.com) there's some unusual syntaxes that are not matched by the
regex.
Many thanks, Baz
Regards
--
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