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

Commit87fa6db

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 parent9e1447c commit87fa6db

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
@@ -231,7 +231,7 @@ def __init__(self, ax, label, image=None,
231231
horizontalalignment='center',
232232
transform=ax.transAxes)
233233

234-
self._useblit=useblitandself.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
ifnotcolors.same_color(c,self.ax.get_facecolor()):
266266
self.ax.set_facecolor(c)
267267
ifself.drawon:
268-
ifself._useblit:
268+
ifself._useblitandself.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
ifactivesisNone:
10881088
actives= [False]*len(labels)
10891089

1090-
self._useblit=useblitandself.canvas.supports_blit
1090+
self._useblit=useblitandself.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=useblitandself.canvas.supports_blit
1677+
self._useblit=useblitandself.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=useblitandself.canvas.supports_blit
1963+
self.useblit=useblitandself.canvas.supports_blit# TODO: make dynamic
19641964

19651965
ifself.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
andall(canvas.supports_blitforcanvasinself._canvas_infos))
2072+
# TODO: make dynamic
20722073

20732074
ifself.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=useblitandself.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+
defuseblit(self):
2183+
"""Return whether blitting is used (requested and supported by canvas)."""
2184+
returnself._useblitandself.canvas.supports_blit
2185+
21802186
defset_active(self,active):
21812187
super().set_active(active)
21822188
ifactive:
@@ -2599,7 +2605,14 @@ def __init__(self, ax, onselect, direction, *, minspan=0, useblit=False,
25992605
ifpropsisNone:
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
ifpropsisNone:
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
**(propsifpropsisnotNoneelse {}),
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
ifpropsisNone:
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=useblitandself.canvas.supports_blit
4231+
self.useblit=useblitandself.canvas.supports_blit# TODO: Make dynamic
42194232
ifself.useblit:
42204233
self.background=self.canvas.copy_from_bbox(self.ax.bbox)
42214234

‎lib/matplotlib/widgets.pyi‎

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

273273
class_SelectorWidget(AxesWidget):
274274
onselect:Callable[[float,float],Any]
275-
useblit:bool
275+
_useblit:bool
276276
background:Any
277277
validButtons:list[MouseButton]
278278
def__init__(
@@ -284,6 +284,8 @@ class _SelectorWidget(AxesWidget):
284284
state_modifier_keys:dict[str,str]|None= ...,
285285
use_data_coordinates:bool= ...,
286286
)->None: ...
287+
@property
288+
defuseblit(self)->bool: ...
287289
defupdate_background(self,event:Event)->None: ...
288290
defconnect_default_events(self)->None: ...
289291
defignore(self,event:Event)->bool: ...

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp