1
0
Fork 0
mirror of synced 2024-06-26 10:11:19 +12:00

Add shared.py

This commit is contained in:
Dummerle 2021-10-07 20:19:24 +02:00
parent 272e72a8dd
commit 3bf6692760
21 changed files with 165 additions and 142 deletions

View file

@ -12,10 +12,10 @@ from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QStyleFactory, QMessa
from legendary.core import LegendaryCore from legendary.core import LegendaryCore
from rare import languages_path, resources_path, cache_dir from rare import languages_path, resources_path, cache_dir
from rare import shared
from rare.components.dialogs.launch_dialog import LaunchDialog from rare.components.dialogs.launch_dialog import LaunchDialog
from rare.components.main_window import MainWindow from rare.components.main_window import MainWindow
from rare.components.tray_icon import TrayIcon from rare.components.tray_icon import TrayIcon
from rare.utils.models import Signals
from rare.utils.utils import load_color_scheme from rare.utils.utils import load_color_scheme
start_time = time.strftime('%y-%m-%d--%H-%M') # year-month-day-hour-minute start_time = time.strftime('%y-%m-%d--%H-%M') # year-month-day-hour-minute
@ -35,12 +35,12 @@ def excepthook(exc_type, exc_value, exc_tb):
class App(QApplication): class App(QApplication):
def __init__(self, args): def __init__(self):
super(App, self).__init__(sys.argv) super(App, self).__init__(sys.argv)
self.args = args # add some options self.args = shared.args # add some options
# init Legendary # init Legendary
try: try:
self.core = LegendaryCore() self.core = shared.init_legendary()
except configparser.MissingSectionHeaderError as e: except configparser.MissingSectionHeaderError as e:
logger.warning(f"Config is corrupt: {e}") logger.warning(f"Config is corrupt: {e}")
if config_path := os.environ.get('XDG_CONFIG_HOME'): if config_path := os.environ.get('XDG_CONFIG_HOME'):
@ -73,7 +73,7 @@ class App(QApplication):
self.setOrganizationName("Rare") self.setOrganizationName("Rare")
self.settings = QSettings() self.settings = QSettings()
self.signals = Signals() self.signals = shared.init_signals()
self.signals.app.connect(lambda x: self.handle_signal(*x)) self.signals.app.connect(lambda x: self.handle_signal(*x))
# Translator # Translator
@ -115,18 +115,17 @@ class App(QApplication):
self.setWindowIcon(QIcon(os.path.join(resources_path, "images", "Rare.png"))) self.setWindowIcon(QIcon(os.path.join(resources_path, "images", "Rare.png")))
# launch app # launch app
self.launch_dialog = LaunchDialog(self.core, args.offline) self.launch_dialog = LaunchDialog()
self.launch_dialog.quit_app.connect(self.launch_dialog.close) self.launch_dialog.quit_app.connect(self.launch_dialog.close)
self.launch_dialog.quit_app.connect(lambda ec: exit(ec)) self.launch_dialog.quit_app.connect(lambda ec: exit(ec))
self.launch_dialog.start_app.connect(self.start_app) self.launch_dialog.start_app.connect(self.start_app)
self.launch_dialog.start_app.connect(self.launch_dialog.close) self.launch_dialog.start_app.connect(self.launch_dialog.close)
if not args.silent or args.subparser == "launch": if not self.args.silent or self.args.subparser == "launch":
self.launch_dialog.login() self.launch_dialog.login()
def start_app(self, offline=False, api_results=None): def start_app(self):
self.args.offline = offline self.mainwindow = MainWindow()
self.mainwindow = MainWindow(self.core, self.args, self.signals, api_results)
self.launch_dialog.close() self.launch_dialog.close()
self.tray_icon = TrayIcon(self) self.tray_icon = TrayIcon(self)
self.tray_icon.exit_action.triggered.connect(self.exit_app) self.tray_icon.exit_action.triggered.connect(self.exit_app)
@ -164,6 +163,7 @@ class App(QApplication):
def start(args): def start(args):
# set excepthook to show dialog with exception # set excepthook to show dialog with exception
sys.excepthook = excepthook sys.excepthook = excepthook
shared.init_args(args)
# configure logging # configure logging
if args.debug: if args.debug:
@ -183,7 +183,7 @@ def start(args):
) )
while True: while True:
app = App(args) app = App()
exit_code = app.exec_() exit_code = app.exec_()
# if not restart # if not restart
# restart app # restart app

View file

@ -7,7 +7,7 @@ from requests.exceptions import ConnectionError, HTTPError
from legendary.core import LegendaryCore from legendary.core import LegendaryCore
from legendary.models.game import GameAsset from legendary.models.game import GameAsset
from rare import image_dir from rare import image_dir, shared
from rare.components.dialogs.login import LoginDialog from rare.components.dialogs.login import LoginDialog
from rare.ui.components.dialogs.launch_dialog import Ui_LaunchDialog from rare.ui.components.dialogs.launch_dialog import Ui_LaunchDialog
from rare.utils.models import ApiResults from rare.utils.models import ApiResults
@ -53,15 +53,15 @@ class ApiRequestWorker(QRunnable):
class LaunchDialog(QDialog, Ui_LaunchDialog): class LaunchDialog(QDialog, Ui_LaunchDialog):
quit_app = pyqtSignal(int) quit_app = pyqtSignal(int)
start_app = pyqtSignal(bool, ApiResults) start_app = pyqtSignal()
finished = False finished = False
def __init__(self, core: LegendaryCore, offline=False, parent=None): def __init__(self, parent=None):
super(LaunchDialog, self).__init__(parent=parent) super(LaunchDialog, self).__init__(parent=parent)
self.setupUi(self) self.setupUi(self)
self.setAttribute(Qt.WA_DeleteOnClose, True) self.setAttribute(Qt.WA_DeleteOnClose, True)
self.core = core self.core = shared.legendary_core
self.offline = offline self.offline = shared.args.offline
self.thread_pool = QThreadPool() self.thread_pool = QThreadPool()
self.thread_pool.setMaxThreadCount(2) self.thread_pool.setMaxThreadCount(2)
self.api_results = ApiResults() self.api_results = ApiResults()
@ -150,6 +150,8 @@ class LaunchDialog(QDialog, Ui_LaunchDialog):
if self.finished: if self.finished:
logger.info("App starting") logger.info("App starting")
self.image_info.setText(self.tr("Starting...")) self.image_info.setText(self.tr("Starting..."))
self.start_app.emit(self.offline, self.api_results) shared.args.offline = self.offline
shared.api_results = self.api_results
self.start_app.emit()
else: else:
self.finished = True self.finished = True

