Add verify button to not block on every change.
Add some behavioral safeguards until thread can be stopped.
This commit is contained in:
parent
181636f2be
commit
fd84065fcb
3 changed files with 45 additions and 13 deletions
|
@ -2,6 +2,7 @@ import os
|
||||||
from multiprocessing import Queue as MPQueue
|
from multiprocessing import Queue as MPQueue
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, QObject, QRunnable, QThreadPool, pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import Qt, QObject, QRunnable, QThreadPool, pyqtSignal, pyqtSlot
|
||||||
|
from PyQt5.QtGui import QCloseEvent
|
||||||
from PyQt5.QtWidgets import QDialog, QFileDialog, QCheckBox
|
from PyQt5.QtWidgets import QDialog, QFileDialog, QCheckBox
|
||||||
|
|
||||||
from custom_legendary.core import LegendaryCore
|
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):
|
def __init__(self, core: LegendaryCore, dl_item: InstallQueueItemModel, update=False, parent=None):
|
||||||
super(InstallDialog, self).__init__(parent)
|
super(InstallDialog, self).__init__(parent)
|
||||||
self.setAttribute(Qt.WA_DeleteOnClose, True)
|
self.setAttribute(Qt.WA_DeleteOnClose, True)
|
||||||
|
self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowStaysOnTopHint)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
self.core = core
|
self.core = core
|
||||||
|
@ -42,7 +44,7 @@ class InstallDialog(QDialog, Ui_InstallDialog):
|
||||||
|
|
||||||
self.install_dir_edit = PathEdit(text=default_path,
|
self.install_dir_edit = PathEdit(text=default_path,
|
||||||
file_type=QFileDialog.DirectoryOnly,
|
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)
|
self.install_dir_layout.addWidget(self.install_dir_edit)
|
||||||
|
|
||||||
if update:
|
if update:
|
||||||
|
@ -54,11 +56,11 @@ class InstallDialog(QDialog, Ui_InstallDialog):
|
||||||
else:
|
else:
|
||||||
max_workers = 0
|
max_workers = 0
|
||||||
self.max_workers_spin.setValue(int(max_workers))
|
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.force_download_check.stateChanged.connect(self.on_option_widget_changed)
|
||||||
self.ignore_space_check.stateChanged.connect(self.get_download_info)
|
self.ignore_space_check.stateChanged.connect(self.on_option_widget_changed)
|
||||||
self.download_only_check.stateChanged.connect(self.get_download_info)
|
self.download_only_check.stateChanged.connect(self.on_option_widget_changed)
|
||||||
|
|
||||||
self.sdl_list_checks = list()
|
self.sdl_list_checks = list()
|
||||||
try:
|
try:
|
||||||
|
@ -72,7 +74,7 @@ class InstallDialog(QDialog, Ui_InstallDialog):
|
||||||
self.sdl_list_checks.append(cb)
|
self.sdl_list_checks.append(cb)
|
||||||
self.sdl_list_frame.resize(self.sdl_list_frame.minimumSize())
|
self.sdl_list_frame.resize(self.sdl_list_frame.minimumSize())
|
||||||
for cb in self.sdl_list_checks:
|
for cb in self.sdl_list_checks:
|
||||||
cb.stateChanged.connect(self.get_download_info)
|
cb.stateChanged.connect(self.on_option_widget_changed)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.sdl_list_frame.setVisible(False)
|
self.sdl_list_frame.setVisible(False)
|
||||||
self.sdl_list_label.setVisible(False)
|
self.sdl_list_label.setVisible(False)
|
||||||
|
@ -80,8 +82,12 @@ class InstallDialog(QDialog, Ui_InstallDialog):
|
||||||
self.get_options()
|
self.get_options()
|
||||||
self.get_download_info()
|
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.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.resize(self.minimumSize())
|
||||||
self.setFixedSize(self.size())
|
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.download_size_info_label.setStyleSheet("font-style: italic; font-weight: normal")
|
||||||
self.install_size_info_label.setText(message)
|
self.install_size_info_label.setText(message)
|
||||||
self.install_size_info_label.setStyleSheet("font-style: italic; font-weight: normal")
|
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.install_button.setEnabled(False)
|
||||||
self.sdl_list_frame.setEnabled(False)
|
self.options_changed = False
|
||||||
self.get_options()
|
self.worker_running = True
|
||||||
info_worker = InstallInfoWorker(self.core, self.dl_item)
|
info_worker = InstallInfoWorker(self.core, self.dl_item)
|
||||||
info_worker.setAutoDelete(True)
|
info_worker.setAutoDelete(True)
|
||||||
info_worker.signals.finished.connect(self.on_worker_finished)
|
info_worker.signals.finished.connect(self.on_worker_finished)
|
||||||
self.threadpool.start(info_worker)
|
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.threadpool.clear()
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def on_cancel_button_clicked(self):
|
def on_install_button_clicked(self):
|
||||||
self.dl_item = False
|
|
||||||
self.threadpool.clear()
|
self.threadpool.clear()
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
@ -133,6 +147,7 @@ class InstallDialog(QDialog, Ui_InstallDialog):
|
||||||
# TODO: Check available size and act accordingly
|
# TODO: Check available size and act accordingly
|
||||||
# TODO: (show message in label | color it | disable install unless ignore)
|
# TODO: (show message in label | color it | disable install unless ignore)
|
||||||
# TODO: Find a way to get the installation size delta and show it
|
# TODO: Find a way to get the installation size delta and show it
|
||||||
|
self.worker_running = False
|
||||||
if dl_item:
|
if dl_item:
|
||||||
self.dl_item = dl_item
|
self.dl_item = dl_item
|
||||||
download_size = self.dl_item.download.analysis.dl_size
|
download_size = self.dl_item.download.analysis.dl_size
|
||||||
|
@ -140,7 +155,7 @@ class InstallDialog(QDialog, Ui_InstallDialog):
|
||||||
if download_size:
|
if download_size:
|
||||||
self.download_size_info_label.setText("{}".format(get_size(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.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:
|
else:
|
||||||
self.install_size_info_label.setText(self.tr("Game already installed"))
|
self.install_size_info_label.setText(self.tr("Game already installed"))
|
||||||
self.install_size_info_label.setStyleSheet("font-style: italics; font-weight: normal")
|
self.install_size_info_label.setStyleSheet("font-style: italics; font-weight: normal")
|
||||||
|
@ -149,8 +164,14 @@ class InstallDialog(QDialog, Ui_InstallDialog):
|
||||||
else:
|
else:
|
||||||
self.download_size_info_label.setText("Error")
|
self.download_size_info_label.setText("Error")
|
||||||
self.install_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)
|
self.sdl_list_frame.setEnabled(True)
|
||||||
|
|
||||||
|
def closeEvent(self, a0: QCloseEvent) -> None:
|
||||||
|
self.threadpool.waitForDone()
|
||||||
|
self.on_cancel_button_clicked()
|
||||||
|
|
||||||
|
|
||||||
class InstallInfoWorkerSignals(QObject):
|
class InstallInfoWorkerSignals(QObject):
|
||||||
finished = pyqtSignal(InstallQueueItemModel)
|
finished = pyqtSignal(InstallQueueItemModel)
|
||||||
|
|
|
@ -27,6 +27,9 @@ class Ui_InstallDialog(object):
|
||||||
self.cancel_button = QtWidgets.QPushButton(InstallDialog)
|
self.cancel_button = QtWidgets.QPushButton(InstallDialog)
|
||||||
self.cancel_button.setObjectName("cancel_button")
|
self.cancel_button.setObjectName("cancel_button")
|
||||||
self.button_layout.addWidget(self.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 = QtWidgets.QPushButton(InstallDialog)
|
||||||
self.install_button.setObjectName("install_button")
|
self.install_button.setObjectName("install_button")
|
||||||
self.button_layout.addWidget(self.install_button)
|
self.button_layout.addWidget(self.install_button)
|
||||||
|
@ -115,6 +118,7 @@ class Ui_InstallDialog(object):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_translate = QtCore.QCoreApplication.translate
|
||||||
self.force_download_label.setText(_translate("InstallDialog", "Force download"))
|
self.force_download_label.setText(_translate("InstallDialog", "Force download"))
|
||||||
self.cancel_button.setText(_translate("InstallDialog", "Cancel"))
|
self.cancel_button.setText(_translate("InstallDialog", "Cancel"))
|
||||||
|
self.verify_button.setText(_translate("InstallDialog", "Verify"))
|
||||||
self.install_button.setText(_translate("InstallDialog", "Install"))
|
self.install_button.setText(_translate("InstallDialog", "Install"))
|
||||||
self.ignore_space_info_label.setText(_translate("InstallDialog", "Use with caution!"))
|
self.ignore_space_info_label.setText(_translate("InstallDialog", "Use with caution!"))
|
||||||
self.install_dir_label.setText(_translate("InstallDialog", "Install directory"))
|
self.install_dir_label.setText(_translate("InstallDialog", "Install directory"))
|
||||||
|
|
|
@ -35,6 +35,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="verify_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Verify</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="install_button">
|
<widget class="QPushButton" name="install_button">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
Loading…
Reference in a new issue