-
-
Notifications
You must be signed in to change notification settings - Fork 443
Enable creation of custom linear colormaps in layer controls #7600
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
Conversation
At a glance, pretty cool! Similar to thoughts I had here: |
Thanks for the issue links! Good to know! |
@Czaki Your issue relates to labels, while I think this is more similar to the feature of passing hex codes to generate colormaps that was added more recently (0.4.19?). |
Whops. I mean to link #1779. That is bigger than this because it also suggests adding of save between sessions. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7600 +/- ##
==========================================
- Coverage 92.87% 92.84% -0.04%
==========================================
Files 629 629
Lines 58900 58973 +73
==========================================
+ Hits 54705 54752 +47
- Misses 4195 4221 +26 ☔ View full report in Codecov by Sentry. |
The more important bigger scope from #1779 is the proposal of a custom segmented colormap creation, which I still oppose. However, reading through the comments, we were quite positive about linear colormaps, which this PR implements. And quite minimally, too! 🥳 The only thing I would add to this PR is naming the colormap from the hex value of the picked colour, see e.g. #1779 (comment). |
Oh and btw, long time no see @lukasz-migas!!! 👋😊 |
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 would like to see some test here.
This is cool! I have no comment on if it's appropriate for napari but I like it. A few things:
Also wondering how this would interact with #7555 where using QColormapComboBox opens up some possibilities |
I made that recording on MacOS and the |
While I personally prefer to have native widgets, I think it's probably better to have the same ones across the app.
For reference, here is the cmap catalog of colormaps: |
This already works for me? @lukasz-migas Edit: I don't see any effect of changing alpha (unlike for Points for example), so lets remove that to prevent confusion. |
It at least works for me now! I think this morning I may have been just trying to put it in without '#' first, but cleverly(?) it prevents any input not starting with '#'
What I was thinking about was the editable width of the cmap in the combobox display. I think it would be awkard to try to use |
I disagree here — let's use the native widgets. It's not just a preference, it also works better: I can't use "pick screen color" with the non-native widget: it only allows me to pick from the widget window, not from the full desktop. I've granted screen permission to the app — if I go to d6764cc, I can pick from the screen no problem. |
@jni I too prefer the native ones! What about the Points/Shapes? my thought was we do a followup to switch to native widgets everywhere? |
yes, let's do this in follow-ups, not here. @lukasz-migas could you revert 8f01d08? Then hopefully the tests will be green and we can merge! |
This reverts commit 8f01d08.
@jni @psobolewskiPhD Done, thanks for the feedback. |
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.
Hi @lukasz-migas 👋🏼 To be a bit more explicit and add context for future devs, I've suggested some docstring additions. Thanks!
@@ -158,6 +158,15 @@ def __init__(self, layer: Image) -> None: | |||
# widgets. | |||
self.layout().addRow(self.button_grid) | |||
|
|||
def _on_make_colormap(self): | |||
"""Make new colormap.""" |
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.
"""Make new colormap.""" | |
"""Make new colormap when receiving this event.""" |
napari/_qt/utils.py
Outdated
from napari.utils.translations import trans | ||
|
||
QBYTE_FLAG = '!QBYTE_' | ||
RICH_TEXT_PATTERN = re.compile('<[^\n]+>') | ||
|
||
|
||
class ColorMode(StringEnum): | ||
"""Looping mode for animating an axis. |
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.
"""Looping mode for animating an axis. | |
"""Represents a color mode, useful for looping mode when animating an axis. |
napari/_qt/utils.py
Outdated
color: str | np.ndarray | QColor | None = None, | ||
mode: ColorMode = ColorMode.HEX, | ||
) -> np.ndarray | None: | ||
"""Get color.""" |
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.
"""Get color.""" | |
"""Get color. Returns a new color when a color and color mode are passed.""" |
Thanks @willingc! I tend to forget to do docstrings (and then forget what the function does...) |
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.
Looks great @lukasz-migas. Thanks for adding context 😄
This fixes a minor layout issue for the image/surface layer controls (which use. the colormapComboBox. I noticed that if the width of the layer controls is changed, the 'colormap' combobox doesn't get resized (because there was a stretch after the control). I should have noticed in #7600 but clearly missed it. before  after  # References and relevant issues # Description
This pull request has been mentioned on Image.sc Forum. There might be relevant details there: |
Description
This PR replaces the 'colormap' label (which displays the current colormap) with a push button (which also displays the colormap as before).
When the button is pressed, it will ask the user to select a color using color picker.
If a color was selected, then it creates a new colormap, otherwise nothing happens.
REC-20250212145409.mp4