[wxPython-users] Reducing the size of a BufferedDC
Christopher Barker
Chris.Barker at noaa.gov
Thu Dec 14 11:29:41 PST 2006
Alexander 'boesi' B=F6secke wrote:
>> So what should I do to get a buffered DC with the correct size? =
I see the same problem with 2.8 on OS-X, but not with 2.6. However, =
there is a bit of odd code. I've re-written it a bit, and it seems to =
work now. You don't need to explicitly call destroy on the dc. In =
general, you don't call Destroy() in wxPython -- python's garbage =
collection handles that for you.
See enclosed.
However, the other option is to create the off-screen bitmap yourself, =
then pass it in the constructor. See the commented code in the example.
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.
also, some odd things do happen with this example, as you are creating a =
bufferedclientDC, but not drawing anything.
-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)
def createDC(self, event=3DNone):
self.dc =3D wx.ClientDC(self.panel)
print 'Unbuffered Size:', self.dc.GetSize(),
#self._buffer =3D wx.EmptyBitmap(*self.GetSize())
if self.btnBuffer.GetValue() =3D=3D True:
self.dc =3D wx.BufferedDC(self.dc, self.dc.GetSize())
#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