From 445285e350bbfc65c72a358bdf5bc84abd9ac03b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Thu, 30 Nov 2023 11:27:11 +0100 Subject: [PATCH] enh: display currently processed file in GUI --- CHANGELOG | 1 + mpl_data_cast/gui/main.py | 31 ++++++++----------------------- mpl_data_cast/gui/main.ui | 7 +++++++ mpl_data_cast/recipe.py | 7 ++++--- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2e6e7c2..8408370 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ 0.6.0 - feat: generalize GUI to use all recipes - enh: prevent GUI from locking when transferring large file + - enh: display currently processed file in GUI - enh: re-use tree count information for transfer progress bar - enh: display the actual directory tree instead of a table - enh: compute file hash while copying, avoiding reading data twice diff --git a/mpl_data_cast/gui/main.py b/mpl_data_cast/gui/main.py index c56503e..b57e081 100644 --- a/mpl_data_cast/gui/main.py +++ b/mpl_data_cast/gui/main.py @@ -5,7 +5,6 @@ import sys import threading import traceback -from typing import Dict import dclab import h5py @@ -153,9 +152,9 @@ def on_task_transfer(self) -> None: self.widget_output.path) tree_counter = self.widget_input.tree_counter - with CastingCallback(self, tree_counter) as callback: + with CastingCallback(self, tree_counter) as path_callback: # run the casting operation in a separate thread - caster = CastingThread(rp, callback=callback) + caster = CastingThread(rp, path_callback=path_callback) caster.start() while not caster.result: @@ -198,10 +197,8 @@ def __init__(self, tree_counter: widget_tree.TreeObjectCounter): self.gui = gui self.counter = 0 - #: This is a thread running in the background, counting all files. + #: This is a thread running in the background, counting recipe files. self.tree_counter = tree_counter - self.size = 0 - self.time_start = time.monotonic() def __enter__(self): return self @@ -210,7 +207,8 @@ def __exit__(self, exc_type, exc_val, exc_tb): pass def __call__(self, path) -> None: - self.size += path.stat().st_size + # Let the user know how far we are + self.gui.label_file.setText(f"Processing {path}...") if self.tree_counter.has_counted: self.gui.progressBar.setRange(0, 100) @@ -224,14 +222,14 @@ def __call__(self, path) -> None: class CastingThread(threading.Thread): - def __init__(self, rp, callback, *args, **kwargs): + def __init__(self, rp, path_callback, *args, **kwargs): super(CastingThread, self).__init__(*args, **kwargs) self.rp = rp - self.callback = callback + self.path_callback = path_callback self.result = {} def run(self): - self.result = self.rp.cast(callback=self.callback) + self.result = self.rp.cast(path_callback=self.path_callback) def excepthook(etype, value, trace) -> None: @@ -265,19 +263,6 @@ def excepthook(etype, value, trace) -> None: cb.setText(exception) -def error(message: str, info: str = "", details: str = "") -> None: - """Shows a little window for error messages.""" - msg = QtWidgets.QMessageBox() - msg.setIcon(QtWidgets.QMessageBox.Icon.Critical) - msg.setWindowTitle("Errors occured") - msg.setText(message) - if info: - msg.setInformativeText(info) - if details: - msg.setDetailedText(details) - msg.exec() - - # Make Ctr+C close the app signal.signal(signal.SIGINT, signal.SIG_DFL) diff --git a/mpl_data_cast/gui/main.ui b/mpl_data_cast/gui/main.ui index f322e00..afb8ca8 100644 --- a/mpl_data_cast/gui/main.ui +++ b/mpl_data_cast/gui/main.ui @@ -114,6 +114,13 @@ + + + + + + + diff --git a/mpl_data_cast/recipe.py b/mpl_data_cast/recipe.py index b849495..1926e14 100644 --- a/mpl_data_cast/recipe.py +++ b/mpl_data_cast/recipe.py @@ -75,7 +75,8 @@ def cast(self, path_callback: Callable = None, **kwargs) -> dict: targ_path = self.get_target_path(path_list) temp_path = self.get_temp_path(path_list) try: - self.convert_dataset(path_list=path_list, temp_path=temp_path, + self.convert_dataset(path_list=path_list, + temp_path=temp_path, **kwargs) except BaseException: errors.append((path_list[0], traceback.format_exc())) @@ -223,9 +224,9 @@ def transfer_to_target_path(temp_path: pathlib.Path, hash_input = copyhashfile(temp_path, target_path) else: shutil.copy2(temp_path, target_path) - # compute md5hash of target path + # compute md5 hash of target path hash_cp = hashfile(target_path) - # compare md5hashes (verification) + # compare md5 hashes (verification) success = hash_input == hash_cp if not success: # Since we copied the wrong file, we are responsible for