royerlab / napari-segment-anything

Segment Anything Model (SAM) native Qt UI
Apache License 2.0
190 stars 17 forks source link

Error when closing and re-opening the plugin #22

Open jo-mueller opened 12 months ago

jo-mueller commented 12 months ago

Hi @JoOkuma ,

I'm getting an error when I open, close and re-open the plugin. The error is this:

        self = <Container ()>
     97 self._viewer.bind_key("X", self._cancel_annot)

File ~\Anaconda3\envs\pytorch\lib\site-packages\napari\utils\key_bindings.py:286, in bind_key(keymap={'C': <bound method SAMWidget._on_confirm_mask of <Container ()>>, 'X': <bound method SAMWidget._cancel_annot of <Container ()>>}, key='C', func=<bound method SAMWidget._on_confirm_mask of <Container ()>>, overwrite=False)
    283     key = normalize_key_combo(key)
    285 if func is not None and key in keymap and not overwrite:
--> 286     raise ValueError(
        trans = <napari.utils.translations.TranslationBundle object at 0x000002265A114730>
        key = 'C'
    287         trans._(
    288             'key combination {key} already used! specify \'overwrite=True\' to bypass this check',
    289             deferred=True,
    290             key=key,
    291         )
    292     )
    294 unbound = keymap.pop(key, None)
    296 if func is not None:

ValueError: key combination C already used! specify 'overwrite=True' to bypass this check

To reproduce:

Open the plugin in napari, close it again, and re-open it.

Fix

The error message points to this line in the code. Adding an overwrite=True to this line fixes it.

PR coming :)