Skip to content

Commit

Permalink
Merge pull request #31 from MPI-Dortmund/fix_issue_23
Browse files Browse the repository at this point in the history
Add prefix and suffix for image and layers
  • Loading branch information
thorstenwagner authored Jun 14, 2023
2 parents d32b842 + 381fa37 commit 72a7011
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/box_manager/_qt/OrganizeLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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", self)
layout = QFormLayout()
Expand All @@ -109,23 +115,25 @@ 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)
.removesuffix(suffix)
)

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)
}
Expand Down

0 comments on commit 72a7011

Please sign in to comment.