From fd84065fcb0ae28ff301ff1d21fd27b5beab47d8 Mon Sep 17 00:00:00 2001 From: Stelios Tsampas Date: Sun, 23 May 2021 19:38:33 +0300 Subject: [PATCH] Add verify button to not block on every change. Add some behavioral safeguards until thread can be stopped. --- rare/components/dialogs/install_dialog.py | 47 ++++++++++++++------ rare/ui/components/dialogs/install_dialog.py | 4 ++ rare/ui/components/dialogs/install_dialog.ui | 7 +++ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/rare/components/dialogs/install_dialog.py b/rare/components/dialogs/install_dialog.py index fff1b949..b14b8e25 100644 --- a/rare/components/dialogs/install_dialog.py +++ b/rare/components/dialogs/install_dialog.py @@ -2,6 +2,7 @@ import os from multiprocessing import Queue as MPQueue from PyQt5.QtCore import Qt, QObject, QRunnable, QThreadPool, pyqtSignal, pyqtSlot +from PyQt5.QtGui import QCloseEvent from PyQt5.QtWidgets import QDialog, QFileDialog, QCheckBox from custom_legendary.core import LegendaryCore @@ -17,6 +18,7 @@ class InstallDialog(QDialog, Ui_InstallDialog): def __init__(self, core: LegendaryCore, dl_item: InstallQueueItemModel, update=False, parent=None): super(InstallDialog, self).__init__(parent) self.setAttribute(Qt.WA_DeleteOnClose, True) + self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowStaysOnTopHint) self.setupUi(self) self.core = core @@ -42,7 +44,7 @@ class InstallDialog(QDialog, Ui_InstallDialog): self.install_dir_edit = PathEdit(text=default_path, file_type=QFileDialog.DirectoryOnly, - edit_func=self.get_download_info) + edit_func=self.on_option_widget_changed) self.install_dir_layout.addWidget(self.install_dir_edit) if update: @@ -54,11 +56,11 @@ class InstallDialog(QDialog, Ui_InstallDialog): else: max_workers = 0 self.max_workers_spin.setValue(int(max_workers)) - self.max_workers_spin.valueChanged.connect(self.get_download_info) + self.max_workers_spin.valueChanged.connect(self.on_option_widget_changed) - self.force_download_check.stateChanged.connect(self.get_download_info) - self.ignore_space_check.stateChanged.connect(self.get_download_info) - self.download_only_check.stateChanged.connect(self.get_download_info) + self.force_download_check.stateChanged.connect(self.on_option_widget_changed) + self.ignore_space_check.stateChanged.connect(self.on_option_widget_changed) + self.download_only_check.stateChanged.connect(self.on_option_widget_changed) self.sdl_list_checks = list() try: @@ -72,7 +74,7 @@ class InstallDialog(QDialog, Ui_InstallDialog): self.sdl_list_checks.append(cb) self.sdl_list_frame.resize(self.sdl_list_frame.minimumSize()) for cb in self.sdl_list_checks: - cb.stateChanged.connect(self.get_download_info) + cb.stateChanged.connect(self.on_option_widget_changed) except KeyError: self.sdl_list_frame.setVisible(False) self.sdl_list_label.setVisible(False) @@ -80,8 +82,12 @@ class InstallDialog(QDialog, Ui_InstallDialog): self.get_options() self.get_download_info() - self.install_button.clicked.connect(self.on_install_button_clicked) self.cancel_button.clicked.connect(self.on_cancel_button_clicked) + self.verify_button.clicked.connect(self.get_download_info) + self.install_button.clicked.connect(self.on_install_button_clicked) + + self.options_changed = False + self.worker_running = False self.resize(self.minimumSize()) self.setFixedSize(self.size()) @@ -112,20 +118,28 @@ class InstallDialog(QDialog, Ui_InstallDialog): self.download_size_info_label.setStyleSheet("font-style: italic; font-weight: normal") self.install_size_info_label.setText(message) self.install_size_info_label.setStyleSheet("font-style: italic; font-weight: normal") + self.cancel_button.setEnabled(False) + self.verify_button.setEnabled(False) self.install_button.setEnabled(False) - self.sdl_list_frame.setEnabled(False) - self.get_options() + self.options_changed = False + self.worker_running = True info_worker = InstallInfoWorker(self.core, self.dl_item) info_worker.setAutoDelete(True) info_worker.signals.finished.connect(self.on_worker_finished) self.threadpool.start(info_worker) - def on_install_button_clicked(self): + def on_option_widget_changed(self): + self.options_changed = True + self.install_button.setEnabled(False) + self.verify_button.setEnabled(not self.worker_running) + self.get_options() + + def on_cancel_button_clicked(self): + self.dl_item.download = None self.threadpool.clear() self.close() - def on_cancel_button_clicked(self): - self.dl_item = False + def on_install_button_clicked(self): self.threadpool.clear() self.close() @@ -133,6 +147,7 @@ class InstallDialog(QDialog, Ui_InstallDialog): # TODO: Check available size and act accordingly # TODO: (show message in label | color it | disable install unless ignore) # TODO: Find a way to get the installation size delta and show it + self.worker_running = False if dl_item: self.dl_item = dl_item download_size = self.dl_item.download.analysis.dl_size @@ -140,7 +155,7 @@ class InstallDialog(QDialog, Ui_InstallDialog): if download_size: self.download_size_info_label.setText("{}".format(get_size(download_size))) self.download_size_info_label.setStyleSheet("font-style: normal; font-weight: bold") - self.install_button.setEnabled(True) + self.install_button.setEnabled(not self.options_changed) else: self.install_size_info_label.setText(self.tr("Game already installed")) self.install_size_info_label.setStyleSheet("font-style: italics; font-weight: normal") @@ -149,8 +164,14 @@ class InstallDialog(QDialog, Ui_InstallDialog): else: self.download_size_info_label.setText("Error") self.install_size_info_label.setText("Error") + self.verify_button.setEnabled(self.options_changed) + self.cancel_button.setEnabled(True) self.sdl_list_frame.setEnabled(True) + def closeEvent(self, a0: QCloseEvent) -> None: + self.threadpool.waitForDone() + self.on_cancel_button_clicked() + class InstallInfoWorkerSignals(QObject): finished = pyqtSignal(InstallQueueItemModel) diff --git a/rare/ui/components/dialogs/install_dialog.py b/rare/ui/components/dialogs/install_dialog.py index 467d4f4c..533703f8 100644 --- a/rare/ui/components/dialogs/install_dialog.py +++ b/rare/ui/components/dialogs/install_dialog.py @@ -27,6 +27,9 @@ class Ui_InstallDialog(object): self.cancel_button = QtWidgets.QPushButton(InstallDialog) self.cancel_button.setObjectName("cancel_button") self.button_layout.addWidget(self.cancel_button) + self.verify_button = QtWidgets.QPushButton(InstallDialog) + self.verify_button.setObjectName("verify_button") + self.button_layout.addWidget(self.verify_button) self.install_button = QtWidgets.QPushButton(InstallDialog) self.install_button.setObjectName("install_button") self.button_layout.addWidget(self.install_button) @@ -115,6 +118,7 @@ class Ui_InstallDialog(object): _translate = QtCore.QCoreApplication.translate self.force_download_label.setText(_translate("InstallDialog", "Force download")) self.cancel_button.setText(_translate("InstallDialog", "Cancel")) + self.verify_button.setText(_translate("InstallDialog", "Verify")) self.install_button.setText(_translate("InstallDialog", "Install")) self.ignore_space_info_label.setText(_translate("InstallDialog", "Use with caution!")) self.install_dir_label.setText(_translate("InstallDialog", "Install directory")) diff --git a/rare/ui/components/dialogs/install_dialog.ui b/rare/ui/components/dialogs/install_dialog.ui index b8a26ba1..0484cd82 100644 --- a/rare/ui/components/dialogs/install_dialog.ui +++ b/rare/ui/components/dialogs/install_dialog.ui @@ -35,6 +35,13 @@ + + + + Verify + + +