2022-01-20 08:10:10 +13:00
|
|
|
import os
|
2021-02-20 06:09:00 +13:00
|
|
|
from logging import getLogger
|
2023-12-19 04:34:18 +13:00
|
|
|
from typing import Optional
|
2021-02-20 06:09:00 +13:00
|
|
|
|
2023-12-19 04:34:18 +13:00
|
|
|
from PyQt5.QtCore import pyqtSignal, Qt, QSignalBlocker
|
|
|
|
from PyQt5.QtGui import QShowEvent
|
|
|
|
from PyQt5.QtWidgets import QFileDialog, QFormLayout, QGroupBox
|
2021-02-20 06:09:00 +13:00
|
|
|
|
2022-02-26 06:43:27 +13:00
|
|
|
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton
|
2023-12-19 04:34:18 +13:00
|
|
|
from rare.utils import config_helper as config
|
2023-02-19 04:29:41 +13:00
|
|
|
from rare.widgets.indicator_edit import PathEdit, IndicatorReasonsCommon
|
2021-02-20 06:09:00 +13:00
|
|
|
|
2023-12-19 04:34:18 +13:00
|
|
|
logger = getLogger("WineSettings")
|
2021-02-20 00:57:55 +13:00
|
|
|
|
|
|
|
|
2023-09-20 10:39:15 +12:00
|
|
|
class WineSettings(QGroupBox):
|
2023-04-01 00:03:32 +13:00
|
|
|
# str: option key
|
|
|
|
environ_changed = pyqtSignal(str)
|
|
|
|
|
2023-12-19 04:34:18 +13:00
|
|
|
def __init__(self, parent=None):
|
2023-09-20 10:39:15 +12:00
|
|
|
super(WineSettings, self).__init__(parent=parent)
|
2023-12-19 04:34:18 +13:00
|
|
|
self.setTitle(self.tr("Wine Setings"))
|
2021-04-28 03:40:10 +12:00
|
|
|
|
2022-02-26 06:43:27 +13:00
|
|
|
self.core = LegendaryCoreSingleton()
|
|
|
|
self.signals = GlobalSignalsSingleton()
|
|
|
|
|
2023-12-19 04:34:18 +13:00
|
|
|
self.app_name: Optional[str] = "default"
|
2021-04-28 03:40:10 +12:00
|
|
|
|
2021-05-02 08:15:42 +12:00
|
|
|
# Wine prefix
|
2021-11-23 03:56:44 +13:00
|
|
|
self.wine_prefix = PathEdit(
|
2023-12-19 04:34:18 +13:00
|
|
|
path="",
|
2023-03-16 09:49:18 +13:00
|
|
|
file_mode=QFileDialog.DirectoryOnly,
|
2023-02-19 01:33:42 +13:00
|
|
|
edit_func=lambda path: (os.path.isdir(path) or not path, path, IndicatorReasonsCommon.DIR_NOT_EXISTS),
|
2021-12-24 22:09:50 +13:00
|
|
|
save_func=self.save_prefix,
|
|
|
|
)
|
2021-02-20 06:09:00 +13:00
|
|
|
|
|
|
|
# Wine executable
|
2021-11-23 03:56:44 +13:00
|
|
|
self.wine_exec = PathEdit(
|
2023-12-19 04:34:18 +13:00
|
|
|
path="",
|
2023-03-16 09:49:18 +13:00
|
|
|
file_mode=QFileDialog.ExistingFile,
|
|
|
|
name_filters=["wine", "wine64"],
|
2023-02-19 01:33:42 +13:00
|
|
|
edit_func=lambda text: (os.path.exists(text) or not text, text, IndicatorReasonsCommon.DIR_NOT_EXISTS),
|
2023-12-19 04:34:18 +13:00
|
|
|
save_func=self.save_exec,
|
2023-09-20 10:39:15 +12:00
|
|
|
)
|
2022-03-22 08:56:03 +13:00
|
|
|
|
2023-12-19 04:34:18 +13:00
|
|
|
layout = QFormLayout(self)
|
|
|
|
layout.addRow(self.tr("Prefix"), self.wine_prefix)
|
|
|
|
layout.addRow(self.tr("Executable"), self.wine_exec)
|
2023-12-20 07:53:21 +13:00
|
|
|
layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
|
2023-12-19 04:34:18 +13:00
|
|
|
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)
|
|
|
|
|
2021-11-23 03:56:44 +13:00
|
|
|
def load_prefix(self) -> str:
|
2023-12-19 04:34:18 +13:00
|
|
|
if self.app_name is None:
|
|
|
|
raise RuntimeError
|
|
|
|
return config.get_wine_prefix(self.app_name, "")
|
2021-11-23 03:56:44 +13:00
|
|
|
|
2023-12-19 04:34:18 +13:00
|
|
|
def save_prefix(self, path: str) -> None:
|
|
|
|
if self.app_name is None:
|
|
|
|
raise RuntimeError
|
|
|
|
config.save_wine_prefix(self.app_name, path)
|
2023-04-01 00:03:32 +13:00
|
|
|
self.environ_changed.emit("WINEPREFIX")
|
2022-12-29 06:55:15 +13:00
|
|
|
self.signals.application.prefix_updated.emit()
|
2021-11-23 03:56:44 +13:00
|
|
|
|
2023-12-19 04:34:18 +13:00
|
|
|
def load_exec(self) -> str:
|
|
|
|
if self.app_name is None:
|
|
|
|
raise RuntimeError
|
|
|
|
return config.get_option(self.app_name, "wine_executable", "")
|
2021-11-23 03:56:44 +13:00
|
|
|
|
2023-12-19 04:34:18 +13:00
|
|
|
def save_exec(self, text: str) -> None:
|
|
|
|
if self.app_name is None:
|
|
|
|
raise RuntimeError
|
|
|
|
config.save_option(self.app_name, "wine_executable", text)
|