1
0
Fork 0
mirror of synced 2024-06-30 20:20:53 +12:00

Merge pull request #39 from Dummerle/dev

Dev
This commit is contained in:
Dummerle 2021-04-12 14:27:48 +02:00 committed by GitHub
commit 2b7f7b076f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 43 deletions

View file

@ -1,14 +1,21 @@
import platform
import time
from PyQt5.QtCore import QSettings from PyQt5.QtCore import QSettings
from PyQt5.QtGui import QCloseEvent from PyQt5.QtGui import QCloseEvent
from PyQt5.QtWidgets import QMainWindow, QMessageBox from PyQt5.QtWidgets import QMainWindow, QMessageBox
from pypresence import Presence
from custom_legendary.core import LegendaryCore
from rare.components.tab_widget import TabWidget from rare.components.tab_widget import TabWidget
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
def __init__(self, core):
def __init__(self, core: LegendaryCore):
super(MainWindow, self).__init__() super(MainWindow, self).__init__()
settings = QSettings() settings = QSettings()
self.core = core
width, height = 1200, 800 width, height = 1200, 800
if settings.value("save_size", False): if settings.value("save_size", False):
width, height = settings.value("window_size", (1200, 800), tuple) width, height = settings.value("window_size", (1200, 800), tuple)
@ -17,8 +24,25 @@ class MainWindow(QMainWindow):
self.setWindowTitle("Rare - GUI for legendary") self.setWindowTitle("Rare - GUI for legendary")
self.tab_widget = TabWidget(core) self.tab_widget = TabWidget(core)
self.setCentralWidget(self.tab_widget) self.setCentralWidget(self.tab_widget)
self.tab_widget.games_tab.default_widget.game_list.game_started.connect(self.set_discord_rpc)
self.tab_widget.delete_presence.connect(self.remove_rpc)
self.show() self.show()
def remove_rpc(self):
self.RPC.clear()
self.RPC.close()
del self.RPC
def set_discord_rpc(self, app_name):
self.RPC = Presence("830732538225360908") # Rare app: https://discord.com/developers/applications
self.RPC.connect()
title = self.core.get_installed_game(app_name).title
start = str(time.time()).split(".")[0]
self.RPC.update(large_image="logo", details=title, large_text=title,
state="via Rare on " + platform.system(), start=start)
def closeEvent(self, e: QCloseEvent): def closeEvent(self, e: QCloseEvent):
settings = QSettings() settings = QSettings()
if settings.value("sys_tray", True, bool): if settings.value("sys_tray", True, bool):

View file

