Add sizer to wx.lib.agw.foldpanelbar.FoldPanelBar

How can I add widgets that are inside of sizers to a panel of wx.lib.agw.foldpanelbar.FoldPanelBar?
It seems that it only accepts widgets subclassed from wx.window.

Does not work:

        fold_panel = panelbar.AddFoldPanel(self.GetLabel())

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        self.textcontrol = wx.TextCtrl(
        hbox.Add(self.textcontrol, proportion=1)

        self.button = wx.Button(
        hbox.Add(self.button, flag=wx.LEFT, border=5)

        vbox.Add(hbox, flag=wx.EXPAND)

        panelbar.AddFoldPanelWindow(fold_panel, vbox)

Any ideas anyone? It seems strange that you can’t use sizers. :thinking:

Hmmm…Could someone at least say “it isn’t possible” if that is the case? I am not really sure why it won’t accept a sizer…

Reviewing the demo for FoldPanelBar the class FoldTestPanel uses sizers. I have never had a need to use the foldpanelbar so that is about the best I can offer.

Thanks. I will look into it.

Well, I guess even the demo doesn’t show a sizer being used to place widgets into the foldpanel. So, maybe that means it must be wx.Window derived or else…

This from the demo

class FoldTestPanel(wx.Panel):

    def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize,
                 style=wx.NO_BORDER | wx.TAB_TRAVERSAL):

        wx.Panel.__init__(self, parent, id, pos, size, style)


        self.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)

    def OnPressCaption(self, event):

    def CreateControls(self):

        sizer = wx.BoxSizer(wx.VERTICAL)

        subpanel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
                            wx.NO_BORDER | wx.TAB_TRAVERSAL)
        sizer.Add(subpanel, 1, wx.GROW | wx.ADJUST_MINSIZE, 5)

        subsizer = wx.BoxSizer(wx.VERTICAL)
        itemstrings = ["One", "Two", "Three"]

        item5 = wx.Choice(subpanel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
                          itemstrings, 0)

        subsizer.Add(item5, 0, wx.GROW | wx.ALL, 5)

        item6 = wx.TextCtrl(subpanel, wx.ID_ANY, "", wx.DefaultPosition, wx.DefaultSize,
        subsizer.Add(item6, 1, wx.GROW | wx.ALL, 5)

        item7 = wx.RadioButton(subpanel, wx.ID_ANY, "I Like This", wx.DefaultPosition,
                               wx.DefaultSize, 0)
        subsizer.Add(item7, 0, wx.ALIGN_LEFT | wx.ALL, 5)

        item8 = wx.RadioButton(subpanel, wx.ID_ANY, "I Hate It", wx.DefaultPosition,
                               wx.DefaultSize, 0)
        subsizer.Add(item8, 0, wx.ALIGN_LEFT | wx.ALL, 5)

# ----------------------------------------------------------------------------

The above code is using the foldpanelbar, sizers and appears to me to allow a sizer to add a widget/control. It looks like a radio button, a textctrl, a choice control and added to sizers.
Unless I don’t understand what you are asking - it looks to me that a sizer is added to the foldpanelbar and widgets are added to the sizer.

Hmmm… Thanks for trying to understand :slight_smile:

Maybe I am missing it(?), because all I see is instances of where individual widgets are added to the panelbar:

From the demo:

        item = pnl.AddFoldPanel("Some Opinions ...", collapsed=False)
        pnl.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "I Like This"))
        pnl.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "And Also This"))
        pnl.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "And Gimme This Too"))

To clarify, I am wanting to put a button alongside a textctrl and place it into the foldpanel (see the original code snippet). I am putting the controls into a sizer which I am wanting to put into the foldpanel, but it doesn’t seem to work because AddFoldPanelWindow doesn’t accept sizers.

I am not sure how to make this work…

Yes I don’t understand. Now please take this post with a grain of salt because I have not had a need to use the FoldPanelBar widget. What I see is a widget added to a sizer and sizer was added to a panel and the panel added to the foldPanelBar. Is it that you are trying to add the sizer directly to FoldPanelBar? Just reading the code that would not work. It must be obvious that widgets are added to the demo code - so even if I’m wrong (and I could be) - there has to be a way to add widgets.

1 Like

Thank you, @jfabiani it now seems to work. Your hint about needing to put the widgets into a regular wx.panel first was the solution. Somehow I was thinking that the sizer would go directly into the foldpanel, but as you said -that doesn’t make sense.

Thanks again. :grinning:

The only issue is that then the sizing is not correct, vertically. If I set the size manually, then it works, but I am not sure I sure do it that way since it’s a hard coded value.

I figured it out.

So, a few notes for others and future reference:

  • Make sure you put the widgets in a wx.Panel before adding to the foldpanel
  • To correct the sizing, call yoursizer.Fit(thepanel) before you call thepanel.SetSizer(yoursizer)