@@ -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'
0 commit comments