0ea4b1a824
Also add a dialog to select optional downloads before verifying and refactor the move widget into a full-fledged dialog. To keep dialogs in a common format and allow them to share the same properties, three classes of dialogs have been implemented inheriting from each other. The classes are `BaseDialog` -> `ButtonDialog` -> `ActionDialog` * Basedialog: is the basis of all dialogs and is responsible for rejecting close requests from the window manager and the keyboard. It also restricts access to `exec()` and `exec_()` because they are harmful. It serves as the basis of Launch and Login dialogs * ButtonDialog: is offering buttons for accepting or rejecting the presented option. It implements its own buttons and exposes abstract methods to implement handling in them. It restricts access to `close()` because these dialogs should always product a result. It is the basis of Uninstall, Selective dialogs. * ActionDialog: in addition to the ButtonDialog, it offers an action buttom with to validate the form or to make the dialog unable to close. It serves as the basis of Install and Move dialogs. Accordingly all dialogs in Rare have been updated to use these classes.
91 lines
3.4 KiB
Python
91 lines
3.4 KiB
Python
import os
|
|
import shutil
|
|
from typing import Tuple, Type, TypeVar
|
|
|
|
from PyQt5.QtCore import Qt, pyqtSlot
|
|
from PyQt5.QtGui import QShowEvent
|
|
from PyQt5.QtWidgets import QCheckBox, QFileDialog, QFormLayout, QVBoxLayout, QGroupBox
|
|
|
|
from rare.shared import LegendaryCoreSingleton
|
|
import rare.utils.config_helper as config
|
|
from rare.widgets.indicator_edit import PathEdit, IndicatorReasonsCommon
|
|
from .wrappers import WrapperSettings
|
|
|
|
|
|
class LaunchSettingsBase(QGroupBox):
|
|
|
|
def __init__(
|
|
self,
|
|
wrapper_widget: Type[WrapperSettings],
|
|
parent=None
|
|
):
|
|
super(LaunchSettingsBase, self).__init__(parent=parent)
|
|
self.setTitle(self.tr("Launch Settings"))
|
|
|
|
self.core = LegendaryCoreSingleton()
|
|
self.app_name: str = "default"
|
|
|
|
self.prelaunch_edit = PathEdit(
|
|
path="",
|
|
placeholder=self.tr("Path to script or program to run before the game launches"),
|
|
file_mode=QFileDialog.ExistingFile,
|
|
edit_func=self.__prelaunch_edit_callback,
|
|
save_func=self.__prelaunch_save_callback,
|
|
)
|
|
|
|
self.wrappers_widget = wrapper_widget(self)
|
|
|
|
self.prelaunch_check = QCheckBox(self.tr("Wait for command to finish before starting the game"))
|
|
font = self.font()
|
|
font.setItalic(True)
|
|
self.prelaunch_check.setFont(font)
|
|
self.prelaunch_check.stateChanged.connect(self.__prelauch_check_changed)
|
|
|
|
prelaunch_layout = QVBoxLayout()
|
|
prelaunch_layout.addWidget(self.prelaunch_edit)
|
|
prelaunch_layout.addWidget(self.prelaunch_check)
|
|
|
|
self.main_layout = QFormLayout(self)
|
|
self.main_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
|
|
self.main_layout.setLabelAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
|
self.main_layout.setFormAlignment(Qt.AlignLeading | Qt.AlignTop)
|
|
|
|
self.main_layout.addRow(self.tr("Wrappers"), self.wrappers_widget)
|
|
self.main_layout.addRow(self.tr("Prelaunch"), prelaunch_layout)
|
|
|
|
def showEvent(self, a0: QShowEvent):
|
|
if a0.spontaneous():
|
|
return super().showEvent(a0)
|
|
command = config.get_option(self.app_name, "pre_launch_command", fallback="")
|
|
wait = config.get_boolean(self.app_name, "pre_launch_wait", fallback=False)
|
|
|
|
self.prelaunch_edit.setText(command)
|
|
self.prelaunch_check.setChecked(wait)
|
|
self.prelaunch_check.setEnabled(bool(command))
|
|
|
|
return super().showEvent(a0)
|
|
|
|
@pyqtSlot()
|
|
def tool_enabled(self):
|
|
self.wrappers_widget.update_state()
|
|
|
|
@staticmethod
|
|
def __prelaunch_edit_callback(text: str) -> Tuple[bool, str, int]:
|
|
if not text.strip():
|
|
return True, text, IndicatorReasonsCommon.VALID
|
|
if not os.path.isfile(text.split()[0]) and not shutil.which(text.split()[0]):
|
|
return False, text, IndicatorReasonsCommon.FILE_NOT_EXISTS
|
|
else:
|
|
return True, text, IndicatorReasonsCommon.VALID
|
|
|
|
def __prelaunch_save_callback(self, text):
|
|
config.save_option(self.app_name, "pre_launch_command", text)
|
|
self.prelaunch_check.setEnabled(bool(text))
|
|
if not text:
|
|
config.remove_option(self.app_name, "pre_launch_wait")
|
|
|
|
def __prelauch_check_changed(self):
|
|
config.set_boolean(self.app_name, "pre_launch_wait", self.prelaunch_check.isChecked())
|
|
|
|
|
|
LaunchSettingsType = TypeVar("LaunchSettingsType", bound=LaunchSettingsBase)
|