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
Conversation
Minor fix related to issue vispy#1251 & vispy#1271 vispy#1271
This needs rebase |
@macrocosme Can you please rebase this. If you do not have time, I can take over. Just let me know. |
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.
@macrocosme Let's get this in, finally. Sorry for the delay.
vispy/scene/widgets/colorbar.py
Outdated
@@ -133,6 +133,15 @@ def label(self, label): | |||
self._colorbar.label = label | |||
|
|||
@property | |||
def label_str(self): | |||
return self._label_str |
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.
Please add a short docstring with the description.
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.
Please change this to self._colorbar.label_str
.
vispy/visuals/colorbar.py
Outdated
@@ -597,6 +597,15 @@ def label(self, label): | |||
self._update() | |||
|
|||
@property | |||
def label_str(self): | |||
return self._label_str |
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.
Same here, add short docstring with description.
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.
Docstrings finally added. Sorry for the wait!
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 Also I'm a little confused about the the colorbar widget with this property. I think it is supposed to be |
vispy/scene/widgets/colorbar.py
Outdated
@@ -133,6 +133,15 @@ def label(self, label): | |||
self._colorbar.label = label | |||
|
|||
@property | |||
def label_str(self): | |||
return self._label_str |
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.
Please change this to self._colorbar.label_str
.
vispy/scene/widgets/colorbar.py
Outdated
|
||
@label_str.setter | ||
def label_str(self, label_str): | ||
self._label_str = label_str |
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.
Please change this also to self._colorbar.label_str
.
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.
Will do as soon as I can.
@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? |
IIRC this was to differentiate the self._label (TextVisual) from the label string itself. |
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 |
Acting on @kmuehlbauer request
Acting on @kmuehlbauer’s request
I have added the requested changes. |
@macrocosme Thanks. Are ready for rebasing this to resolve the conflicts? |
vispy/visuals/colorbar.py
Outdated
@@ -598,7 +598,7 @@ def label(self, label): | |||
|
|||
@property | |||
def label_str(self): | |||
return self._label_str |
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.
@macrocosme This will not work. There is no self._colorbar in vispy/visuals/colorbar.py
I meant to just add some docstring here.
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.
Please revert this change.
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'm at a conference. I'll get back to it when I have a bit more time to concentrate! : )
This should be soon.
vispy/scene/widgets/colorbar.py
Outdated
@@ -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): |
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.
@macrocosme You also need to do this change in the setter
.
As requested by @kmuehlbauer
Changing to set/get using _colorbar Also includes a simple docstring
@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). |
@macrocosme Awesome. Looks like you'll have to rebase or merge the current master branch to resolve some conflicts and get tests to pass. |
@djhoese Done! |
vispy/scene/widgets/colorbar.py
Outdated
""" | ||
self._colorbar._label_str = label_str | ||
self._update() | ||
|
||
def ticks(self): |
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.
You lost the @property
on this ticks property which is causing the errors on travis.
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.
Oh my... ! It's back in.
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.
Thanks for walking me through the process.
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.
Have you actually tested this?
vispy/visuals/colorbar.py
Outdated
@@ -604,6 +604,29 @@ def label(self, label): | |||
self._label = label | |||
self._update() |
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'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?
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.
@djhoese 👍
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 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.
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.
As to merging the two with an if, I like it! 👍
- Rename label_str to label_text - Change label setter to check for str.
@kmuehlbauer @djhoese I finally made the changes, and tested it. Note that I have renamed |
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 @kmuehlbauer Thoughts? |
@djhoese I'm not sure I understand. You mean instead of |
@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. |
@kmuehlbauer The keyword argument in master is |
Yes, sure, users which use matplotlib would expect this. 👍 |
@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? |
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. |
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! |
Minor fix related to issue #1251 & #1271
#1271