Skip to content

Commit

Permalink
look for ome_types metadata at layer.metadata['ome_types'] (#97)
Browse files Browse the repository at this point in the history
* detect layer meta elsewhere

* still look for callable
  • Loading branch information
tlambert03 authored Jul 10, 2021
1 parent 3771124 commit 505d016
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/ome_types/_napari_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from .widgets import OMETree

METADATA_KEY = "ome_types"


@napari_hook_implementation
def napari_experimental_provide_dock_widget():
Expand Down
19 changes: 15 additions & 4 deletions src/ome_types/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,26 @@ def clear(self):
self.headerItem().setText(0, "drag/drop file...")
super().clear()

def _try_load_layer(self, layer):
def _try_load_layer(self, layer: "napari.layers.Layer"):
"""Handle napari viewer behavior"""
from ._napari_plugin import METADATA_KEY

if layer is not None:
path = str(layer.source.path)
ome = None

# deprecated... don't do this ... it should be a dict
if callable(layer.metadata):
ome = layer.metadata()
ome_meta = layer.metadata()
elif isinstance(layer.metadata, OME):
ome = layer.metadata
ome_meta = layer.metadata
else:
ome_meta = layer.metadata.get(METADATA_KEY)
if callable(ome_meta):
ome_meta = ome_meta()

ome = None
if isinstance(ome_meta, OME):
ome = ome_meta
elif path.endswith((".tiff", ".tif")) and path != self._current_path:
try:
ome = OME.from_tiff(path)
Expand Down

0 comments on commit 505d016

Please sign in to comment.