[PyQt] simpler 'connect' function
Aaron Digulla
digulla at hepe.com
Thu Jan 17 13:22:34 GMT 2008
Quoting Ewald de Wit <erdewit at zonnet.nl>:
> On Wednesday 16 January 2008 09:21:40 Aaron Digulla wrote:
>> As for making the API simpler, I'd opt for
>>
>> button.connectClicked(self.buttonWasClicked)
>
> Wouldn't it be nicer if the signals where attributes of your object,
> so that you could write
>
> button.clicked.connect(self.onButtonClicked)
That's one way to look at it. In C++, a signal is much more close to a
method, though. Taking a step back, what happens behind the scenes is:
connect(sender, signal, receiver, slot)
i.e. connect is a global / static function. It just happens to work
only with classes derived from QObject, so it has been implemented as
a member method but actually, it just connects two QObjects. So the
syntax most closely resembling what is actually going on would be:
connect(button.clicked, self.onButtonClicked)
For this to work, "clicked" must be implemented as a method of
QPushButton, for example, so that connect() can pick the sender object
from the call.
As a convenience (since clicked() is now a full-blown method), this
would work, too:
button.clicked(self.onButtonClicked)
Since signals are actually declared in the C++ class headers, I think
there is no possibility to have clashes between method and signal
names. Unfortunately, this again introduces ambiguities because of
argument overloading which must be solved by mapping argument types to
the method name, probably manually.
Regards,
--
Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."
http://www.pdark.de/
More information about the PyQt
mailing list