Help with CollapsiblePane

Hey there.

I have a standard side panel, containing a notebook, which contains one tab with a standard Panel containing a TreeCtrl, and a wx.lib.scrolledpanel in the other.
Basically, I just want to make the container panel collapsible, as I currently have a menu item just for toggling the panel on/off, so I could replace that the the collapsible panel:

I've tried making my code match the CollapsiblePane demo as much as possible, but to no avail.

class SidePanel(wx.Panel):
    """
    The side panel contains a tabbed window, allowing the user to switch
    between thumbnails and notes. It can be toggled on and off.
    """
    def __init__(self, gui):
        wx.Panel.__init__(self, gui, style=wx.RAISED_BORDER)
        self.cp = wx.CollapsiblePane(self, style=wx.CP_DEFAULT_STYLE |
                                                  wx.CP_NO_TLW_RESIZE)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.sizer)
        self.gui = gui

        self.tabs = wx.Notebook(self.cp.GetPane())
        self.thumbs = Thumbs(self.tabs, gui)
        self.notes = Notes(self.tabs, gui)
        self.tabs.AddPage(self.thumbs, "Thumbnails")
        self.tabs.AddPage(self.notes, "Notes")
        self.sizer.Add(self.cp, 0)
        self.sizer.Add(self.tabs, 0)

It seems that making the cpanel the tabs' parent doesn't work, it just displays a blank area where the content should be. I've tried all variations on this code, like not adding the cpanel to the sizer, making the tabs' parent the current panel, all to no avail
I really don't know where to go from here, any ideas?

Thanks very much,
Steve

Steven Sproat wrote:

Hey there.

I have a standard side panel, containing a notebook, which contains one tab with a standard Panel containing a TreeCtrl, and a wx.lib.scrolledpanel in the other.
Basically, I just want to make the container panel collapsible, as I currently have a menu item just for toggling the panel on/off, so I could replace that the the collapsible panel:

I've tried making my code match the CollapsiblePane demo as much as possible, but to no avail.

class SidePanel(wx.Panel):
   """
   The side panel contains a tabbed window, allowing the user to switch
   between thumbnails and notes. It can be toggled on and off.
   """
   def __init__(self, gui):
       wx.Panel.__init__(self, gui, style=wx.RAISED_BORDER)
       self.cp = wx.CollapsiblePane(self, style=wx.CP_DEFAULT_STYLE |
                                                 wx.CP_NO_TLW_RESIZE)
       self.sizer = wx.BoxSizer(wx.VERTICAL)
       self.SetSizer(self.sizer)
       self.gui = gui

       self.tabs = wx.Notebook(self.cp.GetPane())
       self.thumbs = Thumbs(self.tabs, gui)
       self.notes = Notes(self.tabs, gui)
       self.tabs.AddPage(self.thumbs, "Thumbnails")
       self.tabs.AddPage(self.notes, "Notes")
       self.sizer.Add(self.cp, 0)
       self.sizer.Add(self.tabs, 0)

It seems that making the cpanel the tabs' parent doesn't work, it just displays a blank area where the content should be. I've tried all variations on this code, like not adding the cpanel to the sizer, making the tabs' parent the current panel, all to no avail
I really don't know where to go from here, any ideas?

http://wiki.wxpython.org/MakingSampleApps

You probably would have had an answer by now if you had provided a runnable sample.

Just a guess: Did you try it without adding self.tabs to the sizer? The CollapsiblePane will manage the layout of the pane. You may need another sizer for the pane itself that manages the layout of its content (the notebook).

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

http://wiki.wxpython.org/MakingSampleApps

You probably would have had an answer by now if you had provided a runnable sample.

Just a guess: Did you try it without adding self.tabs to the sizer? The CollapsiblePane will manage the layout of the pane. You may need another sizer for the pane itself that manages the layout of its content (the notebook).

Here's a sample app of my program reduced to its bare GUI elements. What I want is to make the side panel into a collapsible vertical pane, I've commented out some of my efforts but I have tried a few things (see below)
Here's a screenshot of what the full thing looks like - http://img19.imageshack.us/img19/3781/whyteboardxpclassic.png

#!/usr/bin/python
import wx
from wx.lib import scrolledpanel as scrolled

class GUI(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, size=(1024, 786))
        tabs = wx.Notebook(self)
        dpanel = DrawingPanel(tabs)
        tabs.AddPage(dpanel, "Tab 1")
        cpanel = ControlPanel(self)
        spanel = SidePanel(self)

        box = wx.BoxSizer(wx.HORIZONTAL) # position windows side-by-side
        box.Add(cpanel, 0, wx.EXPAND)
        box.Add(tabs, 2, wx.EXPAND)
        box.Add(spanel, 0, wx.EXPAND)
        self.SetSizer(box)

class SidePanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, style=wx.RAISED_BORDER)
        #self.cp = wx.CollapsiblePane(self, style=wx.CP_DEFAULT_STYLE |
        # wx.CP_NO_TLW_RESIZE)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.sizer)

        #csizer = wx.BoxSizer(wx.VERTICAL)

        self.tabs = wx.Notebook(self)
        self.thumbs = Thumbs(self.tabs)
        self.notes = Notes(self.tabs)
        self.tabs.AddPage(self.thumbs, "Thumbnails")
        self.tabs.AddPage(self.notes, "Notes")
        #csizer.Add(self.tabs, 0)
        #self.cp.GetPane().SetSizer(csizer)
        self.sizer.Add(self.tabs, 1)

class Notes(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, size=(170, -1), style=wx.RAISED_BORDER)
        tree = wx.TreeCtrl(self, size=(170, -1), style=wx.TR_HAS_BUTTONS)
        tree.AddRoot("nfghf")

class Thumbs(scrolled.ScrolledPanel):

    def __init__(self, parent):
        scrolled.ScrolledPanel.__init__(self, parent, size=(170, -1),
                                        style=wx.VSCROLL | wx.RAISED_BORDER)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.sizer)
        self.SetScrollRate(0, 250)
        btn = wx.BitmapButton(self, size=(150, 150))
        text = wx.StaticText(self, label="Tab 1")

        self.sizer.Add(text, flag=wx.ALIGN_CENTER | wx.TOP, border=5)
        self.sizer.Add(btn, flag=wx.TOP | wx.LEFT, border=6)

class DrawingPanel(wx.ScrolledWindow):
    def __init__(self, tab):
        wx.ScrolledWindow.__init__(self, tab, style=wx.CLIP_CHILDREN)
        self.SetBackgroundColour("White")

class ControlPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        sizer = wx.GridSizer(cols=1, hgap=1, vgap=2)
        sizer.Add(wx.Button(self, label="Thing"), 0)

        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(sizer, 0, wx.ALL, 4)
        self.SetSizer(box)
        self.SetAutoLayout(True)
        box.Fit(self)

class TestApp(wx.App):
    def OnInit(self):
        frame = GUI(None)
        frame.Show(True)
        return True

if __name__ == '__main__':
    app = TestApp()
    app.MainLoop()

some things I've tried:

    def __init__(self, parent):
        wx.Panel.__init__(self, parent, size=(170, -1), style=wx.RAISED_BORDER)
        self.cp = wx.CollapsiblePane(self, style=wx.CP_DEFAULT_STYLE |
                                                  wx.CP_NO_TLW_RESIZE)
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.cp.GetPane().SetSizer(sizer)

        self.tabs = wx.Notebook(self.cp.GetPane())
        self.thumbs = Thumbs(self.tabs)
        self.notes = Notes(self.tabs)
        self.tabs.AddPage(self.thumbs, "Thumbnails")
        self.tabs.AddPage(self.notes, "Notes")
        sizer.Add(self.tabs, 0)

sample.py (2.99 KB)

···

---

    def __init__(self, parent):
        wx.Panel.__init__(self, parent, size=(170, -1), style=wx.RAISED_BORDER)
        self.cp = wx.CollapsiblePane(self, style=wx.CP_DEFAULT_STYLE |
                                                  wx.CP_NO_TLW_RESIZE)
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)
        csizer = wx.BoxSizer(wx.VERTICAL)
        self.cp.GetPane().SetSizer(sizer)

        self.tabs = wx.Notebook(self.cp.GetPane())
        self.thumbs = Thumbs(self.tabs)
        self.notes = Notes(self.tabs)
        self.tabs.AddPage(self.thumbs, "Thumbnails")
        self.tabs.AddPage(self.notes, "Notes")
        csizer.Add(self.tabs, 1)
        sizer.Add(self.cp, 1)

the above is something like I need, except if I don't specify the size, it's too small,and if I do, it stays its size and doesn't shrink/grow, and the notebook doesn't display correctly. I feel like I'm heading down the right lines, but it's all guesswork and there's so many possiblities

cheers,
Steven Sproat

Steven Sproat wrote:

Robin Dunn wrote:

http://wiki.wxpython.org/MakingSampleApps

You probably would have had an answer by now if you had provided a runnable sample.

Just a guess: Did you try it without adding self.tabs to the sizer? The CollapsiblePane will manage the layout of the pane. You may need another sizer for the pane itself that manages the layout of its content (the notebook).

Here's a sample app of my program reduced to its bare GUI elements. What I want is to make the side panel into a collapsible vertical pane, I've commented out some of my efforts but I have tried a few things (see below)
Here's a screenshot of what the full thing looks like - http://img19.imageshack.us/img19/3781/whyteboardxpclassic.png

You're on the right track. I just needed to fix the line setting the sizer for the pane (so it didn't try to reuse the parent's sizer), add some wx.EXPAND flags, and give the Notes page a sizer too. I also added an event handler to redo the layout when the collapsible pane is toggled. Here is a patch to your sample that shows the changes I made.

sample.py.patch (1.43 KB)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

You're on the right track. I just needed to fix the line setting the sizer for the pane (so it didn't try to reuse the parent's sizer), add some wx.EXPAND flags, and give the Notes page a sizer too. I also added an event handler to redo the layout when the collapsible pane is toggled. Here is a patch to your sample that shows the changes I made.

Wonderful! I tried the sample you gave and it worked perfectly, thank you very much, as always!