1
0
Fork 0
mirror of synced 2024-07-01 12:40:28 +12:00

QProcess game. Can't get killed from gui

Env vars settings: Delete row
This commit is contained in:
Dummerle 2020-11-24 11:22:47 +01:00
parent 0d879bd957
commit 7f3565e8c1
3 changed files with 49 additions and 22 deletions

View file

@ -1,7 +1,7 @@
import subprocess import subprocess
from logging import getLogger from logging import getLogger
from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtCore import QThread, pyqtSignal, QProcess
from PyQt5.QtGui import QPixmap from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QVBoxLayout, QPushButton, QStyle from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QVBoxLayout, QPushButton, QStyle
@ -32,7 +32,7 @@ class Thread(QThread):
class GameWidget(QWidget): class GameWidget(QWidget):
proc: subprocess.Popen proc: QProcess
signal = pyqtSignal(str) signal = pyqtSignal(str)
def __init__(self, game): def __init__(self, game):
@ -81,23 +81,28 @@ class GameWidget(QWidget):
def launch(self): def launch(self):
if not self.game_running: if not self.game_running:
logger.info(f"launching {self.title}") logger.info(f"launching {self.title}")
resp = legendaryUtils.launch_game(self.app_name) self.proc = legendaryUtils.launch_game(self.app_name)
if resp != 1: if not self.proc:
self.proc = resp print("Fail")
self.thread = Thread(self.proc) return
self.thread.signal.connect(self.kill)
self.thread.start() self.proc.finished.connect(self.finished)
self.launch_button.setText("Kill") self.launch_button.setText("Kill")
self.game_running = True self.game_running = True
else:
logger.warning("Error")
else: else:
self.kill() self.kill()
def finished(self, exit_code):
self.launch_button.setText("Launch")
logger.info(f"Game {self.title} finished with exit code {exit_code}")
self.game_running = False
def kill(self): def kill(self):
self.proc.kill() self.proc.kill()
self.launch_button.setText("Launch") self.launch_button.setText("Launch")
self.game_running = False self.game_running = False
logger.info("Killing Game")
def get_rating(self) -> str: def get_rating(self) -> str:
return "gold" # TODO return "gold" # TODO

View file

@ -54,8 +54,6 @@ class Settings(QScrollArea):
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
# Settings # Settings
if RareConfig.get_config()["Rare"].get("theme") == "dark":
self.parent().parent().setStyleSheet(open("../Styles/style.qss").read())
self.layout = QVBoxLayout() self.layout = QVBoxLayout()
self.layout.addWidget(QLabel("<h1>Rare Settings</h1>")) self.layout.addWidget(QLabel("<h1>Rare Settings</h1>"))
@ -64,6 +62,10 @@ class Settings(QScrollArea):
self.gen_form_legendary() self.gen_form_legendary()
self.gen_form_rare() self.gen_form_rare()
if RareConfig.get_config()["Rare"].get("theme") == "dark":
self.parent().parent().setStyleSheet(open("../Styles/style.qss").read())
self.style_combo_box.setCurrentIndex(1)
self.logout_button = QPushButton("Logout") self.logout_button = QPushButton("Logout")
self.logout_button.clicked.connect(self.logout) self.logout_button.clicked.connect(self.logout)
self.layout.addWidget(self.logged_in_as) self.layout.addWidget(self.logged_in_as)
@ -88,11 +90,16 @@ class Settings(QScrollArea):
self.setLayout(self.layout) self.setLayout(self.layout)
def update_rare_settings(self): def update_rare_settings(self):
print("Update Rare settings") logger.info("Update Rare settings")
config = {"Rare": {}}
if self.style_combo_box.currentIndex() == 1: if self.style_combo_box.currentIndex() == 1:
self.parent().parent().parent().setStyleSheet(open("../Styles/style.qss").read()) self.parent().parent().parent().setStyleSheet(open("../Styles/style.qss").read())
config["Rare"]["theme"] = "dark"
else: else:
self.parent().parent().parent().setStyleSheet("") self.parent().parent().parent().setStyleSheet("")
config["Rare"]["theme"] = "light"
RareConfig.set_config(config)
def update_legendary_settings(self): def update_legendary_settings(self):
print("Legendary update") print("Legendary update")
@ -137,11 +144,14 @@ class Settings(QScrollArea):
self.lgd_conf_locale = QLineEdit(self.config["Legendary"]["locale"]) self.lgd_conf_locale = QLineEdit(self.config["Legendary"]["locale"])
self.add_button = QPushButton("Add Environment Variable") 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) self.add_button.clicked.connect(self.add_variable)
self.form.addRow(QLabel("Default Wineprefix"), self.lgd_conf_wine_prefix) 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("Wine executable"), self.lgd_conf_wine_exec)
self.form.addRow(QLabel("Environment Variables"), self.table) self.form.addRow(QLabel("Environment Variables"), self.table)
self.form.addRow(QLabel("Add Variable"), self.add_button) self.form.addRow(QLabel("Add Variable"), self.add_button)
self.form.addRow(QLabel("Delete Variable"), self.delete_env_var)
self.form.addRow(QLabel("Locale"), self.lgd_conf_locale) self.form.addRow(QLabel("Locale"), self.lgd_conf_locale)
self.form_group_box.setLayout(self.form) self.form_group_box.setLayout(self.form)
@ -152,6 +162,9 @@ class Settings(QScrollArea):
self.table.setItem(self.table.rowCount(), 0, QTableWidgetItem("")) self.table.setItem(self.table.rowCount(), 0, QTableWidgetItem(""))
self.table.setItem(self.table.rowCount(), 1, QTableWidgetItem("")) self.table.setItem(self.table.rowCount(), 1, QTableWidgetItem(""))
def delete_var(self):
self.table.removeRow(self.table.currentRow())
def gen_form_rare(self): def gen_form_rare(self):
self.rare_form_group_box = QGroupBox("Rare Settings") self.rare_form_group_box = QGroupBox("Rare Settings")
self.rare_form = QFormLayout() self.rare_form = QFormLayout()

