WxPython:FoldPanelBar并没有真正折叠

时间:2009-05-02 20:51:28

标签: python wxpython sizer

我使用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()

这是折叠之前的样子:

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

右侧文本框位于折叠面板中,因此当我单击箭头时,它会消失。但是,它看起来像这样:

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

我预计左侧文本框的大小会增加以填充整个框架。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

这就是你想要的。我没有在foldpanelbar中测试多个面板,您可能需要明确限制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, 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()