1
0
Fork 0
mirror of synced 2024-06-02 02:34:40 +12:00
This commit is contained in:
Dummerle 2020-10-20 16:55:57 +02:00
parent c9c52b0917
commit aff265f018
2 changed files with 36 additions and 115 deletions

View file

@ -1,79 +1,46 @@
import json
import os
import subprocess
import sys
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QStackedLayout, QScrollArea
from PyQt5.QtWidgets import QTabWidget, QMainWindow, QWidget, QApplication
import Rare
from Rare import FlowLayout
from Rare.ShowGame import GameWidget
from Rare.TabWidgets import Settings, GameListInstalled, BrowserTab, GameListUninstalled, UpdateList
class BodyGames(QScrollArea):
def __init__(self, allGames, installedGames):
super().__init__()
self.allGames = allGames
self.installedGames = installedGames
self.initUI()
class MainWindow(QMainWindow):
def initUI(self):
self.layout = FlowLayout.FlowLayout()
self.setLayout(self.layout)
for game in self.allGames:
self.layout.addWidget(GameWidget(game=game, installed=game['app_name'] in self.installedGames))
def addImage(self, pathToImage, layout, x, y):
self.label = Rare.ExtendedQLabel()
self.label.setPixmap(QPixmap(pathToImage).scaled(240, 320))
self.label.clicked.connect(lambda: self.clickedGame(pathToImage.split('/', 2)[1]))
self.label.rightClicked.connect(lambda: self.gameSettings(pathToImage.split('/', 2)[1]))
layout.addWidget(self.label, x, y)
def clickedGame(self, game):
self.game = game
if self.game in self.installedGames:
self.launchGame(self.game)
else:
self.installGame(self.game)
# def launchGame(self, game):
# self.window = LaunchWindow(game)
# self.window.show()
# self.window.outputWindow.appendPlainText('> legendary launch ' + game + '\n')
# self.window.reader.start('legendary', ['launch', game])
def installGame(self, game):
self.window = Rare.InstallWindow(game)
self.window.show()
def gameSettings(self, game):
self.window = Rare.GameSettingsWindow(game)
self.window.show()
class Body(QStackedLayout):
def __init__(self):
super(Body, self).__init__()
super().__init__()
self.setWindowTitle("Rare")
self.setGeometry(0, 0, 800, 600)
self.setCentralWidget(TabWidget(self))
self.show()
all, installed = self.get_games()
self.addWidget(BodyGames(all, installed))
def get_games(self):
all_games = []
for filename in os.listdir(os.path.expanduser("~") + '/.config/legendary/metadata/'):
with open(os.path.expanduser("~") + '/.config/legendary/metadata/' + filename, 'r') as f:
game = json.load(f)
all_games.append(game)
try:
os.mkdir('images/' + game["app_name"])
except OSError:
pass
class TabWidget(QTabWidget):
# print('Parsing installed games')
installedGames = []
for line in subprocess.Popen('legendary list-installed --csv | tail -n +2', shell=True,
stdout=subprocess.PIPE, universal_newlines=True).stdout:
installedGames.append(line.split(',', 1)[0])
def __init__(self, parent):
super(QWidget, self).__init__(parent)
return all_games, installedGames
self.game_list = GameListInstalled(self)
self.addTab(self.game_list, "Games")
self.uninstalled_games = GameListUninstalled(self)
self.addTab(self.uninstalled_games, "Install Games")
self.update_tab = UpdateList(self)
self.addTab(self.update_tab, "Updates")
self.browser = BrowserTab(self)
self.addTab(self.browser, "Store")
self.settings = Settings(self)
self.addTab(self.settings, "Settings")
def main():
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()

View file

@ -1,46 +0,0 @@
import sys
from PyQt5.QtWidgets import QTabWidget, QMainWindow, QWidget, QApplication
from Rare.TabWidgets import Settings, GameListInstalled, BrowserTab, GameListUninstalled, UpdateList
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Rare")
self.setGeometry(0, 0, 800, 600)
self.setCentralWidget(TabWidget(self))
self.show()
class TabWidget(QTabWidget):
def __init__(self, parent):
super(QWidget, self).__init__(parent)
self.game_list = GameListInstalled(self)
self.addTab(self.game_list, "Games")
self.uninstalled_games = GameListUninstalled(self)
self.addTab(self.uninstalled_games, "Install Games")
self.update_tab = UpdateList(self)
self.addTab(self.update_tab, "Updates")
self.browser = BrowserTab(self)
self.addTab(self.browser, "Store")
self.settings = Settings(self)
self.addTab(self.settings, "Settings")
def main():
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()