[Tutor] GUI design

Magnus Lycka magnus@thinkware.se
Sun Jan 19 12:36:08 2003


At 03:23 2003-01-19 +0100, Nicholas Wieland wrote:
>Every comment, suggestion, pointers to 'state of the art' code, flame-wa=
r=20
>and *PLONK* is greatly appreciated.

May I suggest that you never mix tabs with spaces in Python code?
I know that my fellow Swede in Link=F6ping, Mr Lundh, likes tabs,
but may I suggest four spaces for indentation. Most editors can
give you that when you press Tab, and the good ones will remove
as much if you press Shift-Tab or backspace.

Tabnanny can be used to clean up existing code.

Your code was a wee bit tiresome to read due to the messed up
indentation. BTW, I find that an empty line between methods also
increases readability. (Then I have two empty lines between classes
and at some occations empty lines inside larger methods where we
obviously go from doing one thing to doing something else. This
typically happens in __init__, when I build menues etc.

Otherwise, it didn't look too bad I think, but as I said, it
was hard to read, so I'm not sure.

I've often felt that it should be possible to build both menus
and screen layout in a much smarter way, by wrapping things like
wxMenu.Append() in functions that just takes some kind of sequence.

Then we just write something like:

myMenu =3D (
     ('&File',
         ('New', (ALT, 'N'), self.OnFileNew),
         ('Open', (ALT, 'O'), self.OnFileOpen),
         ('Close', (ALT, 'C'), self.OnFileClose)),
     ('%Edit',
         ('Cut', (CTRL, 'X'), self.OnEditCut),
         ('Copy', (CTRL, 'C'), self.OnEditCopy),
         ('Paste', (CTRL, 'V'), self.OnEditPaste)))

and then we feed that to some standard method in some kind of
mixin class that we can use with Frames etc.


--=20
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se