1
0
Fork 0
mirror of synced 2024-06-23 08:40:45 +12:00

Add verify button to not block on every change.

Add some behavioral safeguards until thread can be stopped.
This commit is contained in:
Stelios Tsampas 2021-05-23 19:38:33 +03:00
parent 181636f2be
commit fd84065fcb
3 changed files with 45 additions and 13 deletions

View file

@ -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)

View file

@ -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"))

View file

@ -35,6 +35,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="verify_button">
<property name="text">
<string>Verify</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="install_button">
<property name="text">