View file

@ -5,10 +5,8 @@ from PyQt5.QtCore import Qt, QSettings, QTimer
from PyQt5.QtGui import QCloseEvent from PyQt5.QtGui import QCloseEvent
from PyQt5.QtWidgets import QMainWindow, QMessageBox, QApplication from PyQt5.QtWidgets import QMainWindow, QMessageBox, QApplication
from legendary.core import LegendaryCore from rare import data_dir, shared
from rare import data_dir
from rare.components.tabs.tab_widget import TabWidget from rare.components.tabs.tab_widget import TabWidget
from rare.utils.models import Signals
from rare.utils.rpc import DiscordRPC from rare.utils.rpc import DiscordRPC
logger = getLogger("Window") logger = getLogger("Window")
@ -16,16 +14,16 @@ logger = getLogger("Window")
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
def __init__(self, core: LegendaryCore, args, signals: Signals, api_results): def __init__(self):
super(MainWindow, self).__init__() super(MainWindow, self).__init__()
self.setAttribute(Qt.WA_DeleteOnClose) self.setAttribute(Qt.WA_DeleteOnClose)
self.settings = QSettings() self.settings = QSettings()
self.core = core self.core = shared.legendary_core
self.signals = signals self.signals = shared.signals
self.signals.main_window.connect(lambda x: self.handle_signal(*x)) self.signals.main_window.connect(lambda x: self.handle_signal(*x))
self.offline = args.offline self.offline = shared.args.offline
width, height = 1200, 800 width, height = 1200, 800
if self.settings.value("save_size", False): if self.settings.value("save_size", False):
width, height = self.settings.value("window_size", (1200, 800), tuple) width, height = self.settings.value("window_size", (1200, 800), tuple)
@ -34,12 +32,12 @@ class MainWindow(QMainWindow):
self.setGeometry((desktop.width() - width) / 2, (desktop.height() - height) / 2, width, height) self.setGeometry((desktop.width() - width) / 2, (desktop.height() - height) / 2, width, height)
self.setWindowTitle("Rare - GUI for legendary") self.setWindowTitle("Rare - GUI for legendary")
self.tab_widget = TabWidget(core, self.signals, self, args, api_results) self.tab_widget = TabWidget(self)
self.setCentralWidget(self.tab_widget) self.setCentralWidget(self.tab_widget)
if not args.offline: if not shared.args.offline:
self.rpc = DiscordRPC(core) self.rpc = DiscordRPC(shared.legendary_core)
# Discord RPC on game launch # Discord RPC on game launch
#self.tab_widget.games_tab.default_widget.game_list.game_started.connect( # self.tab_widget.games_tab.default_widget.game_list.game_started.connect(
# lambda: self.rpc.set_discord_rpc(self.tab_widget.games_tab.default_widget.game_list.running_games[0])) # lambda: self.rpc.set_discord_rpc(self.tab_widget.games_tab.default_widget.game_list.running_games[0]))
# Remove RPC # Remove RPC
self.tab_widget.delete_presence.connect(self.rpc.set_discord_rpc) self.tab_widget.delete_presence.connect(self.rpc.set_discord_rpc)
@ -47,16 +45,16 @@ class MainWindow(QMainWindow):
self.tab_widget.settings.rare_settings.rpc.update_settings.connect( self.tab_widget.settings.rare_settings.rpc.update_settings.connect(
lambda: self.rpc.changed_settings(self.tab_widget.games_tab.default_widget.game_list.running_games)) lambda: self.rpc.changed_settings(self.tab_widget.games_tab.default_widget.game_list.running_games))
#game = self.tab_widget.games_tab.default_widget.game_list.active_game # game = self.tab_widget.games_tab.default_widget.game_list.active_game
#if game != ("", 0) and not args.offline: # if game != ("", 0) and not args.offline:
# self.rpc.set_discord_rpc(game[0]) # Appname # self.rpc.set_discord_rpc(game[0]) # Appname
if args.subparser == "launch": if shared.args.subparser == "launch":
logger.info("Launching " + self.core.get_installed_game(args.app_name).title) logger.info("Launching " + self.core.get_installed_game(shared.args.app_name).title)
if args.app_name in self.tab_widget.games_tab.default_widget.game_list.widgets.keys(): if shared.args.app_name in self.tab_widget.games_tab.default_widget.game_list.widgets.keys():
self.tab_widget.games_tab.default_widget.game_list.widgets[args.app_name][1].launch() self.tab_widget.games_tab.default_widget.game_list.widgets[shared.args.app_name][1].launch()
else: else:
logger.info(f"Could not find {args.app_name} in Games") logger.info(f"Could not find {shared.args.app_name} in Games")
self.timer = QTimer() self.timer = QTimer()
self.timer.timeout.connect(self.timer_finished) self.timer.timeout.connect(self.timer_finished)

View file

