[wxPython] Layout Constraints

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

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?

Maybe not better, but I like sizers because they seem easier and
more predictable. YMMV

Instead of the following:

        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)

try this:

        sizer = wxBoxSizer(wxVERTICAL)
        sizer.AddWindow(upper_panel, 0, wxEXPAND)
        sizer.AddWindow(lower_panel, 1, wxEXPAND)
        sizer.Fit(self)
        self.SetAutoLayout(true)
        self.SetSizer(sizer)

Cheers,

···

--- Lindstrom Greg - glinds <Greg.Lindstrom@acxiom.com> wrote:

=====
Donnal Walter
Arkansas Children's Hospital

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

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?

You're missing a self.SetAutoLayout(true)

Are sizers
"better" to use?

Most of the time, once you get past the learning curve they are usually
easier than Layout Constrinats.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!