-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
Keybinding to set a new label doesn't work consistently #6517
Comments
Hi there, just in case, gave this a check and seems like the related logic for that shortcut is at napari/napari/layers/labels/_labels_key_bindings.py Lines 70 to 78 in e6a454e
Seems like it depends on the layer data to work (which I guess is the reason why it only works when you painted something). Also, maybe that is the reason why there are a couple of other shortcuts which change the current selected label regardless of layer data ( |
Sorry I missed this!! |
Oh that makes sense, yes! A warning sounds very reasonable. Thanks! |
So something like this could work?: @register_label_action(
trans._(
"Set the currently selected label to the largest used label plus one."
),
)
def new_label(layer: Labels):
"""Set the currently selected label to the largest used label plus one."""
new_selected_label = np.max(layer.data) + 1
if layer.selected_label == new_selected_label:
warnings.warn(
trans._(
"Largest label already selected",
)
)
else:
layer.selected_label = new_selected_label A preview: Let me know if such an approach could be worthy to submit a PR :) |
Yeah that's exactly what I was thinking, only using napari/napari/utils/notifications.py Line 359 in d507dd6
see also: napari/napari/layers/points/_points_key_bindings.py Lines 66 to 78 in d507dd6
It has a different icon in the notification, versus warning. |
…l to largest used label plus one (#6546) # References and relevant issues Closes #6517 # Description Add showing a notification when the shortcut to set current selected label to largest used label plus one can't change the label value since it is already the largest used label plus one. A preview: ![label](https://github.com/napari/napari/assets/16781833/e62a11e3-21dc-4cba-bc54-6e671e2d8aa8) --------- Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com> Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
🐛 Bug Report
After creating a labels layer, I observed that the
m
keybinding does not behave consistently.💡 Steps to Reproduce
Create a labels layer.
m
keybinding will either do nothing or select another layer wiht a name that starts with the letterm
;m
keybinding doesn't do anything;m
keybinding correctly adds 1 to the label control and a new label is selected and can be used to paint.💡 Expected Behavior
The
m
keybinding should increase the label number in all those situations.🌎 Environment
napari: 0.5.0a2.dev486+g4d60a7ce
Platform: Linux-6.1.64-1-MANJARO-x86_64-with-glibc2.38
System: Manjaro Linux
Python: 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:40:35) [GCC 12.3.0]
Qt: 5.15.2
PyQt5: 5.15.10
NumPy: 1.26.2
SciPy: 1.11.4
Dask: 2023.11.0
VisPy: 0.14.1
magicgui: 0.8.0
superqt: 0.6.1
in-n-out: 0.1.9
app-model: 0.2.2
npe2: 0.7.3
OpenGL:
Screens:
Settings path:
Plugins:
💡 Additional Context
No response
The text was updated successfully, but these errors were encountered: