-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from TimMonko/main_container
Add nDev app
- Loading branch information
Showing
18 changed files
with
410 additions
and
59 deletions.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 71 additions & 50 deletions
121
docs/resources/images/neuralDev-logo.svg → docs/resources/images/nDev-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,8 @@ | ||
"""Open napari with the napari_ndev plugin using command line.""" | ||
|
||
import subprocess | ||
|
||
|
||
def main(): | ||
"""Run napari with the napari_ndev plugin.""" | ||
subprocess.run(["napari", "-w", "napari-ndev"]) |
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,12 @@ | ||
from unittest.mock import patch | ||
|
||
from napari_ndev import __main__ | ||
|
||
|
||
@patch('subprocess.run') | ||
def test_main(mock_run): | ||
__main__.main() | ||
# Check if subprocess.run was called, indicating an attempt to open napari | ||
assert mock_run.called | ||
# Optionally, you can check the arguments to ensure it was called correctly | ||
mock_run.assert_called_with(["napari", "-w", "napari-ndev"]) |
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,58 @@ | ||
from pathlib import Path | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from napari_ndev import nImage | ||
from napari_ndev.widgets._ndev_container import nDevContainer | ||
|
||
|
||
def test_ndev_container_init_no_viewer(): | ||
ndev = nDevContainer() | ||
|
||
assert ndev._viewer is None | ||
assert ndev._apoc_container is not None | ||
assert ndev._measure_container is not None | ||
assert ndev._utilities_container is not None | ||
assert ndev._workflow_container is not None | ||
|
||
with patch('webbrowser.open') as mock_open: | ||
ndev._open_docs_link() | ||
mock_open.assert_called_once_with('https://timmonko.github.io/napari-ndev') | ||
|
||
with patch('webbrowser.open') as mock_open: | ||
ndev._open_bug_report_link() | ||
mock_open.assert_called_once_with('https://github.com/TimMonko/napari-ndev/issues') | ||
|
||
@pytest.fixture | ||
def test_cells3d2ch_image(resources_dir: Path): | ||
path = resources_dir / 'cells3d2ch.tiff' | ||
img = nImage(path) | ||
return path, img | ||
|
||
def test_ndev_container_viewer(make_napari_viewer, test_cells3d2ch_image, tmp_path: Path): | ||
viewer = make_napari_viewer() | ||
|
||
ndev = nDevContainer(viewer=viewer) | ||
assert ndev._viewer is viewer | ||
|
||
path, img = test_cells3d2ch_image | ||
ndev._utilities_container._files.value = path | ||
ndev._utilities_container.open_images() | ||
|
||
# make sure images opened and there are callbacks to the widgets | ||
assert viewer.layers[0] is not None | ||
|
||
# check interacting with alyers in utilities container works | ||
ndev._utilities_container._save_directory.value = tmp_path | ||
ndev._utilities_container._save_name.value = 'test' | ||
layer_data = ndev._utilities_container.save_layers_as_ome_tiff() | ||
|
||
expected_save_loc = tmp_path / 'Image' / 'test.tiff' | ||
assert layer_data.shape.__len__() == 5 | ||
assert expected_save_loc.exists() | ||
|
||
# check interacting with apoc container works | ||
assert ndev._apoc_container._image_layers.choices == ( | ||
viewer.layers[0], viewer.layers[1] | ||
) |
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,121 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from magicclass.widgets import ( | ||
ScrollableContainer, | ||
TabbedContainer, | ||
) | ||
from magicgui.widgets import ( | ||
Container, | ||
Label, | ||
PushButton, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
import napari | ||
|
||
class nDevContainer(ScrollableContainer): | ||
""" | ||
A widget container to container the primary ndev widgets. | ||
Parameters | ||
---------- | ||
viewer: napari.viewer.Viewer, optional | ||
The napari viewer instance. | ||
""" | ||
|
||
def __init__(self, viewer: napari.viewer.Viewer = None): | ||
""" | ||
Initialize the MainContainer. | ||
Parameters | ||
---------- | ||
viewer: napari.viewer.Viewer, optional | ||
The napari viewer instance. | ||
""" | ||
super().__init__(labels=False) | ||
|
||
self.min_width = 700 # TODO: remove this hardcoded value | ||
self._viewer = viewer if viewer is not None else None | ||
|
||
_logo_path = r'resources\nDev-logo-small.png' | ||
self._logo_label = Label( | ||
value='<h1 style="text-align: center;">' | ||
f'<img src="{_logo_path}"/>' | ||
'</h1>' | ||
) | ||
|
||
|
||
self._docs_link_button = PushButton( | ||
text='Docs', | ||
icon='ic:round-menu-book' | ||
) | ||
self._bug_report_link_button = PushButton( | ||
text='Bug Report', | ||
icon='ic:outline-bug-report', | ||
) | ||
self._link_container = Container( | ||
widgets=[self._docs_link_button, self._bug_report_link_button], | ||
layout='vertical', | ||
) | ||
self._header_container = Container( | ||
widgets=[self._logo_label, self._link_container], | ||
layout='horizontal', | ||
) | ||
|
||
self._init_widget_containers() | ||
self._init_layout() | ||
self._init_callbacks() | ||
|
||
def _init_widget_containers(self): | ||
from napari_ndev import ( | ||
ApocContainer, | ||
MeasureContainer, | ||
UtilitiesContainer, | ||
WorkflowContainer, | ||
) | ||
"""Initialize the widget containers.""" | ||
self._apoc_container = ApocContainer(viewer=self._viewer) | ||
self._apoc_container.label = "APOC" | ||
self._measure_container = MeasureContainer(viewer=self._viewer) | ||
self._measure_container.label = "Measure" | ||
self._utilities_container = UtilitiesContainer(viewer=self._viewer) | ||
self._utilities_container.label = "Utilities" | ||
self._workflow_container = WorkflowContainer(viewer=self._viewer) | ||
self._workflow_container.label = "Workflow" | ||
|
||
self._tabbed_container = TabbedContainer( | ||
# labels=["Apoc", "Measure", "Utilities", "Workflow"], | ||
labels = False, | ||
layout="horizontal", | ||
widgets=[ | ||
self._utilities_container, | ||
self._apoc_container, | ||
self._workflow_container, | ||
self._measure_container, | ||
], | ||
) | ||
|
||
def _init_layout(self): | ||
"""Initialize the layout.""" | ||
self.append(self._header_container) | ||
self.append(self._tabbed_container) | ||
# self.stretch(self._tabbed_container) | ||
|
||
def _init_callbacks(self): | ||
"""Initialize the widget callbacks.""" | ||
self._docs_link_button.clicked.connect(self._open_docs_link) | ||
self._bug_report_link_button.clicked.connect(self._open_bug_report_link) | ||
|
||
def _open_docs_link(self): | ||
"""Open the documentation link.""" | ||
import webbrowser | ||
webbrowser.open('https://timmonko.github.io/napari-ndev') | ||
|
||
def _open_bug_report_link(self): | ||
"""Open the bug report link.""" | ||
import webbrowser | ||
webbrowser.open('https://github.com/TimMonko/napari-ndev/issues') |