aquavitae
aquavitae

Reputation: 19114

wxCollapsiblePane forces frame resize

I have a wxCollapsiblePane and a wxGrid in a wxFrame. Every time I collapse or expand the wxCollapsiblePane, the entire frame is resized. What I want is for the wxGrid to grow and shrink instead, and for the frame to stay the same size. I also notice that although I'm explicitly creating the wxFrame at a size of 500x500, it actually shrinks to suit its contents. I assume that this is something to do with the sizers, but nothing I've tried seems to affect this. Can anyone point out where I'm going wrong? Here is my code so far.

import wx
import wx.grid

class Frame(wx.Frame):

    def __init__(self, *args, **kwargs):
        super(Frame, self).__init__(*args, **kwargs)
        cpane = wx.CollapsiblePane(self)
        p = cpane.GetPane()
        sz = wx.BoxSizer()
        sz.Add(wx.TextCtrl(p), 1, wx.EXPAND)
        p.SetSizer(sz)

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.grid = wx.grid.Grid(self)
        self.grid.CreateGrid(5, 5)

        sizer.Add(cpane, 0, wx.EXPAND)
        sizer.Add(self.grid, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.SetAutoLayout(1)
        sizer.Fit(self)
        self.Show()

app = wx.App(False)
win = Frame(None, size=(500, 500))
win.Show()
app.MainLoop()

Upvotes: 1

Views: 864

Answers (1)

RobinDunn
RobinDunn

Reputation: 6206

In order to not allow the CollapsiblePane to resize the frame use the wx.CP_NO_TLW_RESIZE style when you create it. See http://docs.wxwidgets.org/trunk/classwx_collapsible_pane.html

The Fit() call is what is shrinking the frame to fit the contents. It is not needed if you don't want that to happen. And the SetAutoLayout call in your code is redundant since SetSizer will turn that on that property for you.

Upvotes: 4

Related Questions