UninstallDialog: Refactor to use ButtonDialog as base
This commit is contained in:
parent
4e0f3ab59c
commit
d3ec79378e
|
@ -1,81 +1,57 @@
|
|||
from PyQt5.QtCore import Qt, pyqtSignal, QCoreApplication
|
||||
from PyQt5.QtGui import QCloseEvent, QKeyEvent
|
||||
from PyQt5.QtCore import pyqtSignal
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialog,
|
||||
QLabel,
|
||||
QVBoxLayout,
|
||||
QCheckBox,
|
||||
QHBoxLayout,
|
||||
QPushButton, QLayout,
|
||||
)
|
||||
from legendary.utils.selective_dl import get_sdl_appname
|
||||
|
||||
from rare.models.game import RareGame
|
||||
from rare.models.install import UninstallOptionsModel
|
||||
from rare.utils.misc import icon
|
||||
from rare.widgets.dialogs import ButtonDialog, dialog_title_game
|
||||
|
||||
|
||||
class UninstallDialog(QDialog):
|
||||
class UninstallDialog(ButtonDialog):
|
||||
result_ready = pyqtSignal(UninstallOptionsModel)
|
||||
|
||||
def __init__(self, rgame: RareGame, options: UninstallOptionsModel, parent=None):
|
||||
super(UninstallDialog, self).__init__(parent=parent)
|
||||
self.setAttribute(Qt.WA_DeleteOnClose, True)
|
||||
self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint)
|
||||
header = self.tr("Uninstall")
|
||||
self.setWindowTitle(f'{header} "{rgame.app_title}" - {QCoreApplication.instance().applicationName()}')
|
||||
self.title_label = QLabel(
|
||||
self.tr("<h4>Do you really want to uninstall <b>{}</b>?</h4>").format(rgame.app_title)
|
||||
)
|
||||
self.setWindowTitle(dialog_title_game(header, rgame.app_title))
|
||||
|
||||
self.keep_files = QCheckBox(self.tr("Keep game files."))
|
||||
title_label = QLabel(f"<h4>{dialog_title_game(header, rgame.app_title)}</h4>", self)
|
||||
|
||||
self.keep_files = QCheckBox(self.tr("Keep files"))
|
||||
self.keep_files.setChecked(bool(options.keep_files))
|
||||
self.keep_config = QCheckBox(self.tr("Keep game configuation."))
|
||||
|
||||
self.keep_config = QCheckBox(self.tr("Keep configuation"))
|
||||
self.keep_config.setChecked(bool(options.keep_config))
|
||||
|
||||
self.uninstall_button = QPushButton(
|
||||
icon("ei.remove-circle", color="red"), self.tr("Uninstall")
|
||||
)
|
||||
self.uninstall_button.setObjectName("UninstallButton")
|
||||
self.uninstall_button.clicked.connect(self.__on_uninstall)
|
||||
layout = QVBoxLayout()
|
||||
layout.addWidget(title_label)
|
||||
layout.addWidget(self.keep_files)
|
||||
layout.addWidget(self.keep_config)
|
||||
|
||||
self.cancel_button = QPushButton(self.tr("Cancel"))
|
||||
self.cancel_button.clicked.connect(self.__on_cancel)
|
||||
self.setCentralLayout(layout)
|
||||
|
||||
form_layout = QVBoxLayout()
|
||||
form_layout.setContentsMargins(-1, -1, 0, -1)
|
||||
form_layout.addWidget(self.keep_files)
|
||||
form_layout.addWidget(self.keep_config)
|
||||
|
||||
button_layout = QHBoxLayout()
|
||||
button_layout.addWidget(self.cancel_button)
|
||||
button_layout.addStretch(1)
|
||||
button_layout.addWidget(self.uninstall_button)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setSizeConstraint(QLayout.SetFixedSize)
|
||||
layout.addWidget(self.title_label)
|
||||
layout.addLayout(form_layout)
|
||||
layout.addLayout(button_layout)
|
||||
self.accept_button.setText(self.tr("Uninstall"))
|
||||
self.accept_button.setIcon(icon("ri.uninstall-line"))
|
||||
self.accept_button.setObjectName("UninstallButton")
|
||||
|
||||
if rgame.sdl_name is not None:
|
||||
self.keep_config.setChecked(True)
|
||||
|
||||
self.options: UninstallOptionsModel = options
|
||||
|
||||
def closeEvent(self, a0: QCloseEvent) -> None:
|
||||
def done_handler(self) -> None:
|
||||
self.result_ready.emit(self.options)
|
||||
super(UninstallDialog, self).closeEvent(a0)
|
||||
|
||||
def __on_uninstall(self):
|
||||
self.options.values = (True, self.keep_files.isChecked(), self.keep_config.isChecked())
|
||||
self.close()
|
||||
def accept_handler(self):
|
||||
self.options.values = (
|
||||
True,
|
||||
self.keep_files.isChecked(),
|
||||
self.keep_config.isChecked(),
|
||||
)
|
||||
|
||||
def __on_cancel(self):
|
||||
def reject_handler(self):
|
||||
self.options.values = (None, None, None)
|
||||
self.close()
|
||||
|
||||
def keyPressEvent(self, e: QKeyEvent) -> None:
|
||||
if e.key() == Qt.Key_Escape:
|
||||
e.accept()
|
||||
self.__on_cancel()
|
||||
|
|
|
@ -330,7 +330,7 @@ class DownloadsTab(QWidget):
|
|||
parent=self,
|
||||
)
|
||||
uninstall_dialog.result_ready.connect(self.__on_uninstall_dialog_closed)
|
||||
uninstall_dialog.exec()
|
||||
uninstall_dialog.open()
|
||||
|
||||
@pyqtSlot(UninstallOptionsModel)
|
||||
def __on_uninstall_dialog_closed(self, options: UninstallOptionsModel):
|
||||
|
|
Loading…
Reference in a new issue