Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4032a27

Browse files
committed
Moved active and ignore logic to parent class.
1 parent b93970c commit 4032a27

1 file changed

Lines changed: 23 additions & 31 deletions

File tree

lib/matplotlib/widgets.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,29 @@ class Widget(object):
6868
"""
6969
drawon = True
7070
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
7194

7295

7396
class AxesWidget(Widget):
@@ -96,7 +119,6 @@ def __init__(self, ax):
96119
self.ax = ax
97120
self.canvas = ax.figure.canvas
98121
self.cids = []
99-
self._active = True
100122

101123
def connect_event(self, event, callback):
102124
"""Connect callback with an event.
@@ -112,28 +134,6 @@ def disconnect_events(self):
112134
for c in self.cids:
113135
self.canvas.mpl_disconnect(c)
114136

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-
137137

138138
class Button(AxesWidget):
139139
"""
@@ -1020,7 +1020,6 @@ def __init__(self, canvas, axes, useblit=True, horizOn=False, vertOn=True,
10201020
self.axes = axes
10211021
self.horizOn = horizOn
10221022
self.vertOn = vertOn
1023-
self.active = True
10241023

10251024
xmin, xmax = axes[-1].get_xlim()
10261025
ymin, ymax = axes[-1].get_ylim()
@@ -1105,13 +1104,6 @@ def _update(self):
11051104

11061105
self.canvas.draw_idle()
11071106

1108-
def ignore(self, event):
1109-
"""Return True if event should be ignored.
1110-
1111-
This method (or a version of it) should be called at the beginning
1112-
of any event callback.
1113-
"""
1114-
return not self.active
11151107

11161108
class _SelectorWidget(AxesWidget):
11171109

0 commit comments

Comments
 (0)