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

Antoine Pitrou solipsis at pitrou.net
Wed May 10 03:30:57 CEST 2006


Le mercredi 10 mai 2006 à 03:23 +0200, Giovanni Bajo a écrit :
> 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. 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 ;-))




More information about the Python-3000 mailing list