@ -2,24 +2,19 @@ import webbrowser
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QMessageBox, QLabel, QPushButton from PyQt5.QtWidgets import QWidget, QVBoxLayout, QMessageBox, QLabel, QPushButton
from legendary.core import LegendaryCore from rare import shared
from rare.utils.models import Signals
class MiniWidget(QWidget): class MiniWidget(QWidget):
def __init__(self, core: LegendaryCore, signals: Signals): def __init__(self):
super(MiniWidget, self).__init__() super(MiniWidget, self).__init__()
self.layout = QVBoxLayout() self.layout = QVBoxLayout()
self.core = core self.core = shared.legendary_core
self.signals = signals self.signals = shared.signals
self.layout.addWidget(QLabel("Account")) self.layout.addWidget(QLabel("Account"))
username = self.core.lgd.userdata.get("display_name") username = self.core.lgd.userdata.get("display_name")
if not username: if not username:
try: username = "Offline"
self.core.login()
username = self.core.lgd.userdata.get("display_name")
except Exception:
username = "Offline"
self.layout.addWidget(QLabel(self.tr("Logged in as ") + str(username))) self.layout.addWidget(QLabel(self.tr("Logged in as ") + str(username)))

View file

@ -5,10 +5,10 @@ from PyQt5.QtWidgets import QScrollArea, QWidget, QVBoxLayout, QLabel, QPushButt
from legendary.core import LegendaryCore from legendary.core import LegendaryCore
from legendary.models.game import SaveGameStatus from legendary.models.game import SaveGameStatus
from rare import shared
from rare.components.dialogs.path_input_dialog import PathInputDialog from rare.components.dialogs.path_input_dialog import PathInputDialog
from rare.components.tabs.cloud_saves.sync_widget import SyncWidget from rare.components.tabs.cloud_saves.sync_widget import SyncWidget
from rare.utils.extra_widgets import WaitingSpinner from rare.utils.extra_widgets import WaitingSpinner
from rare.utils.models import Signals
logger = getLogger("Sync Saves") logger = getLogger("Sync Saves")
@ -28,15 +28,15 @@ class LoadThread(QThread):
class SyncSaves(QScrollArea): class SyncSaves(QScrollArea):
finished = pyqtSignal(str) finished = pyqtSignal(str)
def __init__(self, core: LegendaryCore, signals: Signals): def __init__(self):
super(SyncSaves, self).__init__() super(SyncSaves, self).__init__()
self.core = core self.core = shared.legendary_core
self.signals = signals self.signals = shared.signals
self.signals.cloud_saves.connect(self.signal_received) self.signals.cloud_saves.connect(self.signal_received)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.load_saves() self.load_saves()
def signal_received(self, action, ): def signal_received(self, action, data):
pass pass
def load_saves(self, app_name=None, auto=False): def load_saves(self, app_name=None, auto=False):

View file

@ -8,10 +8,11 @@ from PyQt5.QtWidgets import QWidget, QMessageBox, QVBoxLayout, QLabel, QGridLayo
from legendary.core import LegendaryCore from legendary.core import LegendaryCore
from legendary.models.downloading import UIUpdate from legendary.models.downloading import UIUpdate
from legendary.models.game import Game, InstalledGame from legendary.models.game import Game, InstalledGame
from rare import shared
from rare.components.dialogs.install_dialog import InstallDialog from rare.components.dialogs.install_dialog import InstallDialog
from rare.components.tabs.downloads.dl_queue_widget import DlQueueWidget from rare.components.tabs.downloads.dl_queue_widget import DlQueueWidget
from rare.components.tabs.downloads.download_thread import DownloadThread from rare.components.tabs.downloads.download_thread import DownloadThread
from rare.utils.models import InstallOptionsModel, InstallQueueItemModel, Signals from rare.utils.models import InstallOptionsModel, InstallQueueItemModel
from rare.utils.utils import get_size from rare.utils.utils import get_size
logger = getLogger("Download") logger = getLogger("Download")
@ -22,13 +23,13 @@ class DownloadTab(QWidget):
dl_queue = [] dl_queue = []
dl_status = pyqtSignal(int) dl_status = pyqtSignal(int)
def __init__(self, core: LegendaryCore, updates: list, signals: Signals): def __init__(self, updates: list):
super(DownloadTab, self).__init__() super(DownloadTab, self).__init__()
self.core = core self.core = shared.legendary_core
self.layout = QVBoxLayout() self.layout = QVBoxLayout()
self.active_game: Game = None self.active_game: Game = None
self.analysis = None self.analysis = None
self.signals = signals self.signals = shared.signals
self.signals.dl_tab.connect(lambda x: self.signal_received(*x)) self.signals.dl_tab.connect(lambda x: self.signal_received(*x))
self.info_layout = QGridLayout() self.info_layout = QGridLayout()

View file

