generated from LouisMazin/PythonApplicationTemplate
105 lines
3.6 KiB
Python
105 lines
3.6 KiB
Python
import sys
|
|
import app.utils.paths as paths
|
|
from PyQt6.QtWidgets import QApplication
|
|
from PyQt6.QtGui import QIcon
|
|
from app.ui.main_window import MainWindow
|
|
from app.ui.windows.splash_screen import SplashScreen
|
|
from app.core.main_manager import MainManager
|
|
|
|
# Variable globale pour stocker la fenêtre préchargée
|
|
preloaded_window = None
|
|
|
|
def preload_application(progress_callback):
|
|
"""
|
|
Fonction de préchargement qui s'exécute pendant l'affichage du splash screen
|
|
|
|
Args:
|
|
progress_callback: Fonction pour mettre à jour le texte de progression
|
|
|
|
Returns:
|
|
bool: True si tout s'est bien passé, False sinon
|
|
"""
|
|
global preloaded_window
|
|
|
|
try:
|
|
main_manager = MainManager.get_instance()
|
|
language_manager = main_manager.get_language_manager()
|
|
update_manager = main_manager.get_update_manager()
|
|
|
|
# Étape 1: Vérification des mises à jour
|
|
progress_callback(language_manager.get_text("checking_updates"))
|
|
|
|
# Vérifier s'il y a une mise à jour
|
|
if update_manager.check_for_update():
|
|
# Une mise à jour est en cours de téléchargement, on ferme l'app
|
|
return False
|
|
|
|
# Étape 2: Initialisation de la fenêtre principale
|
|
progress_callback(language_manager.get_text("initializing"))
|
|
|
|
# Créer la fenêtre principale avec tous ses composants
|
|
preloaded_window = MainWindow()
|
|
|
|
# Étape 3: Finalisation
|
|
progress_callback(language_manager.get_text("loading_complete"))
|
|
|
|
return True
|
|
|
|
except Exception:
|
|
return False
|
|
|
|
def main() -> int:
|
|
global preloaded_window
|
|
|
|
main_manager: MainManager = MainManager.get_instance()
|
|
theme_manager = main_manager.get_theme_manager()
|
|
settings_manager = main_manager.get_settings_manager()
|
|
|
|
app: QApplication = QApplication(sys.argv)
|
|
app.setStyleSheet(theme_manager.get_sheet())
|
|
app.setApplicationName(settings_manager.get_config("app_name"))
|
|
app.setWindowIcon(QIcon(paths.get_asset_path("icon")))
|
|
|
|
# Vérifier si l'image splash existe
|
|
splash_image_path = paths.get_asset_path(settings_manager.get_config("splash_image"))
|
|
use_splash = splash_image_path and paths.Path(splash_image_path).exists()
|
|
|
|
if use_splash:
|
|
# Créer et afficher le splash screen avec préchargement
|
|
splash = SplashScreen(preload_function=preload_application)
|
|
splash.show_splash()
|
|
|
|
# Connecter le signal finished pour afficher la fenêtre principale préchargée
|
|
def on_splash_finished(success):
|
|
global preloaded_window
|
|
if not success:
|
|
# Le préchargement a échoué ou une mise à jour est en cours
|
|
app.quit()
|
|
return
|
|
|
|
# Afficher la fenêtre préchargée
|
|
if preloaded_window:
|
|
preloaded_window.show()
|
|
else:
|
|
# Fallback si le préchargement a échoué
|
|
window = MainWindow()
|
|
window.show()
|
|
|
|
splash.finished.connect(on_splash_finished)
|
|
else:
|
|
# Pas de splash screen, exécuter le préchargement directement
|
|
def dummy_progress(text):
|
|
pass # Pas de callback de progression sans splash
|
|
|
|
success = preload_application(dummy_progress)
|
|
if not success:
|
|
return 0
|
|
|
|
# Utiliser la fenêtre préchargée ou en créer une nouvelle
|
|
window = preloaded_window if preloaded_window else MainWindow()
|
|
window.show()
|
|
|
|
return app.exec()
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |