Is it possible to "lock" layers (prevent deletion)?

Hi! Is it possible to lock a layer in a way that it is prevented from ever being deleted in the current Napari session?
I still want to interact with the sliders/rolling and change image contrasts etc. - the only thing I want is for it to not be able to be deleted.


Currently that isn’t straightforward. Could you suggest it as a new feature at

To get started programmatically, though, you could subclass the napari QtViewer and the QtLayerList to change the _remove method by checking whether the layer is locked:

You would need to do the same in LayerList if you wanted it to be protected from the API also.

Maybe @sofroniewn has further ideas here…

1 Like

By the way, when I say “check whether the layer is locked” — currently layers don’t have that attribute, so you would have to keep track of that yourself.

Thanks for your reply, makes sense! I will suggest it as feature.

1 Like

Discussion on this feature request has now moved here, and further input is welcome there!!