Skip to content
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

Merged
merged 5 commits into from Sep 11, 2014

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Aug 17, 2014

The method was previously defined only for RectangleSelectors (#3375).

Also, an redundant line was removed (RectangleSelectors are already set
active on init by the superclass).

The method was previously defined only for RectangleSelectors (matplotlib#3375).

Also, an redundant line was removed (RectangleSelectors are already set
active on __init__ by the superclass).
@tacaswell tacaswell added this to the v1.5.x milestone Aug 17, 2014
@tacaswell
Copy link
Member

Could you also property-ify it while you are at it?

@tacaswell
Copy link
Member

And this will need to be documented in whats_new, see #3349 for a draft of how we are going to do this going forward.

Because selectors must update their background on set_active(True),
widget.active was made a property for backwards compatibility.
Because _Selector is a private class there are no references to the
actual getter and setter in the rst file.
@tacaswell
Copy link
Member

You added it to the 1.4.0 whats_new section, this should be under the 1.5.0 section.

class SpanSelector(AxesWidget):
class _SelectorWidget(AxesWidget):
def set_active(self, active):
super(_SelectorWidget, self).set_active(active)
Copy link
Member

Choose a reason for hiding this comment

The 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 AxesWidget class strucutre also needs to use super.

@anntzer
Copy link
Contributor Author

anntzer commented Aug 17, 2014

If this doesn't go in a bugfix release of 1.4, there should at least be an indication in the docstrings of the Selector classes that changing the underlying background when the selector is not active is (was) not supported (if useblit=True, which is the default).

@tacaswell
Copy link
Member

This seems to me to be too big of a change to go into a bug-fix release.

I don't fully understand your comment.

@anntzer
Copy link
Contributor Author

anntzer commented Aug 18, 2014

My point is that this is not just an API change; the previous behaviour is actually buggy. Consider the embedding_in_qt4.py from the official docs and apply the following patch:

***************
*** 61,62 ****
--- 61,64 ----
          timer.start(1000)
+         from matplotlib.widgets import LassoSelector
+         self._selector = LassoSelector(self.axes, print)

***************
*** 69,72 ****
--- 71,76 ----

+         self._selector.active = False
          self.axes.plot([0, 1, 2, 3], l, 'r')
          self.draw()
+         self._selector.active = True

Now, if you try to use the lasso selector after an update of the dynamic canvas, the canvas will go back to the original plot. The reason is that update_background has not been called (because the selector ignored the draw_event), so the selector believes that it can still use the initial background. (This is also why in my patch update_background is called when setting active back to True).

@@ -1081,7 +1093,21 @@ def _update(self):
self.canvas.draw_idle()


class SpanSelector(AxesWidget):
class _SelectorWidget(AxesWidget):
def set_active(self, active):
Copy link
Member

Choose a reason for hiding this comment

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

This should over-ride the property as well.

Copy link
Member

Choose a reason for hiding this comment

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

@tacaswell, is this the only thing holding this PR up?

Copy link
Member

Choose a reason for hiding this comment

The 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.

@tacaswell
Copy link
Member

Ah, it was not clear that this was also fixing a bug and I missed the behavior change reading through.

@mdboom @efiring I am inclined to leave this just on 1.5, if it is broken in 1.4 it has been broken for a long time and widgets are not as widely used as they should/could be. It is not worth picking this apart to back-port just the bug fix. I can also be convinced that this whole thing should be back-ported.

... so it should dynamically retrieve the set_active method.
@anntzer
Copy link
Contributor Author

anntzer commented Aug 18, 2014

I agree that breaking the patch apart for the sake of it is a bit overkill, although there are nearly no API changes and one could even remove the {set,get}_active methods themselves to keep the exact same API.

@fariza fariza mentioned this pull request Sep 10, 2014
@tacaswell
Copy link
Member

@blink1073 I will try to take a look at this tomorrow.

@blink1073
Copy link
Member

Okay, my suggestion would be for me to handle the change in my PR in lieu of waiting.

tacaswell added a commit that referenced this pull request Sep 11, 2014
ENH : Move widget.{get,set}_active to AxisWidget.
@tacaswell tacaswell merged commit c74dfa5 into matplotlib:master Sep 11, 2014
@tacaswell
Copy link
Member

@blink1073 I re-read this now and my concern was addressed with out me realizing it.

I am against back-porting this change to 1.4.x.

@anntzer anntzer deleted the widget-active-setter-getter branch September 11, 2014 06:48
agardelein added a commit to agardelein/oscopy that referenced this pull request Nov 11, 2014
Blitting is not used in matplotlib GTK3Cairo backend, disabled here as well.
SpanSelector and RectangleSelector now have same properties "active" and "visible" (see matplotlib/matplotlib#3376 )
FIXME: On layout change, more than one SpanSelector appears on Graph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants