[wxPython-users] BoxSizers and resizable panels

Robin Dunn robin at alldunn.com
Fri Feb 8 14:13:02 PST 2008


Aaron MacDonald wrote:
> I have three panels within one root panel.  Two of them have fixed =

> sizes, while one has a fixed width and a (theoretically) variable =

> height. The largest fixed-size panel is on the left hand side of the =

> root panel.  On the right hand side is the smaller fixed-size and the =

> variable-height panel stacked on top of each other.  The top of the two =

> fixed-sized panels are supposed to match.  The variable-height panel is =

> centered horizontally and stretched vertically within its space.  This =

> is shown in the attached picture.
> =

> The problem is that the variable-height panel is not showing up.  This =

> is the code I'm using:

It's there, but with a zero height because the parent sizers are not =

being expanded to fill the available space.  Try this one (attached) =

instead.

BTW, I suggest using either the widget inspector to help diagnose things =

like this, or you can do your layout mockup in XRCed and then translate =

to source if you don't want to use XRC itself.  (Sample also attached.)

-- =

Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!

-------------- next part --------------

import wx

def makePanel(parent, fixedSize, colour):
    resultPanel =3D wx.Panel(parent)

    resultPanel.SetBackgroundColour(colour)
    resultPanel.SetMinSize(fixedSize)
    resultPanel.SetMaxSize(fixedSize)

    return resultPanel

def makeFlexiblePanel(parent, sideLen, colour):
    # Height is variable
    resultPanel =3D wx.Panel(parent, size =3D (sideLen, -1))
    resultPanel.SetBackgroundColour(colour)

    return resultPanel

class OverPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        self.SetBackgroundColour((16, 16, 16))

        bigPanel =3D makePanel(self, (500, 500), (0, 0, 255))
        midPanel =3D makePanel(self, (200, 200), (0, 255, 0))
        longPanel =3D makeFlexiblePanel(self, 50, (255, 0, 0))

        sizerH =3D wx.BoxSizer(wx.HORIZONTAL)
        self.SetSizer(sizerH)

        sizerH.Add(bigPanel, flag =3D wx.ALL, border =3D 10)

        sizerV =3D wx.BoxSizer(wx.VERTICAL)
        sizerH.Add(sizerV,  flag =3D wx.TOP|wx.RIGHT|wx.BOTTOM|wx.EXPAND,
                   border =3D 10)

        sizerV.Add(midPanel)

        sizerH2 =3D wx.BoxSizer(wx.HORIZONTAL)
        sizerV.Add(sizerH2, 1, flag =3D wx.TOP|wx.EXPAND, border =3D 10)

        sizerH2.AddStretchSpacer()
        sizerH2.Add(longPanel, flag =3D wx.EXPAND) # !! Not visible !!
        sizerH2.AddStretchSpacer()

class TestFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, title =3D 'Test')
        sizer =3D wx.BoxSizer()
        self.SetSizer(sizer)

        panel =3D OverPanel(self)
        sizer.Add(panel, 1, flag =3D wx.EXPAND)

        sizer.Fit(self)
        self.SetMinSize(self.GetSize())

if __name__ =3D=3D '__main__':
    app =3D wx.App(False)
    frame =3D TestFrame(None)
    frame.Show()
    import wx.lib.inspection
    wx.lib.inspection.InspectionTool().Show()
    app.MainLoop()

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sizer_test.xrc
Type: text/xml
Size: 1609 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20080=
208/9b8423b5/sizer_test.bin


More information about the wxpython-users mailing list