@ -1,9 +1,10 @@
import webbrowser import webbrowser
from PyQt5.QtCore import QSize from PyQt5.QtCore import QSize, pyqtSignal
from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction
from qtawesome import icon from qtawesome import icon
from custom_legendary.core import LegendaryCore
from rare.components.tab_utils import TabBar, TabButtonWidget from rare.components.tab_utils import TabBar, TabButtonWidget
from rare.components.tabs.account import MiniWidget from rare.components.tabs.account import MiniWidget
from rare.components.tabs.cloud_saves import SyncSaves from rare.components.tabs.cloud_saves import SyncSaves
@ -11,69 +12,96 @@ from rare.components.tabs.downloads.__init__ import DownloadTab
from rare.components.tabs.games import GameTab from rare.components.tabs.games import GameTab
from rare.components.tabs.settings import SettingsTab from rare.components.tabs.settings import SettingsTab
from rare.utils.models import InstallOptions from rare.utils.models import InstallOptions
from custom_legendary.core import LegendaryCore
class TabWidget(QTabWidget): class TabWidget(QTabWidget):
delete_presence = pyqtSignal()
def __init__(self, core: LegendaryCore): def __init__(self, core: LegendaryCore):
super(TabWidget, self).__init__() super(TabWidget, self).__init__()
disabled_tab = 3 disabled_tab = 3
self.setTabBar(TabBar(disabled_tab)) self.setTabBar(TabBar(disabled_tab))
self.settings = SettingsTab(core)
self.game_list = GameTab(core) # Generate Tabs
self.game_list.default_widget.game_list.update_game.connect(lambda: self.setCurrentIndex(1)) self.games_tab = GameTab(core)
updates = self.game_list.default_widget.game_list.updates updates = self.games_tab.default_widget.game_list.updates
self.addTab(self.game_list, self.tr("Games"))
self.downloadTab = DownloadTab(core, updates) self.downloadTab = DownloadTab(core, updates)
self.addTab(self.downloadTab, "Downloads" + (" (" + str(len(updates)) + ")" if len(updates) != 0 else ""))
self.downloadTab.finished.connect(self.dl_finished)
self.game_list.default_widget.game_list.install_game.connect(lambda x: self.downloadTab.install_game(x))
self.game_list.game_info.info.verify_game.connect(lambda app_name: self.downloadTab.install_game(
InstallOptions(app_name, core.get_installed_game(app_name).install_path, repair=True)))
self.tabBarClicked.connect(lambda x: self.game_list.layout.setCurrentIndex(0) if x == 0 else None)
self.cloud_saves = SyncSaves(core) self.cloud_saves = SyncSaves(core)
self.settings = SettingsTab(core)
# add tabs
self.addTab(self.games_tab, self.tr("Games"))
self.addTab(self.downloadTab, "Downloads" + (" (" + str(len(updates)) + ")" if len(updates) != 0 else ""))
self.addTab(self.cloud_saves, "Cloud Saves") self.addTab(self.cloud_saves, "Cloud Saves")
self.cloud_saves.finished.connect(self.finished_sync)
self.game_list.default_widget.game_list.sync_cloud.connect(
lambda app_name: self.cloud_saves.sync_game(app_name, True))
# Space Tab # Space Tab
self.addTab(QWidget(), "") self.addTab(QWidget(), "")
self.setTabEnabled(disabled_tab, False) self.setTabEnabled(disabled_tab, False)
# Buttons
store_button = TabButtonWidget(core, 'fa.shopping-cart', 'Epic Games Store')
store_button.pressed.connect(lambda: webbrowser.open("https://www.epicgames.com/store"))
self.tabBar().setTabButton(3, self.tabBar().RightSide, store_button)
self.account = QWidget() self.account = QWidget()
self.addTab(self.account, "") self.addTab(self.account, "")
self.setTabEnabled(disabled_tab + 1, False) self.setTabEnabled(disabled_tab + 1, False)
# self.settings = SettingsTab(core)
self.addTab(self.settings, icon("fa.gear", color='white'), "(!)" if self.settings.about.update_available else "") account_action = QWidgetAction(self)
self.setIconSize(QSize(25, 25))
store_button = TabButtonWidget(core, 'fa.shopping-cart', 'Epic Games Store')
store_button.pressed.connect(lambda: webbrowser.open("https://www.epicgames.com/store"))
self.tabBar().setTabButton(3, self.tabBar().RightSide, store_button)
account_action = QWidgetAction(self)
account_action.setDefaultWidget(MiniWidget(core)) account_action.setDefaultWidget(MiniWidget(core))
account_button = TabButtonWidget(core, 'mdi.account-circle', 'Account') account_button = TabButtonWidget(core, 'mdi.account-circle', 'Account')
account_button.setMenu(QMenu()) account_button.setMenu(QMenu())
account_button.menu().addAction(account_action) account_button.menu().addAction(account_action)
self.tabBar().setTabButton(4, self.tabBar().RightSide, account_button) self.tabBar().setTabButton(4, self.tabBar().RightSide, account_button)
def dl_finished(self): self.addTab(self.settings, icon("fa.gear", color='white'),
self.game_list.default_widget.game_list.update_list() "(!)" if self.settings.about.update_available else "")
self.setTabText(1, "Downloads")
# Signals
# open download tab
self.games_tab.default_widget.game_list.update_game.connect(lambda: self.setCurrentIndex(1))
# Download finished
self.downloadTab.finished.connect(self.dl_finished)
# start download
self.games_tab.default_widget.game_list.install_game.connect(self.start_download)
# repair game
self.games_tab.game_info.info.verify_game.connect(lambda app_name: self.downloadTab.install_game(
InstallOptions(app_name, core.get_installed_game(app_name).install_path, repair=True)))
# Open game list on click on Games tab button
self.tabBarClicked.connect(lambda x: self.games_tab.layout.setCurrentIndex(0) if x == 0 else None)
# Finished sync
self.cloud_saves.finished.connect(self.finished_sync)
self.games_tab.default_widget.game_list.game_exited.connect(self.game_finished)
self.setIconSize(QSize(25, 25))
# Sync game and delete dc rpc
def game_finished(self, app_name):
self.delete_presence.emit()
self.cloud_saves.sync_game(app_name, True)
# Update gamelist and set text of Downlaods to "Downloads"
def dl_finished(self, update_list):
if update_list:
self.games_tab.default_widget.game_list.update_list()
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys())
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
def start_download(self, app_name):
self.downloadTab.install_game(app_name)
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys()) + 1
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
def resizeEvent(self, event): def resizeEvent(self, event):
self.tabBar().setMinimumWidth(self.width()) self.tabBar().setMinimumWidth(self.width())
super(TabWidget, self).resizeEvent(event) super(TabWidget, self).resizeEvent(event)
# Remove text "sync game"
def finished_sync(self, app_name): def finished_sync(self, app_name):
self.game_list.default_widget.game_list.widgets[app_name][0].info_text = "" self.games_tab.default_widget.games_tab.widgets[app_name][0].info_text = ""
self.game_list.default_widget.game_list.widgets[app_name][0].info_label.setText("") self.games_tab.default_widget.games_tab.widgets[app_name][0].info_label.setText("")
self.game_list.default_widget.game_list.widgets[app_name][1].info_label.setText("") self.games_tab.default_widget.games_tab.widgets[app_name][1].info_label.setText("")

