The code below shows 4 custom windows (in a GridBagSizer) placed on a
panel which is, in turn, placed on another panel (using a BoxSizer).
The latter panel is stretched to fill an entire 300x300 window.
My question: how do I make the panel containing the custom windows to
take into account its border (set with "style = wx.RAISED_BORDER"), so
that the border does not obscure the custom windows?
Code (just copy, paste and run to see the problem):
# -- CODE START --
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, size = (300, 300))
mainPanel = wx.Panel(self)
subPanel = wx.Panel(mainPanel, style = wx.RAISED_BORDER)
mainSizer = wx.BoxSizer()
subSizer = wx.GridBagSizer(hgap = 13, vgap = 13)
mainSizer.Add(subPanel)
subSizer.Add(CustomWindow(subPanel), wx.GBPosition(0, 0))
subSizer.Add(CustomWindow(subPanel), wx.GBPosition(0, 1))
subSizer.Add(CustomWindow(subPanel), wx.GBPosition(1, 0))
subSizer.Add(CustomWindow(subPanel), wx.GBPosition(1, 1))
subPanel.SetSizer(subSizer)
mainPanel.SetSizer(mainSizer)
self.Show(True)
class CustomWindow(wx.PyWindow):
def __init__(self, parent):
wx.PyWindow.__init__(self, parent, wx.ID_ANY, style =
wx.SIMPLE_BORDER, size = (50, 50))
self.Bind(wx.EVT_PAINT, self.OnPaint)
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 DoGetBestSize(self):
return (50, 50)
app = TestApp(0)
app.MainLoop()
# -- CODE END --
//Jonatan