[wxPython-users] refresh problems
Christopher Barker
Chris.Barker at noaa.gov
Tue Jul 25 21:59:22 PDT 2006
Michael P. Soulier wrote:
> Leaning on "wxPython in Action", I now have code to draw a graph on a buffer.
> For some reason though, while it doesn't do this on Linux, on Windows, the
> buffer isn't clearing itself on each paint event like I'd like, so remnants of
> previous drawings are present after a resize.
This is odd. The call to dc.Clear() should set the whole buffer to the
background color. However, while I'm not sure what you issue is, I have
a few comments:
First: put some example code in a small working app that does just what
you need to show the problem, and no more. You may find the problem
yourself this way, and if you don't, we'll have something we can run
ourselves, to test and tweak.
> def OnPaint(self, event):
> """Paint the window. We call InitBuffer here each time to detect the
> current size of the drawing area."""
> self.InitBuffer()
> dc = wx.BufferedPaintDC(self, self.buffer)
You don't want to re-init the buffer in every Paint event. This kind of
defeats the purpose of double buffering. The buffer doesn't need to
change unless the Window size changes, so you want to call InitBuffer in
a SIZE event instead. OnPaint should ONLY dump the buffer to the screen.
See the Double buffered pages in the Wiki for more discussion and examples.
> def InitBuffer(self):
> """Initialize the buffer, and draw the lines on it."""
> size = self.GetClientSize()
> self.buffer = wx.EmptyBitmap(size.width, size.height)
This is pretty much all you should have in the InitBuffer Code. The
actual drawing should be in a separate method.
Also, why start from scratch? I'm not sure what you mean by "graph", but
is supect that wxPyPlot, or matplotlib, or floatcanvas or wxOGL would
likely suit your needs.
-Chris
More information about the wxpython-users
mailing list