@@ -61,7 +61,7 @@ def locked(self):
61
61
62
62
class Widget :
63
63
"""
64
- Abstract base class for GUI neutral widgets
64
+ Abstract base class for GUI neutral widgets.
65
65
"""
66
66
drawon = True
67
67
eventson = True
@@ -118,7 +118,7 @@ def __init__(self, ax):
118
118
119
119
def connect_event (self , event , callback ):
120
120
"""
121
- Connect callback with an event.
121
+ Connect a callback function with an event.
122
122
123
123
This should be used in lieu of ``figure.canvas.mpl_connect`` since this
124
124
function stores callback ids for later clean up.
@@ -277,6 +277,7 @@ def __init__(self, ax, orientation, closedmin, closedmax,
277
277
self ._observers = cbook .CallbackRegistry ()
278
278
279
279
def _stepped_value (self , val ):
280
+ """Return *val* coerced to closest number in the ``valstep`` grid."""
280
281
if isinstance (self .valstep , Number ):
281
282
val = (self .valmin
282
283
+ round ((val - self .valmin ) / self .valstep ) * self .valstep )
@@ -291,17 +292,17 @@ def _stepped_value(self, val):
291
292
292
293
def disconnect (self , cid ):
293
294
"""
294
- Remove the observer with connection id *cid*
295
+ Remove the observer with connection id *cid*.
295
296
296
297
Parameters
297
298
----------
298
299
cid : int
299
- Connection id of the observer to be removed
300
+ Connection id of the observer to be removed.
300
301
"""
301
302
self ._observers .disconnect (cid )
302
303
303
304
def reset (self ):
304
- """Reset the slider to the initial value"""
305
+ """Reset the slider to the initial value. """
305
306
if self .val != self .valinit :
306
307
self .set_val (self .valinit )
307
308
@@ -490,7 +491,7 @@ def _format(self, val):
490
491
491
492
def set_val (self , val ):
492
493
"""
493
- Set slider value to *val*
494
+ Set slider value to *val*.
494
495
495
496
Parameters
496
497
----------
@@ -513,8 +514,7 @@ def set_val(self, val):
513
514
514
515
def on_changed (self , func ):
515
516
"""
516
- When the slider value is changed call *func* with the new
517
- slider value
517
+ Connect *func* as callback function to changes of the slider value.
518
518
519
519
Parameters
520
520
----------
@@ -525,7 +525,7 @@ def on_changed(self, func):
525
525
Returns
526
526
-------
527
527
int
528
- Connection id (which can be used to disconnect *func*)
528
+ Connection id (which can be used to disconnect *func*).
529
529
"""
530
530
return self ._observers .connect ('changed' , lambda val : func (val ))
531
531
@@ -663,9 +663,7 @@ def __init__(
663
663
self .set_val (valinit )
664
664
665
665
def _min_in_bounds (self , min ):
666
- """
667
- Ensure the new min value is between valmin and self.val[1]
668
- """
666
+ """Ensure the new min value is between valmin and self.val[1]."""
669
667
if min <= self .valmin :
670
668
if not self .closedmin :
671
669
return self .val [0 ]
@@ -676,9 +674,7 @@ def _min_in_bounds(self, min):
676
674
return self ._stepped_value (min )
677
675
678
676
def _max_in_bounds (self , max ):
679
- """
680
- Ensure the new max value is between valmax and self.val[0]
681
- """
677
+ """Ensure the new max value is between valmax and self.val[0]."""
682
678
if max >= self .valmax :
683
679
if not self .closedmax :
684
680
return self .val [1 ]
@@ -692,9 +688,7 @@ def _value_in_bounds(self, val):
692
688
return (self ._min_in_bounds (val [0 ]), self ._max_in_bounds (val [1 ]))
693
689
694
690
def _update_val_from_pos (self , pos ):
695
- """
696
- Given a position update the *val*
697
- """
691
+ """Update the slider value based on a given position."""
698
692
idx = np .argmin (np .abs (self .val - pos ))
699
693
if idx == 0 :
700
694
val = self ._min_in_bounds (pos )
@@ -742,7 +736,7 @@ def _format(self, val):
742
736
743
737
def set_min (self , min ):
744
738
"""
745
- Set the lower value of the slider to *min*
739
+ Set the lower value of the slider to *min*.
746
740
747
741
Parameters
748
742
----------
@@ -752,7 +746,7 @@ def set_min(self, min):
752
746
753
747
def set_max (self , max ):
754
748
"""
755
- Set the lower value of the slider to *max*
749
+ Set the lower value of the slider to *max*.
756
750
757
751
Parameters
758
752
----------
@@ -762,11 +756,11 @@ def set_max(self, max):
762
756
763
757
def set_val (self , val ):
764
758
"""
765
- Set slider value to *val*
759
+ Set slider value to *val*.
766
760
767
761
Parameters
768
762
----------
769
- val : tuple or arraylike of float
763
+ val : tuple or array-like of float
770
764
"""
771
765
val = np .sort (np .asanyarray (val ))
772
766
if val .shape != (2 ,):
@@ -798,8 +792,7 @@ def set_val(self, val):
798
792
799
793
def on_changed (self , func ):
800
794
"""
801
- When the slider value is changed call *func* with the new
802
- slider value
795
+ Connect *func* as callback function to changes of the slider value.
803
796
804
797
Parameters
805
798
----------
@@ -810,7 +803,7 @@ def on_changed(self, func):
810
803
Returns
811
804
-------
812
805
int
813
- Connection id (which can be used to disconnect *func*)
806
+ Connection id (which can be used to disconnect *func*).
814
807
"""
815
808
return self ._observers .connect ('changed' , lambda val : func (val ))
816
809
@@ -844,7 +837,7 @@ class CheckButtons(AxesWidget):
844
837
845
838
def __init__ (self , ax , labels , actives = None ):
846
839
"""
847
- Add check buttons to `matplotlib.axes.Axes` instance *ax*
840
+ Add check buttons to `matplotlib.axes.Axes` instance *ax*.
848
841
849
842
Parameters
850
843
----------
@@ -1836,7 +1829,7 @@ def press(self, event):
1836
1829
return False
1837
1830
1838
1831
def _press (self , event ):
1839
- """Button press handler."""
1832
+ """Button press event handler."""
1840
1833
1841
1834
def release (self , event ):
1842
1835
"""Button release event handler and validator."""
@@ -2028,7 +2021,7 @@ def ignore(self, event):
2028
2021
return super ().ignore (event ) or not self .visible
2029
2022
2030
2023
def _press (self , event ):
2031
- """on button press event"""
2024
+ """Button press event handler. """
2032
2025
self .rect .set_visible (self .visible )
2033
2026
if self .span_stays :
2034
2027
self .stay_rect .set_visible (False )
@@ -2046,7 +2039,7 @@ def _press(self, event):
2046
2039
return False
2047
2040
2048
2041
def _release (self , event ):
2049
- """on button release event"""
2042
+ """Button release event handler. """
2050
2043
if self .pressv is None :
2051
2044
return
2052
2045
@@ -2077,7 +2070,7 @@ def _release(self, event):
2077
2070
return False
2078
2071
2079
2072
def _onmove (self , event ):
2080
- """on motion notify event"""
2073
+ """Motion notify event handler. """
2081
2074
if self .pressv is None :
2082
2075
return
2083
2076
@@ -2156,7 +2149,7 @@ def y(self):
2156
2149
return self ._markers .get_ydata ()
2157
2150
2158
2151
def set_data (self , pts , y = None ):
2159
- """Set x and y positions of handles"""
2152
+ """Set x and y positions of handles. """
2160
2153
if y is not None :
2161
2154
x = pts
2162
2155
pts = np .array ([x , y ])
@@ -2341,7 +2334,7 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
2341
2334
self ._extents_on_press = None
2342
2335
2343
2336
def _press (self , event ):
2344
- """on button press event"""
2337
+ """Button press event handler. """
2345
2338
# make the drawn box/line visible get the click-coordinates,
2346
2339
# button, ...
2347
2340
if self .interactive and self .to_draw .get_visible ():
@@ -2361,7 +2354,7 @@ def _press(self, event):
2361
2354
self .set_visible (self .visible )
2362
2355
2363
2356
def _release (self , event ):
2364
- """on button release event"""
2357
+ """Button release event handler. """
2365
2358
if not self .interactive :
2366
2359
self .to_draw .set_visible (False )
2367
2360
@@ -2404,7 +2397,7 @@ def _release(self, event):
2404
2397
return False
2405
2398
2406
2399
def _onmove (self , event ):
2407
- """on motion notify event if box/line is wanted """
2400
+ """Motion notify event handler. """
2408
2401
# resize an existing shape
2409
2402
if self .active_handle and self .active_handle != 'C' :
2410
2403
x1 , x2 , y1 , y2 = self ._extents_on_press
@@ -2492,7 +2485,7 @@ def edge_centers(self):
2492
2485
2493
2486
@property
2494
2487
def center (self ):
2495
- """Center of rectangle"""
2488
+ """Center of rectangle. """
2496
2489
x0 , y0 , width , height = self ._rect_bbox
2497
2490
return x0 + width / 2. , y0 + height / 2.
2498
2491
@@ -2537,7 +2530,7 @@ def draw_shape(self, extents):
2537
2530
self .to_draw .set_data ([xmin , xmax ], [ymin , ymax ])
2538
2531
2539
2532
def _set_active_handle (self , event ):
2540
- """Set active handle based on the location of the mouse event"""
2533
+ """Set active handle based on the location of the mouse event. """
2541
2534
# Note: event.xdata/ydata in data coordinates, event.x/y in pixels
2542
2535
c_idx , c_dist = self ._corner_handles .closest (event .x , event .y )
2543
2536
e_idx , e_dist = self ._edge_handles .closest (event .x , event .y )
@@ -2802,7 +2795,7 @@ def __init__(self, ax, onselect, useblit=False,
2802
2795
self .set_visible (True )
2803
2796
2804
2797
def _press (self , event ):
2805
- """Button press event handler"""
2798
+ """Button press event handler. """
2806
2799
# Check for selection of a tool handle.
2807
2800
if ((self ._polygon_completed or 'move_vertex' in self .state )
2808
2801
and len (self ._xs ) > 0 ):
@@ -2814,7 +2807,7 @@ def _press(self, event):
2814
2807
self ._xs_at_press , self ._ys_at_press = self ._xs .copy (), self ._ys .copy ()
2815
2808
2816
2809
def _release (self , event ):
2817
- """Button release event handler"""
2810
+ """Button release event handler. """
2818
2811
# Release active tool handle.
2819
2812
if self ._active_handle_idx >= 0 :
2820
2813
self ._active_handle_idx = - 1
@@ -2836,7 +2829,7 @@ def _release(self, event):
2836
2829
self .onselect (self .verts )
2837
2830
2838
2831
def onmove (self , event ):
2839
- """Cursor move event handler and validator"""
2832
+ """Cursor move event handler and validator. """
2840
2833
# Method overrides _SelectorWidget.onmove because the polygon selector
2841
2834
# needs to process the move callback even if there is no button press.
2842
2835
# _SelectorWidget.onmove include logic to ignore move event if
@@ -2848,7 +2841,7 @@ def onmove(self, event):
2848
2841
return False
2849
2842
2850
2843
def _onmove (self , event ):
2851
- """Cursor move event handler"""
2844
+ """Cursor move event handler. """
2852
2845
# Move the active vertex (ToolHandle).
2853
2846
if self ._active_handle_idx >= 0 :
2854
2847
idx = self ._active_handle_idx
@@ -2886,7 +2879,7 @@ def _onmove(self, event):
2886
2879
self ._draw_polygon ()
2887
2880
2888
2881
def _on_key_press (self , event ):
2889
- """Key press event handler"""
2882
+ """Key press event handler. """
2890
2883
# Remove the pending vertex if entering the 'move_vertex' or
2891
2884
# 'move_all' mode
2892
2885
if (not self ._polygon_completed
@@ -2895,7 +2888,7 @@ def _on_key_press(self, event):
2895
2888
self ._draw_polygon ()
2896
2889
2897
2890
def _on_key_release (self , event ):
2898
- """Key release event handler"""
2891
+ """Key release event handler. """
2899
2892
# Add back the pending vertex if leaving the 'move_vertex' or
2900
2893
# 'move_all' mode (by checking the released key)
2901
2894
if (not self ._polygon_completed
0 commit comments