View file

@ -20,7 +20,7 @@ logger = getLogger("Download")
class DownloadTab(QWidget): class DownloadTab(QWidget):
finished = pyqtSignal() finished = pyqtSignal(bool)
thread: QThread thread: QThread
dl_queue = [] dl_queue = []
@ -140,6 +140,9 @@ class DownloadTab(QWidget):
def start_installation(self, dlm, game, status_queue, igame, repair_file, options: InstallOptions, analysis): def start_installation(self, dlm, game, status_queue, igame, repair_file, options: InstallOptions, analysis):
print("start installation", game.app_title) print("start installation", game.app_title)
if self.dl_queue:
self.dl_queue.pop(0)
self.queue_widget.update_queue(self.dl_queue)
self.active_game = game self.active_game = game
self.thread = DownloadThread(dlm, self.core, status_queue, igame, options.repair, repair_file) self.thread = DownloadThread(dlm, self.core, status_queue, igame, options.repair, repair_file)
self.thread.status.connect(self.status) self.thread.status.connect(self.status)
@ -221,7 +224,7 @@ class DownloadTab(QWidget):
for i in self.update_widgets.values(): for i in self.update_widgets.values():
i.update_button.setDisabled(False) i.update_button.setDisabled(False)
self.finished.emit() self.finished.emit(True)
self.reset_infos() self.reset_infos()
if len(self.dl_queue) != 0: if len(self.dl_queue) != 0:
@ -235,6 +238,9 @@ class DownloadTab(QWidget):
elif text == "stop": elif text == "stop":
self.reset_infos() self.reset_infos()
self.active_game = None self.active_game = None
self.finished.emit(False)
if self.dl_queue:
self.start_installation(*self.dl_queue[0])
def reset_infos(self): def reset_infos(self):
self.kill_button.setDisabled(True) self.kill_button.setDisabled(True)

View file

@ -21,7 +21,8 @@ class GameList(QStackedWidget):
install_game = pyqtSignal(InstallOptions) install_game = pyqtSignal(InstallOptions)
show_game_info = pyqtSignal(str) show_game_info = pyqtSignal(str)
update_game = pyqtSignal() update_game = pyqtSignal()
sync_cloud = pyqtSignal(str) game_exited = pyqtSignal(str)
game_started = pyqtSignal(str)
def __init__(self, core: LegendaryCore): def __init__(self, core: LegendaryCore):
super(GameList, self).__init__() super(GameList, self).__init__()
@ -165,12 +166,13 @@ class GameList(QStackedWidget):
logger.info("Auto saves disabled") logger.info("Auto saves disabled")
return return
self.sync_cloud.emit(app_name) self.game_exited.emit(app_name)
self.widgets[app_name][0].info_text = self.tr("Sync CLoud saves") self.widgets[app_name][0].info_text = self.tr("Sync CLoud saves")
self.widgets[app_name][0].info_label.setText(self.tr("Sync CLoud saves")) self.widgets[app_name][0].info_label.setText(self.tr("Sync CLoud saves"))
self.widgets[app_name][1].info_label.setText(self.tr("Sync CLoud saves")) self.widgets[app_name][1].info_label.setText(self.tr("Sync CLoud saves"))
def launch(self, app_name): def launch(self, app_name):
self.game_started.emit(app_name)
self.widgets[app_name][0].info_text = self.tr("Game running") self.widgets[app_name][0].info_text = self.tr("Game running")
self.widgets[app_name][1].launch_button.setDisabled(True) self.widgets[app_name][1].launch_button.setDisabled(True)
self.widgets[app_name][1].launch_button.setText(self.tr("Game running")) self.widgets[app_name][1].launch_button.setText(self.tr("Game running"))

View file

@ -4,3 +4,4 @@ PyQt5
QtAwesome QtAwesome
notify-py notify-py
psutil psutil
pypresence

View file

@ -33,6 +33,7 @@ setuptools.setup(
"PyQt5", "PyQt5",
"QtAwesome", "QtAwesome",
"notify-py", "notify-py",
"psutil" "psutil",
"pypresence"
], ],
) )