From 431a5598b906ca9e2f06c6ec5841f1de0e8dd1e5 Mon Sep 17 00:00:00 2001 From: Dummerle Date: Tue, 20 Oct 2020 22:46:17 +0200 Subject: [PATCH] launch gui not installed gui --- Rare/FlowLayout.py | 92 ------------------- Rare/GameWidget.py | 34 ++++++- Rare/TabWidgets.py | 19 +++- .../utils/{legendary.py => legendaryUtils.py} | 24 ++++- 4 files changed, 63 insertions(+), 106 deletions(-) delete mode 100644 Rare/FlowLayout.py rename Rare/utils/{legendary.py => legendaryUtils.py} (56%) diff --git a/Rare/FlowLayout.py b/Rare/FlowLayout.py deleted file mode 100644 index 66441fce..00000000 --- a/Rare/FlowLayout.py +++ /dev/null @@ -1,92 +0,0 @@ -from PyQt5 import Qt -from PyQt5.QtCore import QRect, QPoint, QSize -from PyQt5.QtWidgets import QSizePolicy, QLayout - - -class FlowLayout(QLayout): - def __init__(self, parent=None, margin=0, spacing=-1): - super(FlowLayout, self).__init__(parent) - - if parent is not None: - self.setContentsMargins(margin, margin, margin, margin) - - self.setSpacing(spacing) - - self.itemList = [] - - def __del__(self): - item = self.takeAt(0) - while item: - item = self.takeAt(0) - - def addItem(self, item): - self.itemList.append(item) - - def count(self): - return len(self.itemList) - - def itemAt(self, index): - if index >= 0 and index < len(self.itemList): - return self.itemList[index] - - return None - - def takeAt(self, index): - if index >= 0 and index < len(self.itemList): - return self.itemList.pop(index) - - return None - - def expandingDirections(self): - return Qt.Orientations(Qt.Orientation(0)) - - def hasHeightForWidth(self): - return True - - def heightForWidth(self, width): - height = self.doLayout(QRect(0, 0, width, 0), True) - return height - - def setGeometry(self, rect): - super(FlowLayout, self).setGeometry(rect) - self.doLayout(rect, False) - - def sizeHint(self): - return self.minimumSize() - - def minimumSize(self): - size = QSize() - - for item in self.itemList: - size = size.expandedTo(item.minimumSize()) - - margin, _, _, _ = self.getContentsMargins() - - size += QSize(2 * margin, 2 * margin) - return size - - def doLayout(self, rect, testOnly): - x = rect.x() - y = rect.y() - lineHeight = 0 - - for item in self.itemList: - wid = item.widget() - spaceX = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton, QSizePolicy.PushButton, - Qt.Horizontal) - spaceY = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton, QSizePolicy.PushButton, - Qt.Vertical) - nextX = x + item.sizeHint().width() + spaceX - if nextX - spaceX > rect.right() and lineHeight > 0: - x = rect.x() - y = y + lineHeight + spaceY - nextX = x + item.sizeHint().width() + spaceX - lineHeight = 0 - - if not testOnly: - item.setGeometry(QRect(QPoint(x, y), item.sizeHint())) - - x = nextX - lineHeight = max(lineHeight, item.sizeHint().height()) - - return y + lineHeight - rect.y() diff --git a/Rare/GameWidget.py b/Rare/GameWidget.py index 52b810a5..fab48c11 100644 --- a/Rare/GameWidget.py +++ b/Rare/GameWidget.py @@ -10,14 +10,14 @@ class GameWidget(QWidget): self.title = game.title self.version = game.version + self.size = game.install_size self.layout = QHBoxLayout() - - self.pixmap = QPixmap(f"../images/{game.app_name}/FinalArt.png") - self.pixmap = self.pixmap.scaled(240, 320) + pixmap = QPixmap(f"../images/{game.app_name}/FinalArt.png") + pixmap = pixmap.scaled(240, 320) self.image = QLabel() - self.image.setPixmap(self.pixmap) + self.image.setPixmap(pixmap) self.layout.addWidget(self.image) ##Layout on the right @@ -28,12 +28,16 @@ class GameWidget(QWidget): self.launch_button = QPushButton(play_icon, "Launch") self.launch_button.clicked.connect(self.launch) - self.wine_rating = QLabel("Wine Rating: Comming Soon") + 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.childLayout.addWidget(self.launch_button) self.childLayout.addWidget(self.wine_rating) self.childLayout.addWidget(self.version_label) + self.childLayout.addWidget(self.size_label) + self.childLayout.addWidget(self.settings) self.childLayout.addStretch(1) # self.layout.addWidget(QLabel(game.title)) @@ -42,3 +46,23 @@ class GameWidget(QWidget): def launch(self): print(f"launch {self.title}") + # TODO + + def get_rating(self) -> str: + return "gold" # TODO + + +class UninstalledGameWidget(QWidget): + def __init__(self, game): + super(UninstalledGameWidget, self).__init__() + self.title = game.app_title + self.layout = QHBoxLayout() + + 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 diff --git a/Rare/TabWidgets.py b/Rare/TabWidgets.py index ac6aa5f2..1a7cb969 100644 --- a/Rare/TabWidgets.py +++ b/Rare/TabWidgets.py @@ -2,8 +2,8 @@ from PyQt5.QtCore import QUrl, Qt from PyQt5.QtWebEngineWidgets import QWebEngineView from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QScrollArea -from Rare.utils.legendary import get_installed -from Rare.GameWidget import GameWidget +from Rare.utils.legendaryUtils import get_installed, get_not_installed +from Rare.GameWidget import GameWidget, UninstalledGameWidget class BrowserTab(QWebEngineView): @@ -30,12 +30,12 @@ class GameListInstalled(QScrollArea): super(GameListInstalled, self).__init__(parent=parent) self.widget = QWidget() self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + self.layout = QVBoxLayout() for i in get_installed(): widget = GameWidget(i) - #widget.setFixedSize(240, 340) + #print(i.) self.layout.addWidget(widget) self.widget.setLayout(self.layout) @@ -45,7 +45,16 @@ class GameListInstalled(QScrollArea): class GameListUninstalled(QScrollArea): def __init__(self, parent): super(GameListUninstalled, self).__init__(parent=parent) - self.setWidget(QLabel("Hier kommen die nicht installierten Spiele")) + self.widget = QWidget() + self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) + self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + + self.layout = QVBoxLayout() + + for game in get_not_installed(): + self.layout.addWidget(UninstalledGameWidget(game)) + self.widget.setLayout(self.layout) + self.setWidget(self.widget) class UpdateList(QWidget): diff --git a/Rare/utils/legendary.py b/Rare/utils/legendaryUtils.py similarity index 56% rename from Rare/utils/legendary.py rename to Rare/utils/legendaryUtils.py index d34d541a..7d03e8aa 100644 --- a/Rare/utils/legendary.py +++ b/Rare/utils/legendaryUtils.py @@ -9,7 +9,6 @@ cli = LegendaryCLI def get_installed(): return core.get_installed_list() - # games = sorted(get_installed, key=lambda x: x.title) def get_installed_names(): @@ -18,23 +17,40 @@ def get_installed_names(): names.append(i.app_name) return names +def get_not_installed(): + games = [] + installed = get_installed_names() + for game in get_games(): + if not game.app_name in installed: + games.append(game) + return games # return (games, dlcs) def get_games_and_dlcs(): if not core.login(): print("Login Failed") exit(1) - print('Getting game list... (this may take a while)') + return core.get_game_and_dlc_list() +def get_games_by_name(): + if not core.login(): + print("Login Failed") + exit(1) + game = [] + 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") exit(1) - print('Getting game list... (this may take a while)') return core.get_game_list() def start(game_name: str, args): - subprocess.run(["legendary", "launch", game_name]) \ No newline at end of file + subprocess.run(["legendary", "launch", game_name]) +