andy-sweet / napari-metadata

A napari plugin to view and edit metadata
BSD 3-Clause "New" or "Revised" License
10 stars 3 forks source link

Always coerce extra metadata #43

Closed andy-sweet closed 1 year ago

andy-sweet commented 1 year ago

This uses coerce_extra_metadata instead of extra_metadata in the widgets, so that it is always present. This change handles a few cases that would previously result in bugs or strange behavior due to missing extras.

1. Layer.metadata is assigned to an entirely new dictionary. When coming back to the widget, the extras are missing which causes an error. 2. Units were selected for the first selected layer. Then we selected a different layer, and both layers lost their units (because none is used instead).

Even after this PR, (1) will cause the previous metadata to be lost and we'll just repopulate it with the defaults. We could try to fix this by connecting a callback to Layer.events.metadata, but I don't think that's worth the associated trouble and is not a complete fix anyway.

Closes #40