c1a008dce1
Instead of connecting to the global `exit_app` signal, pass the signals through their respective widgets. Because signals are queued by default, this ensures that slots are executed in the order they are connected. Makes it cleaner to do cleanup procedures where they should make sense, unlike the global signal, where it has to be inferred by the widget instantiating order.
115 lines
4.4 KiB
Python
115 lines
4.4 KiB
Python
from PyQt5.QtCore import QSize, pyqtSignal
|
|
from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction, QShortcut
|
|
|
|
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton, ArgumentsSingleton
|
|
from rare.components.tabs.account import AccountWidget
|
|
from rare.components.tabs.downloads import DownloadsTab
|
|
from rare.components.tabs.games import GamesTab
|
|
from rare.components.tabs.settings import SettingsTab
|
|
from rare.components.tabs.settings.debug import DebugSettings
|
|
from rare.components.tabs.shop import Shop
|
|
from rare.components.tabs.tab_utils import MainTabBar, TabButtonWidget
|
|
from rare.utils.misc import icon
|
|
|
|
|
|
class TabWidget(QTabWidget):
|
|
# int: exit code
|
|
exit_app: pyqtSignal = pyqtSignal(int)
|
|
|
|
def __init__(self, parent):
|
|
super(TabWidget, self).__init__(parent=parent)
|
|
self.core = LegendaryCoreSingleton()
|
|
self.signals = GlobalSignalsSingleton()
|
|
self.args = ArgumentsSingleton()
|
|
disabled_tab = 3 if not self.args.offline else 1
|
|
self.setTabBar(MainTabBar(disabled_tab))
|
|
# lk: Figure out why this adds a white line at the top
|
|
# lk: despite setting qproperty-drawBase to 0 in the stylesheet
|
|
# self.setDocumentMode(True)
|
|
# Generate Tabs
|
|
self.games_tab = GamesTab()
|
|
self.addTab(self.games_tab, self.tr("Games"))
|
|
|
|
if not self.args.offline:
|
|
# updates = self.games_tab.default_widget.game_list.updates
|
|
self.downloads_tab = DownloadsTab(self.games_tab.updates)
|
|
self.addTab(
|
|
self.downloads_tab,
|
|
"Downloads"
|
|
+ (
|
|
" (" + str(len(self.games_tab.updates)) + ")"
|
|
if len(self.games_tab.updates) != 0
|
|
else ""
|
|
),
|
|
)
|
|
self.store = Shop(self.core)
|
|
self.addTab(self.store, self.tr("Store (Beta)"))
|
|
|
|
self.settings = SettingsTab(self)
|
|
if self.args.debug:
|
|
self.settings.addTab(DebugSettings(), "Debug")
|
|
|
|
# Space Tab
|
|
self.addTab(QWidget(), "")
|
|
self.setTabEnabled(disabled_tab, False)
|
|
# Button
|
|
self.account = QWidget()
|
|
self.addTab(self.account, "")
|
|
self.setTabEnabled(disabled_tab + 1, False)
|
|
|
|
self.account_widget = AccountWidget(self, self.downloads_tab)
|
|
self.account_widget.exit_app.connect(self.exit_app)
|
|
account_action = QWidgetAction(self)
|
|
account_action.setDefaultWidget(self.account_widget)
|
|
account_button = TabButtonWidget("mdi.account-circle", "Account", fallback_icon="fa.user")
|
|
account_button.setMenu(QMenu())
|
|
account_button.menu().addAction(account_action)
|
|
self.tabBar().setTabButton(
|
|
disabled_tab + 1, self.tabBar().RightSide, account_button
|
|
)
|
|
|
|
self.addTab(self.settings, icon("fa.gear"), "")
|
|
|
|
self.settings.about.update_available_ready.connect(
|
|
lambda: self.tabBar().setTabText(5, "(!)")
|
|
)
|
|
# Signals
|
|
# set current index
|
|
self.signals.set_main_tab_index.connect(self.setCurrentIndex)
|
|
|
|
# update dl tab text
|
|
self.signals.update_download_tab_text.connect(self.update_dl_tab_text)
|
|
|
|
# Open game list on click on Games tab button
|
|
self.tabBarClicked.connect(self.mouse_clicked)
|
|
self.setIconSize(QSize(25, 25))
|
|
|
|
# shortcuts
|
|
QShortcut("Alt+1", self).activated.connect(lambda: self.setCurrentIndex(0))
|
|
QShortcut("Alt+2", self).activated.connect(lambda: self.setCurrentIndex(1))
|
|
QShortcut("Alt+3", self).activated.connect(lambda: self.setCurrentIndex(2))
|
|
QShortcut("Alt+4", self).activated.connect(lambda: self.setCurrentIndex(5))
|
|
|
|
def update_dl_tab_text(self):
|
|
num_downloads = len(
|
|
set(
|
|
[i.options.app_name for i in self.downloads_tab.dl_queue]
|
|
+ [i for i in self.downloads_tab.update_widgets.keys()]
|
|
)
|
|
)
|
|
|
|
if num_downloads != 0:
|
|
self.setTabText(1, f"Downloads ({num_downloads})")
|
|
else:
|
|
self.setTabText(1, "Downloads")
|
|
|
|
def mouse_clicked(self, tab_num):
|
|
if tab_num == 0:
|
|
self.games_tab.layout().setCurrentIndex(0)
|
|
|
|
if not self.args.offline and tab_num == 2:
|
|
self.store.load()
|
|
|
|
def resizeEvent(self, event):
|
|
self.tabBar().setMinimumWidth(self.width())
|
|
super(TabWidget, self).resizeEvent(event)
|