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
Move widget.{get,set}_active to AxisWidget. #3376
Changes from 3 commits
13ce609
8a6845c
51f6a6e
f1161df
1b39b24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ def __init__(self, ax): | |
self.ax = ax | ||
self.canvas = ax.figure.canvas | ||
self.cids = [] | ||
self.active = True | ||
self._active = True | ||
|
||
def connect_event(self, event, callback): | ||
"""Connect callback with an event. | ||
|
@@ -111,6 +111,18 @@ 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 | ||
|
||
active = property(set_active, get_active, doc="Is the widget active?") | ||
|
||
def ignore(self, event): | ||
"""Return True if event should be ignored. | ||
|
||
|
@@ -1081,7 +1093,21 @@ def _update(self): | |
self.canvas.draw_idle() | ||
|
||
|
||
class SpanSelector(AxesWidget): | ||
class _SelectorWidget(AxesWidget): | ||
def set_active(self, active): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should over-ride the property as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tacaswell, is this the only thing holding this PR up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, looking at this again, it does update, the property method is tricksy. |
||
super(_SelectorWidget, self).set_active(active) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a good of an idea is it seems, because we aren't using super every where can you hard-code the over loading? The reason I am worried is that if this ends up in an MRO where not everything is cooperating, you can get strange bugs. If we are going to go down this route, everything in the |
||
if active: | ||
self.update_background(None) | ||
|
||
def update_background(self, event): | ||
"""force an update of the background""" | ||
# If you add a call to `ignore` here, you'll want to check edge case: | ||
# `release` can call a draw event even when `ignore` is True. | ||
if self.useblit: | ||
self.background = self.canvas.copy_from_bbox(self.ax.bbox) | ||
|
||
|
||
class SpanSelector(_SelectorWidget): | ||
""" | ||
Select a min/max range of the x or y axes for a matplotlib Axes. | ||
|
||
|
@@ -1189,13 +1215,6 @@ def new_axes(self, ax): | |
if not self.useblit: | ||
self.ax.add_patch(self.rect) | ||
|
||
def update_background(self, event): | ||
"""force an update of the background""" | ||
# If you add a call to `ignore` here, you'll want to check edge case: | ||
# `release` can call a draw event even when `ignore` is True. | ||
if self.useblit: | ||
self.background = self.canvas.copy_from_bbox(self.ax.bbox) | ||
|
||
def ignore(self, event): | ||
"""return *True* if *event* should be ignored""" | ||
widget_off = not self.visible or not self.active | ||
|
@@ -1302,7 +1321,7 @@ def onmove(self, event): | |
return False | ||
|
||
|
||
class RectangleSelector(AxesWidget): | ||
class RectangleSelector(_SelectorWidget): | ||
""" | ||
Select a rectangular region of an axes. | ||
|
||
|
@@ -1393,7 +1412,6 @@ def __init__(self, ax, onselect, drawtype='box', | |
self.connect_event('button_release_event', self.release) | ||
self.connect_event('draw_event', self.update_background) | ||
|
||
self.active = True # for activation / deactivation | ||
self.to_draw = None | ||
self.background = None | ||
|
||
|
@@ -1437,11 +1455,6 @@ def __init__(self, ax, onselect, drawtype='box', | |
# will save the data (pos. at mouserelease) | ||
self.eventrelease = None | ||
|
||
def update_background(self, event): | ||
"""force an update of the background""" | ||
if self.useblit: | ||
self.background = self.canvas.copy_from_bbox(self.ax.bbox) | ||
|
||
def ignore(self, event): | ||
"""return *True* if *event* should be ignored""" | ||
if not self.active: | ||
|
@@ -1575,19 +1588,8 @@ def onmove(self, event): | |
self.update() | ||
return False | ||
|
||
def set_active(self, active): | ||
""" | ||
Use this to activate / deactivate the RectangleSelector | ||
from your program with an boolean parameter *active*. | ||
""" | ||
self.active = active | ||
|
||
def get_active(self): | ||
""" Get status of active mode (boolean variable)""" | ||
return self.active | ||
|
||
|
||
class LassoSelector(AxesWidget): | ||
class LassoSelector(_SelectorWidget): | ||
"""Selection curve of an arbitrary shape. | ||
|
||
For the selector to remain responsive you much keep a reference to | ||
|
@@ -1679,12 +1681,6 @@ def onmove(self, event): | |
else: | ||
self.canvas.draw_idle() | ||
|
||
def update_background(self, event): | ||
if self.ignore(event): | ||
return | ||
if self.useblit: | ||
self.background = self.canvas.copy_from_bbox(self.ax.bbox) | ||
|
||
|
||
class Lasso(AxesWidget): | ||
"""Selection curve of an arbitrary shape. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdboom @efiring Do we have a style preference on using this method or the decorators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On 2014/08/17, 10:41 AM, Thomas A Caswell wrote:
I don't think this has been discussed. The majority of existing
properties use the function form.
Eric
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer the decorator form, but usually that implies that the
setter and/or getter is doing something non-trivial. The functional form is
nice for trivial setting/getting and can even be used in a templating-ish
fashion.
On Mon, Aug 18, 2014 at 4:48 AM, Eric Firing notifications@github.com
wrote: