wxPython sizer tutorial version 1.5

python@bdurham.com wrote:

Mike,

Your 2nd tutorial looks great! Here's my feedback/questions on your 2nd
example:

1. You pick an arbitrary size for your dialog via your SetSizeHints()
call. Shouldn't sizers be able to size your dialog optimally given the
size of its child sizers/widgets? In other words, shouldn't there be a
way to specify a left and bottom margin and have the dialog size itself
accordingly? (And once this size has been calculated, the SetSizeHints()
called to lock-in a min size for the dialog?)
  

Yes, that is arbitrary size I chose to try to make the form usable by blocking the user from making it too small or too large. You can comment it out and see that the sizers do indeed calculate a decent size for the form or you could just play with the Fit() command too.

I'm not aware of a way to set margins per se. If anyone else knows, please let me know.

Note: By left margin I mean a width identical to the margin between the
text controls and the right edge of the frame. By bottom margin I mean a
height identical to the vertical margin between the top of the OK/Cancel
buttons and the separator line above them.
  
Technically speaking, there is a margin on the left that is the same on the right (I think). Unfortunately since the first item in the horizontal sizer is a spacer, you cannot see the margin, so to speak. I tried commenting out the addition of the spacer, but that didn't help me. Hmmm....not sure how to answer this...

2. Your text controls are not optimally sized for their font. If you
type text into your text controls there's a larger margin on the bottom
than the top of the input text. I see two approaches: Either vertically
center the text in the text control (is this possible via a flag?) or
size the height of the text control to the font/font size of the text
control (a more generic approach?)
  
This would probably look better if you changed all the lines where you add the TextCtrl to the GridSizer from this:

gridSizer.Add(inputTxtOne, 0, wx.EXPAND)

to this:

gridSizer.Add(inputTxtOne, 0, wx.EXPAND|wx.ALL, 5)

I noticed that it looked a little odd, but decided to leave it. I guess I shouldn't have done that. Oh well...live and learn.

3. When you maximize the form, it jumps to the upper left hand corner of
the display. Is there any way to have a form remember its maximized
position if one moves the form once its been maximized and/or have the
form center itself on the desktop when its initially maximized? (I know
this isn't a sizer question per se).
  
Probably. There are wx.EVT_MOVE and wx.EVT_MOVING events, so theoretically you could do a self.GetPosition() in your handler. Then just save that as a property and in your wx.EVT_MAXIMIZE, call the SetPosition() method using your saved values.

Apologies if my feedback is too picky and thanks again for taking the
time to help new wxPython developers learn best practice development
patterns.

Regards,
Malcolm

Mike