@@ -428,6 +428,7 @@ def __init__(self, bitmap, renderer):
428
428
GraphicsContextBase .__init__ (self )
429
429
#assert self.Ok(), "wxMemoryDC not OK to use"
430
430
DEBUG_MSG ("__init__()" , 1 , self )
431
+ DEBUG_MSG ("__init__() 2: %s" % bitmap , 1 , self )
431
432
432
433
dc , gfx_ctx = self ._cache .get (bitmap , (None , None ))
433
434
if dc is None :
@@ -695,7 +696,6 @@ def do_nothing(*args, **kwargs):
695
696
696
697
self .Bind (wx .EVT_SIZE , self ._onSize )
697
698
self .Bind (wx .EVT_PAINT , self ._onPaint )
698
- self .Bind (wx .EVT_ERASE_BACKGROUND , self ._onEraseBackground )
699
699
self .Bind (wx .EVT_KEY_DOWN , self ._onKeyDown )
700
700
self .Bind (wx .EVT_KEY_UP , self ._onKeyUp )
701
701
self .Bind (wx .EVT_RIGHT_DOWN , self ._onRightButtonDown )
@@ -714,7 +714,13 @@ def do_nothing(*args, **kwargs):
714
714
self .Bind (wx .EVT_MIDDLE_DCLICK , self ._onMiddleButtonDClick )
715
715
self .Bind (wx .EVT_MIDDLE_UP , self ._onMiddleButtonUp )
716
716
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 )
718
724
719
725
self .macros = {} # dict from wx id to seq of macros
720
726
@@ -862,20 +868,31 @@ def _get_imagesave_wildcards(self):
862
868
wildcards = '|' .join (wildcards )
863
869
return wildcards , extensions , filter_index
864
870
865
- def gui_repaint (self , drawDC = None ):
871
+ def gui_repaint (self , drawDC = None , origin = 'WX' ):
866
872
"""
867
873
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.
870
877
"""
871
878
DEBUG_MSG ("gui_repaint()" , 1 , self )
872
879
if self .IsShownOnScreen ():
873
- if drawDC is None :
880
+ if not drawDC :
881
+ # not called from OnPaint use a ClientDC
874
882
drawDC = wx .ClientDC (self )
875
883
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 )
879
896
880
897
filetypes = FigureCanvasBase .filetypes .copy ()
881
898
filetypes ['bmp' ] = 'Windows bitmap'
0 commit comments