@ -3,7 +3,7 @@ from logging import getLogger
from PyQt5.QtCore import pyqtSignal, QSettings, QObjectCleanupHandler from PyQt5.QtCore import pyqtSignal, QSettings, QObjectCleanupHandler
from PyQt5.QtWidgets import QStackedWidget, QVBoxLayout, QWidget from PyQt5.QtWidgets import QStackedWidget, QVBoxLayout, QWidget
from legendary.core import LegendaryCore from rare import shared
from rare.components.dialogs.uninstall_dialog import UninstallDialog from rare.components.dialogs.uninstall_dialog import UninstallDialog
from rare.components.tabs.games.game_info import InfoTabs from rare.components.tabs.games.game_info import InfoTabs
from rare.components.tabs.games.game_info.uninstalled_info import UninstalledTabInfo from rare.components.tabs.games.game_info.uninstalled_info import UninstalledTabInfo
@ -19,7 +19,6 @@ from rare.components.tabs.games.import_widget import ImportWidget
from rare.ui.components.tabs.games.games_tab import Ui_GamesTab from rare.ui.components.tabs.games.games_tab import Ui_GamesTab
from rare.utils import legendary_utils from rare.utils import legendary_utils
from rare.utils.extra_widgets import FlowLayout from rare.utils.extra_widgets import FlowLayout
from rare.utils.models import Signals, ApiResults
from rare.utils.utils import get_pixmap, download_image, get_uninstalled_pixmap from rare.utils.utils import get_pixmap, download_image, get_uninstalled_pixmap
logger = getLogger("GamesTab") logger = getLogger("GamesTab")
@ -32,12 +31,11 @@ class GamesTab(QStackedWidget, Ui_GamesTab):
game_started = pyqtSignal(str) game_started = pyqtSignal(str)
updates = set() updates = set()
def __init__(self, core: LegendaryCore, offline, signals: Signals, api_results: ApiResults): def __init__(self):
super(GamesTab, self).__init__() super(GamesTab, self).__init__()
self.setupUi(self) self.setupUi(self)
self.core = core self.core = shared.legendary_core
self.offline = offline self.signals = shared.signals
self.signals = signals
self.signals.games_tab.connect(lambda x: self.signal_received(*x)) self.signals.games_tab.connect(lambda x: self.signal_received(*x))
self.settings = QSettings() self.settings = QSettings()
@ -47,10 +45,10 @@ class GamesTab(QStackedWidget, Ui_GamesTab):
self.game_info = InfoTabs(self.core, self.signals, self) self.game_info = InfoTabs(self.core, self.signals, self)
self.addWidget(self.game_info) self.addWidget(self.game_info)
self.import_widget = ImportWidget(core, self) self.import_widget = ImportWidget()
self.addWidget(self.import_widget) self.addWidget(self.import_widget)
self.uninstalled_info_widget = UninstalledTabInfo(core, self.signals, self.offline, self) self.uninstalled_info_widget = UninstalledTabInfo()
self.layout().addWidget(self.uninstalled_info_widget) self.layout().addWidget(self.uninstalled_info_widget)
# navigation # navigation
@ -58,13 +56,13 @@ class GamesTab(QStackedWidget, Ui_GamesTab):
self.import_widget.back_button.clicked.connect(lambda: self.setCurrentIndex(0)) self.import_widget.back_button.clicked.connect(lambda: self.setCurrentIndex(0))
self.uninstalled_info_widget.tabBarClicked.connect(lambda x: self.setCurrentIndex(0) if x == 0 else None) self.uninstalled_info_widget.tabBarClicked.connect(lambda x: self.setCurrentIndex(0) if x == 0 else None)
self.game_list = api_results.game_list self.game_list = shared.api_results.game_list
self.dlcs = api_results.dlcs self.dlcs = shared.api_results.dlcs
self.bit32 = api_results.bit32_games self.bit32 = shared.api_results.bit32_games
self.mac_games = api_results.mac_games self.mac_games = shared.api_results.mac_games
self.no_assets = api_results.no_asset_games self.no_assets = shared.api_results.no_asset_games
self.no_asset_names = [] self.no_asset_names = []
if not self.offline: if not shared.args.offline:
for game in self.no_assets: for game in self.no_assets:
self.no_asset_names.append(game.app_name) self.no_asset_names.append(game.app_name)
else: else:
@ -170,9 +168,9 @@ class GamesTab(QStackedWidget, Ui_GamesTab):
else: else:
igame = self.core.get_installed_game(game.app_name) igame = self.core.get_installed_game(game.app_name)
icon_widget = InstalledIconWidget(igame, self.core, pixmap, self.offline, is_origin, game) icon_widget = InstalledIconWidget(igame, pixmap, is_origin, game)
list_widget = InstalledListWidget(igame, self.core, pixmap, self.offline, is_origin, game) list_widget = InstalledListWidget(igame, pixmap, is_origin, game)
self.widgets[game.app_name] = (icon_widget, list_widget) self.widgets[game.app_name] = (icon_widget, list_widget)

View file

@ -75,7 +75,7 @@ class GameSettings(QWidget, Ui_GameSettings):
self.proton_prefix = PathEdit("None", QFileDialog.DirectoryOnly, save_func=self.update_prefix) self.proton_prefix = PathEdit("None", QFileDialog.DirectoryOnly, save_func=self.update_prefix)
self.proton_prefix_layout.addWidget(self.proton_prefix) self.proton_prefix_layout.addWidget(self.proton_prefix)
self.linux_settings = LinuxAppSettings(core) self.linux_settings = LinuxAppSettings()
self.linux_layout.addWidget(self.linux_settings) self.linux_layout.addWidget(self.linux_settings)
else: else:
self.proton_groupbox.setVisible(False) self.proton_groupbox.setVisible(False)
@ -238,8 +238,8 @@ class GameSettings(QWidget, Ui_GameSettings):
class LinuxAppSettings(LinuxSettings): class LinuxAppSettings(LinuxSettings):
def __init__(self, core): def __init__(self):
super(LinuxAppSettings, self).__init__(core, "app") super(LinuxAppSettings, self).__init__("app")
def update_game(self, app_name): def update_game(self, app_name):
self.name = app_name self.name = app_name

View file

