from logging import getLogger from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtWidgets import QDialog, QLabel, QProgressBar, QVBoxLayout from rare.components.dialogs.login import LoginDialog from rare.utils.utils import download_images from custom_legendary.core import LegendaryCore logger = getLogger("Login") class LaunchThread(QThread): download_progess = pyqtSignal(int) action = pyqtSignal(str) def __init__(self, core: LegendaryCore, parent=None): super(LaunchThread, self).__init__(parent) self.core = core def run(self): self.action.emit("Login") self.action.emit(self.tr("Downloading Images")) download_images(self.download_progess, self.core) self.action.emit("finish") class LoginThread(QThread): login = pyqtSignal() start_app = pyqtSignal() def __init__(self, core: LegendaryCore): super(LoginThread, self).__init__() self.core = core def run(self): logger.info("Try if you are logged in") try: if self.core.login(): logger.info("You are logged in") self.start_app.emit() else: self.run() except ValueError: logger.info("You are not logged in. Open Login Window") self.login.emit() class LaunchDialog(QDialog): start_app = pyqtSignal() def __init__(self, core: LegendaryCore): super(LaunchDialog, self).__init__() self.core = core self.login_thread = LoginThread(core) self.login_thread.login.connect(self.login) self.login_thread.start_app.connect(self.launch) self.login_thread.start() self.title = QLabel("