软讯网络 > 软件时空 > 软件相关 > 在wxPython中应用双缓冲(double buffering)
【标 题】:在wxPython中应用双缓冲(double buffering)
【关键字】:
wxPython,double,buffering
【来 源】:http://blog.csdn.net/zhuoqiang/archive/2006/05/25/755423.aspx
在wxPython中应用双缓冲(double buffering)
class Canvas(wx.Window):
def __init__(self, parent, id=wx.ID_ANY, colour=wx.WHITE,
pos=wx.DefaultPosition, size=None,
style=wx.NO_FULL_REPAINT_ON_RESIZE,
name='qiang.canvas'):
wx.Window.__init__(self, parent, id, pos, size, style, name)
if not size:
size = wx.ScreenDC().GetSize()
self._buffer = wx.EmptyBitmap(size[0], size[1])
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.Bind(wx.EVT_PAINT, self.__OnPaint)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.SetBackgroundColour(colour)
self.ClearBackground()
def ClearBackground(self):
dc = self.GetDC()
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
def GetDC(self):
return wx.BufferedDC(wx.ClientDC(self), self._buffer)
def Enlarge(self, size):
newWidth, newHeight = size
width, height = self._buffer.GetSize()
needEnlarge = False
if newWidth > width:
width, needEnlarge = newWidth, True
if newHeight > height:
height, newHeight = newHeight, True
if needEnlarge:
self._buffer = wx.EmptyBitmap(width, height)
self.ClearBackground()
def __OnPaint(self, event):
wx.BufferedPaintDC(self, self._buffer)
def OnSize(self, event):
self.Enlarge(self.GetSize())