@ -5,28 +5,28 @@ from PyQt5.QtGui import QKeyEvent
from PyQt5.QtWidgets import QWidget, QTabWidget, QTreeView from PyQt5.QtWidgets import QWidget, QTabWidget, QTreeView
from qtawesome import icon from qtawesome import icon
from legendary.core import LegendaryCore
from legendary.models.game import Game from legendary.models.game import Game
from rare import shared
from rare.ui.components.tabs.games.game_info.game_info import Ui_GameInfo from rare.ui.components.tabs.games.game_info.game_info import Ui_GameInfo
from rare.utils.extra_widgets import SideTabBar from rare.utils.extra_widgets import SideTabBar
from rare.utils.json_formatter import QJsonModel from rare.utils.json_formatter import QJsonModel
from rare.utils.models import Signals, InstallOptionsModel from rare.utils.models import InstallOptionsModel
from rare.utils.steam_grades import SteamWorker from rare.utils.steam_grades import SteamWorker
from rare.utils.utils import get_pixmap from rare.utils.utils import get_pixmap
class UninstalledTabInfo(QTabWidget): class UninstalledTabInfo(QTabWidget):
def __init__(self, core, signals: Signals, offline, parent): def __init__(self):
super(UninstalledTabInfo, self).__init__(parent=parent) super(UninstalledTabInfo, self).__init__()
self.app_name = "" self.app_name = ""
self.core = core self.core = shared.legendary_core
self.signals = signals self.signals = shared.signals
self.setTabBar(SideTabBar()) self.setTabBar(SideTabBar())
self.setTabPosition(QTabWidget.West) self.setTabPosition(QTabWidget.West)
self.addTab(QWidget(), icon("mdi.keyboard-backspace"), self.tr("Back")) self.addTab(QWidget(), icon("mdi.keyboard-backspace"), self.tr("Back"))
self.info = UninstalledInfo(core, self.signals, self) self.info = UninstalledInfo()
self.info.install_button.setDisabled(offline) self.info.install_button.setDisabled(shared.args.offline)
self.addTab(self.info, self.tr("Game Info")) self.addTab(self.info, self.tr("Game Info"))
self.view = QTreeView() self.view = QTreeView()
@ -58,11 +58,11 @@ class UninstalledTabInfo(QTabWidget):
class UninstalledInfo(QWidget, Ui_GameInfo): class UninstalledInfo(QWidget, Ui_GameInfo):
game: Game game: Game
def __init__(self, core: LegendaryCore, signals: Signals, parent=None): def __init__(self):
super(UninstalledInfo, self).__init__(parent=parent) super(UninstalledInfo, self).__init__()
self.setupUi(self) self.setupUi(self)
self.core = core self.core = shared.legendary_core
self.signals = signals self.signals = shared.signals
self.install_button.clicked.connect(self.install_game) self.install_button.clicked.connect(self.install_game)
if platform.system() != "Windows": if platform.system() != "Windows":
self.steam_worker = SteamWorker(self.core) self.steam_worker = SteamWorker(self.core)

View file

@ -7,8 +7,8 @@ from PyQt5.QtCore import pyqtSignal, QProcess, QSettings, Qt, QByteArray, QProce
from PyQt5.QtGui import QPixmap from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QGroupBox, QMessageBox, QAction, QLabel, QPushButton from PyQt5.QtWidgets import QGroupBox, QMessageBox, QAction, QLabel, QPushButton
from legendary.core import LegendaryCore
from legendary.models.game import InstalledGame, Game from legendary.models.game import InstalledGame, Game
from rare import shared
from rare.components.dialogs.uninstall_dialog import UninstallDialog from rare.components.dialogs.uninstall_dialog import UninstallDialog
from rare.components.extra.console import ConsoleWindow from rare.components.extra.console import ConsoleWindow
from rare.utils import legendary_utils, utils from rare.utils import legendary_utils, utils
@ -24,11 +24,11 @@ class BaseInstalledWidget(QGroupBox):
update_list = pyqtSignal() update_list = pyqtSignal()
proc: QProcess() proc: QProcess()
def __init__(self, igame: InstalledGame, core: LegendaryCore, pixmap: QPixmap, offline, is_origin: bool = False, game: Game = None): def __init__(self, igame: InstalledGame, pixmap: QPixmap, is_origin: bool = False, game: Game = None):
super(BaseInstalledWidget, self).__init__() super(BaseInstalledWidget, self).__init__()
self.igame = igame self.igame = igame
self.is_origin = is_origin self.is_origin = is_origin
self.core = core self.core = shared.legendary_core
if not game: if not game:
self.game = self.core.get_game(self.igame.app_name) self.game = self.core.get_game(self.igame.app_name)
else: else:
@ -36,7 +36,7 @@ class BaseInstalledWidget(QGroupBox):
self.image = QLabel() self.image = QLabel()
self.image.setPixmap(pixmap.scaled(200, int(200 * 4 / 3), transformMode=Qt.SmoothTransformation)) self.image.setPixmap(pixmap.scaled(200, int(200 * 4 / 3), transformMode=Qt.SmoothTransformation))
self.game_running = False self.game_running = False
self.offline = offline self.offline = shared.args.offline
if is_origin: if is_origin:
self.update_available = False self.update_available = False
else: else:

View file

@ -5,8 +5,8 @@ from PyQt5.QtGui import QMouseEvent
from PyQt5.QtWidgets import QVBoxLayout, QHBoxLayout, QPushButton, QLabel from PyQt5.QtWidgets import QVBoxLayout, QHBoxLayout, QPushButton, QLabel
from qtawesome import icon from qtawesome import icon
from legendary.core import LegendaryCore
from legendary.models.game import InstalledGame, Game from legendary.models.game import InstalledGame, Game
from rare import shared
from rare.components.tabs.games.game_widgets.base_installed_widget import BaseInstalledWidget from rare.components.tabs.games.game_widgets.base_installed_widget import BaseInstalledWidget
logger = getLogger("GameWidgetInstalled") logger = getLogger("GameWidgetInstalled")
@ -16,14 +16,14 @@ class InstalledIconWidget(BaseInstalledWidget):
update_list = pyqtSignal(str) update_list = pyqtSignal(str)
update_game = pyqtSignal() update_game = pyqtSignal()
def __init__(self, igame: InstalledGame, core: LegendaryCore, pixmap, offline, is_origin: bool = False, def __init__(self, igame: InstalledGame, pixmap, is_origin: bool = False,
game: Game = None): game: Game = None):
super(InstalledIconWidget, self).__init__(igame, core, pixmap, offline, is_origin, game) super(InstalledIconWidget, self).__init__(igame, pixmap, is_origin, game)
self.setObjectName("game_widget_icon") self.setObjectName("game_widget_icon")
self.setContextMenuPolicy(Qt.ActionsContextMenu) self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.layout = QVBoxLayout() self.layout = QVBoxLayout()
self.core = core self.core = shared.legendary_core
self.running = False self.running = False
self.info_text = "" self.info_text = ""

