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

Config update

Style, wine executable, wine prefix, locale
This commit is contained in:
Dummerle 2020-11-21 11:50:13 +01:00
parent 9edaf030dd
commit d4f0fd1dcb
7 changed files with 195 additions and 21 deletions

View file

@ -107,8 +107,9 @@ class InstallDialog(QDialog):
class GameSettingsDialog(QDialog):
action: str = None
def __init__(self, settings=None):
def __init__(self, game):
super(GameSettingsDialog, self).__init__()
self.game = game
self.layout = QVBoxLayout()
self.layout.addWidget(QLabel("Einstellungen"))
@ -135,9 +136,47 @@ class GameSettingsDialog(QDialog):
return self.action
def uninstall(self):
self.action = "uninstall"
dia = AcceptDialog(f"Do you really want to delete {self.game.title}")
if dia.get_accept():
self.action = "uninstall"
else:
self.action = "nothing"
self.close()
def exit_settings(self):
self.action = self.wine_prefix.text()
self.close()
class AcceptDialog(QDialog):
def __init__(self, text: str):
super(AcceptDialog, self).__init__()
self.accept_status = False
self.text = QLabel(text)
self.accept_button = QPushButton("Yes")
self.accept_button.clicked.connect(self.accept)
self.exit_button = QPushButton("Cancel")
self.exit_button.clicked.connect(self.cancel)
self.layout = QVBoxLayout()
self.child_layout = QHBoxLayout()
self.layout.addWidget(self.text)
self.child_layout.addStretch(1)
self.child_layout.addWidget(self.accept_button)
self.child_layout.addWidget(self.exit_button)
self.layout.addStretch(1)
self.layout.addLayout(self.child_layout)
self.setLayout(self.layout)
def get_accept(self):
self.exec_()
return self.accept_status
def accept(self):
self.accept_status = True
self.close()
def cancel(self):
self.accept_status = False
self.close()

View file

@ -37,6 +37,7 @@ class GameWidget(QWidget):
def __init__(self, game):
super(GameWidget, self).__init__()
self.game = game
self.title = game.title
self.app_name = game.app_name
self.version = game.version
@ -102,7 +103,7 @@ class GameWidget(QWidget):
return "gold" # TODO
def settings(self):
settings_dialog = GameSettingsDialog()
settings_dialog = GameSettingsDialog(self.game)
action = settings_dialog.get_settings()
if action == "uninstall":
legendaryUtils.uninstall(self.app_name)

View file

@ -48,11 +48,11 @@ class TabWidget(QTabWidget):
def main():
app = QApplication(sys.argv)
if legendaryUtils.core.login():
logger.info("Login credentials found")
else:
# app.setStyleSheet(open("../style.qss").read())
try:
if legendaryUtils.core.login():
logger.info("Login credentials found")
except:
logger.info("No login data found")
dia = LoginDialog()
code = dia.get_login()

View file

