Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/dev/update_frame_thick.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def main():


def process_files(args):
from PartSegCore.io_utils import get_tarinfo, load_metadata_base
from PartSegCore.io_utils import get_tarinfo, load_metadata_from_string
from PartSegCore.json_hooks import PartSegEncoder

files = list(glob(f"{args.input}/*.seg"))
Expand All @@ -49,7 +49,7 @@ def process_files(args):
new_path = path.with_suffix(".tgz")
shutil.move(file_path, new_path)
with tarfile.open(new_path, "r:*") as f:
metadata = load_metadata_base(f.extractfile("metadata.json").read().decode("utf8"))
metadata = load_metadata_from_string(f.extractfile("metadata.json").read())
segmentation_buff = io.BytesIO()
segmentation_tar = f.extractfile("segmentation.tif")
segmentation_buff.write(segmentation_tar.read())
Expand Down
10 changes: 1 addition & 9 deletions package/PartSeg/_launcher/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from functools import partial
from typing import TYPE_CHECKING

import napari
from packaging.version import parse as parse_version
from qtpy.QtCore import QSize, Qt, QThread, Signal
from qtpy.QtGui import QIcon
from qtpy.QtWidgets import QGridLayout, QMainWindow, QMessageBox, QProgressBar, QToolButton, QWidget
Expand All @@ -20,9 +18,6 @@
from PartSeg.common_gui.main_window import BaseMainWindow


_napari_ge_5 = parse_version(napari.__version__) >= parse_version("0.5.0a1")


class Prepare(QThread):
def __init__(self, module: str):
super().__init__()
Expand Down Expand Up @@ -146,9 +141,6 @@ def __init__(self, title):

def _update_theme(self):
napari_settings = napari_get_settings(state_store.save_folder)
if _napari_ge_5:
theme = get_theme(napari_settings.appearance.theme).to_rgb_dict()
else:
theme = get_theme(napari_settings.appearance.theme, as_dict=True)
theme = get_theme(napari_settings.appearance.theme).to_rgb_dict()
# TODO understand qss overwrite mechanism
self.setStyleSheet(napari_template(get_stylesheet(), **theme))
31 changes: 2 additions & 29 deletions package/PartSeg/common_backend/base_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
import logging
import os
import os.path
import re
import sys
import warnings
from argparse import Namespace
from collections.abc import Callable, Sequence
from contextlib import suppress
from datetime import datetime
Expand All @@ -19,7 +17,6 @@
from napari.utils import Colormap
from napari.utils.theme import get_theme
from napari.utils.theme import template as napari_template
from packaging.version import parse as parse_version
from qtpy.QtCore import QObject, Signal
from qtpy.QtWidgets import QMessageBox, QWidget

Expand All @@ -40,8 +37,6 @@
from napari.settings import NapariSettings
logger = logging.getLogger(__name__)

_napari_ge_5 = parse_version(napari.__version__) >= parse_version("0.5.0a1")

DIR_HISTORY = "io.dir_location_history"
FILE_HISTORY = "io.files_open_history"
MULTIPLE_FILES_OPEN_HISTORY = "io.multiple_files_open_history"
Expand Down Expand Up @@ -278,28 +273,15 @@ def theme_name(self) -> str:
@property
def theme(self):
"""Theme as structure."""
if _napari_ge_5:
return get_theme(self.theme_name)
try:
return get_theme(self.theme_name, as_dict=False)
except TypeError: # pragma: no cover
theme = get_theme(self.theme_name)
return Namespace(
**{k: Color(v) if isinstance(v, str) and v.startswith("rgb") else v for k, v in theme.items()}
)
return get_theme(self.theme_name)

@property
def style_sheet(self):
return self.get_style_sheet()

def get_style_sheet(self):
"""QSS style sheet for current theme."""
with warnings.catch_warnings():
warnings.simplefilter("ignore", FutureWarning)
if _napari_ge_5:
theme = get_theme(self.theme_name).to_rgb_dict()
else:
theme = get_theme(self.theme_name, as_dict=True)
theme = get_theme(self.theme_name).to_rgb_dict()
# TODO understand qss overwrite mechanism
return napari_template("\n".join(register.qss_list) + get_stylesheet() + "\n".join(register.qss_list), **theme)

