Skip to content

Provide way to disable Multi Cursor (Implement #2663) #4225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/users/whats_new/updated_widgets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Moved ``ignore``, ``set_active``, and ``get_active`` methods to base class ``Widget``
`````````````````````````````````````````````````````````````````````````````````
Pushes up duplicate methods in child class to parent class to avoid duplication of code.


Adds enable/disable feature to MultiCursor
``````````````````````````````````````````
A MultiCursor object can be disabled (and enabled) after it has been created without destroying the object.
Example:
multi_cursor.active = False
51 changes: 27 additions & 24 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@ class Widget(object):
"""
drawon = True
eventson = True
_active = True

def set_active(self, active):
"""Set whether the widget is active.
"""
self._active = active

def get_active(self):
"""Get whether the widget is active.
"""
return self._active

# set_active is overriden by SelectorWidgets.
active = property(get_active, lambda self, active: self.set_active(active),
doc="Is the widget active?")

def ignore(self, event):
"""Return True if event should be ignored.

This method (or a version of it) should be called at the beginning
of any event callback.
"""
return not self.active


class AxesWidget(Widget):
Expand Down Expand Up @@ -96,7 +119,6 @@ def __init__(self, ax):
self.ax = ax
self.canvas = ax.figure.canvas
self.cids = []
self._active = True

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

def set_active(self, active):
"""Set whether the widget is active.
"""
self._active = active

def get_active(self):
"""Get whether the widget is active.
"""
return self._active

# set_active is overriden by SelectorWidgets.
active = property(get_active, lambda self, active: self.set_active(active),
doc="Is the widget active?")

def ignore(self, event):
"""Return True if event should be ignored.

This method (or a version of it) should be called at the beginning
of any event callback.
"""
return not self.active


class Button(AxesWidget):
"""
Expand Down Expand Up @@ -1061,13 +1061,17 @@ def disconnect(self):

def clear(self, event):
"""clear the cursor"""
if self.ignore(event):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear should probably work even if the widget is not active

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this behavior is consistent with the other widgets then disregard my last comment.

return
if self.useblit:
self.background = (
self.canvas.copy_from_bbox(self.canvas.figure.bbox))
for line in self.vlines + self.hlines:
line.set_visible(False)

def onmove(self, event):
if self.ignore(event):
return
if event.inaxes is None:
return
if not self.canvas.widgetlock.available(self):
Expand Down Expand Up @@ -1097,7 +1101,6 @@ def _update(self):
ax.draw_artist(line)
self.canvas.blit(self.canvas.figure.bbox)
else:

self.canvas.draw_idle()


Expand Down