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

Adding setter for colorbar's label_str #1292

Closed
wants to merge 12 commits into from
Closed

Conversation

macrocosme
Copy link
Contributor

Minor fix related to issue #1251 & #1271

#1271

@larsoner
Copy link
Member

larsoner commented May 4, 2017

This needs rebase

@kmuehlbauer
Copy link
Contributor

@macrocosme Can you please rebase this. If you do not have time, I can take over. Just let me know.

Copy link
Contributor

@kmuehlbauer kmuehlbauer left a comment

Choose a reason for hiding this comment

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

@macrocosme Let's get this in, finally. Sorry for the delay.

@@ -133,6 +133,15 @@ def label(self, label):
self._colorbar.label = label

@property
def label_str(self):
return self._label_str
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a short docstring with the description.

Copy link
Member

Choose a reason for hiding this comment

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

Please change this to self._colorbar.label_str.

@@ -597,6 +597,15 @@ def label(self, label):
self._update()

@property
def label_str(self):
return self._label_str
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, add short docstring with description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Docstrings finally added. Sorry for the wait!

@djhoese
Copy link
Member

djhoese commented Nov 7, 2017

I know this is out of the scope for this PR most likely but as a style guideline we should probably avoid keyword arguments with datatypes in them label_str. IMO the visual should have a self._label_visual and store the string as self._label. Or at least name the keyword argument label.

Also I'm a little confused about the the colorbar widget with this property. I think it is supposed to be self._colorbar.label_str.

@@ -133,6 +133,15 @@ def label(self, label):
self._colorbar.label = label

@property
def label_str(self):
return self._label_str
Copy link
Member

Choose a reason for hiding this comment

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

Please change this to self._colorbar.label_str.


@label_str.setter
def label_str(self, label_str):
self._label_str = label_str
Copy link
Member

Choose a reason for hiding this comment

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

Please change this also to self._colorbar.label_str.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do as soon as I can.

@kmuehlbauer
Copy link
Contributor

I know this is out of the scope for this PR most likely but as a style guideline we should probably avoid keyword arguments with datatypes in them label_str.

@davidh-ssec This change was introduced with #979, there was surely some logic behind to do this. @bollu could you chime in, when you find the time?

@kmuehlbauer
Copy link
Contributor

IIRC this was to differentiate the self._label (TextVisual) from the label string itself.

@djhoese
Copy link
Member

djhoese commented Nov 7, 2017

Yes of course, but that's why I think in the future we need to be careful about what the user sees and what they don't. Having the keyword argument label is a lot cleaner than label_str. This means self._label becomes self._label_visual. However, I've been finding more and more that user's need to access these sub-visuals by name. This either means that the interface is not complete enough or we need to make less "private" attributes: self.label versus self._label

@macrocosme
Copy link
Contributor Author

I have added the requested changes.

@kmuehlbauer
Copy link
Contributor

@macrocosme Thanks. Are ready for rebasing this to resolve the conflicts?

@@ -598,7 +598,7 @@ def label(self, label):

@property
def label_str(self):
return self._label_str
Copy link
Contributor

Choose a reason for hiding this comment

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

@macrocosme This will not work. There is no self._colorbar in vispy/visuals/colorbar.py

I meant to just add some docstring here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm at a conference. I'll get back to it when I have a bit more time to concentrate! : )
This should be soon.

@@ -134,7 +134,7 @@ def label(self, label):

@property
def label_str(self):
return self._label_str
return self._colorbar._label_str

@label_str.setter
def label_str(self, label_str):
Copy link
Contributor

Choose a reason for hiding this comment

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

@macrocosme You also need to do this change in the setter.

Changing to set/get using _colorbar
Also includes a simple docstring
@macrocosme
Copy link
Contributor Author

macrocosme commented Nov 19, 2017

@kmuehlbauer @davidh-ssec Okay. I have now changed both setter and getter in widgets/colorbar.py, and also added docstrings to both files (widgets/colorbar.py and visuals/colorbar.py).

@djhoese
Copy link
Member

djhoese commented May 4, 2018

@macrocosme Awesome. Looks like you'll have to rebase or merge the current master branch to resolve some conflicts and get tests to pass.

@macrocosme
Copy link
Contributor Author

@djhoese Done!

