Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollbars are not appearing on expanding FoldPanelBar in wxPython

When the fold panels expand, it goes outside of the frame and scroll bars are not appearing. I tried using a ScrolledPanel, but did not help. Any idea what I am missing here?

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()
like image 629
softwarematter Avatar asked Nov 09 '22 20:11

softwarematter


1 Answers

Don't use the FoldPanelBar's default size. For some reason, it seems to make the widget behave in a dumb manner. If you specify a size, the scrollbars appear correctly.

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()

You might consider submitting a bug for this to the wxPython project.

like image 153
Mike Driscoll Avatar answered Nov 14 '22 23:11

Mike Driscoll