1
0
Fork 0
mirror of synced 2024-06-02 02:34:40 +12:00

Settings Update

This commit is contained in:
Dummerle 2021-01-10 21:44:09 +01:00
parent 913328d290
commit aead9dcd4f
12 changed files with 218 additions and 146 deletions

View file

@ -9,26 +9,26 @@ class MainWindow(QMainWindow):
super().__init__()
self.setWindowTitle("Rare - GUI for legendary-gl")
self.setGeometry(0, 0, 1200, 900)
self.setCentralWidget(TabWidget(self, core))
self.setCentralWidget(TabWidget(core))
self.show()
class TabWidget(QTabWidget):
def __init__(self, parent, core):
super(QWidget, self).__init__(parent)
def __init__(self, core):
super(QWidget, self).__init__()
self.game_list = GameListInstalled(self, core)
self.game_list = GameListInstalled(core)
self.addTab(self.game_list, "Games")
self.uninstalled_games = GameListUninstalled(self, core)
self.uninstalled_games = GameListUninstalled(core)
self.addTab(self.uninstalled_games, "Install Games")
self.update_tab = UpdateTab(self, core)
self.update_tab = UpdateTab(core)
self.addTab(self.update_tab, "Updates")
self.browser = BrowserTab(self)
self.browser = BrowserTab()
self.addTab(self.browser, "Store")
self.settings = SettingsTab(self, core)
self.settings = SettingsTab(core)
self.addTab(self.settings, "Settings")

144
Rare/SettingsForm.py Normal file
View file

@ -0,0 +1,144 @@
import os
from PyQt5.QtGui import QIntValidator
from PyQt5.QtWidgets import *
from Rare.utils import legendaryConfig
class SettingsForm(QGroupBox):
def __init__(self, app_name, settings: [tuple], table: bool):
super(SettingsForm, self).__init__()
self.config = legendaryConfig.get_config()
self.app_name = app_name
self.form = QFormLayout()
self.rows = []
self.has_table = table
for i in settings:
self.add_Row(*i)
if table:
if not f"{self.app_name}.env" in self.config:
env_vars = {}
else:
env_vars = self.config[f"{self.app_name}.env"]
if env_vars:
self.table = QTableWidget(len(env_vars), 2)
for i, label in enumerate(env_vars):
self.table.setItem(i, 0, QTableWidgetItem(label))
self.table.setItem(i, 1, QTableWidgetItem(env_vars[label]))
else:
self.table = QTableWidget(0, 2)
self.table.setHorizontalHeaderLabels(["Variable", "Value"])
self.form.addRow(QLabel("Environment Variables"), self.table)
self.add_button = QPushButton("Add Variable")
self.add_button.clicked.connect(self.add_variable)
self.delete_button = QPushButton("Delete Variable")
self.delete_button.clicked.connect(lambda: self.table.removeRow(self.table.currentRow()))
self.form.addRow(self.add_button)
self.form.addRow(self.delete_button)
self.update_button = QPushButton("Update Settings")
self.update_button.clicked.connect(self.update_config)
self.form.addRow(self.update_button)
self.setLayout(self.form)
def add_Row(self, info_text: str, type_of_input: str, lgd_name: str, flags: [] = None):
if flags is None:
flags = []
if os.name == "nt" and "wine" in flags:
return
field = None
if not self.app_name in self.config.sections():
self.config[self.app_name] = {}
if not lgd_name in self.config[self.app_name]:
self.config[self.app_name][lgd_name] = ""
if type_of_input == "QLineEdit":
field = QLineEdit(self.config[self.app_name][lgd_name])
field.setPlaceholderText("Default")
if "only_int" in flags:
field.setValidator(QIntValidator())
elif type_of_input == "QComboBox":
combo_list = []
if "binary" in flags:
combo_list = ["unset", "true", "false"]
else:
combo_list = flags
field = QComboBox()
field.addItems(combo_list)
if self.config[self.app_name][lgd_name] == "":
field.setCurrentIndex(0)
elif self.config[self.app_name][lgd_name] == "true":
field.setCurrentIndex(1)
elif not self.config[self.app_name][lgd_name] == "false":
field.setCurrentIndex(2)
if not field:
return
self.form.addRow(QLabel(info_text), field)
self.rows.append((field, type_of_input, lgd_name))
# pprint(self.rows)
def add_variable(self):
self.table.insertRow(self.table.rowCount())
self.table.setItem(self.table.rowCount(), 0, QTableWidgetItem(""))
self.table.setItem(self.table.rowCount(), 1, QTableWidgetItem(""))
def update_config(self):
config = {self.app_name: {}}
for setting in self.rows:
field, type_of_input, lgd_name = setting
if type_of_input == "QLineEdit":
if field.text() != "":
config[self.app_name][lgd_name] = field.text()
elif type_of_input == "QComboBox":
# print(type(field.currentText()), field.currentText())
if field.currentText() == "true":
config[self.app_name][lgd_name] = True
elif field.currentText() == "false":
config[self.app_name][lgd_name] = False
elif field.currentText == "unset":
pass
else:
pass
# config[self.app_name][lgd_name] = field.currentText()
if self.has_table:
if self.table.rowCount() > 0:
config[f"{self.app_name}.env"] = {}
for row in range(self.table.rowCount()):
config[f"{self.app_name}.env"][self.table.item(row, 0).text()] = self.table.item(row, 1).text()
else:
config[f"{self.app_name}.env"] = {}
lgd_config = legendaryConfig.get_config()
if config[self.app_name] == {}:
config.pop(self.app_name)
lgd_config.remove_section(self.app_name)
else:
lgd_config[self.app_name] = config[self.app_name]
if self.has_table:
if config[self.app_name + ".env"] == {}:
config.pop(self.app_name + ".env")
lgd_config.remove_section(self.app_name + ".env")
else:
lgd_config[self.app_name + ".env"] = config[f"{self.app_name}.env"]
# legendaryConfig.set_config()
legendaryConfig.set_config(lgd_config)
def use_proton_template(self):
for i in self.rows:
pass # TODO

