Skip to content

Commit

Permalink
Show notification when using shortcut to change current selected labe…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
4 people committed Feb 3, 2024
1 parent 65e5d38 commit ad78ee2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions napari/layers/labels/_labels_key_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,21 @@ def activate_labels_erase_mode(layer: Labels):
def new_label(layer: Labels):
"""Set the currently selected label to the largest used label plus one."""
if isinstance(layer.data, np.ndarray):
layer.selected_label = np.max(layer.data) + 1
new_selected_label = np.max(layer.data) + 1
if layer.selected_label == new_selected_label:
show_info(
trans._(
"Current selected label is not being used. You will need to use it first "
"to be able to set the current select label to the next one available",
)
)
else:
layer.selected_label = new_selected_label
else:
show_info(
"Calculating empty label on non-numpy array is not supported"
trans._(
"Calculating empty label on non-numpy array is not supported"
)
)


Expand Down

0 comments on commit ad78ee2

Please sign in to comment.