AccountWidget: Use ExitCodes enum everywhere instead of magic values
This commit is contained in:
parent
757e1c7ef2
commit
a33c4e5cf2
|
@ -1,6 +1,5 @@
|
|||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from argparse import Namespace
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
@ -14,6 +13,7 @@ from rare.components.dialogs.launch_dialog import LaunchDialog
|
|||
from rare.components.main_window import MainWindow
|
||||
from rare.shared import RareCore
|
||||
from rare.utils import config_helper, paths
|
||||
from rare.utils.misc import ExitCodes
|
||||
from rare.widgets.rare_app import RareApp, RareAppException
|
||||
|
||||
|
||||
|
@ -126,6 +126,6 @@ def start(args) -> int:
|
|||
app = Rare(args)
|
||||
exit_code = app.exec()
|
||||
del app
|
||||
if exit_code != -133742:
|
||||
if exit_code != ExitCodes.LOGOUT:
|
||||
break
|
||||
return exit_code
|
||||
|
|
|
@ -2,7 +2,7 @@ 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.utils.misc import icon
|
||||
from rare.utils.misc import icon, ExitCodes
|
||||
from .account import AccountWidget
|
||||
from .downloads import DownloadsTab
|
||||
from .games import GamesTab
|
||||
|
@ -99,12 +99,12 @@ class MainTabWidget(QTabWidget):
|
|||
if self.downloads_tab.is_download_active:
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
self.tr("Quit") if exit_code == self.account_widget.ExitCodes.EXIT else self.tr("Logout"),
|
||||
self.tr("Quit") if exit_code == ExitCodes.EXIT else self.tr("Logout"),
|
||||
self.tr("There are active downloads. Stop them before trying to quit."),
|
||||
)
|
||||
return
|
||||
# FIXME: End of FIXME
|
||||
if exit_code == self.account_widget.ExitCodes.LOGOUT:
|
||||
if exit_code == ExitCodes.LOGOUT:
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
self.tr("Logout"),
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
import webbrowser
|
||||
from enum import IntEnum
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton
|
||||
|
||||
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton
|
||||
from rare.utils.misc import icon
|
||||
from rare.utils.misc import icon, ExitCodes
|
||||
|
||||
|
||||
class AccountWidget(QWidget):
|
||||
exit_app: pyqtSignal = pyqtSignal(int)
|
||||
logout: pyqtSignal = pyqtSignal()
|
||||
|
||||
class ExitCodes(IntEnum):
|
||||
EXIT = 0
|
||||
LOGOUT = -133742
|
||||
|
||||
def __init__(self, parent):
|
||||
super(AccountWidget, self).__init__(parent=parent)
|
||||
self.core = LegendaryCoreSingleton()
|
||||
|
@ -45,8 +40,8 @@ class AccountWidget(QWidget):
|
|||
|
||||
@pyqtSlot()
|
||||
def __on_quit(self):
|
||||
self.exit_app.emit(AccountWidget.ExitCodes.EXIT)
|
||||
self.exit_app.emit(ExitCodes.EXIT)
|
||||
|
||||
@pyqtSlot()
|
||||
def __on_logout(self):
|
||||
self.exit_app.emit(AccountWidget.ExitCodes.LOGOUT)
|
||||
self.exit_app.emit(ExitCodes.LOGOUT)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
from enum import IntEnum
|
||||
from logging import getLogger
|
||||
from typing import List, Union, Type, Dict
|
||||
|
||||
|
@ -19,6 +20,12 @@ from rare.utils.paths import resources_path
|
|||
|
||||
logger = getLogger("Utils")
|
||||
|
||||
|
||||
class ExitCodes(IntEnum):
|
||||
EXIT = 0
|
||||
LOGOUT = -133742
|
||||
|
||||
|
||||
color_role_map: Dict[int, str] = {
|
||||
0: "WindowText",
|
||||
1: "Button",
|
||||
|
@ -143,7 +150,8 @@ def get_translations():
|
|||
def get_latest_version():
|
||||
try:
|
||||
resp = requests.get(
|
||||
"https://api.github.com/repos/RareDevs/Rare/releases/latest", timeout=2,
|
||||
"https://api.github.com/repos/RareDevs/Rare/releases/latest",
|
||||
timeout=2,
|
||||
)
|
||||
tag = resp.json()["tag_name"]
|
||||
return tag
|
||||
|
@ -155,7 +163,8 @@ def path_size(path: Union[str, os.PathLike]) -> int:
|
|||
return sum(
|
||||
os.stat(os.path.join(dp, f)).st_size
|
||||
for dp, dn, filenames in os.walk(path)
|
||||
for f in filenames if os.path.isfile(os.path.join(dp,f ))
|
||||
for f in filenames
|
||||
if os.path.isfile(os.path.join(dp, f))
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue