[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] simpler 'connect' function
From: Aaron Digulla <digulla () hepe ! com>
Date: 2008-01-17 13:22:34
Message-ID: 20080117142234.sv997tf6j4wu8w4o () www ! hepe ! com
[Download RAW message or body]
Quoting Ewald de Wit <erdewit@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/
_______________________________________________
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