From 39a68ec724fb8a36078bf25a9f8ad84385e9ff63 Mon Sep 17 00:00:00 2001 From: hanjinliu Date: Sun, 5 Sep 2021 18:19:11 +0900 Subject: [PATCH] typing, v1.23.0 --- README.md | 3 +-- impy/__init__.py | 2 +- impy/viewer/menus.py | 40 +++++++++++++++++++++------------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 80050252..9ae5bfa9 100644 --- a/README.md +++ b/README.md @@ -121,5 +121,4 @@ git clone https://github.com/hanjinliu/impy `impy` is partly dependent on `numba`, `cupy`, `trackpy` and `dask-image`. Please install these packages if needed. -:warning: Image processing algorithms in `ImgArray` are almost stable so that their behavior will not change a lot. However, since `napari` is under development and I'm groping for better UI right now, any functions that currently implemented in `impy` viewer may change or no longer work in the future. Make sure keeping `napari` and `impy` updated when you use. - +:warning: Image processing algorithms in `ImgArray` are almost stable so that their behavior will not change a lot. However, since `napari` is under development and I'm groping for better UI right now, any functions that currently implemented in `impy` viewer may change or no longer work in the future. Make sure keeping `napari` and `impy` updated when you use. \ No newline at end of file diff --git a/impy/__init__.py b/impy/__init__.py index 28f16a7e..0acf4e25 100644 --- a/impy/__init__.py +++ b/impy/__init__.py @@ -1,4 +1,4 @@ -__version__ = "1.22.2" +__version__ = "1.23.0" import logging from ._const import Const, SetConst diff --git a/impy/viewer/menus.py b/impy/viewer/menus.py index 3e85d041..ba5b48a3 100644 --- a/impy/viewer/menus.py +++ b/impy/viewer/menus.py @@ -1,6 +1,9 @@ from __future__ import annotations from warnings import warn import napari +from napari.utils.notifications import Notification, notification_manager +from napari.utils import history +from napari.layers import Image, Shapes, Points, Labels, Tracks import magicgui from functools import wraps from qtpy.QtWidgets import QFileDialog, QAction @@ -40,7 +43,6 @@ "tophat", "rolling_ball"] def catch_notification(func): - from napari.utils.notifications import Notification, notification_manager @wraps(func) def wrapped(*args, **kwargs): try: @@ -58,7 +60,7 @@ def add_imread_menu(viewer:"napari.Viewer"): @catch_notification def _(*args): dlg = QFileDialog() - hist = napari.utils.history.get_open_history() + hist = history.get_open_history() dlg.setHistory(hist) filenames, _ = dlg.getOpenFileNames( parent=viewer.window.qt_viewer, @@ -68,7 +70,7 @@ def _(*args): if filenames != [] and filenames is not None: img = imread(filenames[0]) add_labeledarray(viewer, img) - napari.utils.history.update_open_history(filenames[0]) + history.update_open_history(filenames[0]) return None viewer.window.file_menu.addAction(action) @@ -88,7 +90,7 @@ def _(*args): raise ValueError("Select only one layer.") img = layer_to_impy_object(viewer, layers[0]) - hist = napari.utils.history.get_save_history() + hist = history.get_save_history() dlg.setHistory(hist) if img.dirpath: @@ -103,7 +105,7 @@ def _(*args): if filename: img.imsave(filename) - napari.utils.history.update_save_history(filename) + history.update_save_history(filename) return None viewer.window.file_menu.addAction(action) @@ -115,7 +117,7 @@ def add_read_csv_menu(viewer:"napari.Viewer"): @catch_notification def _(*args): dlg = QFileDialog() - hist = napari.utils.history.get_open_history() + hist = history.get_open_history() dlg.setHistory(hist) filenames, _ = dlg.getOpenFileNames( parent=viewer.window.qt_viewer, @@ -125,7 +127,7 @@ def _(*args): if (filenames != []) and (filenames is not None): path = filenames[0] read_csv(viewer, path) - napari.utils.history.update_open_history(filenames[0]) + history.update_open_history(filenames[0]) return None viewer.window.file_menu.addAction(action) @@ -142,7 +144,7 @@ def _(*args): if name in viewer.window._dock_widgets.keys(): viewer.window._dock_widgets[name].show() else: - root = napari.utils.history.get_open_history()[0] + root = history.get_open_history()[0] ex = Explorer(viewer, root) viewer.window.add_dock_widget(ex, name="Explorer", area="right", allowed_areas=["right"]) return None @@ -159,7 +161,7 @@ def add_duplicate_menu(viewer:"napari.Viewer"): def _(): layer = get_a_selected_layer(viewer) - if isinstance(layer, (napari.layers.Image, napari.layers.Labels)): + if isinstance(layer, (Image, Labels)): dlg = DuplicateDialog(viewer, layer) dlg.exec_() else: @@ -190,19 +192,19 @@ def _(): "opacity": layer.opacity, "ndim": 2, "name": f"[Proj]{layer.name}"}) - if isinstance(layer, napari.layers.Image): + if isinstance(layer, Image): if layer.data.ndim < 3: return None dlg = ImageProjectionDialog(viewer, layer) dlg.exec_() - elif isinstance(layer, napari.layers.Labels): + elif isinstance(layer, Labels): if layer.data.ndim < 3: return None dlg = LabelProjectionDialog(viewer, layer) dlg.exec_() - elif isinstance(layer, napari.layers.Shapes): + elif isinstance(layer, Shapes): data = [d[:,-2:] for d in data] if layer.nshapes > 0: @@ -214,7 +216,7 @@ def _(): kwargs["shape_type"] = layer.shape_type viewer.add_shapes(data, **kwargs) - elif isinstance(layer, napari.layers.Points): + elif isinstance(layer, Points): data = data[:, -2:] for k in ["face_color", "edge_color", "size", "symbol"]: kwargs[k] = getattr(layer, k, None) @@ -224,7 +226,7 @@ def _(): kwargs["ndim"] = 2 viewer.add_points(data, **kwargs) - elif isinstance(layer, napari.layers.Tracks): + elif isinstance(layer, Tracks): data = data[:, [0, -2, -1]] # p, y, x axes viewer.add_tracks(data, **kwargs) @@ -375,7 +377,7 @@ def add_time_stamper_menu(viewer:"napari.Viewer"): @catch_notification def _(*args): layer = get_a_selected_layer(viewer) - if not isinstance(layer, napari.layers.Image): + if not isinstance(layer, Image): raise TypeError("Select an image layer.") layer.data.axisof("t") # check image axes here. dlg = TimeStamper(viewer, layer) @@ -402,7 +404,7 @@ def _(*args): layer.current_properties = {"1": np.array([""], dtype="