[Python-3000] GUI -- an API, not a toolkit

Giovanni Bajo rasky at develer.com
Wed May 10 03:58:43 CEST 2006


Antoine Pitrou <solipsis at pitrou.net> wrote:

>> No, you're over-generalizing. What if I wanted the buttons Ok/Cancel
>> instead? Or "Abort"/"Retry"/"Cancel"? The mental overhead is having
>> to remember different APIs from the Yes/No case, if you're going to
>> use a specialized version returning just a boolean.
>
> But magic numbers are ugly, even if they are hidden behind an
> enumeration.

You're changing the subject of the discussion. It was said existing solutions
for Python GUI toolkits required too much overhead to display a simple yes/no
messagebox. I demonstrated this is false.

I wasn't debating that PyQt has a Pythonic design. It is *by design* a wrapper
of Qt meant to be as similar as possible to the original C++ Qt library (in
fact, it doesn't have a formal documentation: I use the Qt C++ documentation -- 
which is btw award-winning as best software documentation -- and it works for
PyQt too).

> If you try to print them for debugging, it will only show
> the numeric values, which is hardly intuitive. GUI APIs generally
> define dozens or hundreds of such numeric constants which clutter
> their
> namespaces (ever tried "dir(wx)" ? ;-)).
>
> IIRC the PyGUI solution is simple and elegant, i.e. it uses a string.
>
> if answer == 'yes':
>     ....
> elif answer == 'cancel':
>     ....
>
> (of course you shouldn't internationalize that one ;-))

These are small-scale details I really don't think they are very important.
OTOH it would be far too easy to provide a simple wrapper to QMessageBox so to
expose a similar API. The problem is not here, there's more to GUI design. How
simple is it to do a new widget? Is it possible to inherit existing components
in easy way and to create new reusable components? Is it possible to connect
components of the GUI without them depending on each other in any way?

Say I need a pushbutton, with toggle state, which contains a embossed rectangle
which is filled of red when the button is pressed and filled of green when the
button is raised. Say I need a listbox which displays items as text with small
icons attached, in which the selection follows some custom rules (click: toggle
item selection, double-click: deselect all, select double-clicked element). Say
a need a table view where the first row is made of non-selectable images of
square size (so that if the user enlarges the first row, also the columns
automatically adjust to keep the images square), and the other rows contain
toggle buttons with custom text (and a custom yes/no icon). Can I do that with
the minimal code I expect to write (that is, only write code for the
differences against the default behaviour, and inherit everything else)?

Giovanni Bajo



More information about the Python-3000 mailing list