Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export option for single-scale OME-Zarr #316

Merged
merged 8 commits into from
Oct 15, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###############################################################################
# volumina: volume slicing and editing library
#
# Copyright (C) 2011-2018, the ilastik developers
# Copyright (C) 2011-2024, the ilastik developers
# <team@ilastik.org>
#
# This program is free software; you can redistribute it and/or
Expand All @@ -20,26 +20,35 @@
# http://ilastik.org/license/
###############################################################################
import os
from typing import Tuple

Check warning on line 23 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L23

Added line #L23 was not covered by tests

from PyQt5 import uic
from PyQt5.QtCore import pyqtSignal, Qt, QEvent
from PyQt5.QtWidgets import QWidget, QFileDialog


class Hdf5ExportFileOptionsWidget(QWidget):
class HierarchicalFileExportOptionsWidget(QWidget):

Check warning on line 30 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L30

Added line #L30 was not covered by tests
pathValidityChange = pyqtSignal(bool)

def __init__(self, parent):
super(Hdf5ExportFileOptionsWidget, self).__init__(parent)
def __init__(self, parent, file_extensions: Tuple[str, ...], extension_description: str):
super().__init__(parent)

Check warning on line 34 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L33-L34

Added lines #L33 - L34 were not covered by tests
uic.loadUi(os.path.splitext(__file__)[0] + ".ui", self)
self.file_extensions = file_extensions
self.default_extension = file_extensions[0]
self.extension_description = extension_description

Check warning on line 38 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L36-L38

Added lines #L36 - L38 were not covered by tests

self.settings_are_valid = True

# We need to watch the textEdited signal because Qt has a bug that causes the OK button
# to receive it's click event BEFORE the LineEdit receives its FocusOut event.
# (That is, we can't just watch for FocusOut events and disable the button before the click.)
self.datasetEdit.textEdited.connect(lambda: self._handleTextEdited(self.datasetEdit))
self.filepathEdit.textEdited.connect(lambda: self._handleTextEdited(self.filepathEdit))
if self.default_extension == ".zarr":
self.datasetLabel.setVisible(False)
self.datasetEdit.setVisible(False)
self.datasetEdit.setEnabled(False)

Check warning on line 49 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L46-L49

Added lines #L46 - L49 were not covered by tests
else:
self.datasetEdit.textEdited.connect(lambda: self._handleTextEdited(self.datasetEdit))

Check warning on line 51 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L51

Added line #L51 was not covered by tests

def initSlots(self, filepathSlot, datasetNameSlot, fullPathOutputSlot):
self._filepathSlot = filepathSlot
Expand All @@ -51,7 +60,7 @@
self.datasetEdit.installEventFilter(self)

def showEvent(self, event):
super(Hdf5ExportFileOptionsWidget, self).showEvent(event)
super().showEvent(event)

Check warning on line 63 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L63

Added line #L63 was not covered by tests
self.updateFromSlots()

def eventFilter(self, watched, event):
Expand Down Expand Up @@ -95,8 +104,8 @@
if self._filepathSlot.ready():
file_path = self._filepathSlot.value
file_path, ext = os.path.splitext(file_path)
if ext != ".h5" and ext != ".hdf5":
file_path += ".h5"
if ext not in self.file_extensions:
file_path += self.default_extension

Check warning on line 108 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L107-L108

Added lines #L107 - L108 were not covered by tests
else:
file_path += ext
self.filepathEdit.setText(file_path)
Expand All @@ -115,9 +124,9 @@
else:
starting_dir = os.path.expanduser("~")

dlg = QFileDialog(self, "Export Location", starting_dir, "HDF5 Files (*.h5 *.hdf5)")
dlg = QFileDialog(self, "Export Location", starting_dir, self.extension_description)

Check warning on line 127 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L127

Added line #L127 was not covered by tests

dlg.setDefaultSuffix("h5")
dlg.setDefaultSuffix(self.default_extension.lstrip("."))

Check warning on line 129 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L129

Added line #L129 was not covered by tests
dlg.setAcceptMode(QFileDialog.AcceptSave)
if not dlg.exec_():
return
Expand Down Expand Up @@ -148,7 +157,7 @@
op = OpMock(graph=Graph())

