[Pygui] signals and slots
list at qtrac.plus.com
Mon Nov 30 15:14:02 CET 2009
On 2009-11-30, Greg Ewing wrote:
> inhahe wrote:
> > it would be nice to see PyGUI turn into something like PyQt - but of
> > course a lot lightweight and therefore probably with a simpler
> > interface.. mainly what i like about PyQt is its signals and slots
> > mechanism.
> I'm not all that familiar with Qt, but my experiences with
> gtk make me less than enthusiastic about the signal/slot
> paradigm for event handling. I find it tedious having to
> make a bunch of calls to plug in event handlers every time
> I create a widget.
That's not at all how PyQt works. Here's a complete working custom
widget in PyQt:
class MyWidget(QWidget): pass
If you want the widget to paint itself then you implement a
paintEvent()---but you don't have to do this if you have inherited a
widget that already paints itself the way you want:
class MyListWidget(QListWidget): pass
If you want to handle mouse clicks or key presses, then you implement
the corresponding event handlers.
So, you only need to implement what you actually want to use (or that
you want to be different).
Signals and slots are used to combine widgets to get particular
behaviours, e.g., to only enable an OK button if various fields are
filled in, or to repsond to a button click, that kind of thing. Qt's
event handling mechanism is used for creating custom widgets.
I know that it is nice creating things from scratch but PyQt represents
a lot of prior art that has proved very durable and popular so I think
you'd at least find it interesting to try it out---it might even help
you avoid some pitfalls. (And with Python 3/PyQt 4.6 the API is now much
more Pythonic than it used to be---although my book only covers the
older well-established API.)
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
C++, Python, Qt, PyQt - training and consultancy
"Rapid GUI Programming with Python and Qt" - ISBN 0132354187
More information about the Pygui