@@ -95,7 +95,7 @@ def __init__(self, ax):
9595 self .ax = ax
9696 self .canvas = ax .figure .canvas
9797 self .cids = []
98- self .active = True
98+ self ._active = True
9999
100100 def connect_event (self , event , callback ):
101101 """Connect callback with an event.
@@ -114,12 +114,14 @@ def disconnect_events(self):
114114 def set_active (self , active ):
115115 """Set whether the widget is active.
116116 """
117- self .active = active
117+ self ._active = active
118118
119119 def get_active (self ):
120120 """Get whether the widget is active.
121121 """
122- return self .active
122+ return self ._active
123+
124+ active = property (set_active , get_active , doc = "Is the widget active?" )
123125
124126 def ignore (self , event ):
125127 """Return True if event should be ignored.
@@ -1091,7 +1093,21 @@ def _update(self):
10911093 self .canvas .draw_idle ()
10921094
10931095
1094- class SpanSelector (AxesWidget ):
1096+ class _SelectorWidget (AxesWidget ):
1097+ def set_active (self , active ):
1098+ super (_SelectorWidget , self ).set_active (active )
1099+ if active :
1100+ self .update_background (None )
1101+
1102+ def update_background (self , event ):
1103+ """force an update of the background"""
1104+ # If you add a call to `ignore` here, you'll want to check edge case:
1105+ # `release` can call a draw event even when `ignore` is True.
1106+ if self .useblit :
1107+ self .background = self .canvas .copy_from_bbox (self .ax .bbox )
1108+
1109+
1110+ class SpanSelector (_SelectorWidget ):
10951111 """
10961112 Select a min/max range of the x or y axes for a matplotlib Axes.
10971113
@@ -1199,13 +1215,6 @@ def new_axes(self, ax):
11991215 if not self .useblit :
12001216 self .ax .add_patch (self .rect )
12011217
1202- def update_background (self , event ):
1203- """force an update of the background"""
1204- # If you add a call to `ignore` here, you'll want to check edge case:
1205- # `release` can call a draw event even when `ignore` is True.
1206- if self .useblit :
1207- self .background = self .canvas .copy_from_bbox (self .ax .bbox )
1208-
12091218 def ignore (self , event ):
12101219 """return *True* if *event* should be ignored"""
12111220 widget_off = not self .visible or not self .active
@@ -1312,7 +1321,7 @@ def onmove(self, event):
13121321 return False
13131322
13141323
1315- class RectangleSelector (AxesWidget ):
1324+ class RectangleSelector (_SelectorWidget ):
13161325 """
13171326 Select a rectangular region of an axes.
13181327
@@ -1446,11 +1455,6 @@ def __init__(self, ax, onselect, drawtype='box',
14461455 # will save the data (pos. at mouserelease)
14471456 self .eventrelease = None
14481457
1449- def update_background (self , event ):
1450- """force an update of the background"""
1451- if self .useblit :
1452- self .background = self .canvas .copy_from_bbox (self .ax .bbox )
1453-
14541458 def ignore (self , event ):
14551459 """return *True* if *event* should be ignored"""
14561460 if not self .active :
@@ -1585,7 +1589,7 @@ def onmove(self, event):
15851589 return False
15861590
15871591
1588- class LassoSelector (AxesWidget ):
1592+ class LassoSelector (_SelectorWidget ):
15891593 """Selection curve of an arbitrary shape.
15901594
15911595 For the selector to remain responsive you much keep a reference to
@@ -1677,12 +1681,6 @@ def onmove(self, event):
16771681 else :
16781682 self .canvas .draw_idle ()
16791683
1680- def update_background (self , event ):
1681- if self .ignore (event ):
1682- return
1683- if self .useblit :
1684- self .background = self .canvas .copy_from_bbox (self .ax .bbox )
1685-
16861684
16871685class Lasso (AxesWidget ):
16881686 """Selection curve of an arbitrary shape.
0 commit comments