wxPython MDI question
Robert Amesz
sheershion at mailexpire.com
Fri Feb 22 08:34:49 EST 2002
rockmuelle wrote:
> I am trying to create an MDI application that has a list control
> on the left side of the main MDI frame and the MDI client area on
> the right side, similar to the way Visual Studio has other windows
> surrounding its client area.
>
> I've tried creating the list control and then adding it and the
> client area to a sizer, but the client area always takes up the
> whole main frame. The client area and the list control are
> situated at (0, 0), as if there was no sizer. If I add more
> controls to the sizer, the non-client area windows get layed out
> correctly, but the sizer and client area still overlap.
>
> [snip]
>
> sizer = wxBoxSizer(wxHORIZONTAL)
> sizer.Add(wxListCtrl(self, -1))
> sizer.Add(wxListCtrl(self, -1)) # add another list
> sizer.Add(self.GetClientWindow())
I can see what you're trying to do here, but it's obvious the
wxMDIParentFrame doesn't cooperate, even after correcting the code (see
caveats below).
This would seem a task for manual resizing, as sizers obviously don't
work properly here. Modify your MyMDIFrame thus (tested with wxPython
2.3.2, Python 2.1.1 and Win98):
class MyMDIFrame(wxMDIParentFrame):
"""
Main frame that has list control and MDI client area.
"""
def __init__(self, parent, id=-1, title='MDI Example'):
wxMDIParentFrame.__init__(self, parent, id, title=title)
self.list = wxListCtrl(self, -1)
EVT_SIZE(self, self.onSize)
return
def onSize(self, evt):
width, height = self.GetClientSizeTuple()
listwidth = self.list.GetSizeTuple()[0]
self.GetClientWindow().SetDimensions(listwidth, 0,
width - listwidth, height)
self.list.SetDimensions(0, 0, listwidth, height)
Note that I've removed the second wxListCtrl to make the calculation
simpler. As such, it is simply a matter of dividing the available space
into two parts, using SetDimensions() to resize and position both
windows.
Robert Amesz
--
A few caveats concerning sizers: don't call Layout() before SetSizer(),
for obvious reasons. And after SetSizer(), there's no need to call
Layout(), that should happen automatically, but *do* put a
self.SetAutoLayout(true) in your frame or panel, otherwise nothing will
happen at all.
More information about the Python-list
mailing list