View file

@ -3,8 +3,8 @@ from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile, QWebEngi
class BrowserTab(QWebEngineView):
def __init__(self, parent):
super(BrowserTab, self).__init__(parent=parent)
def __init__(self):
super(BrowserTab, self).__init__()
self.profile = QWebEngineProfile("storage", self)
self.webpage = QWebEnginePage(self.profile, self)
self.setPage(self.webpage)

View file

@ -2,8 +2,8 @@ import os
from PyQt5.QtWidgets import *
from Rare.Dialogs import AcceptDialog
from Rare.Tabs.GamesInstalled.SettingsForm import SettingsForm
from Rare.SettingsForm import SettingsForm
from Rare.utils.constants import game_settings
class GameSettingsDialog(QDialog):
@ -20,7 +20,7 @@ class GameSettingsDialog(QDialog):
self.wine_prefix.setPlaceholderText("Wineprefix")
self.uninstall_button = QPushButton("Uninstall Game")
self.settings = SettingsForm(self.game.app_name)
self.settings = SettingsForm(self.game.app_name, game_settings, table=True)
self.uninstall_button.clicked.connect(self.uninstall)
self.exit_button = QPushButton("Exit")

View file

@ -9,7 +9,6 @@ from Rare.Tabs.GamesInstalled.GameSettingsDialog import GameSettingsDialog
from Rare.utils import legendaryUtils
from Rare.utils.RareConfig import IMAGE_DIR
from legendary.core import LegendaryCore
from legendary.models.game import InstalledGame
logger = getLogger("GameWidget")

View file

@ -14,14 +14,18 @@ logger = getLogger("InstalledList")
class GameListInstalled(QScrollArea):
def __init__(self, parent, core: LegendaryCore):
super(GameListInstalled, self).__init__(parent=parent)
def __init__(self, core: LegendaryCore):
super(GameListInstalled, self).__init__()
self.widget = QWidget()
self.core = core
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.layout = QVBoxLayout()
self.update_button = QPushButton("Update")
self.update_button.clicked.connect(lambda: self.__init__(self.core))
self.layout.addWidget(self.update_button)
self.widgets = {}
games = sorted(core.get_installed_list(), key=lambda game: game.title)
if games:
@ -50,6 +54,7 @@ class GameListInstalled(QScrollArea):
self.layout.removeWidget(self.widgets[app_name])
self.widgets[app_name].deleteLater()
self.widgets.pop(app_name)
self.__init__(self.core)
def import_games_prepare(self):
# Automatically import from windows
@ -80,12 +85,16 @@ class GameListInstalled(QScrollArea):
json_path = game_path + path + "/.egstore"
print(json_path)
if not os.path.isdir(json_path):
logger.info(f"Game at {game_path+path} doesn't exist")
logger.info(f"Game at {game_path + path} doesn't exist")
continue
for file in os.listdir(json_path):
if file.endswith(".mancpn"):
app_name = json.load(open(os.path.join(json_path, file)))["AppName"]
if legendaryUtils.import_game(self.core, app_name, game_path + path):
imported +=1
imported += 1
return imported
def update(self):
self.__init__(self.core)
self.update()

