@@ -2013,15 +2013,20 @@ def add_artist(self, artist):
2013
2013
2014
2014
@property
2015
2015
def artists (self ):
2016
- """Tuple of the artists of the selector"""
2016
+ """Tuple of the artists of the selector. """
2017
2017
return tuple (self ._artists )
2018
2018
2019
+ @property
2020
+ def _selection_artist (self ):
2021
+ """The selection artist."""
2022
+ return self .artists [0 ]
2023
+
2019
2024
def set_props (self , ** props ):
2020
2025
"""
2021
- Set the properties of the selector artist. See the `props` argument
2026
+ Set the properties of the selection artist. See the `props` argument
2022
2027
in the selector docstring to know which properties are supported.
2023
2028
"""
2024
- self .artists [ 0 ] .set (** props )
2029
+ self ._selection_artist .set (** props )
2025
2030
self .update ()
2026
2031
self ._props = props
2027
2032
@@ -2168,7 +2173,7 @@ def __init__(self, ax, onselect, direction, minspan=0, useblit=False,
2168
2173
self ._prev = (0 , 0 )
2169
2174
2170
2175
rect = _api .deprecated ("3.5" )(
2171
- property (lambda self : self .artists [ 0 ] )
2176
+ property (lambda self : self ._selection_artist )
2172
2177
)
2173
2178
2174
2179
rectprops = _api .deprecated ("3.5" )(
@@ -2244,7 +2249,7 @@ def connect_default_events(self):
2244
2249
def _press (self , event ):
2245
2250
"""Button press event handler."""
2246
2251
self ._set_cursor (True )
2247
- if self ._interactive and self .artists [ 0 ] .get_visible ():
2252
+ if self ._interactive and self ._selection_artist .get_visible ():
2248
2253
self ._set_active_handle (event )
2249
2254
else :
2250
2255
self ._active_handle = None
@@ -2300,7 +2305,7 @@ def _release(self, event):
2300
2305
"""Button release event handler."""
2301
2306
self ._set_cursor (False )
2302
2307
if not self ._interactive :
2303
- self .artists [ 0 ] .set_visible (False )
2308
+ self ._selection_artist .set_visible (False )
2304
2309
2305
2310
vmin , vmax = self .extents
2306
2311
span = vmax - vmin
@@ -2377,11 +2382,11 @@ def _draw_shape(self, vmin, vmax):
2377
2382
if vmin > vmax :
2378
2383
vmin , vmax = vmax , vmin
2379
2384
if self .direction == 'horizontal' :
2380
- self .artists [ 0 ] .set_x (vmin )
2381
- self .artists [ 0 ] .set_width (vmax - vmin )
2385
+ self ._selection_artist .set_x (vmin )
2386
+ self ._selection_artist .set_width (vmax - vmin )
2382
2387
else :
2383
- self .artists [ 0 ] .set_y (vmin )
2384
- self .artists [ 0 ] .set_height (vmax - vmin )
2388
+ self ._selection_artist .set_y (vmin )
2389
+ self ._selection_artist .set_height (vmax - vmin )
2385
2390
2386
2391
def _set_active_handle (self , event ):
2387
2392
"""Set active handle based on the location of the mouse event."""
@@ -2411,17 +2416,17 @@ def _set_active_handle(self, event):
2411
2416
2412
2417
def _contains (self , event ):
2413
2418
"""Return True if event is within the patch."""
2414
- return self .artists [ 0 ] .contains (event , radius = 0 )[0 ]
2419
+ return self ._selection_artist .contains (event , radius = 0 )[0 ]
2415
2420
2416
2421
@property
2417
2422
def extents (self ):
2418
2423
"""Return extents of the span selector."""
2419
2424
if self .direction == 'horizontal' :
2420
- vmin = self .artists [ 0 ] .get_x ()
2421
- vmax = vmin + self .artists [ 0 ] .get_width ()
2425
+ vmin = self ._selection_artist .get_x ()
2426
+ vmax = vmin + self ._selection_artist .get_width ()
2422
2427
else :
2423
- vmin = self .artists [ 0 ] .get_y ()
2424
- vmax = vmin + self .artists [ 0 ] .get_height ()
2428
+ vmin = self ._selection_artist .get_y ()
2429
+ vmax = vmin + self ._selection_artist .get_height ()
2425
2430
return vmin , vmax
2426
2431
2427
2432
@extents .setter
@@ -2802,7 +2807,7 @@ def __init__(self, ax, onselect, drawtype='box',
2802
2807
self ._extents_on_press = None
2803
2808
2804
2809
to_draw = _api .deprecated ("3.5" )(
2805
- property (lambda self : self .artists [ 0 ] )
2810
+ property (lambda self : self ._selection_artist )
2806
2811
)
2807
2812
2808
2813
drawtype = _api .deprecate_privatize_attribute ("3.5" )
@@ -2824,7 +2829,7 @@ def _press(self, event):
2824
2829
"""Button press event handler."""
2825
2830
# make the drawn box/line visible get the click-coordinates,
2826
2831
# button, ...
2827
- if self ._interactive and self .artists [ 0 ] .get_visible ():
2832
+ if self ._interactive and self ._selection_artist .get_visible ():
2828
2833
self ._set_active_handle (event )
2829
2834
else :
2830
2835
self ._active_handle = None
@@ -2847,7 +2852,7 @@ def _press(self, event):
2847
2852
def _release (self , event ):
2848
2853
"""Button release event handler."""
2849
2854
if not self ._interactive :
2850
- self .artists [ 0 ] .set_visible (False )
2855
+ self ._selection_artist .set_visible (False )
2851
2856
2852
2857
# update the eventpress and eventrelease with the resulting extents
2853
2858
x0 , x1 , y0 , y1 = self .extents
@@ -2947,13 +2952,13 @@ def _onmove(self, event):
2947
2952
@property
2948
2953
def _rect_bbox (self ):
2949
2954
if self ._drawtype == 'box' :
2950
- x0 = self .artists [ 0 ] .get_x ()
2951
- y0 = self .artists [ 0 ] .get_y ()
2952
- width = self .artists [ 0 ] .get_width ()
2953
- height = self .artists [ 0 ] .get_height ()
2955
+ x0 = self ._selection_artist .get_x ()
2956
+ y0 = self ._selection_artist .get_y ()
2957
+ width = self ._selection_artist .get_width ()
2958
+ height = self ._selection_artist .get_height ()
2954
2959
return x0 , y0 , width , height
2955
2960
else :
2956
- x , y = self .artists [ 0 ] .get_data ()
2961
+ x , y = self ._selection_artist .get_data ()
2957
2962
x0 , x1 = min (x ), max (x )
2958
2963
y0 , y1 = min (y ), max (y )
2959
2964
return x0 , y0 , x1 - x0 , y1 - y0
@@ -3017,13 +3022,13 @@ def _draw_shape(self, extents):
3017
3022
ymax = min (ymax , ylim [1 ])
3018
3023
3019
3024
if self ._drawtype == 'box' :
3020
- self .artists [ 0 ] .set_x (xmin )
3021
- self .artists [ 0 ] .set_y (ymin )
3022
- self .artists [ 0 ] .set_width (xmax - xmin )
3023
- self .artists [ 0 ] .set_height (ymax - ymin )
3025
+ self ._selection_artist .set_x (xmin )
3026
+ self ._selection_artist .set_y (ymin )
3027
+ self ._selection_artist .set_width (xmax - xmin )
3028
+ self ._selection_artist .set_height (ymax - ymin )
3024
3029
3025
3030
elif self ._drawtype == 'line' :
3026
- self .artists [ 0 ] .set_data ([xmin , xmax ], [ymin , ymax ])
3031
+ self ._selection_artist .set_data ([xmin , xmax ], [ymin , ymax ])
3027
3032
3028
3033
def _set_active_handle (self , event ):
3029
3034
"""Set active handle based on the location of the mouse event."""
@@ -3067,7 +3072,7 @@ def _set_active_handle(self, event):
3067
3072
3068
3073
def _contains (self , event ):
3069
3074
"""Return True if event is within the patch."""
3070
- return self .artists [ 0 ] .contains (event , radius = 0 )[0 ]
3075
+ return self ._selection_artist .contains (event , radius = 0 )[0 ]
3071
3076
3072
3077
@property
3073
3078
def geometry (self ):
@@ -3078,12 +3083,12 @@ def geometry(self):
3078
3083
of the four corners of the rectangle starting and ending
3079
3084
in the top left corner.
3080
3085
"""
3081
- if hasattr (self .artists [ 0 ] , 'get_verts' ):
3086
+ if hasattr (self ._selection_artist , 'get_verts' ):
3082
3087
xfm = self .ax .transData .inverted ()
3083
- y , x = xfm .transform (self .artists [ 0 ] .get_verts ()).T
3088
+ y , x = xfm .transform (self ._selection_artist .get_verts ()).T
3084
3089
return np .array ([x , y ])
3085
3090
else :
3086
- return np .array (self .artists [ 0 ] .get_data ())
3091
+ return np .array (self ._selection_artist .get_data ())
3087
3092
3088
3093
3089
3094
@docstring .Substitution (_RECTANGLESELECTOR_PARAMETERS_DOCSTRING .replace (
@@ -3137,24 +3142,24 @@ def _draw_shape(self, extents):
3137
3142
b = (ymax - ymin ) / 2.
3138
3143
3139
3144
if self ._drawtype == 'box' :
3140
- self .artists [ 0 ] .center = center
3141
- self .artists [ 0 ] .width = 2 * a
3142
- self .artists [ 0 ] .height = 2 * b
3145
+ self ._selection_artist .center = center
3146
+ self ._selection_artist .width = 2 * a
3147
+ self ._selection_artist .height = 2 * b
3143
3148
else :
3144
3149
rad = np .deg2rad (np .arange (31 ) * 12 )
3145
3150
x = a * np .cos (rad ) + center [0 ]
3146
3151
y = b * np .sin (rad ) + center [1 ]
3147
- self .artists [ 0 ] .set_data (x , y )
3152
+ self ._selection_artist .set_data (x , y )
3148
3153
3149
3154
@property
3150
3155
def _rect_bbox (self ):
3151
3156
if self ._drawtype == 'box' :
3152
- x , y = self .artists [ 0 ] .center
3153
- width = self .artists [ 0 ] .width
3154
- height = self .artists [ 0 ] .height
3157
+ x , y = self ._selection_artist .center
3158
+ width = self ._selection_artist .width
3159
+ height = self ._selection_artist .height
3155
3160
return x - width / 2. , y - height / 2. , width , height
3156
3161
else :
3157
- x , y = self .artists [ 0 ] .get_data ()
3162
+ x , y = self ._selection_artist .get_data ()
3158
3163
x0 , x1 = min (x ), max (x )
3159
3164
y0 , y1 = min (y ), max (y )
3160
3165
return x0 , y0 , x1 - x0 , y1 - y0
@@ -3218,7 +3223,7 @@ def onpress(self, event):
3218
3223
3219
3224
def _press (self , event ):
3220
3225
self .verts = [self ._get_data (event )]
3221
- self .artists [ 0 ] .set_visible (True )
3226
+ self ._selection_artist .set_visible (True )
3222
3227
3223
3228
def onrelease (self , event ):
3224
3229
self .release (event )
@@ -3227,16 +3232,16 @@ def _release(self, event):
3227
3232
if self .verts is not None :
3228
3233
self .verts .append (self ._get_data (event ))
3229
3234
self .onselect (self .verts )
3230
- self .artists [ 0 ] .set_data ([[], []])
3231
- self .artists [ 0 ] .set_visible (False )
3235
+ self ._selection_artist .set_data ([[], []])
3236
+ self ._selection_artist .set_visible (False )
3232
3237
self .verts = None
3233
3238
3234
3239
def _onmove (self , event ):
3235
3240
if self .verts is None :
3236
3241
return
3237
3242
self .verts .append (self ._get_data (event ))
3238
3243
3239
- self .artists [ 0 ] .set_data (list (zip (* self .verts )))
3244
+ self ._selection_artist .set_data (list (zip (* self .verts )))
3240
3245
3241
3246
self .update ()
3242
3247
@@ -3343,7 +3348,7 @@ def __init__(self, ax, onselect, useblit=False,
3343
3348
self .set_visible (True )
3344
3349
3345
3350
line = _api .deprecated ("3.5" )(
3346
- property (lambda self : self .artists [ 0 ] )
3351
+ property (lambda self : self ._selection_artist )
3347
3352
)
3348
3353
3349
3354
vertex_select_radius = _api .deprecated ("3.5" , name = "vertex_select_radius" ,
@@ -3459,7 +3464,7 @@ def _onmove(self, event):
3459
3464
# Position pending vertex.
3460
3465
else :
3461
3466
# Calculate distance to the start vertex.
3462
- x0 , y0 = self .artists [ 0 ] .get_transform ().transform ((self ._xs [0 ],
3467
+ x0 , y0 = self ._selection_artist .get_transform ().transform ((self ._xs [0 ],
3463
3468
self ._ys [0 ]))
3464
3469
v0_dist = np .hypot (x0 - event .x , y0 - event .y )
3465
3470
# Lock on to the start vertex if near it and ready to complete.
@@ -3500,7 +3505,7 @@ def _on_key_release(self, event):
3500
3505
3501
3506
def _draw_polygon (self ):
3502
3507
"""Redraw the polygon based on the new vertex positions."""
3503
- self .artists [ 0 ] .set_data (self ._xs , self ._ys )
3508
+ self ._selection_artist .set_data (self ._xs , self ._ys )
3504
3509
# Only show one tool handle at the start and end vertex of the polygon
3505
3510
# if the polygon is completed or the user is locked on to the start
3506
3511
# vertex.
0 commit comments