@@ -222,7 +222,7 @@ def __init__(self, ax, label, image=None,
222222 horizontalalignment = 'center' ,
223223 transform = ax .transAxes )
224224
225- self ._useblit = useblit and self . canvas . supports_blit
225+ self ._useblit = useblit
226226
227227 self ._observers = cbook .CallbackRegistry (signals = ["clicked" ])
228228
@@ -256,7 +256,7 @@ def _motion(self, event):
256256 if not colors .same_color (c , self .ax .get_facecolor ()):
257257 self .ax .set_facecolor (c )
258258 if self .drawon :
259- if self ._useblit :
259+ if self ._useblit and self . canvas . supports_blit :
260260 self .ax .draw_artist (self .ax )
261261 self .canvas .blit (self .ax .bbox )
262262 else :
@@ -1078,7 +1078,7 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
10781078 if actives is None :
10791079 actives = [False ] * len (labels )
10801080
1081- self ._useblit = useblit and self .canvas .supports_blit
1081+ self ._useblit = useblit and self .canvas .supports_blit # TODO: make dynamic
10821082
10831083 ys = np .linspace (1 , 0 , len (labels )+ 2 )[1 :- 1 ]
10841084
@@ -1665,7 +1665,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16651665
16661666 ys = np .linspace (1 , 0 , len (labels ) + 2 )[1 :- 1 ]
16671667
1668- self ._useblit = useblit and self .canvas .supports_blit
1668+ self ._useblit = useblit and self .canvas .supports_blit # TODO: make dynamic
16691669
16701670 label_props = _expand_text_props (label_props )
16711671 self .labels = [
@@ -1951,7 +1951,7 @@ def __init__(self, ax, *, horizOn=True, vertOn=True, useblit=False,
19511951 self .visible = True
19521952 self .horizOn = horizOn
19531953 self .vertOn = vertOn
1954- self .useblit = useblit and self .canvas .supports_blit
1954+ self .useblit = useblit and self .canvas .supports_blit # TODO: make dynamic
19551955
19561956 if self .useblit :
19571957 lineprops ['animated' ] = True
@@ -2060,6 +2060,7 @@ def __init__(self, canvas, axes, *, useblit=True, horizOn=False, vertOn=True,
20602060 self .useblit = (
20612061 useblit
20622062 and all (canvas .supports_blit for canvas in self ._canvas_infos ))
2063+ # TODO: make dynamic
20632064
20642065 if self .useblit :
20652066 lineprops ['animated' ] = True
@@ -2144,7 +2145,7 @@ def __init__(self, ax, onselect=None, useblit=False, button=None,
21442145 self .onselect = lambda * args : None
21452146 else :
21462147 self .onselect = onselect
2147- self .useblit = useblit and self . canvas . supports_blit
2148+ self ._useblit = useblit
21482149 self .connect_default_events ()
21492150
21502151 self ._state_modifier_keys = dict (move = ' ' , clear = 'escape' ,
@@ -2168,6 +2169,11 @@ def __init__(self, ax, onselect=None, useblit=False, button=None,
21682169 self ._prev_event = None
21692170 self ._state = set ()
21702171
2172+ @property
2173+ def useblit (self ):
2174+ """Return whether blitting is used (requested and supported by canvas)."""
2175+ return self ._useblit and self .canvas .supports_blit
2176+
21712177 def set_active (self , active ):
21722178 super ().set_active (active )
21732179 if active :
@@ -2590,7 +2596,14 @@ def __init__(self, ax, onselect, direction, *, minspan=0, useblit=False,
25902596 if props is None :
25912597 props = dict (facecolor = 'red' , alpha = 0.5 )
25922598
2593- props ['animated' ] = self .useblit
2599+ # Note: We set this based on the user setting during ínitialization,
2600+ # not on the actual capability of blitting. But the value is
2601+ # irrelevant if the backend does not support blitting, so that
2602+ # we don't have to dynamically update this on the backend.
2603+ # This relies on the current behavior that the request for
2604+ # useblit is fixed during initialization and cannot be changed
2605+ # afterwards.
2606+ props ['animated' ] = self ._useblit
25942607
25952608 self .direction = direction
25962609 self ._extents_on_press = None
@@ -2656,7 +2669,7 @@ def _setup_edge_handles(self, props):
26562669 self ._edge_handles = ToolLineHandles (self .ax , positions ,
26572670 direction = self .direction ,
26582671 line_props = props ,
2659- useblit = self .useblit )
2672+ useblit = self ._useblit )
26602673
26612674 @property
26622675 def _handles_artists (self ):
@@ -3223,7 +3236,7 @@ def __init__(self, ax, onselect=None, *, minspanx=0,
32233236 if props is None :
32243237 props = dict (facecolor = 'red' , edgecolor = 'black' ,
32253238 alpha = 0.2 , fill = True )
3226- props = {** props , 'animated' : self .useblit }
3239+ props = {** props , 'animated' : self ._useblit }
32273240 self ._visible = props .pop ('visible' , self ._visible )
32283241 to_draw = self ._init_shape (** props )
32293242 self .ax .add_patch (to_draw )
@@ -3248,18 +3261,18 @@ def __init__(self, ax, onselect=None, *, minspanx=0,
32483261 xc , yc = self .corners
32493262 self ._corner_handles = ToolHandles (self .ax , xc , yc ,
32503263 marker_props = self ._handle_props ,
3251- useblit = self .useblit )
3264+ useblit = self ._useblit )
32523265
32533266 self ._edge_order = ['W' , 'S' , 'E' , 'N' ]
32543267 xe , ye = self .edge_centers
32553268 self ._edge_handles = ToolHandles (self .ax , xe , ye , marker = 's' ,
32563269 marker_props = self ._handle_props ,
3257- useblit = self .useblit )
3270+ useblit = self ._useblit )
32583271
32593272 xc , yc = self .center
32603273 self ._center_handle = ToolHandles (self .ax , [xc ], [yc ], marker = 's' ,
32613274 marker_props = self ._handle_props ,
3262- useblit = self .useblit )
3275+ useblit = self ._useblit )
32633276
32643277 self ._active_handle = None
32653278
@@ -3744,7 +3757,7 @@ def __init__(self, ax, onselect=None, *, useblit=True, props=None, button=None):
37443757 ** (props if props is not None else {}),
37453758 # Note that self.useblit may be != useblit, if the canvas doesn't
37463759 # support blitting.
3747- 'animated' : self .useblit , 'visible' : False ,
3760+ 'animated' : self ._useblit , 'visible' : False ,
37483761 }
37493762 line = Line2D ([], [], ** props )
37503763 self .ax .add_line (line )
@@ -3868,7 +3881,7 @@ def __init__(self, ax, onselect=None, *, useblit=False,
38683881
38693882 if props is None :
38703883 props = dict (color = 'k' , linestyle = '-' , linewidth = 2 , alpha = 0.5 )
3871- props = {** props , 'animated' : self .useblit }
3884+ props = {** props , 'animated' : self ._useblit }
38723885 self ._selection_artist = line = Line2D ([], [], ** props )
38733886 self .ax .add_line (line )
38743887
@@ -3877,7 +3890,7 @@ def __init__(self, ax, onselect=None, *, useblit=False,
38773890 markerfacecolor = props .get ('color' , 'k' ))
38783891 self ._handle_props = handle_props
38793892 self ._polygon_handles = ToolHandles (self .ax , [], [],
3880- useblit = self .useblit ,
3893+ useblit = self ._useblit ,
38813894 marker_props = self ._handle_props )
38823895
38833896 self ._active_handle_idx = - 1
@@ -3897,7 +3910,7 @@ def _get_bbox(self):
38973910
38983911 def _add_box (self ):
38993912 self ._box = RectangleSelector (self .ax ,
3900- useblit = self .useblit ,
3913+ useblit = self ._useblit ,
39013914 grab_range = self .grab_range ,
39023915 handle_props = self ._box_handle_props ,
39033916 props = self ._box_props ,
@@ -4177,7 +4190,7 @@ class Lasso(AxesWidget):
41774190 def __init__ (self , ax , xy , callback , * , useblit = True , props = None ):
41784191 super ().__init__ (ax )
41794192
4180- self .useblit = useblit and self .canvas .supports_blit
4193+ self .useblit = useblit and self .canvas .supports_blit # TODO: Make dynamic
41814194 if self .useblit :
41824195 self .background = self .canvas .copy_from_bbox (self .ax .bbox )
41834196
0 commit comments