@ -1,11 +1,16 @@
import os
import os
import signal
from logging import getLogger
from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QScrollArea, QLineEdit, QPushButton
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QScrollArea, QLineEdit, QPushButton, QFormLayout, QGroupBox, \
QComboBox, QHBoxLayout
from Rare.GameWidget import GameWidget, UninstalledGameWidget
from Rare.utils.legendaryUtils import get_installed, get_not_installed, logout, get_updates, get_name
from Rare.utils import legendaryConfig
from Rare.utils.legendaryUtils import get_installed, get_not_installed, logout, get_updates, get_name, update
logger = getLogger("TabWidgets")
@ -23,23 +28,90 @@ class Settings(QWidget):
self.layout = QVBoxLayout()
self.layout.addWidget(QLabel("<h1>Rare Settings</h1>"))
self.logged_in_as = QLabel(f"Logged in as {get_name()}")
self.get_legendary_config()
self.gen_form()
self.gen_form_rare()
self.logout_button = QPushButton("Logout")
self.logout_button.clicked.connect(self.logout)
self.layout.addWidget(self.logged_in_as)
self.layout.addWidget(self.rare_form_group_box)
self.update_rare_button = QPushButton("Update Rare Settings")
self.update_rare_button.clicked.connect(self.update_rare_settings)
self.layout.addWidget(self.update_rare_button)
self.layout.addWidget(self.form_group_box)
self.update_legendary_button = QPushButton("Update Legendary Settings")
self.update_legendary_button.clicked.connect(self.update_legendary_settings)
self.layout.addWidget(self.update_legendary_button)
self.layout.addStretch(1)
self.layout.addWidget(self.logout_button)
self.info_label = QLabel("<h2>Credits</h2>")
self.infotext = QLabel("""Developers : Dummerle, CommandMC\nLegendary Dev: Derrod\nLicence: GPL v3""")
self.infotext = QLabel("Developers : Dummerle, CommandMC\nLegendary Dev: Derrod\nLicence: GPL v.3")
self.layout.addWidget(self.info_label)
self.layout.addWidget(self.infotext)
self.layout.addStretch(1)
self.setLayout(self.layout)
def update_rare_settings(self):
print("Update Rare settings")
if self.style_combo_box.currentIndex() == 1:
self.parent().parent().parent().setStyleSheet(open("../style.qss").read())
else:
self.parent().parent().parent().setStyleSheet("")
def update_legendary_settings(self):
print("Legendary update")
self.config["Legendary"]["wine_executable"] = self.lgd_conf_wine_exec.text()
self.config["Legendary"]["wine_prefix"] = self.lgd_conf_wine_prefix.text()
self.config["Legendary"]["locale"] = self.lgd_conf_locale.text()
# self.config["default.env"] = self.lgd_conf_env_vars.toPlainText()
legendaryConfig.set_config(self.config)
def logout(self):
logout()
exit(0)
def gen_form(self):
# Default Config
if not self.config.get("Legendary"):
self.config["Legendary"] = {}
if not self.config["Legendary"].get("wine_executable"):
self.config["Legendary"]["wine_executable"] = "wine"
if not self.config["Legendary"].get("wine_prefix"):
self.config["Legendary"]["wine_prefix"] = f"{os.path.expanduser('~')}/.wine"
if not self.config["Legendary"].get("locale"):
self.config["Legendary"]["locale"] = "en-US"
self.form_group_box = QGroupBox("Legendary Defaults")
self.form = QFormLayout()
self.lgd_conf_wine_prefix = QLineEdit(self.config["Legendary"]["wine_prefix"])
self.lgd_conf_wine_exec = QLineEdit(self.config["Legendary"]["wine_executable"])
# self.lgd_conf_env_vars = QTextEdit(str(self.config["default.env"]))
self.lgd_conf_locale = QLineEdit(self.config["Legendary"]["locale"])
self.form.addRow(QLabel("Default Wineprefix"), self.lgd_conf_wine_prefix)
self.form.addRow(QLabel("Wine executable"), self.lgd_conf_wine_exec)
# self.form.addRow(QLabel("Environment Variables"), self.lgd_conf_env_vars)
self.form.addRow(QLabel("Locale"), self.lgd_conf_locale)
self.form_group_box.setLayout(self.form)
def gen_form_rare(self):
self.rare_form_group_box = QGroupBox("Rare Settings")
self.rare_form = QFormLayout()
self.style_combo_box = QComboBox()
self.style_combo_box.addItems(["Light", "Dark"])
self.rare_form.addRow(QLabel("Style"), self.style_combo_box)
self.rare_form_group_box.setLayout(self.rare_form)
def get_legendary_config(self):
self.config = legendaryConfig.get_config()
class GameListInstalled(QScrollArea):
def __init__(self, parent):
@ -88,15 +160,45 @@ class GameListUninstalled(QScrollArea):
class UpdateList(QWidget):
class UpdateWidget(QWidget):
def __init__(self, game):
super().__init__()
self.updating = False
self.game = game
self.layout = QHBoxLayout()
self.label = QLabel("Update available for " + self.game.title)
self.button = QPushButton("Update")
self.button.clicked.connect(self.update_game)
self.layout.addWidget(self.label)
self.layout.addWidget(self.button)
self.setLayout(self.layout)
def update_game(self):
if not self.updating:
logger.info("Update " + self.game.title)
self.proc = update(self.game.app_name)
self.button.setText("Cancel")
self.updating = True
else:
logger.info("Terminate process")
self.proc.send_signal(signal.SIGINT)
self.button.setText("Update")
self.updating = False
def __init__(self, parent):
super(UpdateList, self).__init__(parent=parent)
self.layout = QVBoxLayout()
updates = get_updates()
if not updates:
if updates:
for game in get_updates():
self.layout.addWidget(QLabel("Update available for " + game.title))
self.layout.addWidget(self.UpdateWidget(game))
else:
self.layout.addWidget(QLabel("No updates available"))
self.layout.addStretch(1)
self.setLayout(self.layout)
def update_game(self):
pass
# TODO

15
Rare/utils/RareConfig.py Normal file
View file

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

View file

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

View file

@ -6,6 +6,7 @@ from getpass import getuser
from legendary.core import LegendaryCore
core = LegendaryCore()
logger = logging.getLogger("LegendaryUtils")
def get_installed():
@ -88,13 +89,7 @@ def launch_game(app_name: str, offline: bool = False, skip_version_check: bool =
def auth_import(lutris: bool = False, wine_prefix: str = None) -> bool:
'''
import Data from existing Egl installation
:param lutris only linux automate using lutris wine prefix:
:param wine_prefix only linux path to wine_prefix:
:return success:
'''
print(lutris, wine_prefix)
# Linux
if not core.egl.appdata_path:
@ -164,3 +159,9 @@ def get_name():
def uninstall(app_name: str):
core.uninstall_game(core.get_installed_game(app_name), True, True)
# logger.info("Uninstalling " + app_name)
def update(app_name) -> subprocess.Popen:
logger.info(f"Updating {app_name}")
return subprocess.Popen(f"legendary -y update {app_name}".split())