From f4abb0a21d8c6b9b014106cf31adc58b576c7182 Mon Sep 17 00:00:00 2001 From: Peter Sobolewski Date: Sat, 29 Oct 2022 21:56:54 +0200 Subject: [PATCH 1/8] initial widget --- napari_aicsimageio/_settings_widget.py | 18 ++++++++++++++++++ napari_aicsimageio/napari.yaml | 7 +++++++ 2 files changed, 25 insertions(+) create mode 100644 napari_aicsimageio/_settings_widget.py diff --git a/napari_aicsimageio/_settings_widget.py b/napari_aicsimageio/_settings_widget.py new file mode 100644 index 0000000..e69d146 --- /dev/null +++ b/napari_aicsimageio/_settings_widget.py @@ -0,0 +1,18 @@ +from typing import List + +import napari +from magicgui import magic_factory + + +@magic_factory( + delimiter={"label": "Delimiter in scene labels:"}, + in_mem_size={"label": "Threshold for out-of-memory loading (GB)"}, + frac_mem_size={"label": "Threshold for out-of-memory loading (% free memory):"}, + call_button="Set Reader Settings", +) +def set_settings(delimiter: str = " :: ", in_mem_size: float = 4, frac_mem_size: int = 30) -> None: + import napari_aicsimageio.core + + napari_aicsimageio.core.SCENE_LABEL_DELIMITER = delimiter + napari_aicsimageio.core.IN_MEM_THRESHOLD_SIZE_BYTES = in_mem_size * 1e9 + napari_aicsimageio.core.IN_MEM_THRESHOLD_PERCENT = frac_mem_size / 100 diff --git a/napari_aicsimageio/napari.yaml b/napari_aicsimageio/napari.yaml index 42a051f..12f347d 100644 --- a/napari_aicsimageio/napari.yaml +++ b/napari_aicsimageio/napari.yaml @@ -5,6 +5,13 @@ contributions: - id: napari-aicsimageio.get_reader title: Get AICSImageIO Reader python_name: napari_aicsimageio.core:get_reader + - id: napari-aicsimageio.settings_widget + title: Open AICSImageIO Reader Settings + python_name: napari_aicsimageio._settings_widget:set_settings + + widgets: + - command: napari-aicsimageio.settings_widget + display_name: AICSImageIO Reader Settings readers: - command: napari-aicsimageio.get_reader filename_patterns: [ From 4ab5c96fe0115c4d2309a36697f6b94eac313e73 Mon Sep 17 00:00:00 2001 From: Peter Sobolewski Date: Sat, 29 Oct 2022 22:19:02 +0200 Subject: [PATCH 2/8] Black format, delete un-needed imports --- napari_aicsimageio/_settings_widget.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/napari_aicsimageio/_settings_widget.py b/napari_aicsimageio/_settings_widget.py index e69d146..da4dc1c 100644 --- a/napari_aicsimageio/_settings_widget.py +++ b/napari_aicsimageio/_settings_widget.py @@ -1,6 +1,3 @@ -from typing import List - -import napari from magicgui import magic_factory @@ -10,7 +7,9 @@ frac_mem_size={"label": "Threshold for out-of-memory loading (% free memory):"}, call_button="Set Reader Settings", ) -def set_settings(delimiter: str = " :: ", in_mem_size: float = 4, frac_mem_size: int = 30) -> None: +def set_settings( + delimiter: str = " :: ", in_mem_size: float = 4, frac_mem_size: int = 30 +) -> None: import napari_aicsimageio.core napari_aicsimageio.core.SCENE_LABEL_DELIMITER = delimiter From aed3adf612a8a5f20c6c17ed6e0f07af548d732e Mon Sep 17 00:00:00 2001 From: Peter Sobolewski Date: Sat, 29 Oct 2022 22:39:17 +0200 Subject: [PATCH 3/8] Fix lint (line length) --- napari_aicsimageio/_settings_widget.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/napari_aicsimageio/_settings_widget.py b/napari_aicsimageio/_settings_widget.py index da4dc1c..124c3b9 100644 --- a/napari_aicsimageio/_settings_widget.py +++ b/napari_aicsimageio/_settings_widget.py @@ -4,7 +4,8 @@ @magic_factory( delimiter={"label": "Delimiter in scene labels:"}, in_mem_size={"label": "Threshold for out-of-memory loading (GB)"}, - frac_mem_size={"label": "Threshold for out-of-memory loading (% free memory):"}, + frac_mem_size={"label": \ + "Threshold for out-of-memory loading (% free memory):"}, call_button="Set Reader Settings", ) def set_settings( From c7e26a1f89109c80692ca87432a791e18a477510 Mon Sep 17 00:00:00 2001 From: Peter Sobolewski Date: Sun, 30 Oct 2022 09:47:47 +0100 Subject: [PATCH 4/8] Use hints from @Czaki & get close to work. --- napari_aicsimageio/_settings_widget.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/napari_aicsimageio/_settings_widget.py b/napari_aicsimageio/_settings_widget.py index 124c3b9..750428f 100644 --- a/napari_aicsimageio/_settings_widget.py +++ b/napari_aicsimageio/_settings_widget.py @@ -1,18 +1,25 @@ +import napari from magicgui import magic_factory +import napari_aicsimageio.core + @magic_factory( delimiter={"label": "Delimiter in scene labels:"}, in_mem_size={"label": "Threshold for out-of-memory loading (GB)"}, - frac_mem_size={"label": \ - "Threshold for out-of-memory loading (% free memory):"}, - call_button="Set Reader Settings", + frac_mem_size={"label": "Threshold for out-of-memory loading (% free memory):"}, + call_button="Set Reader Settings and Close Widget", ) def set_settings( - delimiter: str = " :: ", in_mem_size: float = 4, frac_mem_size: int = 30 + napari_viewer: napari.Viewer, + delimiter: str = napari_aicsimageio.core.SCENE_LABEL_DELIMITER, + in_mem_size: float = napari_aicsimageio.core.IN_MEM_THRESHOLD_SIZE_BYTES / 1e9, + frac_mem_size: int = int(napari_aicsimageio.core.IN_MEM_THRESHOLD_PERCENT * 100), ) -> None: - import napari_aicsimageio.core napari_aicsimageio.core.SCENE_LABEL_DELIMITER = delimiter napari_aicsimageio.core.IN_MEM_THRESHOLD_SIZE_BYTES = in_mem_size * 1e9 napari_aicsimageio.core.IN_MEM_THRESHOLD_PERCENT = frac_mem_size / 100 + + viewer = napari_viewer + viewer.window.remove_dock_widget(set_settings.native) From 158f311b2e61f95cb2965d7b2834403df61b183b Mon Sep 17 00:00:00 2001 From: Peter Sobolewski Date: Sun, 30 Oct 2022 09:48:15 +0100 Subject: [PATCH 5/8] Make widget params persist --- napari_aicsimageio/_settings_widget.py | 1 + 1 file changed, 1 insertion(+) diff --git a/napari_aicsimageio/_settings_widget.py b/napari_aicsimageio/_settings_widget.py index 750428f..7d28500 100644 --- a/napari_aicsimageio/_settings_widget.py +++ b/napari_aicsimageio/_settings_widget.py @@ -9,6 +9,7 @@ in_mem_size={"label": "Threshold for out-of-memory loading (GB)"}, frac_mem_size={"label": "Threshold for out-of-memory loading (% free memory):"}, call_button="Set Reader Settings and Close Widget", + persist=True, ) def set_settings( napari_viewer: napari.Viewer, From 82a925085f2ce225f431da003521b524db4e8612 Mon Sep 17 00:00:00 2001 From: Peter Sobolewski Date: Sun, 30 Oct 2022 22:50:26 +0100 Subject: [PATCH 6/8] Add label to inform about applying settings --- napari_aicsimageio/_settings_widget.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/napari_aicsimageio/_settings_widget.py b/napari_aicsimageio/_settings_widget.py index 7d28500..faac150 100644 --- a/napari_aicsimageio/_settings_widget.py +++ b/napari_aicsimageio/_settings_widget.py @@ -7,11 +7,18 @@ @magic_factory( delimiter={"label": "Delimiter in scene labels:"}, in_mem_size={"label": "Threshold for out-of-memory loading (GB)"}, - frac_mem_size={"label": "Threshold for out-of-memory loading (% free memory):"}, - call_button="Set Reader Settings and Close Widget", + frac_mem_size={ + "label": "Threshold for out-of-memory loading (% free memory):" + }, + call_button="Apply Reader Settings and Close Widget", + info_label=dict( + widget_type="Label", + label="

For each napari session, to use the settings:
press the Apply button!

", + ), persist=True, ) def set_settings( + info_label: str, napari_viewer: napari.Viewer, delimiter: str = napari_aicsimageio.core.SCENE_LABEL_DELIMITER, in_mem_size: float = napari_aicsimageio.core.IN_MEM_THRESHOLD_SIZE_BYTES / 1e9, From 0c28014a8e3cb4a17649406e07c87237dca8525a Mon Sep 17 00:00:00 2001 From: Peter Sobolewski Date: Fri, 11 Nov 2022 21:06:37 +0100 Subject: [PATCH 7/8] Formating, plus eliminate close-on-apply --- napari_aicsimageio/_settings_widget.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/napari_aicsimageio/_settings_widget.py b/napari_aicsimageio/_settings_widget.py index faac150..0035e90 100644 --- a/napari_aicsimageio/_settings_widget.py +++ b/napari_aicsimageio/_settings_widget.py @@ -6,28 +6,29 @@ @magic_factory( delimiter={"label": "Delimiter in scene labels:"}, - in_mem_size={"label": "Threshold for out-of-memory loading (GB)"}, + in_mem_size={"label": "Threshold for \ +
out-of-memory loading \ +
(GB)"}, frac_mem_size={ - "label": "Threshold for out-of-memory loading (% free memory):" + "label": "Threshold for
out-of-memory loading \ +
(% free memory):" }, - call_button="Apply Reader Settings and Close Widget", + call_button="Apply Reader Settings", info_label=dict( widget_type="Label", - label="

For each napari session, to use the settings:
press the Apply button!

", + label="

For each napari session, \ +
to use the settings: \ +
press the Apply button!

", ), persist=True, ) def set_settings( info_label: str, - napari_viewer: napari.Viewer, delimiter: str = napari_aicsimageio.core.SCENE_LABEL_DELIMITER, in_mem_size: float = napari_aicsimageio.core.IN_MEM_THRESHOLD_SIZE_BYTES / 1e9, frac_mem_size: int = int(napari_aicsimageio.core.IN_MEM_THRESHOLD_PERCENT * 100), ) -> None: - + napari_aicsimageio.core.SCENE_LABEL_DELIMITER = delimiter napari_aicsimageio.core.IN_MEM_THRESHOLD_SIZE_BYTES = in_mem_size * 1e9 napari_aicsimageio.core.IN_MEM_THRESHOLD_PERCENT = frac_mem_size / 100 - - viewer = napari_viewer - viewer.window.remove_dock_widget(set_settings.native) From da7cccc9db499525492999464948252693c0cccc Mon Sep 17 00:00:00 2001 From: Peter Sobolewski Date: Fri, 11 Nov 2022 23:11:05 +0100 Subject: [PATCH 8/8] lint --- napari_aicsimageio/_settings_widget.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/napari_aicsimageio/_settings_widget.py b/napari_aicsimageio/_settings_widget.py index 0035e90..f41cc9b 100644 --- a/napari_aicsimageio/_settings_widget.py +++ b/napari_aicsimageio/_settings_widget.py @@ -1,14 +1,15 @@ -import napari from magicgui import magic_factory -import napari_aicsimageio.core +import napari_aicsimageio.core as n_aics_core @magic_factory( delimiter={"label": "Delimiter in scene labels:"}, - in_mem_size={"label": "Threshold for \ + in_mem_size={ + "label": "Threshold for \
out-of-memory loading \ -
(GB)"}, +
(GB)" + }, frac_mem_size={ "label": "Threshold for
out-of-memory loading \
(% free memory):" @@ -24,11 +25,11 @@ ) def set_settings( info_label: str, - delimiter: str = napari_aicsimageio.core.SCENE_LABEL_DELIMITER, - in_mem_size: float = napari_aicsimageio.core.IN_MEM_THRESHOLD_SIZE_BYTES / 1e9, - frac_mem_size: int = int(napari_aicsimageio.core.IN_MEM_THRESHOLD_PERCENT * 100), + delimiter: str = n_aics_core.SCENE_LABEL_DELIMITER, + in_mem_size: float = n_aics_core.IN_MEM_THRESHOLD_SIZE_BYTES / 1e9, + frac_mem_size: int = int(n_aics_core.IN_MEM_THRESHOLD_PERCENT * 100), ) -> None: - - napari_aicsimageio.core.SCENE_LABEL_DELIMITER = delimiter - napari_aicsimageio.core.IN_MEM_THRESHOLD_SIZE_BYTES = in_mem_size * 1e9 - napari_aicsimageio.core.IN_MEM_THRESHOLD_PERCENT = frac_mem_size / 100 + + n_aics_core.SCENE_LABEL_DELIMITER = delimiter + n_aics_core.IN_MEM_THRESHOLD_SIZE_BYTES = in_mem_size * 1e9 + n_aics_core.IN_MEM_THRESHOLD_PERCENT = frac_mem_size / 100