Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 25798d5

Browse files
committed
- make 'WX' and 'WXAgg' work with wxPython 2.8, 2.9, 3.0 and 3.0.2 Phoenix
1 parent 70d6d70 commit 25798d5

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

lib/matplotlib/backends/backend_wx.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ def __init__(self, bitmap, renderer):
428428
GraphicsContextBase.__init__(self)
429429
#assert self.Ok(), "wxMemoryDC not OK to use"
430430
DEBUG_MSG("__init__()", 1, self)
431+
DEBUG_MSG("__init__() 2: %s" % bitmap, 1, self)
431432

432433
dc, gfx_ctx = self._cache.get(bitmap, (None, None))
433434
if dc is None:
@@ -695,7 +696,6 @@ def do_nothing(*args, **kwargs):
695696

696697
self.Bind(wx.EVT_SIZE, self._onSize)
697698
self.Bind(wx.EVT_PAINT, self._onPaint)
698-
self.Bind(wx.EVT_ERASE_BACKGROUND, self._onEraseBackground)
699699
self.Bind(wx.EVT_KEY_DOWN, self._onKeyDown)
700700
self.Bind(wx.EVT_KEY_UP, self._onKeyUp)
701701
self.Bind(wx.EVT_RIGHT_DOWN, self._onRightButtonDown)
@@ -714,7 +714,13 @@ def do_nothing(*args, **kwargs):
714714
self.Bind(wx.EVT_MIDDLE_DCLICK, self._onMiddleButtonDClick)
715715
self.Bind(wx.EVT_MIDDLE_UP, self._onMiddleButtonUp)
716716

717-
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
717+
if wx.VERSION_STRING < "2.9":
718+
# only needed in 2.8 to reduce flicker
719+
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
720+
self.Bind(wx.EVT_ERASE_BACKGROUND, self._onEraseBackground)
721+
else:
722+
# this does the same in 2.9+
723+
self.SetBackgroundStyle(wx.BG_STYLE_PAINT)
718724

719725
self.macros = {} # dict from wx id to seq of macros
720726

@@ -862,20 +868,31 @@ def _get_imagesave_wildcards(self):
862868
wildcards = '|'.join(wildcards)
863869
return wildcards, extensions, filter_index
864870

865-
def gui_repaint(self, drawDC=None):
871+
def gui_repaint(self, drawDC=None, origin='WX'):
866872
"""
867873
Performs update of the displayed image on the GUI canvas, using the
868-
supplied device context. If drawDC is None, a ClientDC will be used to
869-
redraw the image.
874+
supplied wx.PaintDC device context.
875+
876+
The 'WXAgg' backend sets origin accordingly.
870877
"""
871878
DEBUG_MSG("gui_repaint()", 1, self)
872879
if self.IsShownOnScreen():
873-
if drawDC is None:
880+
if not drawDC:
881+
# not called from OnPaint use a ClientDC
874882
drawDC = wx.ClientDC(self)
875883

876-
drawDC.DrawBitmap(self.bitmap, 0, 0)
877-
else:
878-
pass
884+
# ensure that canvas has no 'left' over stuff when resizing frame
885+
drawDC.Clear()
886+
887+
# following is for 'WX' backend on Windows
888+
# the bitmap can not be in use by another DC,
889+
# see GraphicsContextWx._cache
890+
if wx.Platform == '__WXMSW__' and origin == 'WX':
891+
img = self.bitmap.ConvertToImage()
892+
bmp = img.ConvertToBitmap()
893+
drawDC.DrawBitmap(bmp, 0, 0)
894+
else:
895+
drawDC.DrawBitmap(self.bitmap, 0, 0)
879896

880897
filetypes = FigureCanvasBase.filetypes.copy()
881898
filetypes['bmp'] = 'Windows bitmap'

lib/matplotlib/backends/backend_wxagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def draw(self, drawDC=None):
5252

5353
self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
5454
self._isDrawn = True
55-
self.gui_repaint(drawDC=drawDC)
55+
self.gui_repaint(drawDC=drawDC, origin='WXAgg')
5656

5757
def blit(self, bbox=None):
5858
"""

0 commit comments

Comments
 (0)