pythonwxpythonsizer

WxPython: FoldPanelBar not really folding


I've written the following code using FoldPanelBar:

import wx
import wx.lib.agw.foldpanelbar as fpb

class frame(wx.Frame):
    def __init__(self,*args,**kwargs):
        wx.Frame.__init__(self,*args,**kwargs)
        self.text_ctrl_1=wx.TextCtrl(self,-1,style=wx.TE_MULTILINE)

        self.fpb=fpb.FoldPanelBar(self,-1, style=fpb.FPB_HORIZONTAL)
        self.fold_panel=self.fpb.AddFoldPanel("Thing")
        self.thing=wx.TextCtrl(self.fold_panel,-1, size=(400,-1), style=wx.TE_MULTILINE)
        self.fpb.AddFoldPanelWindow(self.fold_panel, self.thing)

        self.sizer_1=wx.BoxSizer(wx.HORIZONTAL)

        self.sizer_1.Add(self.text_ctrl_1,1,wx.EXPAND)
        self.sizer_1.Add(self.fpb,1,wx.EXPAND)

        self.SetSizer(self.sizer_1)

        self.Show()



if __name__=="__main__":
    app=wx.PySimpleApp()
    frame(None,-1)
    app.MainLoop()

This is what it looks like before folding:

alt text http://img23.imageshack.us/img23/4309/before.gif

The right textbox is in the fold panel, so when I click the arrow, it disappears. However, it looks like this:

alt text http://img22.imageshack.us/img22/6306/afterz.gif

I expected the left textbox to grow in size to fill the whole frame.

What am I doing wrong?


Solution

  • This does what you want I think. I haven't tested multiple panels in the foldpanelbar, you might need to limit the size of the foldpanelbar explicitly to prevent it from getting too wide.

    import wx
    import wx.lib.agw.foldpanelbar as fpb
    
    class frame(wx.Frame):
        def __init__(self, *args, **kwargs):
            wx.Frame.__init__(self, *args, **kwargs)
            self.text_ctrl_1=wx.TextCtrl(self, -1, size=(400, 100),
                                         style=wx.TE_MULTILINE)
            self.fpb = fpb.FoldPanelBar(self, -1,
                style=fpb.FPB_HORIZONTAL|fpb.FPB_DEFAULT_STYLE)
            self.fold_panel = self.fpb.AddFoldPanel("Thing")
            self.thing = wx.TextCtrl(self.fold_panel, -1, size=(400, -1),
                                     style=wx.TE_MULTILINE)
            self.fpb.AddFoldPanelWindow(self.fold_panel, self.thing)
            self.fpb.Bind(fpb.EVT_CAPTIONBAR, self.onCaptionBar)
            self.sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
            self.sizer_1.Add(self.text_ctrl_1, 1, wx.EXPAND)
            self.sizer_1.Add(self.fpb, 0, wx.EXPAND)
            self.SetSizer(self.sizer_1)
            self.ResizeFPB()
    
        def onCaptionBar(self, event):
            event.Skip()
            wx.CallAfter(self.ResizeFPB)
    
        def ResizeFPB(self):
            sizeNeeded = self.fpb.GetPanelsLength(0, 0)[2]
            self.fpb.SetMinSize((sizeNeeded, self.fpb.GetSize()[1]))
            self.Fit()
    
    
    app = wx.App(0)
    f = frame(None)
    f.Show()
    app.MainLoop()