-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuffered_window.py
More file actions
50 lines (39 loc) · 1.65 KB
/
buffered_window.py
File metadata and controls
50 lines (39 loc) · 1.65 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
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
# This file is part of Gertrude.
#
# Gertrude is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Gertrude is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gertrude; if not, see <http://www.gnu.org/licenses/>.
import wx
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.ForceRefresh()
def Draw(self, dc):
pass
def OnSize(self, _):
self.width, self.height = self.GetClientSizeTuple()
self.bufferDC = wx.EmptyBitmap(self.width, self.height)
self.needs_drawing = True
self.Refresh()
def OnPaint(self, event):
if self.needs_drawing:
self.UpdateDrawing()
self.needs_drawing = False
dc = wx.BufferedPaintDC(self, self.bufferDC)
def ForceRefresh(self):
self.OnSize(None)
def UpdateDrawing(self):
dc = wx.BufferedDC(wx.ClientDC(self), self.bufferDC)
self.Draw(dc)