diff --git a/Rare/Dialogs.py b/Rare/Dialogs.py new file mode 100644 index 00000000..fe72486d --- /dev/null +++ b/Rare/Dialogs.py @@ -0,0 +1,23 @@ +from PyQt5.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QPushButton, QLabel + + +class InstallDialog(QDialog): + def __init__(self, game): + super(InstallDialog, self).__init__() + self.setWindowTitle("Install Game") + self.layout = QVBoxLayout() + + + self.options = QLabel("Verschiedene Optionene") + self.layout.addWidget(self.options) + + self.layout.addStretch(1) + self.yes_button = QPushButton("Install") + self.cancel_button = QPushButton("cancel") + + self.button_layout = QHBoxLayout() + self.button_layout.addWidget(self.yes_button) + self.button_layout.addWidget(self.cancel_button) + self.cancel_button.clicked.connect(self.exit) + self.layout.addLayout(self.button_layout) + self.setLayout(self.layout) diff --git a/Rare/GameWidget.py b/Rare/GameWidget.py index fab48c11..41e012d3 100644 --- a/Rare/GameWidget.py +++ b/Rare/GameWidget.py @@ -1,16 +1,20 @@ -import qtawesome as qta from PyQt5.QtGui import QPixmap -from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QVBoxLayout, QPushButton +from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QVBoxLayout, QPushButton, QStyle + +from Rare.Dialogs import InstallDialog +from Rare.utils import legendaryUtils class GameWidget(QWidget): def __init__(self, game): super(GameWidget, self).__init__() - # self.setStyleSheet("border:1px solid rgb(0, 0, 0)") self.title = game.title + self.app_name = game.app_name self.version = game.version self.size = game.install_size + self.launch_params = game.launch_parameters + #self.dev = self.layout = QHBoxLayout() @@ -23,16 +27,17 @@ class GameWidget(QWidget): ##Layout on the right self.childLayout = QVBoxLayout() - self.childLayout.addWidget(QLabel(f"

{self.title}

")) - play_icon = qta.icon('fa5s.play') - + play_icon = self.style().standardIcon(getattr(QStyle, 'SP_MediaPlay')) + settings_icon = self.style().standardIcon(getattr(QStyle, 'SP_DirIcon')) + self.title_widget = QLabel(f"

{self.title}

") self.launch_button = QPushButton(play_icon, "Launch") self.launch_button.clicked.connect(self.launch) self.wine_rating = QLabel("Wine Rating: " + self.get_rating()) self.version_label = QLabel("Version: " + str(self.version)) self.size_label = QLabel(f"Installed size: {round(self.size / (1024 ** 3), 2)} GB") - self.settings = QPushButton(qta.icon("fa5s.cogs"), " Settings") + self.settings = QPushButton(settings_icon, " Settings (Icon TODO)") + self.childLayout.addWidget(self.title_widget) self.childLayout.addWidget(self.launch_button) self.childLayout.addWidget(self.wine_rating) self.childLayout.addWidget(self.version_label) @@ -46,7 +51,9 @@ class GameWidget(QWidget): def launch(self): print(f"launch {self.title}") - # TODO + self.launch_button.setText("Running") + self.launch_button.setDisabled(True) + legendaryUtils.start(self.app_name) # adding launch params #TODO def get_rating(self) -> str: return "gold" # TODO @@ -57,12 +64,30 @@ class UninstalledGameWidget(QWidget): super(UninstalledGameWidget, self).__init__() self.title = game.app_title self.layout = QHBoxLayout() + self.game = game + self.visible = True pixmap = QPixmap(f"../images/{game.app_name}/UninstalledArt.png") pixmap = pixmap.scaled(240, 320) self.image = QLabel() self.image.setPixmap(pixmap) - self.layout.addWidget(self.image) - self.layout.addWidget(QLabel(f"

{self.title}

")) - self.setLayout(self.layout) \ No newline at end of file + self.child_layout = QVBoxLayout() + + self.title_label = QLabel(f"

{self.title}

