Hello All,
I am having difficulties properly sizing notebook pages insde a splitter
window. I hope somebody can help.
I am using wxPython 2.8.0.1 (wxMSW, unicode, wx-assertions-on, SWIG-1.3.29)
running on Python 2.4, on XP, all service packs installed.
To explore various options, I created a new demo called Leo in the wxPython
demo. So to run the following code, copy it to a file called Leo.py in the
wxPython demo folder, and add an entry for Leo in the Recent
Additions/Updates section in Main.py.
The code is at the end of the posting. First I'll explain what it does and
what I would like it to do.
1. There are two switches in runTest called useNotebook and useSizer. Let
us assume that useSizer is always True. When useNotebook is False, the code
uses a FlexGridSizer to insert two TextCtrls with labels into the right-hand
splitter window. Everything works as expected: all controls are aligned
nicely.
2. When useNotebook is True the code creates a Notebook with two pages
called 'Log' and 'Find'. The Log page has a textCtrl that should fill the
Notebook page (It does, but the page is too small). The Find page should
look pretty much exactly the same as when useNotebook is False: that is, it
should contain two TextCtrls with labels that are managed by a
FlexGridSizer.
I would like both notebook pages to fill the right-hand splitter window, but
have found no way to do this. The present code doesn't even show all the
widgets that are (presumably) in the 'Find' window. Can anyone suggest the
solution? Thanks!
Here is Leo.py:
# Leo test stuff for wxWidgets.
overview = """<html>Leo"""
import wx
class MySplitter(wx.SplitterWindow): ### Unchanged from the SpitterWindow
demo.
def __init__(self, parent, ID, log):
wx.SplitterWindow.__init__(self, parent, ID,
style = wx.SP_LIVE_UPDATE
)
self.log = log
self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSashChanged)
self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.OnSashChanging)
def OnSashChanged(self, evt):
self.log.WriteText("sash changed to %s\n" %
str(evt.GetSashPosition()))
def OnSashChanging(self, evt):
self.log.WriteText("sash changing to %s\n" %
str(evt.GetSashPosition()))
# uncomment this to not allow the change
#evt.SetSashPosition(-1)
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent)
def makeNBPanel(parent): # Like makeColorPanel in Notebook demo.
p = wx.Panel(parent, -1)
def OnCPSize(evt,p=p):
p.SetPosition((0,0))
p.SetSize(evt.GetSize())
p.Bind(wx.EVT_SIZE, OnCPSize)
return p
def runTest(frame, nb, log):
splitter = MySplitter(nb, -1, log)
p1 = wx.Window(splitter, style=wx.BORDER_SUNKEN)
p1.SetBackgroundColour("pink")
wx.StaticText(p1, -1, "Panel One", (5,5))
p2 = wx.Window(splitter, style=wx.BORDER_SUNKEN)
p2.SetBackgroundColour("sky blue")
# wx.StaticText(p2, -1, "Panel Two", (5,5))
splitter.SetMinimumPaneSize(20)
splitter.SplitVertically(p1, p2, -100)
useNotebook = False
useSizer = True
if useNotebook:
nbParent = wx.Panel(p2)
nb = wx.Notebook(nbParent,style=wx.BK_DEFAULT)
log = makeNBPanel(nb)
wx.TextCtrl(log,size=(1000,2000))
nb.AddPage(log,'Log')
p = makeNBPanel(nb)
nb.AddPage(p,'Find')
else:
p = wx.Panel(p2, -1,
style = wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN |
wx.FULL_REPAINT_ON_RESIZE)
if useSizer:
label1 = wx.StaticText(p,label='Find',style=wx.ALIGN_LEFT)
label2 = wx.StaticText(p,label='Change',style=wx.ALIGN_LEFT)
sizer1 = wx.FlexGridSizer(2, 2, vgap=10,hgap=5)
sizer1.Add(wx.TextCtrl(p),1,wx.EXPAND)
sizer1.Add(label1,0,wx.EXPAND)
sizer1.Add(wx.TextCtrl(p),1,wx.EXPAND)
sizer1.Add(label2,0,wx.EXPAND)
if useNotebook:
nbParent.SetSizerAndFit(sizer1)
nb.SetClientSize(nbParent.GetSize())
# nb.SetClientSize(p2.GetSize())
# Notebook disappears completely.
else:
p.SetSizerAndFit(sizer1)
p2.SetClientSize(p.GetSize())
else:
if useNotebook:
nb.SetClientSize(nbParent.GetSize())
return splitter
#### End of Leo.py
Edward
···
--------------------------------------------------------------------
Edward K. Ream email: edreamleo@charter.net
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------