Expand Down Expand Up @@ -816,12 +798,3 @@ class TimeAndStackException(Exception):
Exception which inform that current image has both time
and stack dat which is not supported
"""


class Color: # pragma: no cover
def __init__(self, text):
color_re = re.compile(r"rgb\((\d+), (\d+), (\d+)\)")
self.colors = tuple(map(int, color_re.match(text).groups()))

def as_rgb_tuple(self):
return self.colors
10 changes: 1 addition & 9 deletions package/PartSeg/common_gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

_EXIT = object()

NAPARI_LE_4_16 = parse_version(napari.__version__) <= parse_version("0.4.16")
_napari_le_7_0 = parse_version(napari.__version__) <= parse_version("0.7.0")


Expand Down Expand Up @@ -185,8 +184,6 @@ def __init__(
self.console_dock.hide()
self.addDockWidget(Qt.BottomDockWidgetArea, self.console_dock)

self._scale_bar_warning = True # remove after drop napari 0.4.16

def _toggle_console(self):
if self.console is None:
self.console = QtConsole(self)
Expand Down Expand Up @@ -389,9 +386,4 @@ def deleteLater(self) -> None:
super().deleteLater()

def _toggle_scale_bar(self):
"""Remove after drop napari 0.4.16"""
if NAPARI_LE_4_16 and self._scale_bar_warning and self.settings.theme_name == "light": # pragma: no cover
QMessageBox.warning(
self, "Not supported", "Scale bar is not supported for light theme and napari below 0.4.17"
)
self._scale_bar_warning = False
"""Hook for subclasses to toggle scale bar visibility."""
12 changes: 1 addition & 11 deletions package/PartSeg/launcher_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,7 @@ def create_parser():
return parser


def main(): # pragma: no cover # noqa: PLR0915
from importlib.metadata import version

from packaging.version import parse as parse_version

napari_version = parse_version(version("napari"))
pydantic_version = parse_version(version("pydantic"))
if napari_version < parse_version("0.4.19") and pydantic_version >= parse_version("2"):
print("napari version is too low, please update to version 0.4.19 or higher or downgrade pydantic to version 1")
sys.exit(1)

def main(): # pragma: no cover
if len(sys.argv) > 1 and sys.argv[1] == "_test":
_test_imports()
return
Expand Down
19 changes: 3 additions & 16 deletions package/PartSeg/plugins/napari_widgets/search_label_widget.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import warnings

import napari
import numpy as np
from magicgui.widgets import Container, HBox, PushButton, SpinBox, create_widget
from napari import Viewer
from napari.layers import Labels
from napari.utils.notifications import show_info
from packaging.version import parse as parse_version
from qtpy.QtCore import QTimer
from vispy.geometry import Rect

Expand All @@ -15,8 +13,6 @@

HIGHLIGHT_LABEL_NAME = ".Highlight"

_napari_ge_5 = parse_version(napari.__version__) >= parse_version("0.5.0a1")


class SearchLabel(Container):
def __init__(self, napari_viewer: Viewer):
Expand Down Expand Up @@ -110,10 +106,7 @@ def _shift_if_need(self, labels, bound_info):
u_bound = upper_bound[-2:][::-1]
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Public access to Window.qt_viewer")
if _napari_ge_5:
rect = Rect(self.napari_viewer.window.qt_viewer.canvas.view.camera.get_state()["rect"])
else:
rect = Rect(self.napari_viewer.window.qt_viewer.view.camera.get_state()["rect"])
rect = Rect(self.napari_viewer.window.qt_viewer.canvas.view.camera.get_state()["rect"])
if rect.contains(*l_bound) and rect.contains(*u_bound):
return
size = u_bound - l_bound
Expand All @@ -130,10 +123,7 @@ def _shift_if_need(self, labels, bound_info):
rect.pos = pos
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Public access to Window.qt_viewer")
if _napari_ge_5:
self.napari_viewer.window.qt_viewer.canvas.view.camera.set_state({"rect": rect})
else:
self.napari_viewer.window.qt_viewer.view.camera.set_state({"rect": rect})
self.napari_viewer.window.qt_viewer.canvas.view.camera.set_state({"rect": rect})

@staticmethod
def _data_to_world(layer: Labels, cords):
Expand All @@ -156,10 +146,7 @@ def _zoom(self):
rect = Rect(pos=(lower_bound - frame)[-2:][::-1], size=(diff + 2 * frame)[-2:][::-1])
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Public access to Window.qt_viewer")
if _napari_ge_5:
self.napari_viewer.window.qt_viewer.canvas.view.camera.set_state({"rect": rect})
else:
self.napari_viewer.window.qt_viewer.view.camera.set_state({"rect": rect})
self.napari_viewer.window.qt_viewer.canvas.view.camera.set_state({"rect": rect})
self._update_point(lower_bound, upper_bound)

def _update_point(self, lower_bound, upper_bound):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ def __init__(self, napari_viewer: Viewer):
self.insert(1, bottom_layout)

self.image_choice.native.currentIndexChanged.connect(self._refresh_measurements)
with warnings.catch_warnings():
warnings.simplefilter("ignore", FutureWarning)
self.labels_choice.changed.connect(self._refresh_measurements)
self.calculate_btn.changed.connect(self._calculate)
self.labels_choice.changed.connect(self._refresh_measurements)
self.calculate_btn.changed.connect(self._calculate)
register_plugins()

def _calculate(self, event=None):
Expand Down
Loading
Loading