Skip to content

Commit

Permalink
Merge pull request #316 from btbest/ome-zarr-export
Browse files Browse the repository at this point in the history
Add export option for single-scale OME-Zarr
  • Loading branch information
btbest authored Oct 15, 2024
2 parents d7e1d54 + 5292923 commit 7d58143
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 242 deletions.
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

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


class Hdf5ExportFileOptionsWidget(QWidget):
class HierarchicalFileExportOptionsWidget(QWidget):
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)
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

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)
else:
self.datasetEdit.textEdited.connect(lambda: self._handleTextEdited(self.datasetEdit))

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

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

def eventFilter(self, watched, event):
Expand Down Expand Up @@ -95,8 +104,8 @@ def updateFromSlots(self):
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
else:
file_path += ext
self.filepathEdit.setText(file_path)
Expand All @@ -115,9 +124,9 @@ def _browseForFilepath(self):
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)

dlg.setDefaultSuffix("h5")
dlg.setDefaultSuffix(self.default_extension.lstrip("."))
dlg.setAcceptMode(QFileDialog.AcceptSave)
if not dlg.exec_():
return
Expand Down Expand Up @@ -148,7 +157,7 @@ def propagateDirty(self, *args):
op = OpMock(graph=Graph())

app = QApplication([])
w = Hdf5ExportFileOptionsWidget(None)
w = HierarchicalFileExportOptionsWidget(None, (".h5",), "H5 Files (*.h5)")
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
from .stackExportFileOptionsWidget import StackExportFileOptionsWidget

try:
Expand Down Expand Up @@ -73,7 +72,7 @@ def initExportOp(self, opDataExport):

# HDF5
for fmt in ("compressed hdf5", "hdf5"):
hdf5OptionsWidget = Hdf5ExportFileOptionsWidget(self)
hdf5OptionsWidget = HierarchicalFileExportOptionsWidget(self, (".h5", ".hdf5"), "HDF5 files (*.h5 *.hdf5)")
hdf5OptionsWidget.initSlots(
opDataExport.OutputFilenameFormat, opDataExport.OutputInternalPath, opDataExport.ExportPath
)
Expand All @@ -82,13 +81,21 @@ def initExportOp(self, opDataExport):

# N5
for fmt in ("compressed n5", "n5"):
n5OptionsWidget = N5ExportFileOptionsWidget(self)
n5OptionsWidget = HierarchicalFileExportOptionsWidget(self, (".n5",), "N5 files (*.n5)")
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(
opDataExport.OutputFilenameFormat, opDataExport.OutputInternalPath, opDataExport.ExportPath
)
zarrOptionsWidget.pathValidityChange.connect(self._handlePathValidityChange)
self._format_option_editors["single-scale OME-Zarr"] = zarrOptionsWidget

# 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.

0 comments on commit 7d58143

Please sign in to comment.