"""
self._colorbar._label_str = label_str
self._update()

def ticks(self):
Copy link
Member

Choose a reason for hiding this comment

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

You lost the @property on this ticks property which is causing the errors on travis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh my... ! It's back in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for walking me through the process.

Copy link
Member

@djhoese djhoese left a comment

Choose a reason for hiding this comment

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

Have you actually tested this?

@@ -604,6 +604,29 @@ def label(self, label):
self._label = label
self._update()
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why it took me this wrong to realize this, but why can't all of this be done with an if statement for the regular label property? I know I've expressed my dislike of label_str as a property and I didn't see a way around it before, but why not do:

@label.setter
def label(self, label):
    if isinstance(label, str):
        self._label.text = label
    else:
        self._label = label
        self._update()

I'm not sure if the _update needs to be done in both cases since the TextVisual would call its own update. With this change the label_str property could be removed. Additionally, have you actually tested this? When does the ColorbarVisual._label_str get used? It doesn't seem to show up in the _update function.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

@djhoese 👍

Copy link
Contributor Author

@macrocosme macrocosme May 7, 2018

Choose a reason for hiding this comment

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

I was using this code here https://github.com/macrocosme/shwirl/blob/master/shwirl/extern/vispy/scene/widgets/colorbar.py without a fuss. But I should indeed sit down and properly test this. I'm travelling so it may be a few days.

Edit: I'm finally working on the clean-up. I realised I have had modified _update to include this property: https://github.com/macrocosme/shwirl/blob/15cf73631007cba45a37db698f5e06c48714e598/shwirl/extern/vispy/visuals/colorbar.py#L347

Nevertheless, I think the using self.label.text is the way to go. A bit more to come later today hopefully.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As to merging the two with an if, I like it! 👍

- Rename label_str to label_text
- Change label setter to check for str.
@macrocosme
Copy link
Contributor Author

macrocosme commented Jul 5, 2018

@kmuehlbauer @djhoese I finally made the changes, and tested it. Note that I have renamed label_str to label_text as it was discussed that having str in the variable name isn't ideal.

@macrocosme macrocosme changed the title Adding setter for label_str Adding setter for colorbar's label_str Jul 5, 2018
@djhoese
Copy link
Member

djhoese commented Aug 31, 2020

I'm not sure what happened with this PR and I'm extremely sorry we lost track of it (I think your last comment was right before SciPy 2018 started). I see the tests passed and things are basically as we've described. I know you will hate me but now that the setter can handle a string is there a reason we can't have label= in the __init__ method?

@kmuehlbauer Thoughts?

@kmuehlbauer
Copy link
Contributor

@djhoese I'm not sure I understand. You mean instead of self._label=... it should be self.label=...?

@macrocosme
Copy link
Contributor Author

@djhoese @kmuehlbauer It's okay. These things happen. Nearly 4 years in, I will admit I thought this project had slowly stopped. I will let these final changes to you two if that is okay.

@djhoese
Copy link
Member

djhoese commented Sep 1, 2020

@kmuehlbauer The keyword argument in master is label_str. Is there a reason it couldn't (or shouldn't) be just label?

@kmuehlbauer
Copy link
Contributor

The keyword argument in master is label_str. Is there a reason it couldn't (or shouldn't) be just label?

Yes, sure, users which use matplotlib would expect this. 👍

@kmuehlbauer
Copy link
Contributor

kmuehlbauer commented Sep 1, 2020

@djhoese This seems impossible to merge master into this branch. Should we extract all needed commits and rebase on current master? Then this can run on the recent CI?

@djhoese
Copy link
Member

djhoese commented Sep 1, 2020

It is impossible to merge master because it is @macrocosme 's master branch (instead of a separate "feature" branch). GitHub doesn't give maintainers implicit permission to fork's master branches. We'll need to take the fork's master branch and create our own branch on our own fork, merge vispy master, then make a new PR.

@djhoese djhoese closed this Apr 28, 2021
@djhoese djhoese deleted the branch vispy:main April 28, 2021 19:00
@djhoese djhoese reopened this Apr 28, 2021
@djhoese djhoese closed this Apr 28, 2021
@djhoese djhoese deleted the branch vispy:main April 28, 2021 19:27
@djhoese djhoese reopened this Apr 28, 2021
@djhoese djhoese changed the base branch from master to main April 28, 2021 20:57
@djhoese
Copy link
Member

djhoese commented Jun 9, 2021

This has been replaced by #2057 and don't worry I kept you as the author of the commit for your work in this PR (had to copy some files around to get the commit history to not be garbage). Thanks @macrocosme!

@djhoese djhoese closed this Jun 9, 2021
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

4 participants