View file

@ -4,7 +4,6 @@ from PyQt5.QtCore import QProcess, pyqtSignal
from PyQt5.QtWidgets import QHBoxLayout, QLabel, QPushButton, QVBoxLayout from PyQt5.QtWidgets import QHBoxLayout, QLabel, QPushButton, QVBoxLayout
from qtawesome import icon from qtawesome import icon
from legendary.core import LegendaryCore
from legendary.models.game import InstalledGame, Game from legendary.models.game import InstalledGame, Game
from rare.components.tabs.games.game_widgets.base_installed_widget import BaseInstalledWidget from rare.components.tabs.games.game_widgets.base_installed_widget import BaseInstalledWidget
@ -16,10 +15,10 @@ class InstalledListWidget(BaseInstalledWidget):
signal = pyqtSignal(str) signal = pyqtSignal(str)
update_game = pyqtSignal() update_game = pyqtSignal()
def __init__(self, igame: InstalledGame, core: LegendaryCore, pixmap, offline, is_orign: bool = False, game: Game = None): def __init__(self, igame: InstalledGame, pixmap, is_origin: bool = False, game: Game = None):
super(InstalledListWidget, self).__init__(igame, core, pixmap, offline, is_orign, game) super(InstalledListWidget, self).__init__(igame, pixmap, is_origin, game)
self.dev = self.game.metadata["developer"] self.dev = self.game.metadata["developer"]
if not is_orign: if not is_origin:
self.size = igame.install_size self.size = igame.install_size
self.launch_params = igame.launch_parameters self.launch_params = igame.launch_parameters
else: else:

View file

@ -7,7 +7,7 @@ from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QPushButton, QVBoxLayo
QGroupBox QGroupBox
from qtawesome import icon from qtawesome import icon
from legendary.core import LegendaryCore from rare import shared
from rare.utils import legendary_utils from rare.utils import legendary_utils
from rare.utils.extra_widgets import PathEdit from rare.utils.extra_widgets import PathEdit
@ -17,9 +17,9 @@ logger = getLogger("Import")
class ImportWidget(QWidget): class ImportWidget(QWidget):
update_list = pyqtSignal(str) update_list = pyqtSignal(str)
def __init__(self, core: LegendaryCore, parent): def __init__(self):
super(ImportWidget, self).__init__(parent=parent) super(ImportWidget, self).__init__()
self.core = core self.core = shared.legendary_core
self.game_list = [i.app_name for i in self.core.get_game_list()] self.game_list = [i.app_name for i in self.core.get_game_list()]
self.main_layout = QHBoxLayout() self.main_layout = QHBoxLayout()

View file

@ -10,16 +10,15 @@ from rare.utils.extra_widgets import SideTabBar
class SettingsTab(QTabWidget): class SettingsTab(QTabWidget):
def __init__(self, core, parent): def __init__(self):
super(SettingsTab, self).__init__(parent=parent) super(SettingsTab, self).__init__()
self.core = core
self.setTabBar(SideTabBar()) self.setTabBar(SideTabBar())
self.setTabPosition(QTabWidget.West) self.setTabPosition(QTabWidget.West)
self.rare_settings = RareSettings(self.core) self.rare_settings = RareSettings()
self.addTab(self.rare_settings, "Rare") self.addTab(self.rare_settings, "Rare")
self.addTab(LegendarySettings(core), "Legendary") self.addTab(LegendarySettings(), "Legendary")
if platform.system() != "Windows": if platform.system() != "Windows":
self.addTab(LinuxSettings(core), "Linux") self.addTab(LinuxSettings(), "Linux")
self.about = About() self.about = About()
self.addTab(self.about, "About (!)" if self.about.update_available else "About") self.addTab(self.about, "About (!)" if self.about.update_available else "About")

View file

