MainTabWidget: Use returned indices instead of hard-coding disabled tabs
Parent the tabs properly for consistency
This commit is contained in:
parent
34839d469e
commit
211f92d2d6
|
@ -10,10 +10,10 @@ from PyQt5.QtWidgets import (
|
|||
QScrollArea,
|
||||
QScroller,
|
||||
QComboBox,
|
||||
QMessageBox, QLabel,
|
||||
QMessageBox, QLabel, QSizePolicy,
|
||||
)
|
||||
|
||||
from rare.components.tabs import TabWidget
|
||||
from rare.components.tabs import MainTabWidget
|
||||
from rare.components.tray_icon import TrayIcon
|
||||
from rare.shared import RareCore
|
||||
from rare.utils.paths import lock_file
|
||||
|
@ -26,8 +26,8 @@ class MainWindow(QMainWindow):
|
|||
exit_app: pyqtSignal = pyqtSignal(int)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
self._exit_code = 0
|
||||
self._accept_close = False
|
||||
self.__exit_code = 0
|
||||
self.__accept_close = False
|
||||
self._window_launched = False
|
||||
super(MainWindow, self).__init__(parent=parent)
|
||||
self.setAttribute(Qt.WA_DeleteOnClose, True)
|
||||
|
@ -38,11 +38,11 @@ class MainWindow(QMainWindow):
|
|||
self.settings = QSettings()
|
||||
|
||||
self.setWindowTitle("Rare - GUI for legendary")
|
||||
self.tab_widget = TabWidget(self)
|
||||
self.tab_widget = MainTabWidget(self)
|
||||
self.tab_widget.exit_app.connect(self.on_exit_app)
|
||||
self.setCentralWidget(self.tab_widget)
|
||||
|
||||
self.status_bar = QStatusBar()
|
||||
self.status_bar = QStatusBar(self)
|
||||
self.setStatusBar(self.status_bar)
|
||||
|
||||
self.signals.application.update_statusbar.connect(self.update_statusbar)
|
||||
|
@ -125,10 +125,11 @@ class MainWindow(QMainWindow):
|
|||
@pyqtSlot()
|
||||
def update_statusbar(self):
|
||||
for label in self.status_bar.findChildren(QLabel, options=Qt.FindDirectChildrenOnly):
|
||||
self.status_bar.layout().removeWidget(label)
|
||||
self.status_bar.removeWidget(label)
|
||||
label.deleteLater()
|
||||
for info in self.rcore.queue_info():
|
||||
label = QLabel(f"{info.worker_type}: {info.app_title}")
|
||||
label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
||||
label.setStyleSheet(
|
||||
"""
|
||||
QLabel {
|
||||
|
@ -153,17 +154,17 @@ class MainWindow(QMainWindow):
|
|||
@pyqtSlot()
|
||||
@pyqtSlot(int)
|
||||
def on_exit_app(self, exit_code=0) -> None:
|
||||
self._exit_code = exit_code
|
||||
self.__exit_code = exit_code
|
||||
self.close()
|
||||
|
||||
def close(self) -> bool:
|
||||
self._accept_close = True
|
||||
self.__accept_close = True
|
||||
return super(MainWindow, self).close()
|
||||
|
||||
def closeEvent(self, e: QCloseEvent) -> None:
|
||||
# lk: `accept_close` is set to `True` by the `close()` method, overrides exiting to tray in `closeEvent()`
|
||||
# lk: ensures exiting instead of hiding when `close()` is called programmatically
|
||||
if not self._accept_close:
|
||||
if not self.__accept_close:
|
||||
if self.settings.value("sys_tray", False, bool):
|
||||
self.hide()
|
||||
e.ignore()
|
||||
|
@ -186,6 +187,6 @@ class MainWindow(QMainWindow):
|
|||
self.timer.stop()
|
||||
self.tray_icon.deleteLater()
|
||||
self.hide()
|
||||
self.exit_app.emit(self._exit_code)
|
||||
self.exit_app.emit(self.__exit_code)
|
||||
super(MainWindow, self).closeEvent(e)
|
||||
|
||||
|
|
|
@ -2,53 +2,53 @@ from PyQt5.QtCore import QSize, pyqtSignal, pyqtSlot
|
|||
from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction, QShortcut, QMessageBox
|
||||
|
||||
from rare.shared import RareCore, 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
|
||||
from .account import AccountWidget
|
||||
from .downloads import DownloadsTab
|
||||
from .games import GamesTab
|
||||
from .settings import SettingsTab
|
||||
from .settings.debug import DebugSettings
|
||||
from .shop import Shop
|
||||
from .tab_widgets import MainTabBar, TabButtonWidget
|
||||
|
||||
|
||||
class TabWidget(QTabWidget):
|
||||
class MainTabWidget(QTabWidget):
|
||||
# int: exit code
|
||||
exit_app: pyqtSignal = pyqtSignal(int)
|
||||
|
||||
def __init__(self, parent):
|
||||
super(TabWidget, self).__init__(parent=parent)
|
||||
super(MainTabWidget, self).__init__(parent=parent)
|
||||
self.rcore = RareCore.instance()
|
||||
self.core = LegendaryCoreSingleton()
|
||||
self.signals = GlobalSignalsSingleton()
|
||||
self.args = ArgumentsSingleton()
|
||||
disabled_tab = 3 if not self.args.offline else 1
|
||||
self.setTabBar(MainTabBar(disabled_tab))
|
||||
|
||||
self.tab_bar = MainTabBar(parent=self)
|
||||
self.setTabBar(self.tab_bar)
|
||||
|
||||
# Generate Tabs
|
||||
self.games_tab = GamesTab(self)
|
||||
self.addTab(self.games_tab, self.tr("Games"))
|
||||
self.games_index = self.addTab(self.games_tab, self.tr("Games"))
|
||||
|
||||
# Downloads Tab after Games Tab to use populated RareCore games list
|
||||
if not self.args.offline:
|
||||
self.downloads_tab = DownloadsTab(self)
|
||||
# update dl tab text
|
||||
self.addTab(self.downloads_tab, "")
|
||||
self.downloads_index = self.addTab(self.downloads_tab, "")
|
||||
self.downloads_tab.update_title.connect(self.__on_downloads_update_title)
|
||||
self.downloads_tab.update_queues_count()
|
||||
self.store = Shop(self.core)
|
||||
self.addTab(self.store, self.tr("Store (Beta)"))
|
||||
self.setTabEnabled(self.downloads_index, not self.args.offline)
|
||||
|
||||
self.settings_tab = SettingsTab(self)
|
||||
if self.args.debug:
|
||||
self.settings_tab.addTab(DebugSettings(), "Debug")
|
||||
self.store_tab = Shop(self.core)
|
||||
self.store_index = self.addTab(self.store_tab, self.tr("Store (Beta)"))
|
||||
self.setTabEnabled(self.store_index, not self.args.offline)
|
||||
|
||||
# Space Tab
|
||||
self.addTab(QWidget(), "")
|
||||
self.setTabEnabled(disabled_tab, False)
|
||||
space_index = self.addTab(QWidget(self), "")
|
||||
self.setTabEnabled(space_index, False)
|
||||
self.tab_bar.expanded = space_index
|
||||
# Button
|
||||
self.addTab(QWidget(), "")
|
||||
self.setTabEnabled(disabled_tab + 1, False)
|
||||
button_index = self.addTab(QWidget(self), "")
|
||||
self.setTabEnabled(button_index, False)
|
||||
|
||||
self.account_widget = AccountWidget(self)
|
||||
self.account_widget.logout.connect(self.logout)
|
||||
|
@ -57,14 +57,14 @@ class TabWidget(QTabWidget):
|
|||
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.tab_bar.setTabButton(
|
||||
button_index, MainTabBar.RightSide, account_button
|
||||
)
|
||||
|
||||
self.addTab(self.settings_tab, icon("fa.gear"), "")
|
||||
|
||||
self.settings_tab = SettingsTab(self)
|
||||
self.settings_index = self.addTab(self.settings_tab, icon("fa.gear"), "")
|
||||
self.settings_tab.about.update_available_ready.connect(
|
||||
lambda: self.tabBar().setTabText(5, "(!)")
|
||||
lambda: self.tab_bar.setTabText(self.settings_index, "(!)")
|
||||
)
|
||||
|
||||
# Open game list on click on Games tab button
|
||||
|
@ -72,26 +72,26 @@ class TabWidget(QTabWidget):
|
|||
self.setIconSize(QSize(24, 24))
|
||||
|
||||
# shortcuts
|
||||
QShortcut("Alt+1", self).activated.connect(lambda: self.setCurrentWidget(self.games_tab))
|
||||
QShortcut("Alt+1", self).activated.connect(lambda: self.setCurrentIndex(self.games_index))
|
||||
if not self.args.offline:
|
||||
QShortcut("Alt+2", self).activated.connect(lambda: self.setCurrentWidget(self.downloads_tab))
|
||||
QShortcut("Alt+3", self).activated.connect(lambda: self.setCurrentWidget(self.store))
|
||||
QShortcut("Alt+4", self).activated.connect(lambda: self.setCurrentWidget(self.settings_tab))
|
||||
QShortcut("Alt+2", self).activated.connect(lambda: self.setCurrentIndex(self.downloads_index))
|
||||
QShortcut("Alt+3", self).activated.connect(lambda: self.setCurrentIndex(self.store_index))
|
||||
QShortcut("Alt+4", self).activated.connect(lambda: self.setCurrentIndex(self.settings_index))
|
||||
|
||||
@pyqtSlot(int)
|
||||
def __on_downloads_update_title(self, num_downloads: int):
|
||||
self.setTabText(self.indexOf(self.downloads_tab), self.tr("Downloads ({})").format(num_downloads))
|
||||
|
||||
def mouse_clicked(self, tab_num):
|
||||
if tab_num == 0:
|
||||
def mouse_clicked(self, index):
|
||||
if index == self.games_index:
|
||||
self.games_tab.setCurrentWidget(self.games_tab.games_page)
|
||||
|
||||
if not self.args.offline and tab_num == 2:
|
||||
self.store.load()
|
||||
if not self.args.offline and index == self.store_index:
|
||||
self.store_tab.load()
|
||||
|
||||
def resizeEvent(self, event):
|
||||
self.tabBar().setMinimumWidth(self.width())
|
||||
super(TabWidget, self).resizeEvent(event)
|
||||
self.tab_bar.setMinimumWidth(self.width())
|
||||
super(MainTabWidget, self).resizeEvent(event)
|
||||
|
||||
@pyqtSlot()
|
||||
def logout(self):
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from rare.components.tabs.settings.widgets.linux import LinuxSettings
|
||||
from rare.shared import ArgumentsSingleton
|
||||
from rare.utils.extra_widgets import SideTabWidget
|
||||
from .about import About
|
||||
from .debug import DebugSettings
|
||||
from .default_game_settings import DefaultGameSettings
|
||||
from .legendary import LegendarySettings
|
||||
from .rare import RareSettings
|
||||
|
@ -9,18 +11,19 @@ from .rare import RareSettings
|
|||
class SettingsTab(SideTabWidget):
|
||||
def __init__(self, parent=None):
|
||||
super(SettingsTab, self).__init__(parent=parent)
|
||||
about_tab = 3
|
||||
self.rare_settings = RareSettings()
|
||||
self.rare_index = self.addTab(self.rare_settings, "Rare")
|
||||
|
||||
self.legendary_index = self.addTab(LegendarySettings(), "Legendary")
|
||||
self.args = ArgumentsSingleton()
|
||||
|
||||
self.rare_index = self.addTab(RareSettings(self), "Rare")
|
||||
self.legendary_index = self.addTab(LegendarySettings(self), "Legendary")
|
||||
self.settings_index = self.addTab(DefaultGameSettings(True, self), self.tr("Default Settings"))
|
||||
|
||||
self.about = About()
|
||||
self.about = About(self)
|
||||
self.about_index = self.addTab(self.about, "About", "About")
|
||||
self.about.update_available_ready.connect(
|
||||
lambda: self.tabBar().setTabText(about_tab, "About (!)")
|
||||
lambda: self.tabBar().setTabText(self.about_index, "About (!)")
|
||||
)
|
||||
|
||||
if self.args.debug:
|
||||
self.debug_index = self.addTab(DebugSettings(self), "Debug")
|
||||
|
||||
self.setCurrentIndex(self.rare_index)
|
||||
|
|
|
@ -19,11 +19,10 @@ def versiontuple(v):
|
|||
|
||||
|
||||
class About(QWidget, Ui_About):
|
||||
update_available = False
|
||||
update_available_ready = pyqtSignal()
|
||||
|
||||
def __init__(self):
|
||||
super(About, self).__init__()
|
||||
def __init__(self, parent=None):
|
||||
super(About, self).__init__(parent=parent)
|
||||
self.setupUi(self)
|
||||
|
||||
self.version.setText(f"{__version__} {code_name}")
|
||||
|
@ -42,6 +41,8 @@ class About(QWidget, Ui_About):
|
|||
lambda: webbrowser.open("https://github.com/Dummerle/Rare/releases/latest")
|
||||
)
|
||||
|
||||
self.update_available = False
|
||||
|
||||
def update_available_finished(self, data: dict):
|
||||
if latest_tag := data.get("tag_name"):
|
||||
self.update_available = versiontuple(latest_tag) > versiontuple(__version__)
|
||||
|
|
|
@ -4,8 +4,8 @@ from rare.shared import GlobalSignalsSingleton
|
|||
|
||||
|
||||
class DebugSettings(QWidget):
|
||||
def __init__(self):
|
||||
super(DebugSettings, self).__init__()
|
||||
def __init__(self, parent=None):
|
||||
super(DebugSettings, self).__init__(parent=parent)
|
||||
self.setLayout(QVBoxLayout())
|
||||
|
||||
self.raise_runtime_exception_button = QPushButton("Raise Exception")
|
||||
|
|
|
@ -36,8 +36,8 @@ languages = [("en", "English"),
|
|||
|
||||
|
||||
class RareSettings(QWidget, Ui_RareSettings):
|
||||
def __init__(self):
|
||||
super(RareSettings, self).__init__()
|
||||
def __init__(self, parent=None):
|
||||
super(RareSettings, self).__init__(parent=parent)
|
||||
self.setupUi(self)
|
||||
self.core = LegendaryCoreSingleton()
|
||||
# (widget_name, option_name, default)
|
||||
|
@ -235,9 +235,6 @@ class RareSettings(QWidget, Ui_RareSettings):
|
|||
self.settings.setValue("save_size", self.save_size.isChecked())
|
||||
self.settings.remove("window_size")
|
||||
|
||||
def save_path(self):
|
||||
self.update_path()
|
||||
|
||||
def update_lang(self, i: int):
|
||||
self.settings.setValue("language", languages[i][0])
|
||||
self.interface_info.setVisible(True)
|
||||
|
|
|
@ -5,19 +5,18 @@ from rare.utils.misc import icon
|
|||
|
||||
|
||||
class MainTabBar(QTabBar):
|
||||
def __init__(self, expanded):
|
||||
super(MainTabBar, self).__init__()
|
||||
self._expanded = expanded
|
||||
def __init__(self, parent=None):
|
||||
super(MainTabBar, self).__init__(parent=parent)
|
||||
self.setObjectName("MainTabBar")
|
||||
font = self.font()
|
||||
font.setPointSize(font.pointSize() + 2)
|
||||
font.setBold(True)
|
||||
self.setFont(font)
|
||||
# self.setContentsMargins(0,10,0,10)
|
||||
self.expanded = -1
|
||||
|
||||
def tabSizeHint(self, index):
|
||||
size = super(MainTabBar, self).tabSizeHint(index)
|
||||
if index == self._expanded:
|
||||
if index == self.expanded:
|
||||
offset = self.width()
|
||||
for index in range(self.count()):
|
||||
offset -= super(MainTabBar, self).tabSizeHint(index).width()
|
||||
|
@ -26,8 +25,8 @@ class MainTabBar(QTabBar):
|
|||
|
||||
|
||||
class TabButtonWidget(QToolButton):
|
||||
def __init__(self, button_icon: str, tool_tip: str, fallback_icon=None):
|
||||
super(TabButtonWidget, self).__init__()
|
||||
def __init__(self, button_icon: str, tool_tip: str, fallback_icon=None, parent=None):
|
||||
super(TabButtonWidget, self).__init__(parent=parent)
|
||||
self.setText("Icon")
|
||||
self.setPopupMode(QToolButton.InstantPopup)
|
||||
self.setIcon(icon(button_icon, fallback_icon, scale_factor=1.25))
|
Loading…
Reference in a new issue