Hi guys,
Okay, I'm stumped. I'm trying to write an "Editor" class which builds input
screens from an XML template. After some mucking about I managed to get the
basic input screen layout working nicely -- but for the life of me I can't get
a wxNotebook to size itself correctly when the editor is first opened.
I'm using a wxNotebookSizer to size the notebook appropriately, and the
wxNotebook itself is inside a wxBoxSizer along with some other input-screen
elements. The thing is, the wxNotebook never seems to be sized correctly --
the bottom-most fields are partially hidden because the notebook is too small.
I'll paste some code below which shows up the problem. Initially, I suspected
I was using the wxBoxSizer in a strange way -- but if I replace the wxNotebook
with another panel everything works. It's only with the wxNotebook that the
wxBoxSizer seems to be getting the size wrong...
Anyway, here's the code:
···
=============================================================================
from wxPython.wx import *
class TestFrame(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, id, title)
sizer = wxBoxSizer(wxVERTICAL)
notebook = wxNotebook(self, -1)
notebook.AddPage(self.makePanel(notebook), "1")
notebook.AddPage(self.makePanel(notebook), "2")
notebook.AddPage(self.makePanel(notebook), "3")
nbSizer = wxNotebookSizer(notebook)
sizer.Add(nbSizer, 1, wxGROW)
sizer.Add(self.makePanel(self), 1, wxGROW)
self.SetSizer(sizer)
self.SetAutoLayout(TRUE)
sizer.Fit(self)
def makePanel(self, parent):
panel = wxPanel(parent, -1)
sizer = wxFlexGridSizer(0, 2, 2, 2)
label1 = wxStaticText(panel, -1, "Field 1")
sizer.Add(label1, -1, wxALIGN_RIGHT)
field1 = wxTextCtrl(panel, -1, "Value 1")
sizer.Add(field1, -1, wxALIGN_LEFT)
label2 = wxStaticText(panel, -1, "Field 2")
sizer.Add(label2, -1, wxALIGN_RIGHT)
field2 = wxTextCtrl(panel, -1, "Value 2")
sizer.Add(field2, -1, wxALIGN_LEFT)
panel.SetSizer(sizer)
panel.SetAutoLayout(true)
sizer.Fit(panel)
return panel
class TestApp(wxApp):
def OnInit(self):
frame = TestFrame(NULL, -1, "Test")
self.SetTopWindow(frame)
frame.Show(TRUE)
return TRUE
app = TestApp(0)
app.MainLoop()
Any suggestions?
Thanks,
- Erik.