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

Skip to content

Commit 19224ec

Browse files
committed
Merge pull request #4225 from JayP16/JayP16-patch-1
ENH/API : Provide way to disable MultiCursor, move enable logic to Widget
2 parents e262edb + 8a38b79 commit 19224ec

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Moved ``ignore``, ``set_active``, and ``get_active`` methods to base class ``Widget``
2+
`````````````````````````````````````````````````````````````````````````````````
3+
Pushes up duplicate methods in child class to parent class to avoid duplication of code.
4+
5+
6+
Adds enable/disable feature to MultiCursor
7+
``````````````````````````````````````````
8+
A MultiCursor object can be disabled (and enabled) after it has been created without destroying the object.
9+
Example:
10+
multi_cursor.active = False

lib/matplotlib/widgets.py

Lines changed: 27 additions & 24 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
"""
@@ -1090,13 +1090,17 @@ def disconnect(self):
10901090

10911091
def clear(self, event):
10921092
"""clear the cursor"""
1093+
if self.ignore(event):
1094+
return
10931095
if self.useblit:
10941096
self.background = (
10951097
self.canvas.copy_from_bbox(self.canvas.figure.bbox))
10961098
for line in self.vlines + self.hlines:
10971099
line.set_visible(False)
10981100

10991101
def onmove(self, event):
1102+
if self.ignore(event):
1103+
return
11001104
if event.inaxes is None:
11011105
return
11021106
if not self.canvas.widgetlock.available(self):
@@ -1126,7 +1130,6 @@ def _update(self):
11261130
ax.draw_artist(line)
11271131
self.canvas.blit(self.canvas.figure.bbox)
11281132
else:
1129-
11301133
self.canvas.draw_idle()
11311134

11321135

0 commit comments

Comments
 (0)