Skip to content

Commit

Permalink
feat: allow to specify an output directory in the GUI (close #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 19, 2024
1 parent 44487d7 commit bd08375
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
52 changes: 52 additions & 0 deletions chipstream/gui/main_window.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import atexit
from importlib import import_module, resources
import inspect
import logging
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"""
Expand Down
7 changes: 2 additions & 5 deletions chipstream/gui/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,10 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<property name="enabled">
<bool>false</bool>
</property>
<widget class="QComboBox" name="comboBox_output">
<item>
<property name="text">
<string>Output to input directory</string>
<string>Output alongside input files</string>
</property>
</item>
<item>
Expand Down

0 comments on commit bd08375

Please sign in to comment.