[wxPython-users] Reducing the size of a BufferedDC
Christopher Barker
Chris.Barker at noaa.gov
Mon Dec 18 11:28:54 PST 2006
Alexander 'boesi' B=F6secke wrote:
> Am 14.12.2006 20:29:41 schrieb Christopher Barker:
> So GetSize returns now the correct size (of the target DC)?
oops, no, it looks like it's still doing the same thing -- not reducing =
the size when the window is shrunk.
>> In real use, it's likely you want to keep that bitmap around anyway, so =
>> that your OnPaint handler can just blit it to the screen. See the =
>> DoubleBuffer demo in the Wiki.
> =
> Hmm but with BufferedDC this isn't needed, is it?
Sure it is. if you don't keep the bitmap around, then you need to =
re-draw it in every Paint event. With your code, you're getting double =
buffering, but only when drawing, so you don't see the drawing happening =
in progress (I actually generally like to see the drawing in progress -- =
it lets me know something is happening)
> I'm not really interested
> in the size of the DC - but for drawing I need the correct size. Of
> course I can save the size of the DC before doubble buffering, but this
> confuses me somewhat.
Yes, the BufferedDC should return the correct size, if it's using a =
large bitmap under the covers, that shouldn't keep it from returning the =
correct value.
Again, see the DoubleBuffer example in the Wiki.
Enclosed is an example that keeps the off-screen buffer around.
-Chris
-- =
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
# -*- coding: iso8859_15 -*-
import wx
class myFrame(wx.Frame):
def __init__(self, parent=3DNone):
wx.Frame.__init__(self, parent, -1, 'Test')
self.dc =3D None
self.panel =3D wx.Panel(self, -1)
self.btnBuffer =3D wx.ToggleButton(self.panel, label=3D'Use Buffere=
d DC', pos=3D(0, 0))
self.btnDC =3D wx.Button(self.panel, label=3D'Create DC', pos=3D(0,=
25))
self.btnDC.Bind(wx.EVT_BUTTON, self.createDC)
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self,event):
self._buffer =3D wx.EmptyBitmap(*self.GetSize())
event.Skip()
=
def createDC(self, event=3DNone):
self.dc =3D wx.ClientDC(self.panel)
print 'Unbuffered Size:', self.dc.GetSize(),
if self.btnBuffer.GetValue() =3D=3D True:
self.dc =3D wx.BufferedDC(self.dc, self._buffer)
print 'Buffered Size:', self.dc.GetSize()
else:
print "UnBuffered Size:", self.dc.GetSize()
app =3D wx.PySimpleApp()
frame =3D myFrame()
frame.Show()
app.MainLoop()
More information about the wxpython-users
mailing list