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

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

Conversation

JayP16
Copy link
Contributor

@JayP16 JayP16 commented Mar 15, 2015

Implemented MultiCursor disable function. Now can disable the multi cursor the same way as Cursor; using "cursor.active = False"
( #2663)

Implemented MultiCursor disable function
@tacaswell tacaswell added this to the next point release milestone Mar 16, 2015
@tacaswell
Copy link
Member

Could you move the self.active and ignore logic up to the Widget base-class? I think that would be a more-general solution (and remove duplicate code).

If you are feeling ambitious, making sure that all of the sub-classes make proper use of super in the ignore calls is also probably a good thing to do.

@JayP16
Copy link
Contributor Author

JayP16 commented Mar 16, 2015

Done. Moved all the active logic up to the Widget class. And removed the basic ignore functions from the subclasses.

@tacaswell
Copy link
Member

Great.

I am a bit wary of the class level attribute which it silently made an instance attribute when you assign to it, but do anything about that until someone else weighs in.

attn @efiring @mdboom @blink1073

@tacaswell
Copy link
Member

also attn @WeatherGod

@blink1073
Copy link
Member

IMO MultiCursor should subclass AxesWidget and leave Widget alone.

@JayP16
Copy link
Contributor Author

JayP16 commented Mar 17, 2015

IMO MultiCursor should subclass AxesWidget and leave Widget alone.

That was my initial thoughts as well. But the AxesWidget takes in only single axis and all the child classes only require one so this would be the odd one out. It would also require modifications in all the subclasses of AxesWidget to check type; more ambition! Or perhaps for the single axes case make a single element tuple? But still requires modification to the subclasses.

@tacaswell
Copy link
Member

I was in the process of typing out what @JayP16 said.

@efiring
Copy link
Member

efiring commented Mar 17, 2015

@tacaswell, you are referring to the _active attribute? I don't see any problem with this. It seems to me that this idiom makes the code more compact and makes it easier to see what the attributes are. What is it that makes you wary of it?

@WeatherGod
Copy link
Member

I have to agree with @tacaswell, class-level attributes turned into
instance attributes hurts my brain

On Tue, Mar 17, 2015 at 5:05 PM, Eric Firing [email protected]
wrote:

@tacaswell https://github.com/tacaswell, you are referring to the
_active attribute? I don't see any problem with this. It seems to me that
this idiom makes the code more compact and makes it easier to see what the
attributes are. What is it that makes you wary of it?


Reply to this email directly or view it on GitHub
#4225 (comment)
.

@WeatherGod
Copy link
Member

oh, wow... I never noticed that there were those other class-level attributes! That is unfortunate, and I now need an excedrin.

@tacaswell
Copy link
Member

@efiring Yes. It is is part as Ben says a source of headaches/confusion. If seems like a nice way to do default state, but it might open up a can of worms with mutable values (which _active is not). In general any prospect of unintentionally shared state makes we wary.

@efiring
Copy link
Member

efiring commented Mar 17, 2015

@WeatherGod Why? I still don't understand the problem. Does this idiom introduce some risk? Is it any harder to understand than, say, properties? It seems straightforward to me, and something that can enhance rather than reduce readability. I think it is quite common. It is similar to the situation where module-level variables turn into local variables via assignment in a function. That's actually something I try to avoid, but in the case of classes, it seems natural to me.

@WeatherGod
Copy link
Member

do class-level attributes get inherited upon subclassing? I thought they didn't.

@efiring
Copy link
Member

efiring commented Mar 17, 2015

@tacaswell, OK, so it requires a bit of care, to avoid mutable variables.

@efiring
Copy link
Member

efiring commented Mar 17, 2015

I was just looking at http://ioam.github.io/param/index.html, which depends on this type of behavior, including the inheritance. I think traitlets also use this idiom of class-level initialization. I need to look.

@tacaswell
Copy link
Member

Those are a bit different though as they are using meta-class magic to turn the class level attributes into instance level properties, right?

@efiring
Copy link
Member

efiring commented Mar 17, 2015

At least in params, the conversion into instance attributes happens only when a value is changed, so it is very much like the simple case. I don't know how traitlets handles them.

@efiring
Copy link
Member

efiring commented Mar 17, 2015

It looks like HasTraits initialization causes immediate instance-level initialization of all Traits, so this is handled differently than in params.

@JayP16
Copy link
Contributor Author

JayP16 commented Mar 19, 2015

Any suggestions on what should be done? It would be problematic if it were mutable; which _active is not, like @tacaswell mentioned. Do we want a initialize method in widgets; can we see a use for it in the future?

@tacaswell
Copy link
Member

Sorry, this PR discussion went off on a tangent (part of a rolling conversation @efiring and I are having). Eric convinced me that it is fine as implemented.

@@ -1061,6 +1061,8 @@ 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.

@tacaswell
Copy link
Member

Only other comment is that it might be worth starting the deprecation process on the get/set_active methods in favor of the just using the property, but that is probably out of scope for this PR.

@tacaswell
Copy link
Member

Can you also add an entry into https://github.com/matplotlib/matplotlib/tree/master/doc/users/whats_new It should be documented that all Widget sub-classes now have these functions.

@tacaswell
Copy link
Member

ping @JayP16 re whats_new entry.

@JayP16
Copy link
Contributor Author

JayP16 commented Mar 30, 2015

Sorry for the delay. It's been created. :)

tacaswell added a commit that referenced this pull request Apr 12, 2015
ENH/API : Provide way to disable MultiCursor, move enable logic to Widget
@tacaswell tacaswell merged commit 19224ec into matplotlib:master Apr 12, 2015
@tacaswell
Copy link
Member

@JayP16 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants