@@ -231,7 +231,7 @@ def __init__(self, ax, label, image=None,
231231 horizontalalignment = 'center' ,
232232 transform = ax .transAxes )
233233
234- self ._useblit = useblit and self . canvas . supports_blit
234+ self ._useblit = useblit
235235
236236 self ._observers = cbook .CallbackRegistry (signals = ["clicked" ])
237237
@@ -265,7 +265,7 @@ def _motion(self, event):
265265 if not colors .same_color (c , self .ax .get_facecolor ()):
266266 self .ax .set_facecolor (c )
267267 if self .drawon :
268- if self ._useblit :
268+ if self ._useblit and self . canvas . supports_blit :
269269 self .ax .draw_artist (self .ax )
270270 self .canvas .blit (self .ax .bbox )
271271 else :
@@ -1087,7 +1087,7 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
10871087 if actives is None :
10881088 actives = [False ] * len (labels )
10891089
1090- self ._useblit = useblit and self .canvas .supports_blit
1090+ self ._useblit = useblit and self .canvas .supports_blit # TODO: make dynamic
10911091
10921092 ys = np .linspace (1 , 0 , len (labels )+ 2 )[1 :- 1 ]
10931093
@@ -1674,7 +1674,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16741674
16751675 ys = np .linspace (1 , 0 , len (labels ) + 2 )[1 :- 1 ]
16761676
1677- self ._useblit = useblit and self .canvas .supports_blit
1677+ self ._useblit = useblit and self .canvas .supports_blit # TODO: make dynamic
16781678
16791679 label_props = _expand_text_props (label_props )
16801680 self .labels = [
@@ -1960,7 +1960,7 @@ def __init__(self, ax, *, horizOn=True, vertOn=True, useblit=False,
19601960 self .visible = True
19611961 self .horizOn = horizOn
19621962 self .vertOn = vertOn
1963- self .useblit = useblit and self .canvas .supports_blit
1963+ self .useblit = useblit and self .canvas .supports_blit # TODO: make dynamic
19641964
19651965 if self .useblit :
19661966 lineprops ['animated' ] = True
@@ -2069,6 +2069,7 @@ def __init__(self, canvas, axes, *, useblit=True, horizOn=False, vertOn=True,
20692069 self .useblit = (
20702070 useblit
20712071 and all (canvas .supports_blit for canvas in self ._canvas_infos ))
2072+ # TODO: make dynamic
20722073
20732074 if self .useblit :
20742075 lineprops ['animated' ] = True
@@ -2153,7 +2154,7 @@ def __init__(self, ax, onselect=None, useblit=False, button=None,
21532154 self .onselect = lambda * args : None
21542155 else :
21552156 self .onselect = onselect
2156- self .useblit = useblit and self . canvas . supports_blit
2157+ self ._useblit = useblit
21572158 self .connect_default_events ()
21582159
21592160 self ._state_modifier_keys = dict (move = ' ' , clear = 'escape' ,
@@ -2177,6 +2178,11 @@ def __init__(self, ax, onselect=None, useblit=False, button=None,
21772178 self ._prev_event = None
21782179 self ._state = set ()
21792180
2181+ @property
2182+ def useblit (self ):
2183+ """Return whether blitting is used (requested and supported by canvas)."""
2184+ return self ._useblit and self .canvas .supports_blit
2185+
21802186 def set_active (self , active ):
21812187 super ().set_active (active )
21822188 if active :
@@ -2599,7 +2605,14 @@ def __init__(self, ax, onselect, direction, *, minspan=0, useblit=False,
25992605 if props is None :
26002606 props = dict (facecolor = 'red' , alpha = 0.5 )
26012607
2602- props ['animated' ] = self .useblit
2608+ # Note: We set this based on the user setting during ínitialization,
2609+ # not on the actual capability of blitting. But the value is
2610+ # irrelevant if the backend does not support blitting, so that
2611+ # we don't have to dynamically update this on the backend.
2612+ # This relies on the current behavior that the request for
2613+ # useblit is fixed during initialization and cannot be changed
2614+ # afterwards.
2615+ props ['animated' ] = self ._useblit
26032616
26042617 self .direction = direction
26052618 self ._extents_on_press = None
@@ -2665,7 +2678,7 @@ def _setup_edge_handles(self, props):
26652678 self ._edge_handles = ToolLineHandles (self .ax , positions ,
26662679 direction = self .direction ,
26672680 line_props = props ,
2668- useblit = self .useblit )
2681+ useblit = self ._useblit )
26692682
26702683 @property
26712684 def _handles_artists (self ):
@@ -3239,7 +3252,7 @@ def __init__(self, ax, onselect=None, *, minspanx=0,
32393252 if props is None :
32403253 props = dict (facecolor = 'red' , edgecolor = 'black' ,
32413254 alpha = 0.2 , fill = True )
3242- props = {** props , 'animated' : self .useblit }
3255+ props = {** props , 'animated' : self ._useblit }
32433256 self ._visible = props .pop ('visible' , self ._visible )
32443257 to_draw = self ._init_shape (** props )
32453258 self .ax .add_patch (to_draw )
@@ -3264,18 +3277,18 @@ def __init__(self, ax, onselect=None, *, minspanx=0,
32643277 xc , yc = self .corners
32653278 self ._corner_handles = ToolHandles (self .ax , xc , yc ,
32663279 marker_props = self ._handle_props ,
3267- useblit = self .useblit )
3280+ useblit = self ._useblit )
32683281
32693282 self ._edge_order = ['W' , 'S' , 'E' , 'N' ]
32703283 xe , ye = self .edge_centers
32713284 self ._edge_handles = ToolHandles (self .ax , xe , ye , marker = 's' ,
32723285 marker_props = self ._handle_props ,
3273- useblit = self .useblit )
3286+ useblit = self ._useblit )
32743287
32753288 xc , yc = self .center
32763289 self ._center_handle = ToolHandles (self .ax , [xc ], [yc ], marker = 's' ,
32773290 marker_props = self ._handle_props ,
3278- useblit = self .useblit )
3291+ useblit = self ._useblit )
32793292
32803293 self ._active_handle = None
32813294
@@ -3782,7 +3795,7 @@ def __init__(self, ax, onselect=None, *, useblit=True, props=None, button=None):
37823795 ** (props if props is not None else {}),
37833796 # Note that self.useblit may be != useblit, if the canvas doesn't
37843797 # support blitting.
3785- 'animated' : self .useblit , 'visible' : False ,
3798+ 'animated' : self ._useblit , 'visible' : False ,
37863799 }
37873800 line = Line2D ([], [], ** props )
37883801 self .ax .add_line (line )
@@ -3906,7 +3919,7 @@ def __init__(self, ax, onselect=None, *, useblit=False,
39063919
39073920 if props is None :
39083921 props = dict (color = 'k' , linestyle = '-' , linewidth = 2 , alpha = 0.5 )
3909- props = {** props , 'animated' : self .useblit }
3922+ props = {** props , 'animated' : self ._useblit }
39103923 self ._selection_artist = line = Line2D ([], [], ** props )
39113924 self .ax .add_line (line )
39123925
@@ -3915,7 +3928,7 @@ def __init__(self, ax, onselect=None, *, useblit=False,
39153928 markerfacecolor = props .get ('color' , 'k' ))
39163929 self ._handle_props = handle_props
39173930 self ._polygon_handles = ToolHandles (self .ax , [], [],
3918- useblit = self .useblit ,
3931+ useblit = self ._useblit ,
39193932 marker_props = self ._handle_props )
39203933
39213934 self ._active_handle_idx = - 1
@@ -3935,7 +3948,7 @@ def _get_bbox(self):
39353948
39363949 def _add_box (self ):
39373950 self ._box = RectangleSelector (self .ax ,
3938- useblit = self .useblit ,
3951+ useblit = self ._useblit ,
39393952 grab_range = self .grab_range ,
39403953 handle_props = self ._box_handle_props ,
39413954 props = self ._box_props ,
@@ -4215,7 +4228,7 @@ class Lasso(AxesWidget):
42154228 def __init__ (self , ax , xy , callback , * , useblit = True , props = None ):
42164229 super ().__init__ (ax )
42174230
4218- self .useblit = useblit and self .canvas .supports_blit
4231+ self .useblit = useblit and self .canvas .supports_blit # TODO: Make dynamic
42194232 if self .useblit :
42204233 self .background = self .canvas .copy_from_bbox (self .ax .bbox )
42214234
0 commit comments