-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add metadata viewer as napari widget (#1195)
<!-- Generated by sourcery-ai[bot]: start summary --> ## Summary by Sourcery Add a new LayerMetadata widget to the napari viewer for displaying layer metadata, update the DictViewer class to use a set_data method, and include tests for the new widget. New Features: - Introduce a new LayerMetadata widget for viewing metadata of layers in the napari viewer. Enhancements: - Modify the DictViewer class to use a set_data method for initializing data. Tests: - Add tests for the LayerMetadata widget to verify its initialization and functionality with and without layers. <!-- Generated by sourcery-ai[bot]: end summary --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Introduced the "View Layer Metadata" feature in the Napari interface, allowing users to view metadata associated with image layers. - Added a new `LayerMetadata` widget for selecting layers and displaying their metadata. - **Bug Fixes** - Enhanced metadata handling for image layers, ensuring relevant information is included in layer configurations. - **Tests** - Added a new test class for the `LayerMetadata` widget to ensure proper functionality during initialization and layer updates. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
6 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import napari | ||
from magicgui.widgets import create_widget | ||
from napari.layers import Image as NapariImage | ||
from qtpy.QtWidgets import QVBoxLayout, QWidget | ||
|
||
from PartSeg.common_gui.dict_viewer import DictViewer | ||
|
||
|
||
class LayerMetadata(QWidget): | ||
def __init__(self, viewer: napari.Viewer): | ||
super().__init__() | ||
self._viewer = viewer | ||
self.layer_selector = create_widget(annotation=NapariImage, label="Layer", options={}) | ||
self._dict_viewer = DictViewer() | ||
layout = QVBoxLayout() | ||
layout.addWidget(self.layer_selector.native) | ||
layout.addWidget(self._dict_viewer) | ||
|
||
self.setLayout(layout) | ||
self.update_metadata() | ||
self.layer_selector.changed.connect(self.update_metadata) | ||
|
||
def reset_choices(self): | ||
self.layer_selector.reset_choices() | ||
|
||
def update_metadata(self): | ||
if self.layer_selector.value is None: | ||
return | ||
self._dict_viewer.set_data(self.layer_selector.value.metadata) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters