@@ -68,6 +68,29 @@ class Widget(object):
68
68
"""
69
69
drawon = True
70
70
eventson = True
71
+ _active = True
72
+
73
+ def set_active (self , active ):
74
+ """Set whether the widget is active.
75
+ """
76
+ self ._active = active
77
+
78
+ def get_active (self ):
79
+ """Get whether the widget is active.
80
+ """
81
+ return self ._active
82
+
83
+ # set_active is overriden by SelectorWidgets.
84
+ active = property (get_active , lambda self , active : self .set_active (active ),
85
+ doc = "Is the widget active?" )
86
+
87
+ def ignore (self , event ):
88
+ """Return True if event should be ignored.
89
+
90
+ This method (or a version of it) should be called at the beginning
91
+ of any event callback.
92
+ """
93
+ return not self .active
71
94
72
95
73
96
class AxesWidget (Widget ):
@@ -96,7 +119,6 @@ def __init__(self, ax):
96
119
self .ax = ax
97
120
self .canvas = ax .figure .canvas
98
121
self .cids = []
99
- self ._active = True
100
122
101
123
def connect_event (self , event , callback ):
102
124
"""Connect callback with an event.
@@ -112,28 +134,6 @@ def disconnect_events(self):
112
134
for c in self .cids :
113
135
self .canvas .mpl_disconnect (c )
114
136
115
- def set_active (self , active ):
116
- """Set whether the widget is active.
117
- """
118
- self ._active = active
119
-
120
- def get_active (self ):
121
- """Get whether the widget is active.
122
- """
123
- return self ._active
124
-
125
- # set_active is overriden by SelectorWidgets.
126
- active = property (get_active , lambda self , active : self .set_active (active ),
127
- doc = "Is the widget active?" )
128
-
129
- def ignore (self , event ):
130
- """Return True if event should be ignored.
131
-
132
- This method (or a version of it) should be called at the beginning
133
- of any event callback.
134
- """
135
- return not self .active
136
-
137
137
138
138
class Button (AxesWidget ):
139
139
"""
@@ -1090,13 +1090,17 @@ def disconnect(self):
1090
1090
1091
1091
def clear (self , event ):
1092
1092
"""clear the cursor"""
1093
+ if self .ignore (event ):
1094
+ return
1093
1095
if self .useblit :
1094
1096
self .background = (
1095
1097
self .canvas .copy_from_bbox (self .canvas .figure .bbox ))
1096
1098
for line in self .vlines + self .hlines :
1097
1099
line .set_visible (False )
1098
1100
1099
1101
def onmove (self , event ):
1102
+ if self .ignore (event ):
1103
+ return
1100
1104
if event .inaxes is None :
1101
1105
return
1102
1106
if not self .canvas .widgetlock .available (self ):
@@ -1126,7 +1130,6 @@ def _update(self):
1126
1130
ax .draw_artist (line )
1127
1131
self .canvas .blit (self .canvas .figure .bbox )
1128
1132
else :
1129
-
1130
1133
self .canvas .draw_idle ()
1131
1134
1132
1135
0 commit comments