[wxPython-users] Re: Layout Trouble
Christopher Barker
Chris.Barker at noaa.gov
Tue Sep 19 09:36:55 PDT 2006
Bulkan-Savun Evcimen wrote:
> Do you mean ;
>
> A (Panel): uses a BoxSizer(Horizontal), and Contains two Panels "B" and
> "C"
> B (Panel): BoxSizer(Vertical), wx.GenericDirCtrl + "D"
> Im getting confused in how you say that A is a vertical BoxSizer which
> contains two other sizers, as a window can contain only one sizer (?)
This is one of the major sources of confusion (and power) with wxPython:
There are three parallel, yet distinct hierarchies when building your GUI:
The wx parent-child hierarchy:
- controls on Panels on Panels, on Frames, etc.
The Python class hierarchy:
- subclasses of wxPanels, etc, and the controls on them.
The Sizer hierarchy:
-- controls in sizers, in sizers, in... on a Panel, etc.
The trick as that these different hierarchies can be mixed and matched
in unlimited ways.
* The key point you NEED to know:
Sizers are ONLY used to do layout of controls, they don't have anything
to do with the parent-child relationships or Python classes. However,
I'm pretty sure that the controls in a given Sizer hierarchy have to
have the same parent.
* My advise for good design:
Use a Python class (usually a subclass of wx.Panel) to group controls
that have are logically used together. Usually, controls that work
together also should be arranged together in your GUI, so this works
well. If you find yourself writing code like:
self.panel1 = wx.Panel(self, ...)
self.panel2 = wx.Panel(self.panel1, ...)
self.AButton = wx.Button(self.panel2, ....)
You've got a LOT of nested parent-child relationships all in one Python
class. Chances are You'd be better of with panel2 as it's own class, and
probably panel1 also.
For instance, I'm not sure what functionality you're going for, but it
looks like it might make sense for the stuff in the upper right of your
layout (wx.Gauge and Start and Abort) to be all on a custom wx.Panel class.
See:
http://wiki.wxpython.org/index.cgi/wxPython_Style_Guide
For some more hints.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the wxpython-users
mailing list