View file

@ -1,116 +0,0 @@
import os
from logging import getLogger
from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem, QFormLayout, QGroupBox, QLineEdit, QPushButton, \
QLabel, QCheckBox
from Rare.utils import legendaryConfig
class SettingsForm(QGroupBox):
config: dict
def __init__(self, app_name: str):
self.app_name = app_name
self.logger = getLogger(f"{app_name} Settings")
config: dict
super(SettingsForm, self).__init__(f'Settings for Game {self.app_name}')
self.config = legendaryConfig.get_config()
if not self.config.get(self.app_name):
self.config[self.app_name] = {}
if not self.config[self.app_name].get("wine_executable"):
self.config[self.app_name]["wine_executable"] = ""
if not self.config[self.app_name].get("wine_prefix"):
self.config[self.app_name]["wine_prefix"] = ""
if not self.config[self.app_name].get("language"):
self.config[self.app_name]["language"] = ""
# if not self.config["Legendary"].get("offline"):
# self.config["Legendary"]["offline"] = ""
env_vars = self.config.get(f"{self.app_name}.env")
if env_vars:
self.table = QTableWidget(len(env_vars), 2)
for i, label in enumerate(env_vars):
self.table.setItem(i, 0, QTableWidgetItem(label))
self.table.setItem(i, 1, QTableWidgetItem(env_vars[label]))
else:
self.table = QTableWidget(0, 2)
self.table.setHorizontalHeaderLabels(["Variable", "Value"])
self.form = QFormLayout()
self.game_conf_wine_prefix = QLineEdit(self.config[self.app_name]["wine_prefix"])
self.game_conf_wine_prefix.setPlaceholderText("Default")
self.game_conf_wine_exec = QLineEdit(self.config[self.app_name]["wine_executable"])
self.game_conf_wine_exec.setPlaceholderText("Default")
self.language = QLineEdit(self.config[self.app_name]["language"])
self.language.setPlaceholderText("Default")
# self.offline = QCheckBox(self.config["offline"] == "false")
self.add_button = QPushButton("Add Environment Variable")
self.delete_env_var = QPushButton("Delete selected Variable")
self.delete_env_var.clicked.connect(self.delete_var)
self.add_button.clicked.connect(self.add_variable)
if os.name != "nt":
self.form.addRow(QLabel("Default Wineprefix"), self.game_conf_wine_prefix)
self.form.addRow(QLabel("Wine executable"), self.game_conf_wine_exec)
# self.form.addRow(QLabel("Offline"), self.offline)
self.form.addRow(QLabel("Environment Variables"), self.table)
self.form.addRow(QLabel("Add Variable"), self.add_button)
self.form.addRow(QLabel("Delete Variable"), self.delete_env_var)
self.form.addRow(QLabel("language"), self.language)
self.submit_button = QPushButton("Update")
self.submit_button.clicked.connect(self.update_legendary_settings)
self.form.addRow(self.submit_button)
self.setLayout(self.form)
def add_variable(self):
print("add row")
self.table.insertRow(self.table.rowCount())
self.table.setItem(self.table.rowCount(), 0, QTableWidgetItem(""))
self.table.setItem(self.table.rowCount(), 1, QTableWidgetItem(""))
def delete_var(self):
self.table.removeRow(self.table.currentRow())
def update_legendary_settings(self):
self.logger.info("Updating Game Settings")
# Wine exec
if not self.config.get(self.app_name):
self.config[self.app_name] = {}
if self.game_conf_wine_exec.text() != "":
self.config[self.app_name]["wine_executable"] = self.game_conf_wine_exec.text()
elif "wine_executable" in self.config[self.app_name]:
self.config[self.app_name].pop("wine_executable")
# Wineprefix
if self.game_conf_wine_prefix.text() != '':
self.config[self.app_name]["wine_prefix"] = self.game_conf_wine_prefix.text()
pass
elif "wine_prefix" in self.config[self.app_name]:
self.config[self.app_name].pop("wine_prefix")
# language
if self.language.text() != "":
self.config[self.app_name]["language"] = self.language.text()
elif "language" in self.config[self.app_name]:
self.config[self.app_name].pop("language")
# Env vars
if self.table.rowCount() > 0:
self.config[f"{self.app_name}.env"] = {}
for row in range(self.table.rowCount()):
self.config[f"{self.app_name}.env"][self.table.item(row, 0).text()] = self.table.item(row, 1).text()
elif f"{self.app_name}.env" in self.config:
self.config.pop(f"{self.app_name}.env")
if self.config.get(self.app_name) == {}:
self.config.pop(self.app_name)
legendaryConfig.set_config(self.config)
print(self.config)

