Greetings!
I am a total beginner when it comes to wxPython, and am looking forward to getting savvy with it, so, first of all, hello to all my wxComrades!
I have a real project to try to produce in wxPython. I have Noel & Robin's fine book and am trying to work through various parts of it. I have read chapters 1 & 2 and part of 3 (and will probably be reviewing 3 again) and am now trying to jump around to the parts I think I need, which is sizers at the moment.
What I want to know is why the BlockWindow's of the Basic Grid Sizer example do not repaint correctly after squishing the window very small and then dragging it back out (i.e., there are all sorts of artifacts left in the individual BlockWindow frames. For example if you squish the window narrow enough so that the 'n' in 'nine' is drawn within the boundaires of the 'eight' box, when you stretch it back out an 'n' is left showing in the 'eight' block.)
Note that if you cover the whole window with some other window, and then expose it, it all re-renders cleanly. The code for listing 11.1 and 11.2 is below (slightly modified) so that you can try it, but what I'm really looking for is an explanation of exactly why this behaves the way it does and what code changes could be made so that these artifacts don't occur in the first place (or to re-paint the individual BlockWindow's after each resize if that's what it takes to correct it).
Thanks for taking the time to look at my problem. Looking forward to learning to be productive with wxPython!
-ej
Here's the code:
#!/usr/bin/env python
'BlockWindow.py'
import wx
···
#=======================================================================
class BlockWindow(wx.Panel):
def __init__(self, parent, id=-1, label="",
pos=wx.DefaultPosition, size=(100, 25)):
wx.Panel.__init__(self, parent, id, pos, size,
wx.RAISED_BORDER, label)
self.label = label
self.SetBackgroundColour('white')
self.SetMinSize(size)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, evt):
sz = self.GetClientSize()
dc = wx.PaintDC(self)
(w, h) = dc.GetTextExtent(self.label)
dc.SetFont(self.GetFont())
dc.DrawText(self.label, (sz.width-w)/2, (sz.height-h)/2)
#=======================================================================
#!/usr/bin/env python
import wx
from BlockWindow import BlockWindow
#=======================================================================
class GridSizerFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Basic Grid Sizer")
sizer = wx.GridSizer(rows=3, cols=3, hgap=5, vgap=5)
labels = "one two three four five six seven eight nine".split()
for l in labels:
bw = BlockWindow(self, label=l)
sizer.Add(bw, 0, 0)
self.SetSizer(sizer)
self.Fit()
#=======================================================================
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = GridSizerFrame()
frame.Show()
app.MainLoop()