Position and size of custom windows

I found it a bit hard to understand how to work with (custom) windows
and sizers.
Maybe if someone can tell me why the code below (just copy, paste and
run) displays only one of the two custom windows that I add to the
mainSizer, I could understand this better.
This should be trivial, but after ending up just doing trial-and-error
with a bunch of methods (Layout, DoGetBestSize, SetBestSize,
SetBestFittingSize, Fit, SetSizeHints etc. etc. -- are there any good,
thorough documentation on how all the size-related methods relate to
each other and what default behaviour -- what gets called
automatically - is?) without getting the desired result, I thought I
should ask the list.

(According to page 114 in
http://www.wxpython.org/OSCON2004/advanced/wxPython-Advanced-OSCON2004.pdf,
it should only be a matter of using SetBestFittingSize and overriding
DoGetBestSize, but this didn't work for me)

Also, am I right if I say that the "Py..."-classes (PyWindow etc.)
should only have to be used when one desires to override class
methods?

//Jonatan

···

-----------------------------------
import wx

class TestApp(wx.App):
    def OnInit(self):
        mainWin = MainWindow(None, -1, "untitled")
        self.SetTopWindow(mainWin)
        return True

class MainWindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        mainPanel = wx.Panel(self, size = (200, 200))
        mainSizer.Add(mainPanel, 0, wx.FIXED_MINSIZE)
        mainSizer.Add(CustomWindow(mainPanel, wx.ID_ANY))
        mainSizer.Add(CustomWindow(mainPanel, wx.ID_ANY))
        mainPanel.SetSizer(mainSizer)
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Show(True)
    
    def OnSize(self, event):
        self.Refresh()

class CustomWindow(wx.PyWindow):
    def __init__(self, parent, id):
        wx.PyWindow.__init__(self, parent, id, style =
wx.SIMPLE_BORDER, size = (50, 50))
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.SetBestFittingSize((50, 50))
        
    def OnPaint(self, event):
        dc = wx.PaintDC(self)
        dc.Clear()
        dc.SetTextForeground(wx.Colour(0, 160, 0))
        text = "Custom"
        width, height = self.GetSize()
        textWidth, textHeight = dc.GetTextExtent(text)
        dc.DrawText(text, (width-textWidth)/2, (height-textHeight)/2)
        
    def OnSize(self, event):
        self.Refresh()
    
    def DoGetBestSize(self):
        return (50, 50)

app = TestApp(0)
app.MainLoop()
-----------------------------------