View file

@ -8,8 +8,8 @@ from Rare.utils.Dialogs.ImportDialog import ImportDialog
class GameListUninstalled(QScrollArea):
def __init__(self, parent, core: LegendaryCore):
super(GameListUninstalled, self).__init__(parent=parent)
def __init__(self, core: LegendaryCore):
super(GameListUninstalled, self).__init__()
self.core = core
self.widget = QWidget()
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)

View file

@ -4,7 +4,8 @@ from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QPushButton, QScrollArea
from Rare.Tabs.Settings.Rare import RareSettingsForm
from Rare.Tabs.Settings.LegendarySettingsForm import SettingsForm
from Rare.SettingsForm import SettingsForm
from Rare.utils.constants import default_settings, legendary_settings
from Rare.utils.legendaryUtils import get_name
from legendary.core import LegendaryCore
@ -12,8 +13,8 @@ logger = getLogger("Settings")
class SettingsTab(QScrollArea):
def __init__(self, parent, core: LegendaryCore):
super(SettingsTab, self).__init__(parent=parent)
def __init__(self, core: LegendaryCore):
super(SettingsTab, self).__init__()
self.core = core
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
@ -21,7 +22,11 @@ class SettingsTab(QScrollArea):
self.layout = QVBoxLayout()
self.layout.addWidget(QLabel("<h1>Rare Settings</h1>"))
self.logged_in_as = QLabel(f"Logged in as {get_name()}")
self.legendary_form =SettingsForm()
#self.legendary_form =SettingsForm()
self.default_settings = SettingsForm("default", default_settings, True)
self.legendary_form = SettingsForm("Legendary", legendary_settings, False)
self.rare_form = RareSettingsForm()
self.logout_button = QPushButton("Logout")
@ -29,7 +34,9 @@ class SettingsTab(QScrollArea):
self.layout.addWidget(self.logged_in_as)
self.layout.addWidget(self.rare_form)
self.layout.addWidget(self.default_settings)
self.layout.addWidget(self.legendary_form)
self.layout.addStretch(1)
self.layout.addWidget(self.logout_button)

View file

@ -110,8 +110,8 @@ class UpdateWidget(QWidget):
class UpdateTab(QWidget):
def __init__(self, parent, core: LegendaryCore):
super(UpdateTab, self).__init__(parent=parent)
def __init__(self, core: LegendaryCore):
super(UpdateTab, self).__init__()
self.core = core
self.layout = QVBoxLayout()
update_games = self.get_updates()

28
Rare/utils/constants.py Normal file
View file

@ -0,0 +1,28 @@
# (Info Text, Type of input, legendary conf name, flags)
# possible flags: wine, path, only_int, binary(ComboBox), Combobox content
from pprint import pprint
default_settings = [
("Wine Prefix", "QLineEdit", "wine_prefix", ["wine", "path"]),
("Wine Executable", "QLineEdit", "wine_executable", ["wine"])
]
legendary_settings = [
("Locale", "QLineEdit", "locale"),
("Max Workers", "QLineEdit", "max_workers", ["only_int"]),
("Default install dir", "QLineEdit", "install_dir", ["path"]),
("Max Memory", "QLineEdit", "max_memory", ["only_int"]),
("Wrapper", "QLineEdit", "wrapper"),
("EGL Sync", "QComboBox", "egl_sync", ["binary"]),
("No Wine", "QComboBox", "no_wine", ["binary"])
]
game_settings = default_settings + [
("Wrapper", "QLineEdit", "wrapper"),
("Offline", "QComboBox", "offline", ["binary"]),
("Skip Update Check", "QComboBox", "skip_update_check", ["binary"]),
("Launch Parameter", "start_params", "QLineEdit"),
("No Wine", "QComboBox", "no_wine", ["binary", "wine"])
]

View file

@ -3,13 +3,14 @@ import os
config_path = os.path.expanduser("~") + "/.config/legendary/"
lgd_config = configparser.ConfigParser()
lgd_config.read(config_path + "config.ini")
def get_config() -> {}:
return lgd_config.__dict__["_sections"]
lgd_config.read(config_path + "config.ini")
return lgd_config
def set_config(new_config: {}):
lgd_config.__dict__["_sections"] = new_config
def set_config( new_config: {}):
lgd_config = new_config
lgd_config.write(open(config_path + "config.ini", "w"))