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