@@ -227,7 +227,7 @@ def __init__(self, ax, label, image=None,
227227 horizontalalignment = 'center' ,
228228 transform = ax .transAxes )
229229
230- self ._useblit = useblit and self . canvas . supports_blit
230+ self ._useblit = useblit
231231
232232 self ._observers = cbook .CallbackRegistry (signals = ["clicked" ])
233233
@@ -261,7 +261,7 @@ def _motion(self, event):
261261 if not colors .same_color (c , self .ax .get_facecolor ()):
262262 self .ax .set_facecolor (c )
263263 if self .drawon :
264- if self ._useblit :
264+ if self ._useblit and self . canvas . supports_blit :
265265 self .ax .draw_artist (self .ax )
266266 self .canvas .blit (self .ax .bbox )
267267 else :
@@ -1083,7 +1083,7 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
10831083 if actives is None :
10841084 actives = [False ] * len (labels )
10851085
1086- self ._useblit = useblit and self .canvas .supports_blit
1086+ self ._useblit = useblit and self .canvas .supports_blit # TODO: make dynamic
10871087
10881088 ys = np .linspace (1 , 0 , len (labels )+ 2 )[1 :- 1 ]
10891089
@@ -1670,7 +1670,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16701670
16711671 ys = np .linspace (1 , 0 , len (labels ) + 2 )[1 :- 1 ]
16721672
1673- self ._useblit = useblit and self .canvas .supports_blit
1673+ self ._useblit = useblit and self .canvas .supports_blit # TODO: make dynamic
16741674
16751675 label_props = _expand_text_props (label_props )
16761676 self .labels = [
@@ -1956,7 +1956,7 @@ def __init__(self, ax, *, horizOn=True, vertOn=True, useblit=False,
19561956 self .visible = True
19571957 self .horizOn = horizOn
19581958 self .vertOn = vertOn
1959- self .useblit = useblit and self .canvas .supports_blit
1959+ self .useblit = useblit and self .canvas .supports_blit # TODO: make dynamic
19601960
19611961 if self .useblit :
19621962 lineprops ['animated' ] = True
@@ -2065,6 +2065,7 @@ def __init__(self, canvas, axes, *, useblit=True, horizOn=False, vertOn=True,
20652065 self .useblit = (
20662066 useblit
20672067 and all (canvas .supports_blit for canvas in self ._canvas_infos ))
2068+ # TODO: make dynamic
20682069
20692070 if self .useblit :
20702071 lineprops ['animated' ] = True
@@ -2149,7 +2150,7 @@ def __init__(self, ax, onselect=None, useblit=False, button=None,
21492150 self .onselect = lambda * args : None
21502151 else :
21512152 self .onselect = onselect
2152- self .useblit = useblit and self . canvas . supports_blit
2153+ self ._useblit = useblit
21532154 self .connect_default_events ()
21542155
21552156 self ._state_modifier_keys = dict (move = ' ' , clear = 'escape' ,
@@ -2173,6 +2174,11 @@ def __init__(self, ax, onselect=None, useblit=False, button=None,
21732174 self ._prev_event = None
21742175 self ._state = set ()
21752176
2177+ @property
2178+ def useblit (self ):
2179+ """Return whether blitting is used (requested and supported by canvas)."""
2180+ return self ._useblit and self .canvas .supports_blit
2181+
21762182 def set_active (self , active ):
21772183 super ().set_active (active )
21782184 if active :
@@ -2595,7 +2601,14 @@ def __init__(self, ax, onselect, direction, *, minspan=0, useblit=False,
25952601 if props is None :
25962602 props = dict (facecolor = 'red' , alpha = 0.5 )
25972603
2598- props ['animated' ] = self .useblit
2604+ # Note: We set this based on the user setting during ínitialization,
2605+ # not on the actual capability of blitting. But the value is
2606+ # irrelevant if the backend does not support blitting, so that
2607+ # we don't have to dynamically update this on the backend.
2608+ # This relies on the current behavior that the request for
2609+ # useblit is fixed during initialization and cannot be changed
2610+ # afterwards.
2611+ props ['animated' ] = self ._useblit
25992612
26002613 self .direction = direction
26012614 self ._extents_on_press = None
@@ -2661,7 +2674,7 @@ def _setup_edge_handles(self, props):
26612674 self ._edge_handles = ToolLineHandles (self .ax , positions ,
26622675 direction = self .direction ,
26632676 line_props = props ,
2664- useblit = self .useblit )
2677+ useblit = self ._useblit )
26652678
26662679 @property
26672680 def _handles_artists (self ):
@@ -3235,7 +3248,7 @@ def __init__(self, ax, onselect=None, *, minspanx=0,
32353248 if props is None :
32363249 props = dict (facecolor = 'red' , edgecolor = 'black' ,
32373250 alpha = 0.2 , fill = True )
3238- props = {** props , 'animated' : self .useblit }
3251+ props = {** props , 'animated' : self ._useblit }
32393252 self ._visible = props .pop ('visible' , self ._visible )
32403253 to_draw = self ._init_shape (** props )
32413254 self .ax .add_patch (to_draw )
@@ -3260,18 +3273,18 @@ def __init__(self, ax, onselect=None, *, minspanx=0,
32603273 xc , yc = self .corners
32613274 self ._corner_handles = ToolHandles (self .ax , xc , yc ,
32623275 marker_props = self ._handle_props ,
3263- useblit = self .useblit )
3276+ useblit = self ._useblit )
32643277
32653278 self ._edge_order = ['W' , 'S' , 'E' , 'N' ]
32663279 xe , ye = self .edge_centers
32673280 self ._edge_handles = ToolHandles (self .ax , xe , ye , marker = 's' ,
32683281 marker_props = self ._handle_props ,
3269- useblit = self .useblit )
3282+ useblit = self ._useblit )
32703283
32713284 xc , yc = self .center
32723285 self ._center_handle = ToolHandles (self .ax , [xc ], [yc ], marker = 's' ,
32733286 marker_props = self ._handle_props ,
3274- useblit = self .useblit )
3287+ useblit = self ._useblit )
32753288
32763289 self ._active_handle = None
32773290
@@ -3778,7 +3791,7 @@ def __init__(self, ax, onselect=None, *, useblit=True, props=None, button=None):
37783791 ** (props if props is not None else {}),
37793792 # Note that self.useblit may be != useblit, if the canvas doesn't
37803793 # support blitting.
3781- 'animated' : self .useblit , 'visible' : False ,
3794+ 'animated' : self ._useblit , 'visible' : False ,
37823795 }
37833796 line = Line2D ([], [], ** props )
37843797 self .ax .add_line (line )
@@ -3902,7 +3915,7 @@ def __init__(self, ax, onselect=None, *, useblit=False,
39023915
39033916 if props is None :
39043917 props = dict (color = 'k' , linestyle = '-' , linewidth = 2 , alpha = 0.5 )
3905- props = {** props , 'animated' : self .useblit }
3918+ props = {** props , 'animated' : self ._useblit }
39063919 self ._selection_artist = line = Line2D ([], [], ** props )
39073920 self .ax .add_line (line )
39083921
@@ -3911,7 +3924,7 @@ def __init__(self, ax, onselect=None, *, useblit=False,
39113924 markerfacecolor = props .get ('color' , 'k' ))
39123925 self ._handle_props = handle_props
39133926 self ._polygon_handles = ToolHandles (self .ax , [], [],
3914- useblit = self .useblit ,
3927+ useblit = self ._useblit ,
39153928 marker_props = self ._handle_props )
39163929
39173930 self ._active_handle_idx = - 1
@@ -3931,7 +3944,7 @@ def _get_bbox(self):
39313944
39323945 def _add_box (self ):
39333946 self ._box = RectangleSelector (self .ax ,
3934- useblit = self .useblit ,
3947+ useblit = self ._useblit ,
39353948 grab_range = self .grab_range ,
39363949 handle_props = self ._box_handle_props ,
39373950 props = self ._box_props ,
@@ -4211,7 +4224,7 @@ class Lasso(AxesWidget):
42114224 def __init__ (self , ax , xy , callback , * , useblit = True , props = None ):
42124225 super ().__init__ (ax )
42134226
4214- self .useblit = useblit and self .canvas .supports_blit
4227+ self .useblit = useblit and self .canvas .supports_blit # TODO: Make dynamic
42154228 if self .useblit :
42164229 self .background = self .canvas .copy_from_bbox (self .ax .bbox )
42174230
0 commit comments