From bd083753e431cec9689cbcac3cde2aebc82457e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Fri, 19 Jan 2024 17:31:17 +0100 Subject: [PATCH] feat: allow to specify an output directory in the GUI (close #3) --- CHANGELOG | 5 ++-- chipstream/gui/main_window.py | 52 +++++++++++++++++++++++++++++++++++ chipstream/gui/main_window.ui | 7 ++--- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a08f942..29998bd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ 0.2.0 - - feat: allow to select pixel size in GUI (#4) - - feat: introduce PathCache for rememering previous output directories + - feat: allow to specify an output directory in the GUI (#3) + - feat: allow to select the pixel size in the GUI (#4) + - feat: introduce PathCache for remembering previous output directories - ref: support latest dcnum version - ci: do not build mac app during checks 0.1.9 diff --git a/chipstream/gui/main_window.py b/chipstream/gui/main_window.py index fcdb7f7..8eb5951 100644 --- a/chipstream/gui/main_window.py +++ b/chipstream/gui/main_window.py @@ -1,3 +1,4 @@ +import atexit from importlib import import_module, resources import inspect import logging @@ -10,7 +11,9 @@ from dcnum.feat import feat_background from PyQt6 import uic, QtCore, QtWidgets +from PyQt6.QtCore import QStandardPaths +from ..path_cache import PathCache from .._version import version from . import splash @@ -73,6 +76,20 @@ def __init__(self, *arguments): # Command button self.commandLinkButton_run.clicked.connect(self.on_run) + # Path selection + cache_loc = pathlib.Path( + QStandardPaths.writableLocation( + QStandardPaths.StandardLocation.CacheLocation)) + cache_loc.mkdir(parents=True, exist_ok=True) + self.path_cache = PathCache(cache_loc / "output_paths.txt") + atexit.register(self.path_cache.cleanup) + self.comboBox_output.clear() + self.comboBox_output.addItem("Output alongside input files", "input") + for ii, path in enumerate(self.path_cache): + self.comboBox_output.addItem(str(path), ii) + self.comboBox_output.addItem("Select output directory", "new") + self.comboBox_output.currentIndexChanged.connect(self.on_path_out) + # Signals self.run_completed.connect(self.on_run_completed) self.tableView_input.row_selected.connect(self.on_select_job) @@ -232,6 +249,41 @@ def on_action_quit(self) -> None: """Determine what happens when the user wants to quit""" QtCore.QCoreApplication.quit() + @QtCore.pyqtSlot() + def on_path_out(self): + data = self.comboBox_output.currentData() + if data == "input": + # Store output data alongside input data + self.manager.set_output_path(None) + elif data == "new": + # New output path + default = "." if len(self.path_cache) == 0 else self.path_cache[-1] + # Open a directory selection dialog + path = QtWidgets.QFileDialog.getExistingDirectory( + self, + "Choose data output directory", + str(default), + ) + self.comboBox_output.blockSignals(True) + if path and pathlib.Path(path).exists(): + self.comboBox_output.insertItem( + len(self.path_cache) + 1, # index in combobox + path, + len(self.path_cache), # user data == index in path_cache + ) + self.comboBox_output.setCurrentIndex(len(self.path_cache) + 1) + self.path_cache.add_path(pathlib.Path(path)) + self.manager.set_output_path(path) + else: + # User pressed cancel + self.comboBox_output.setCurrentIndex(0) + self.manager.set_output_path(None) + self.comboBox_output.blockSignals(False) + else: + # Data is an integer index for `self.path_cache` + self.manager.set_output_path(self.path_cache[data]) + print(self.manager._path_out) + @QtCore.pyqtSlot() def on_run(self): """Run the analysis""" diff --git a/chipstream/gui/main_window.ui b/chipstream/gui/main_window.ui index 1405ec5..64b76be 100644 --- a/chipstream/gui/main_window.ui +++ b/chipstream/gui/main_window.ui @@ -296,13 +296,10 @@ - - - false - + - Output to input directory + Output alongside input files