") + self.install_button = QPushButton("Install") + self.install_button.clicked.connect(self.install) + + self.child_layout.addWidget(self.title_label) + self.child_layout.addWidget(self.install_button) + self.child_layout.addStretch(1) + self.layout.addWidget(self.image) + self.layout.addLayout(self.child_layout) + + self.layout.addStretch(1) + self.setLayout(self.layout) + + def install(self): + print("install " + self.title) + #TODO + # dialog = InstallDialog(self.game) diff --git a/Rare/Main.py b/Rare/Main.py index 4f24e5b6..5376feed 100644 --- a/Rare/Main.py +++ b/Rare/Main.py @@ -1,3 +1,4 @@ +import os import sys from PyQt5.QtWidgets import QTabWidget, QMainWindow, QWidget, QApplication @@ -36,11 +37,36 @@ class TabWidget(QTabWidget): self.addTab(self.settings, "Settings") +class LoginWindow(QMainWindow): + def __init__(self): + super(LoginWindow, self).__init__() + self.setWindowTitle("Rare - Login") + self.setGeometry(0, 0, 200, 150) + self.show() + + def main(): + # Check if Legendary is installed + + if os.path.isfile(os.path.expanduser("~") + '/.config/legendary/user.json'): + startMainProcess() + else: + notLoggedIn() + + +def startMainProcess(): + # TODO Download Images + app = QApplication(sys.argv) ex = MainWindow() sys.exit(app.exec_()) +def notLoggedIn(): + app = QApplication(sys.argv) + window = LoginWindow() + sys.exit(app.exec_()) + + if __name__ == '__main__': main() diff --git a/Rare/TabWidgets.py b/Rare/TabWidgets.py index 1a7cb969..4173c50b 100644 --- a/Rare/TabWidgets.py +++ b/Rare/TabWidgets.py @@ -1,9 +1,9 @@ from PyQt5.QtCore import QUrl, Qt from PyQt5.QtWebEngineWidgets import QWebEngineView -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QScrollArea +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QScrollArea, QLineEdit -from Rare.utils.legendaryUtils import get_installed, get_not_installed from Rare.GameWidget import GameWidget, UninstalledGameWidget +from Rare.utils.legendaryUtils import get_installed, get_not_installed class BrowserTab(QWebEngineView): @@ -18,7 +18,6 @@ class Settings(QWidget): super(Settings, self).__init__(parent=parent) self.layout = QVBoxLayout() label = QLabel() - print(label.fontInfo().pixelSize()) self.layout.addWidget(QLabel("

Settings

")) self.layout.addWidget(QLabel("Coming soon")) self.layout.addStretch(1) @@ -35,9 +34,8 @@ class GameListInstalled(QScrollArea): self.layout = QVBoxLayout() for i in get_installed(): widget = GameWidget(i) - #print(i.) - self.layout.addWidget(widget) + self.layout.addWidget(widget) self.widget.setLayout(self.layout) self.setWidget(self.widget) @@ -51,8 +49,15 @@ class GameListUninstalled(QScrollArea): self.layout = QVBoxLayout() + self.filter = QLineEdit() + self.filter.setPlaceholderText("Search game TODO") + self.layout.addWidget(self.filter) + + self.widgets = [] for game in get_not_installed(): - self.layout.addWidget(UninstalledGameWidget(game)) + game_widget = UninstalledGameWidget(game) + self.layout.addWidget(game_widget) + self.widgets.append(game_widget) self.widget.setLayout(self.layout) self.setWidget(self.widget) diff --git a/Rare/utils/legendaryUtils.py b/Rare/utils/legendaryUtils.py index 7d03e8aa..606d0ca6 100644 --- a/Rare/utils/legendaryUtils.py +++ b/Rare/utils/legendaryUtils.py @@ -1,10 +1,13 @@ -import subprocess +import os +from argparse import Namespace +from distutils.util import strtobool from legendary.cli import LegendaryCLI from legendary.core import LegendaryCore + core = LegendaryCore() -cli = LegendaryCLI +cli = LegendaryCLI() def get_installed(): @@ -17,6 +20,7 @@ def get_installed_names(): names.append(i.app_name) return names + def get_not_installed(): games = [] installed = get_installed_names() @@ -25,6 +29,7 @@ def get_not_installed(): games.append(game) return games + # return (games, dlcs) def get_games_and_dlcs(): if not core.login(): @@ -33,6 +38,7 @@ def get_games_and_dlcs(): return core.get_game_and_dlc_list() + def get_games_by_name(): if not core.login(): print("Login Failed") @@ -41,9 +47,11 @@ def get_games_by_name(): for i in core.get_game_list(): game.append(i.app_name) + def get_game_by_name(name: str): return core.get_game(name) + def get_games(): if not core.login(): print("Login Failed") @@ -51,6 +59,34 @@ def get_games(): return core.get_game_list() -def start(game_name: str, args): - subprocess.run(["legendary", "launch", game_name]) +def start(game_name, + offline=False, + skip_version_check=False, + reset_defaults=None, + set_defaults=None, + wine_bin=os.environ.get('LGDRY_WINE_BINARY', None), + wine_pfx=os.environ.get('LGDRY_WINE_PREFIX', None), + no_wine=strtobool(os.environ.get('LGDRY_NO_WINE', 'False')), + debug=False, + dry_run=False, + user_name_override=None, + language=None + ): + cli.launch_game(Namespace(app_name=game_name, + offline=offline, + wrapper=os.environ.get('LGDRY_WRAPPER', None), + skip_version_check=skip_version_check, + reset_defaults=reset_defaults, + set_defaults=set_defaults, + wine_bin=wine_bin, + wine_pfx=wine_pfx, + no_wine=no_wine, + debug=debug, + dry_run=dry_run, + user_name_override=user_name_override, + language=language + ), + [] # Extra + ) +# start("Sugar")