Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf7ca7cc

Browse files
committed
Support blitting with changing canvas in some widgets
Approach depends a bit on the widget, but generally:- `self._useblit` only stores the flag passed to __init__- canvas.supports_blit is checked dynamically when needed- we sometimes have the property `sef.useblit`, which is the effectivevalue of flag and capability- if animated artists are needed that state is set during __init__ based on the flag. This relies on the fact that the flag cannot be changed later, and that the value of "animated" does not play a role for drawing canvases without blit support.Supported:- Button- _SelectorWidget- SpanSelector- ToolLineHandles- ToolHandles- RectangleSelector- LassoSelector- PolygonSelectorNot supported yet:- CheckButtons- RadioButtons- Cursor- MultiCursor- Lasso
1 parent48346de commitf7ca7cc

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

‎lib/matplotlib/widgets.py‎

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def __init__(self, ax, label, image=None,
222222
horizontalalignment='center',
223223
transform=ax.transAxes)
224224

225-
self._useblit=useblitandself.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
ifnotcolors.same_color(c,self.ax.get_facecolor()):
257257
self.ax.set_facecolor(c)
258258
ifself.drawon:
259-
ifself._useblit:
259+
ifself._useblitandself.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
ifactivesisNone:
10791079
actives= [False]*len(labels)
10801080

1081-
self._useblit=useblitandself.canvas.supports_blit
1081+
self._useblit=useblitandself.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=useblitandself.canvas.supports_blit
1668+
self._useblit=useblitandself.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=useblitandself.canvas.supports_blit
1954+
self.useblit=useblitandself.canvas.supports_blit# TODO: make dynamic
19551955

19561956
ifself.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
andall(canvas.supports_blitforcanvasinself._canvas_infos))
2063+
# TODO: make dynamic
20632064

20642065
ifself.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=useblitandself.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+
defuseblit(self):
2174+
"""Return whether blitting is used (requested and supported by canvas)."""
2175+
returnself._useblitandself.canvas.supports_blit
2176+
21712177
defset_active(self,active):
21722178
super().set_active(active)
21732179
ifactive:
@@ -2590,7 +2596,14 @@ def __init__(self, ax, onselect, direction, *, minspan=0, useblit=False,
25902596
ifpropsisNone:
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
ifpropsisNone:
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
**(propsifpropsisnotNoneelse {}),
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
ifpropsisNone:
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=useblitandself.canvas.supports_blit
4193+
self.useblit=useblitandself.canvas.supports_blit# TODO: Make dynamic
41814194
ifself.useblit:
41824195
self.background=self.canvas.copy_from_bbox(self.ax.bbox)
41834196

‎lib/matplotlib/widgets.pyi‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class MultiCursor(Widget):
270270

271271
class_SelectorWidget(AxesWidget):
272272
onselect:Callable[[float,float],Any]
273-
useblit:bool
273+
_useblit:bool
274274
background:Any
275275
validButtons:list[MouseButton]
276276
def__init__(
@@ -282,6 +282,8 @@ class _SelectorWidget(AxesWidget):
282282
state_modifier_keys:dict[str,str]|None= ...,
283283
use_data_coordinates:bool= ...,
284284
)->None: ...
285+
@property
286+
defuseblit(self)->bool: ...
285287
defupdate_background(self,event:Event)->None: ...
286288
defconnect_default_events(self)->None: ...
287289
defignore(self,event:Event)->bool: ...

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp