forked from studio1247/gertrude
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffered_window.py
More file actions
41 lines (33 loc) · 1.18 KB
/
buffered_window.py
File metadata and controls
41 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import wx
USE_BUFFERED_DC = 1
class BufferedWindow(wx.Window):
def __init__(self, parent,
id = -1,
pos = wx.DefaultPosition,
size = wx.DefaultSize,
style=wx.NO_FULL_REPAINT_ON_RESIZE):
wx.Window.__init__(self, parent, id, pos, size, style)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.OnSize(None)
def Draw(self, dc):
pass
def OnSize(self, event):
self.width, self.height = self.GetClientSizeTuple()
self.bufferDC = wx.EmptyBitmap(self.width, self.height)
self.UpdateDrawing()
def OnPaint(self, event):
if USE_BUFFERED_DC:
dc = wx.BufferedPaintDC(self, self.bufferDC)
else:
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bufferDC, 0, 0)
def UpdateDrawing(self):
if USE_BUFFERED_DC:
dc = wx.BufferedDC(wx.ClientDC(self), self.bufferDC)
self.Draw(dc)
else:
dc = wx.MemoryDC()
dc.SelectObject(self.bufferDC)
self.Draw(dc)
wx.ClientDC(self).Blit(0, 0, self.width, self.height, dc, 0, 0)