@ -5,6 +5,7 @@ from PyQt5.QtWidgets import QGroupBox
from PyQt5.QtWidgets import QWidget, QCheckBox, QVBoxLayout, QWidgetAction, QMenu, QToolButton, QHBoxLayout from PyQt5.QtWidgets import QWidget, QCheckBox, QVBoxLayout, QWidgetAction, QMenu, QToolButton, QHBoxLayout
from legendary.core import LegendaryCore from legendary.core import LegendaryCore
from rare import shared
from rare.ui.components.tabs.settings.dxvk import Ui_DxvkSettings from rare.ui.components.tabs.settings.dxvk import Ui_DxvkSettings
logger = getLogger("DXVK Settings") logger = getLogger("DXVK Settings")
@ -12,12 +13,12 @@ logger = getLogger("DXVK Settings")
class DxvkSettings(QGroupBox, Ui_DxvkSettings): class DxvkSettings(QGroupBox, Ui_DxvkSettings):
def __init__(self, core: LegendaryCore, name=None): def __init__(self, name=None):
super(DxvkSettings, self).__init__() super(DxvkSettings, self).__init__()
self.setupUi(self) self.setupUi(self)
self.name = name if name is not None else "default" self.name = name if name is not None else "default"
self.core = core self.core = shared.legendary_core
self.dxvk_options_map = { self.dxvk_options_map = {
"devinfo": self.devinfo, "devinfo": self.devinfo,
@ -96,9 +97,9 @@ class DxvkSettings(QGroupBox, Ui_DxvkSettings):
class DxvkWidget(QGroupBox): class DxvkWidget(QGroupBox):
def __init__(self, core: LegendaryCore, name=None): def __init__(self, name=None):
super(DxvkWidget, self).__init__() super(DxvkWidget, self).__init__()
self.core = core self.core = shared.legendary_core
self.setObjectName("settings_widget") self.setObjectName("settings_widget")
self.dxvk_settings = { self.dxvk_settings = {
"fps": [False, "Fps"], "fps": [False, "Fps"],

View file

@ -8,6 +8,7 @@ from PyQt5.QtWidgets import QFileDialog, QMessageBox, QVBoxLayout, QDialog, QChe
from qtawesome import icon from qtawesome import icon
from legendary.core import LegendaryCore from legendary.core import LegendaryCore
from rare import shared
from rare.ui.components.tabs.settings.legendary import Ui_LegendarySettings from rare.ui.components.tabs.settings.legendary import Ui_LegendarySettings
from rare.utils.extra_widgets import PathEdit from rare.utils.extra_widgets import PathEdit
from rare.utils.utils import get_size from rare.utils.utils import get_size
@ -16,14 +17,14 @@ logger = getLogger("LegendarySettings")
class LegendarySettings(QWidget, Ui_LegendarySettings): class LegendarySettings(QWidget, Ui_LegendarySettings):
def __init__(self, core: LegendaryCore, parent=None): def __init__(self):
super(LegendarySettings, self).__init__(parent=parent) super(LegendarySettings, self).__init__()
self.setupUi(self) self.setupUi(self)
self.core = core self.core = shared.legendary_core
# Default installation directory # Default installation directory
self.install_dir = PathEdit(core.get_default_install_dir(), self.install_dir = PathEdit(self.core.get_default_install_dir(),
file_type=QFileDialog.DirectoryOnly, file_type=QFileDialog.DirectoryOnly,
save_func=self.save_path) save_func=self.save_path)
self.install_dir_layout.addWidget(self.install_dir) self.install_dir_layout.addWidget(self.install_dir)

View file

@ -2,7 +2,7 @@ from logging import getLogger
from PyQt5.QtWidgets import QFileDialog, QWidget from PyQt5.QtWidgets import QFileDialog, QWidget
from legendary.core import LegendaryCore from rare import shared
from rare.components.tabs.settings.dxvk import DxvkSettings, DxvkWidget from rare.components.tabs.settings.dxvk import DxvkSettings, DxvkWidget
from rare.ui.components.tabs.settings.linux import Ui_LinuxSettings from rare.ui.components.tabs.settings.linux import Ui_LinuxSettings
from rare.utils.extra_widgets import PathEdit from rare.utils.extra_widgets import PathEdit
@ -11,12 +11,12 @@ logger = getLogger("LinuxSettings")
class LinuxSettings(QWidget, Ui_LinuxSettings): class LinuxSettings(QWidget, Ui_LinuxSettings):
def __init__(self, core: LegendaryCore, name=None): def __init__(self, name=None):
super(LinuxSettings, self).__init__() super(LinuxSettings, self).__init__()
self.setupUi(self) self.setupUi(self)
self.name = name if name is not None else "default" self.name = name if name is not None else "default"
self.core = core self.core = shared.legendary_core
# Wine prefix # Wine prefix
self.wine_prefix = PathEdit(self.core.lgd.config.get(self.name, "wine_prefix", fallback=""), self.wine_prefix = PathEdit(self.core.lgd.config.get(self.name, "wine_prefix", fallback=""),
@ -34,9 +34,9 @@ class LinuxSettings(QWidget, Ui_LinuxSettings):
# dxvk # dxvk
# FIXME: Remove this check when done with per game settings # FIXME: Remove this check when done with per game settings
if name is None: if name is None:
self.dxvk = DxvkSettings(core, self.name) self.dxvk = DxvkSettings(self.name)
else: else:
self.dxvk = DxvkWidget(core) self.dxvk = DxvkWidget()
self.dxvk_layout.addWidget(self.dxvk) self.dxvk_layout.addWidget(self.dxvk)
def save_setting(self, widget: PathEdit, setting_name: str): def save_setting(self, widget: PathEdit, setting_name: str):

View file

@ -7,8 +7,7 @@ from logging import getLogger
from PyQt5.QtCore import QSettings, Qt from PyQt5.QtCore import QSettings, Qt
from PyQt5.QtWidgets import QWidget, QMessageBox from PyQt5.QtWidgets import QWidget, QMessageBox
from legendary.core import LegendaryCore from rare import cache_dir, shared
from rare import cache_dir
from rare.components.tabs.settings.rpc_settings import RPCSettings from rare.components.tabs.settings.rpc_settings import RPCSettings
from rare.ui.components.tabs.settings.rare import Ui_RareSettings from rare.ui.components.tabs.settings.rare import Ui_RareSettings
from rare.utils import utils from rare.utils import utils
@ -24,10 +23,10 @@ languages = [
class RareSettings(QWidget, Ui_RareSettings): class RareSettings(QWidget, Ui_RareSettings):
def __init__(self, core: LegendaryCore): def __init__(self):
super(RareSettings, self).__init__() super(RareSettings, self).__init__()
self.setupUi(self) self.setupUi(self)
self.core = core self.core = shared.legendary_core
# (widget_name, option_name, default) # (widget_name, option_name, default)
self.checkboxes = [ self.checkboxes = [
(self.sys_tray, "sys_tray", True), (self.sys_tray, "sys_tray", True),

View file

@ -23,7 +23,7 @@ class TabBar(QTabBar):
class TabButtonWidget(QToolButton): class TabButtonWidget(QToolButton):
def __init__(self, core, button_icon: str, tool_tip: str): def __init__(self, button_icon: str, tool_tip: str):
super(TabButtonWidget, self).__init__() super(TabButtonWidget, self).__init__()
self.setText("Icon") self.setText("Icon")
self.setPopupMode(QToolButton.InstantPopup) self.setPopupMode(QToolButton.InstantPopup)

View file

@ -2,7 +2,7 @@ from PyQt5.QtCore import QSize, pyqtSignal
from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction, QShortcut from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction, QShortcut
from qtawesome import icon from qtawesome import icon
from legendary.core import LegendaryCore from rare import shared
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
from rare.components.tabs.downloads import DownloadTab from rare.components.tabs.downloads import DownloadTab
@ -11,35 +11,34 @@ from rare.components.tabs.settings import SettingsTab
from rare.components.tabs.settings.debug_settings import DebugSettings from rare.components.tabs.settings.debug_settings import DebugSettings
from rare.components.tabs.shop import Shop from rare.components.tabs.shop import Shop
from rare.components.tabs.tab_utils import TabBar, TabButtonWidget from rare.components.tabs.tab_utils import TabBar, TabButtonWidget
from rare.utils.models import InstallOptionsModel, Signals from rare.utils.models import InstallOptionsModel
class TabWidget(QTabWidget): class TabWidget(QTabWidget):
delete_presence = pyqtSignal() delete_presence = pyqtSignal()
def __init__(self, core: LegendaryCore, signals: Signals, parent, args, api_results): def __init__(self, parent):
super(TabWidget, self).__init__(parent=parent) super(TabWidget, self).__init__(parent=parent)
self.offline = args.offline disabled_tab = 4 if not shared.args.offline else 1
disabled_tab = 4 if not self.offline else 1 self.core = shared.legendary_core
self.core = core self.signals = shared.signals
self.signals = signals
self.setTabBar(TabBar(disabled_tab)) self.setTabBar(TabBar(disabled_tab))
# Generate Tabs # Generate Tabs
self.games_tab = GamesTab(core, args.offline, self.signals, api_results) self.games_tab = GamesTab()
self.addTab(self.games_tab, self.tr("Games")) self.addTab(self.games_tab, self.tr("Games"))
self.signals.tab_widget.connect(lambda x: self.handle_signal(*x)) self.signals.tab_widget.connect(lambda x: self.handle_signal(*x))
if not self.offline: if not shared.args.offline:
# updates = self.games_tab.default_widget.game_list.updates # updates = self.games_tab.default_widget.game_list.updates
self.downloadTab = DownloadTab(core, self.games_tab.updates, self.signals) self.downloadTab = DownloadTab(self.games_tab.updates)
self.addTab(self.downloadTab, "Downloads" + ( self.addTab(self.downloadTab, "Downloads" + (
" (" + str(len(self.games_tab.updates)) + ")" if len(self.games_tab.updates) != 0 else "")) " (" + str(len(self.games_tab.updates)) + ")" if len(self.games_tab.updates) != 0 else ""))
self.cloud_saves = SyncSaves(core, self.signals) self.cloud_saves = SyncSaves()
self.addTab(self.cloud_saves, "Cloud Saves") self.addTab(self.cloud_saves, "Cloud Saves")
self.store = Shop(self.core) self.store = Shop(self.core)
self.addTab(self.store, self.tr("Store (Beta)")) self.addTab(self.store, self.tr("Store (Beta)"))
self.settings = SettingsTab(core, self) self.settings = SettingsTab()
if args.debug: if shared.args.debug:
self.settings.addTab(DebugSettings(), "Debug") self.settings.addTab(DebugSettings(), "Debug")
# Space Tab # Space Tab
@ -50,10 +49,10 @@ class TabWidget(QTabWidget):
self.addTab(self.account, "") self.addTab(self.account, "")
self.setTabEnabled(disabled_tab + 1, False) self.setTabEnabled(disabled_tab + 1, False)
self.mini_widget = MiniWidget(core, self.signals) self.mini_widget = MiniWidget()
account_action = QWidgetAction(self) account_action = QWidgetAction(self)
account_action.setDefaultWidget(self.mini_widget) account_action.setDefaultWidget(self.mini_widget)
account_button = TabButtonWidget(core, 'mdi.account-circle', 'Account') account_button = TabButtonWidget('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(disabled_tab + 1, self.tabBar().RightSide, account_button) self.tabBar().setTabButton(disabled_tab + 1, self.tabBar().RightSide, account_button)
@ -65,7 +64,7 @@ class TabWidget(QTabWidget):
# imported # imported
self.games_tab.import_widget.update_list.connect(self.game_imported) self.games_tab.import_widget.update_list.connect(self.game_imported)
if not self.offline: if not shared.args.offline:
# install dlc # install dlc
self.games_tab.game_info.dlc.install_dlc.connect( self.games_tab.game_info.dlc.install_dlc.connect(
lambda app_name, update: self.install_game( lambda app_name, update: self.install_game(
@ -97,7 +96,7 @@ class TabWidget(QTabWidget):
if tab_num == 0: if tab_num == 0:
self.games_tab.layout().setCurrentIndex(0) self.games_tab.layout().setCurrentIndex(0)
if not self.offline and tab_num == 3: if not shared.args.offline and tab_num == 3:
self.store.load() self.store.load()
def game_imported(self, app_name: str): def game_imported(self, app_name: str):

31
rare/shared.py Normal file
View file

@ -0,0 +1,31 @@
from argparse import Namespace
from legendary.core import LegendaryCore
from rare.utils.models import Signals, ApiResults
legendary_core: LegendaryCore = None
signals: Signals = None
args: Namespace = None
api_results: ApiResults = None
def init_legendary():
global legendary_core
legendary_core = LegendaryCore()
return legendary_core
def init_signals():
global signals
signals = Signals()
return signals
def init_args(a: Namespace):
global args
args = a
def init_api_response(res: ApiResults):
global api_results
api_results = res