app = QApplication([])
w = Hdf5ExportFileOptionsWidget(None)
w = HierarchicalFileExportOptionsWidget(None, (".h5",), "H5 Files (*.h5)")

Check warning on line 160 in volumina/widgets/hierarchicalFileExportOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/hierarchicalFileExportOptionsWidget.py#L160

Added line #L160 was not covered by tests
w.initSlots(op.Filepath, op.DatasetName, op.FullPath)
w.show()
app.exec_()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<widget class="QLineEdit" name="filepathEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="datasetLabel">
<property name="text">
<string>Dataset:</string>
</property>
Expand Down
15 changes: 11 additions & 4 deletions volumina/widgets/multiformatSlotExportFileOptionsWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
from PyQt5.QtWidgets import QWidget

from .singleFileExportOptionsWidget import SingleFileExportOptionsWidget
from .hdf5ExportFileOptionsWidget import Hdf5ExportFileOptionsWidget
from .n5ExportFileOptionsWidget import N5ExportFileOptionsWidget
from .hierarchicalFileExportOptionsWidget import HierarchicalFileExportOptionsWidget

Check warning on line 34 in volumina/widgets/multiformatSlotExportFileOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/multiformatSlotExportFileOptionsWidget.py#L34

Added line #L34 was not covered by tests
from .stackExportFileOptionsWidget import StackExportFileOptionsWidget

try:
Expand Down Expand Up @@ -73,7 +72,7 @@

# HDF5
for fmt in ("compressed hdf5", "hdf5"):
hdf5OptionsWidget = Hdf5ExportFileOptionsWidget(self)
hdf5OptionsWidget = HierarchicalFileExportOptionsWidget(self, (".h5", ".hdf5"), "HDF5 files (*.h5 *.hdf5)")

Check warning on line 75 in volumina/widgets/multiformatSlotExportFileOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/multiformatSlotExportFileOptionsWidget.py#L75

Added line #L75 was not covered by tests
hdf5OptionsWidget.initSlots(
opDataExport.OutputFilenameFormat, opDataExport.OutputInternalPath, opDataExport.ExportPath
)
Expand All @@ -82,13 +81,21 @@

# N5
for fmt in ("compressed n5", "n5"):
n5OptionsWidget = N5ExportFileOptionsWidget(self)
n5OptionsWidget = HierarchicalFileExportOptionsWidget(self, (".n5",), "N5 files (*.n5)")

Check warning on line 84 in volumina/widgets/multiformatSlotExportFileOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/multiformatSlotExportFileOptionsWidget.py#L84

Added line #L84 was not covered by tests
n5OptionsWidget.initSlots(
opDataExport.OutputFilenameFormat, opDataExport.OutputInternalPath, opDataExport.ExportPath
)
n5OptionsWidget.pathValidityChange.connect(self._handlePathValidityChange)
self._format_option_editors[fmt] = n5OptionsWidget

# Zarr
zarrOptionsWidget = HierarchicalFileExportOptionsWidget(self, (".zarr",), "Zarr files (*.zarr)")
zarrOptionsWidget.initSlots(

Check warning on line 93 in volumina/widgets/multiformatSlotExportFileOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/multiformatSlotExportFileOptionsWidget.py#L92-L93

Added lines #L92 - L93 were not covered by tests
opDataExport.OutputFilenameFormat, opDataExport.OutputInternalPath, opDataExport.ExportPath
)
zarrOptionsWidget.pathValidityChange.connect(self._handlePathValidityChange)
self._format_option_editors["single-scale OME-Zarr"] = zarrOptionsWidget

Check warning on line 97 in volumina/widgets/multiformatSlotExportFileOptionsWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/multiformatSlotExportFileOptionsWidget.py#L96-L97

Added lines #L96 - L97 were not covered by tests

# Numpy
npyOptionsWidget = SingleFileExportOptionsWidget(self, "npy", "numpy files (*.npy)")
npyOptionsWidget.initSlots(opDataExport.OutputFilenameFormat, opDataExport.ExportPath)
Expand Down
159 changes: 0 additions & 159 deletions volumina/widgets/n5ExportFileOptionsWidget.py

This file was deleted.

67 changes: 0 additions & 67 deletions volumina/widgets/n5ExportFileOptionsWidget.ui

This file was deleted.

Loading