在wxPython中展开FoldPanelBar时不会出现滚动条

时间:2016-02-03 21:00:13

标签: python wxpython wxwidgets

当折叠面板展开时,它会越过框架并且不会出现滚动条。我尝试使用ScrolledPanel,但没有帮助。知道我在这里缺少什么吗?

import wx
from wx.lib import scrolledpanel
import wx.lib.agw.foldpanelbar as fpb
import wx.lib.scrolledpanel as sp

class MyPanel(sp.ScrolledPanel):

    def __init__(self, parent):
        sp.ScrolledPanel.__init__(self, parent=parent, size=parent.GetSize(), style = wx.ALL|wx.EXPAND)
        #self.SetAutoLayout(1)
        self.SetupScrolling()
        ##self.boxSizer = wx.BoxSizer(wx.VERTICAL)###
        csStyle = fpb.CaptionBarStyle()
        csStyle.SetFirstColour(wx.Colour(190, 190, 190, 255))
        csStyle.SetSecondColour(wx.Colour(167, 232, 146, 255))
        csStyle.SetCaptionFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.BOLD))

        m_pnl = fpb.FoldPanelBar(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
                            fpb.FPB_VERTICAL)

        item = m_pnl.AddFoldPanel("Set 1", collapsed=True, cbstyle=csStyle)

        self.listContainer = wx.ListCtrl(item, style=wx.LC_REPORT)
        self.listContainer.InsertColumn(0, 'Column1', width=250)
        self.listContainer.InsertColumn(1, 'Column2', width=150)
        self.listContainer.InsertColumn(2, 'Column3')

        m_pnl.AddFoldPanelWindow(item, self.listContainer)
        btnAutoFix = wx.Button(item, wx.ID_ANY, "Go", size=(50,-1))
        m_pnl.AddFoldPanelWindow(item, btnAutoFix)
        ###self.boxSizer.Add(m_pnl)##


        item = m_pnl.AddFoldPanel("Set 2", collapsed=True, cbstyle=csStyle)
        self.listContainer2 = wx.ListCtrl(item, style=wx.LC_REPORT)
        self.listContainer2.InsertColumn(0, 'Column1', width=250)
        self.listContainer2.InsertColumn(1, 'Column2', width=150)
        self.listContainer2.InsertColumn(2, 'Column3')

        m_pnl.AddFoldPanelWindow(item, self.listContainer2)

        self.pnl = m_pnl
        ##self.SetSizer(self.boxSizer)###

if __name__ == '__main__':
    app = wx.App(False)
    frame = wx.Frame(None, size=(650, 400), style=wx.DEFAULT_FRAME_STYLE)
    panel = MyPanel(frame)
    # Add sizer information for the scrolled panel
    szmain = wx.BoxSizer(wx.VERTICAL)
    szmain.Add(panel.pnl, 1, wx.EXPAND|wx.ALL, 4)
    panel.SetSizer(szmain)
    frame.Show()
    app.MainLoop()

1 个答案:

答案 0 :(得分:1)

请勿使用FoldPanelBar的默认尺寸。出于某种原因,它似乎使小部件表现得很愚蠢。如果指定大小,滚动条将正确显示。

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

class MyPanel(scrolled.ScrolledPanel):

    def __init__(self, parent):
        scrolled.ScrolledPanel.__init__(self, parent=parent,
                                        size=parent.GetSize(),
                                        style = wx.ALL|wx.EXPAND)
        #self.SetAutoLayout(1)
        self.SetupScrolling()
        self.boxSizer = wx.BoxSizer(wx.VERTICAL)
        csStyle = fpb.CaptionBarStyle()
        csStyle.SetFirstColour(wx.Colour(190, 190, 190, 255))
        csStyle.SetSecondColour(wx.Colour(167, 232, 146, 255))
        csStyle.SetCaptionFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.BOLD))

        m_pnl = fpb.FoldPanelBar(self, wx.ID_ANY, wx.DefaultPosition, (600,800),
                            fpb.FPB_VERTICAL)

        item = m_pnl.AddFoldPanel("Set 1", collapsed=True, cbstyle=csStyle)

        self.listContainer = wx.ListCtrl(item, style=wx.LC_REPORT)
        self.listContainer.InsertColumn(0, 'Column1', width=250)
        self.listContainer.InsertColumn(1, 'Column2', width=150)
        self.listContainer.InsertColumn(2, 'Column3')

        m_pnl.AddFoldPanelWindow(item, self.listContainer)
        btnAutoFix = wx.Button(item, wx.ID_ANY, "Go", size=(50,-1))
        m_pnl.AddFoldPanelWindow(item, btnAutoFix)
        self.boxSizer.Add(m_pnl)


        item = m_pnl.AddFoldPanel("Set 2", collapsed=True, cbstyle=csStyle)
        self.listContainer2 = wx.ListCtrl(item, style=wx.LC_REPORT)
        self.listContainer2.InsertColumn(0, 'Column1', width=250)
        self.listContainer2.InsertColumn(1, 'Column2', width=150)
        self.listContainer2.InsertColumn(2, 'Column3')

        m_pnl.AddFoldPanelWindow(item, self.listContainer2)

        self.pnl = m_pnl
        self.SetSizer(self.boxSizer)

class MainFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, title='Test')
        panel = MyPanel(self)
        self.Show()


if __name__ == '__main__':
    app = wx.App(False)
    frame = MainFrame()
    app.MainLoop()

对于wxPython项目,您可能会考虑submitting a bug