Skip to content

Commit

Permalink
enh: display currently processed file in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Nov 30, 2023
1 parent 191ea58 commit 445285e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
1 change: 1 addition & 0 deletions 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
Expand Down
31 changes: 8 additions & 23 deletions mpl_data_cast/gui/main.py
Expand Up @@ -5,7 +5,6 @@
import sys
import threading
import traceback
from typing import Dict

import dclab
import h5py
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions mpl_data_cast/gui/main.ui
Expand Up @@ -114,6 +114,13 @@
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_file">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
Expand Down
7 changes: 4 additions & 3 deletions mpl_data_cast/recipe.py
Expand Up @@ -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()))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 445285e

Please sign in to comment.