Skip to content

Commit

Permalink
ref: minor UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Nov 30, 2023
1 parent 6c86837 commit f0adbd7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 54 deletions.
20 changes: 9 additions & 11 deletions mpl_data_cast/gui/__main__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
def main():
import os
import pkg_resources
from importlib import resources
import sys
from PyQt6 import QtWidgets, QtCore, QtGui

from PyQt6.QtWidgets import QApplication
from .main import MPLDataCast

app = QApplication(sys.argv)
imdir = pkg_resources.resource_filename("mpl_data_cast", "img")
app = QtWidgets.QApplication(sys.argv)
ref_ico = resources.files("mpl_data_cast.gui.img") / "mpldc_icon.png"
with resources.as_file(ref_ico) as path_icon:
app.setWindowIcon(QtGui.QIcon(str(path_icon)))

from PyQt6 import QtGui
from mpl_data_cast.gui import MPLDataCast

# Set Application Icon
icon_path = os.path.join(imdir, "mpldc_icon.png")
app.setWindowIcon(QtGui.QIcon(icon_path))
# Use dots as decimal separators
QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.c()))

window = MPLDataCast() # noqa: F841

Expand Down
7 changes: 2 additions & 5 deletions mpl_data_cast/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ def on_action_preferences(self):
dlg = preferences.Preferences(self)
dlg.setWindowTitle("MPL-Data-Cast Preferences")
dlg.exec()
# update maximum tree depth
self.widget_output.tree_depth_limit = int(self.settings.value(
"main/tree_depth_limit", 8))
self.widget_input.tree_depth_limit = int(self.settings.value(
"main/tree_depth_limit", 8))
# set default output path
self.widget_output.path = self.settings.value("main/output_path",
pathlib.Path.home())

Expand Down Expand Up @@ -147,6 +143,7 @@ def on_task_transfer(self) -> None:
nb_files += 1
with Callback(self, nb_files) as path_callback:
result = rp.cast(path_callback=path_callback)
self.widget_output.trigger_recount_objects()
if result["success"]:
self.progressBar.setValue(100)
QtWidgets.QMessageBox.information(self, "Transfer completed",
Expand Down
11 changes: 6 additions & 5 deletions mpl_data_cast/gui/preferences.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from importlib import resources
import pathlib
import pkg_resources
import warnings

from PyQt6 import uic, QtCore, QtWidgets
Expand All @@ -13,17 +13,18 @@ class Preferences(QtWidgets.QDialog):

def __init__(self, parent, *args, **kwargs):
QtWidgets.QWidget.__init__(self, parent=parent, *args, **kwargs)
path_ui = pkg_resources.resource_filename(
"mpl_data_cast.gui", "preferences.ui")
uic.loadUi(path_ui, self)

ref_ui = resources.files("mpl_data_cast.gui") / "preferences.ui"
with resources.as_file(ref_ui) as path_ui:
uic.loadUi(path_ui, self)

self.settings = QtCore.QSettings()
self.parent = parent

#: configuration keys, corresponding widgets, and defaults
self.config_pairs = [
["main/output_path", self.lineEdit_output_path,
pathlib.Path.home()],
["main/tree_depth_limit", self.spinBox_tree_depth_limit, 3],
]
self.reload()

Expand Down
26 changes: 3 additions & 23 deletions mpl_data_cast/gui/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0">
<widget class="QLabel" name="label">
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_output_path">
<property name="text">
<string>Maximum depth of file tree to display:</string>
<string>Select directory</string>
</property>
</widget>
</item>
Expand All @@ -52,26 +52,6 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_output_path">
<property name="text">
<string>Select directory</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QSpinBox" name="spinBox_tree_depth_limit">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>24</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
38 changes: 28 additions & 10 deletions mpl_data_cast/gui/widget_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ def __init__(self, *args, **kwargs):
self.num_objects = 0
self.size_objects = 0
self.must_break = False
self.abort_current_count = False
self.is_counting = False
self.has_counted = False
self.lock = threading.Lock()

def reset(self):
with self.lock:
self.abort_current_count = True
self.num_objects = 0
self.size_objects = 0
self.has_counted = False
self.is_counting = False

def run(self):
recipe = self.recipe
Expand Down Expand Up @@ -62,23 +72,29 @@ def run(self):
if (self.must_break
or recipe != self.recipe or path != self.path):
self.num_objects = 0
self.size_objects = 0
break
try:
item = next(tree_iterator)
except StopIteration:
self.has_counted = True
break
except BaseException:
# Windows might encounter PermissionError.
pass
else:
self.num_objects += 1
try:
self.size_objects += sum(
[it.stat().st_size for it in item])
except BaseException:
pass
self.is_counting = False
self.has_counted = True
with self.lock:
# check before incrementing
if self.abort_current_count:
self.abort_current_count = False
break
self.num_objects += 1
try:
self.size_objects += sum(
[it.stat().st_size for it in item])
except BaseException:
pass
self.is_counting = False
time.sleep(0.5)


Expand Down Expand Up @@ -121,8 +137,6 @@ def __init__(self,
self.groupBox.setTitle(self.which.capitalize())
self.pushButton_dir.setText(f"Select {self.which} directory")
self.settings = QtCore.QSettings()
self.tree_depth_limit = int(self.settings.value(
"main/tree_depth_limit", 3))

self.pushButton_dir.clicked.connect(
self.on_tree_browse_button)
Expand Down Expand Up @@ -209,6 +223,10 @@ def on_update_object_count(self):
label = f"{objects} objects ({size_str})"
self.label_objects.setText(label)

@QtCore.pyqtSlot()
def trigger_recount_objects(self):
self.tree_counter.reset()


def human_size(bt, units=None):
"""Return a human-eadable string representation of bytes """
Expand Down

0 comments on commit f0adbd7

Please sign in to comment.