Help! I thought I understood layout constraints. I even have an application
that uses them liberally. But as I started work on a new application, I
seem to be stuck. Here is a simple code snippet that I thought would product
a frame with 2 panels, upper and lower. The upper panel is the width of the
main frame, with a fixed height. The lower panel will adjust as the height
of the main frame is adjusted. What am I doing incorrectly? Are sizers
"better" to use?
from wxPython.wx import *
class myExampleFrame(wxFrame):
def __init__(self, parent, id=-1, title='Test', x_size=400, y_size=300):
# create the frame, allow resize in the vertical direction only
wxFrame.__init__(self, parent, id, title, wxDefaultPosition,
wxSize(x_size, y_size))
self.SetSizeHints(minH=y_size, minW=x_size, maxW=y_size)
# build the upper panel. This panel should never change height
upper_panel = wxPanel(self, wxNewId(), wxDefaultPosition,
wxSize(x_size-8, 100), wxSUNKEN_BORDER)
# build the lower panel. This panel will accomodate changes
# in the height of the main window.
lower_panel = wxPanel(self, wxNewId(), wxDefaultPosition,
wxDefaultSize, wxSUNKEN_BORDER)
lc = wxLayoutConstraints()
lc.top.Below(upper_panel)
lc.left.SameAs(upper_panel, wxLeft)
lc.width.SameAs(upper_panel, wxWidth)
lc.bottom.SameAs(self, wxBottom)
lower_panel.SetConstraints(lc)
class myExampleApp(wxApp):
def OnInit(self):
frame = myExampleFrame(NULL, -1, title='My Example App')
frame.Show(true)
self.SetTopWindow(frame)
return true
···
############################################################################
####
### <Mainline>
#################################################################
############################################################################
####
app=myExampleApp(0)
app.MainLoop()
Greg Lindstrom
Acxiom Corporation, mail: CWY10011149
InfoBase Products Development office: (501) 342-1626
301 Industrial Blvd, Conway, AR, 72032 fax: (501) 336-3911
email: Greg.Lindstrom@acxiom.com
The whole problem with the world is that fools and fanatics are always so
certain of themselves, but wiser people so full of doubts. -- Bertrand
Russell