From 381fa3724bccfb2026f32abb166ab830210e7971 Mon Sep 17 00:00:00 2001 From: Markus Stabrin Date: Tue, 13 Jun 2023 11:05:04 +0200 Subject: [PATCH] Add prefix and suffix for image and layers --- src/box_manager/_qt/OrganizeLayer.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/box_manager/_qt/OrganizeLayer.py b/src/box_manager/_qt/OrganizeLayer.py index 2507d09..6f27f7d 100644 --- a/src/box_manager/_qt/OrganizeLayer.py +++ b/src/box_manager/_qt/OrganizeLayer.py @@ -46,6 +46,7 @@ def __init__(self, entries: list[tuple[str, str]]): b2.clicked.connect(self.reject) tmp_layout = QHBoxLayout() + tmp_layout.setContentsMargins(0, 0, 0, 0) tmp_layout.addWidget(b1) tmp_layout.addWidget(b2) self.layout().addLayout(tmp_layout) @@ -54,10 +55,13 @@ def __init__(self, entries: list[tuple[str, str]]): for l1, l2 in entries: tmp_layout = QHBoxLayout() + tmp_layout.setContentsMargins(0, 0, 0, 0) tmp_layout.addWidget(QLabel(l1, self)) tmp_layout.addWidget(QLabel(l2, self)) widget.layout().addLayout(tmp_layout) + widget.layout().addStretch(1) + area.setWidget(widget) self.layout().addWidget(area) @@ -92,8 +96,10 @@ def _link_auto_ui(self): inner_layout.setContentsMargins(0, 0, 0, 0) self.link_auto_layers = { - "prefix": QLineEdit(self), - "suffix": QLineEdit(self), + "prefix image": QLineEdit(self), + "suffix image": QLineEdit(self), + "prefix layer": QLineEdit(self), + "suffix layer": QLineEdit(self), } self.link_run_auto_btn = QPushButton("Link all layers", self) layout = QFormLayout() @@ -109,10 +115,12 @@ def _link_auto_ui(self): @Slot() def _link_auto_layers(self): - prefix = self.link_auto_layers["prefix"].text() - suffix = self.link_auto_layers["suffix"].text() + prefix_image = self.link_auto_layers["prefix image"].text() + suffix_image = self.link_auto_layers["suffix image"].text() + prefix_layer = self.link_auto_layers["prefix layer"].text() + suffix_layer = self.link_auto_layers["suffix layer"].text() - def get_unique(path: str): + def get_unique(path: str, prefix: str, suffix: str): return ( os.path.splitext(os.path.basename(path))[0] .removeprefix(prefix) @@ -120,12 +128,12 @@ def get_unique(path: str): ) image_layers = { - get_unique(_.name): _.name + get_unique(_.name, prefix_image, suffix_image): _.name for _ in self.napari_viewer.layers if isinstance(_, napari.layers.Image) } layer_layers = { - get_unique(_.name): _.name + get_unique(_.name, prefix_layer, suffix_layer): _.name for _ in self.napari_viewer.layers if not isinstance(_, napari.layers.Image) }