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.
92 lines
3.2 KiB
Python
92 lines
3.2 KiB
Python
import os
|
|
from logging import getLogger
|
|
from typing import Optional
|
|
|
|
from PyQt5.QtCore import pyqtSignal, Qt, QSignalBlocker
|
|
from PyQt5.QtGui import QShowEvent
|
|
from PyQt5.QtWidgets import QFileDialog, QFormLayout, QGroupBox
|
|
|
|
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton
|
|
from rare.utils import config_helper as config
|
|
from rare.widgets.indicator_edit import PathEdit, IndicatorReasonsCommon
|
|
|
|
logger = getLogger("WineSettings")
|
|
|
|
|
|
class WineSettings(QGroupBox):
|
|
# str: option key
|
|
environ_changed = pyqtSignal(str)
|
|
|
|
def __init__(self, parent=None):
|
|
super(WineSettings, self).__init__(parent=parent)
|
|
self.setTitle(self.tr("Wine Setings"))
|
|
|
|
self.core = LegendaryCoreSingleton()
|
|
self.signals = GlobalSignalsSingleton()
|
|
|
|
self.app_name: Optional[str] = "default"
|
|
|
|
# Wine prefix
|
|
self.wine_prefix = PathEdit(
|
|
path="",
|
|
file_mode=QFileDialog.DirectoryOnly,
|
|
edit_func=lambda path: (os.path.isdir(path) or not path, path, IndicatorReasonsCommon.DIR_NOT_EXISTS),
|
|
save_func=self.save_prefix,
|
|
)
|
|
|
|
# Wine executable
|
|
self.wine_exec = PathEdit(
|
|
path="",
|
|
file_mode=QFileDialog.ExistingFile,
|
|
name_filters=["wine", "wine64"],
|
|
edit_func=lambda text: (os.path.exists(text) or not text, text, IndicatorReasonsCommon.DIR_NOT_EXISTS),
|
|
save_func=self.save_exec,
|
|
)
|
|
|
|
layout = QFormLayout(self)
|
|
layout.addRow(self.tr("Prefix"), self.wine_prefix)
|
|
layout.addRow(self.tr("Executable"), self.wine_exec)
|
|
layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
|
|
layout.setLabelAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
|
layout.setFormAlignment(Qt.AlignLeading | Qt.AlignTop)
|
|
|
|
def showEvent(self, a0: QShowEvent):
|
|
if a0.spontaneous():
|
|
return super().showEvent(a0)
|
|
|
|
_ = QSignalBlocker(self.wine_prefix)
|
|
self.wine_prefix.setText(self.load_prefix())
|
|
_ = QSignalBlocker(self.wine_exec)
|
|
self.wine_exec.setText(self.load_exec())
|
|
self.setDisabled(config.get_boolean(self.app_name, "no_wine", fallback=False))
|
|
|
|
return super().showEvent(a0)
|
|
|
|
def tool_enabled(self, enabled: bool):
|
|
if enabled:
|
|
config.set_boolean(self.app_name, "no_wine", True)
|
|
else:
|
|
config.remove_option(self.app_name, "no_wine")
|
|
self.setDisabled(enabled)
|
|
|
|
def load_prefix(self) -> str:
|
|
if self.app_name is None:
|
|
raise RuntimeError
|
|
return config.get_wine_prefix(self.app_name, "")
|
|
|
|
def save_prefix(self, path: str) -> None:
|
|
if self.app_name is None:
|
|
raise RuntimeError
|
|
config.save_wine_prefix(self.app_name, path)
|
|
self.environ_changed.emit("WINEPREFIX")
|
|
self.signals.application.prefix_updated.emit()
|
|
|
|
def load_exec(self) -> str:
|
|
if self.app_name is None:
|
|
raise RuntimeError
|
|
return config.get_option(self.app_name, "wine_executable", "")
|
|
|
|
def save_exec(self, text: str) -> None:
|
|
if self.app_name is None:
|
|
raise RuntimeError
|
|
config.save_option(self.app_name, "wine_executable", text)
|