View file

@ -3,6 +3,7 @@ import os
import subprocess import subprocess
from getpass import getuser from getpass import getuser
from PyQt5.QtCore import QProcess, QProcessEnvironment
from legendary.core import LegendaryCore from legendary.core import LegendaryCore
core = LegendaryCore() core = LegendaryCore()
@ -57,35 +58,43 @@ def launch_game(app_name: str, offline: bool = False, skip_version_check: bool =
game = core.get_installed_game(app_name) game = core.get_installed_game(app_name)
if not game: if not game:
print("Game not found") print("Game not found")
return 1 return None
if game.is_dlc: if game.is_dlc:
print("Game is dlc") print("Game is dlc")
return 1 return None
if not os.path.exists(game.install_path): if not os.path.exists(game.install_path):
print("Game doesn't exist") print("Game doesn't exist")
return 1 return None
if not offline: if not offline:
print("logging in") print("logging in")
if not core.login(): if not core.login():
return 1 return None
if not skip_version_check and not core.is_noupdate_game(app_name): if not skip_version_check and not core.is_noupdate_game(app_name):
# check updates # check updates
try: try:
latest = core.get_asset(app_name, update=True) latest = core.get_asset(app_name, update=True)
except ValueError: except ValueError:
print("Metadata doesn't exist") print("Metadata doesn't exist")
return 1 return None
if latest.build_version != game.version: if latest.build_version != game.version:
print("Please update game") print("Please update game")
return 1 return None
params, cwd, env = core.get_launch_parameters(app_name=app_name, offline=offline, params, cwd, env = core.get_launch_parameters(app_name=app_name, offline=offline,
extra_args=extra, user=username_override, extra_args=extra, user=username_override,
wine_bin=wine_bin, wine_pfx=wine_prfix, wine_bin=wine_bin, wine_pfx=wine_prfix,
language=language, wrapper=wrapper, language=language, wrapper=wrapper,
disable_wine=no_wine) disable_wine=no_wine)
process = QProcess()
process.setWorkingDirectory(cwd)
environment = QProcessEnvironment()
for e in env:
environment.insert(e, env[e])
process.setProcessEnvironment(environment)
return subprocess.Popen(params, cwd=cwd, env=env) process.start(params[0], params[1:])
return process
# return subprocess.Popen(params, cwd=cwd, env=env)
def auth_import(lutris: bool = False, wine_prefix: str = None) -> bool: def auth_import(lutris: bool = False, wine_prefix: str = None) -> bool: