QProcess game. Can't get killed from gui
Env vars settings: Delete row
This commit is contained in:
parent
0d879bd957
commit
7f3565e8c1
3 changed files with 49 additions and 22 deletions
|
@ -1,7 +1,7 @@
|
|||
import subprocess
|
||||
from logging import getLogger
|
||||
|
||||
from PyQt5.QtCore import QThread, pyqtSignal
|
||||
from PyQt5.QtCore import QThread, pyqtSignal, QProcess
|
||||
from PyQt5.QtGui import QPixmap
|
||||
from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QVBoxLayout, QPushButton, QStyle
|
||||
|
||||
|
@ -32,7 +32,7 @@ class Thread(QThread):
|
|||
|
||||
|
||||
class GameWidget(QWidget):
|
||||
proc: subprocess.Popen
|
||||
proc: QProcess
|
||||
signal = pyqtSignal(str)
|
||||
|
||||
def __init__(self, game):
|
||||
|
@ -81,23 +81,28 @@ class GameWidget(QWidget):
|
|||
def launch(self):
|
||||
if not self.game_running:
|
||||
logger.info(f"launching {self.title}")
|
||||
resp = legendaryUtils.launch_game(self.app_name)
|
||||
if resp != 1:
|
||||
self.proc = resp
|
||||
self.thread = Thread(self.proc)
|
||||
self.thread.signal.connect(self.kill)
|
||||
self.thread.start()
|
||||
self.launch_button.setText("Kill")
|
||||
self.game_running = True
|
||||
else:
|
||||
logger.warning("Error")
|
||||
self.proc = legendaryUtils.launch_game(self.app_name)
|
||||
if not self.proc:
|
||||
print("Fail")
|
||||
return
|
||||
|
||||
self.proc.finished.connect(self.finished)
|
||||
self.launch_button.setText("Kill")
|
||||
self.game_running = True
|
||||
|
||||
else:
|
||||
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):
|
||||
self.proc.kill()
|
||||
self.launch_button.setText("Launch")
|
||||
self.game_running = False
|
||||
logger.info("Killing Game")
|
||||
|
||||
def get_rating(self) -> str:
|
||||
return "gold" # TODO
|
||||
|
|
|
@ -54,8 +54,6 @@ class Settings(QScrollArea):
|
|||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||
|
||||
# Settings
|
||||
if RareConfig.get_config()["Rare"].get("theme") == "dark":
|
||||
self.parent().parent().setStyleSheet(open("../Styles/style.qss").read())
|
||||
|
||||
self.layout = QVBoxLayout()
|
||||
self.layout.addWidget(QLabel("<h1>Rare Settings</h1>"))
|
||||
|
@ -64,6 +62,10 @@ class Settings(QScrollArea):
|
|||
self.gen_form_legendary()
|
||||
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.clicked.connect(self.logout)
|
||||
self.layout.addWidget(self.logged_in_as)
|
||||
|
@ -88,11 +90,16 @@ class Settings(QScrollArea):
|
|||
self.setLayout(self.layout)
|
||||
|
||||
def update_rare_settings(self):
|
||||
print("Update Rare settings")
|
||||
logger.info("Update Rare settings")
|
||||
config = {"Rare": {}}
|
||||
if self.style_combo_box.currentIndex() == 1:
|
||||
self.parent().parent().parent().setStyleSheet(open("../Styles/style.qss").read())
|
||||
config["Rare"]["theme"] = "dark"
|
||||
else:
|
||||
self.parent().parent().parent().setStyleSheet("")
|
||||
config["Rare"]["theme"] = "light"
|
||||
|
||||
RareConfig.set_config(config)
|
||||
|
||||
def update_legendary_settings(self):
|
||||
print("Legendary update")
|
||||
|
@ -137,11 +144,14 @@ class Settings(QScrollArea):
|
|||
self.lgd_conf_locale = QLineEdit(self.config["Legendary"]["locale"])
|
||||
|
||||
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.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.table)
|
||||
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_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(), 1, QTableWidgetItem(""))
|
||||
|
||||
def delete_var(self):
|
||||
self.table.removeRow(self.table.currentRow())
|
||||
|
||||
def gen_form_rare(self):
|
||||
self.rare_form_group_box = QGroupBox("Rare Settings")
|
||||
self.rare_form = QFormLayout()
|
||||
|
|
|
@ -3,6 +3,7 @@ import os
|
|||
import subprocess
|
||||
from getpass import getuser
|
||||
|
||||
from PyQt5.QtCore import QProcess, QProcessEnvironment
|
||||
from legendary.core import 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)
|
||||
if not game:
|
||||
print("Game not found")
|
||||
return 1
|
||||
return None
|
||||
if game.is_dlc:
|
||||
print("Game is dlc")
|
||||
return 1
|
||||
return None
|
||||
if not os.path.exists(game.install_path):
|
||||
print("Game doesn't exist")
|
||||
return 1
|
||||
return None
|
||||
|
||||
if not offline:
|
||||
print("logging in")
|
||||
if not core.login():
|
||||
return 1
|
||||
return None
|
||||
if not skip_version_check and not core.is_noupdate_game(app_name):
|
||||
# check updates
|
||||
try:
|
||||
latest = core.get_asset(app_name, update=True)
|
||||
except ValueError:
|
||||
print("Metadata doesn't exist")
|
||||
return 1
|
||||
return None
|
||||
if latest.build_version != game.version:
|
||||
print("Please update game")
|
||||
return 1
|
||||
return None
|
||||
params, cwd, env = core.get_launch_parameters(app_name=app_name, offline=offline,
|
||||
extra_args=extra, user=username_override,
|
||||
wine_bin=wine_bin, wine_pfx=wine_prfix,
|
||||
language=language, wrapper=wrapper,
|
||||
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:
|
||||
|
|
Loading…
Reference in a new issue