132 lines
5.0 KiB
Python
132 lines
5.0 KiB
Python
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QLabel
|
|
from PyQt6.QtCore import Qt, QTimer, pyqtSignal
|
|
from PyQt6.QtGui import QPixmap
|
|
from app.core.main_manager import MainManager
|
|
from app.ui.widgets.loading_spinner import LoadingSpinner
|
|
import app.utils.paths as paths
|
|
|
|
class SplashScreen(QWidget):
|
|
finished = pyqtSignal()
|
|
|
|
def __init__(self, duration=3000, parent=None):
|
|
super().__init__(parent)
|
|
self.duration = duration
|
|
|
|
self.main_manager = MainManager.get_instance()
|
|
self.theme_manager = self.main_manager.get_theme_manager()
|
|
self.settings_manager = self.main_manager.get_settings_manager()
|
|
|
|
self.setup_ui()
|
|
self.setup_timer()
|
|
|
|
|
|
def setup_ui(self):
|
|
# Configuration de la fenêtre
|
|
self.setWindowFlags(Qt.WindowType.FramelessWindowHint | Qt.WindowType.WindowStaysOnTopHint)
|
|
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
|
self.setFixedSize(800, 600)
|
|
|
|
# Layout principal
|
|
layout = QVBoxLayout(self)
|
|
layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
layout.setSpacing(60)
|
|
layout.setContentsMargins(80, 80, 80, 80)
|
|
|
|
# Image splash
|
|
self.image_label = QLabel()
|
|
self.image_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
self.load_splash_image()
|
|
layout.addWidget(self.image_label)
|
|
|
|
# Spinner de chargement
|
|
self.spinner = LoadingSpinner(50, self)
|
|
spinner_layout = QVBoxLayout()
|
|
spinner_layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
spinner_layout.addWidget(self.spinner)
|
|
layout.addLayout(spinner_layout)
|
|
|
|
# Appliquer le thème
|
|
self.apply_theme()
|
|
|
|
# Centrer la fenêtre
|
|
self.center_on_screen()
|
|
|
|
def load_splash_image(self):
|
|
"""Charge l'image splash depuis la config"""
|
|
try:
|
|
splash_image_path = paths.get_asset_path(self.settings_manager.get_config("splash_image"))
|
|
if splash_image_path:
|
|
# Essayer le chemin depuis la config
|
|
if not splash_image_path.startswith('/') and not splash_image_path.startswith('\\') and ':' not in splash_image_path:
|
|
# Chemin relatif, le résoudre depuis le dossier assets
|
|
splash_image_path = paths.get_asset_path(splash_image_path)
|
|
|
|
pixmap = QPixmap(splash_image_path)
|
|
if not pixmap.isNull():
|
|
# Redimensionner l'image
|
|
scaled_pixmap = pixmap.scaled(400, 300, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
|
self.image_label.setPixmap(scaled_pixmap)
|
|
return
|
|
|
|
# Fallback : essayer l'icône par défaut
|
|
fallback_path = paths.get_asset_path("icon.png")
|
|
pixmap = QPixmap(fallback_path)
|
|
if not pixmap.isNull():
|
|
scaled_pixmap = pixmap.scaled(240, 240, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
|
self.image_label.setPixmap(scaled_pixmap)
|
|
else:
|
|
# Dernier fallback : texte
|
|
self.image_label.setText("🚀")
|
|
self.image_label.setStyleSheet("font-size: 48px;")
|
|
except Exception:
|
|
# En cas d'erreur, afficher un emoji
|
|
self.image_label.setText("🚀")
|
|
self.image_label.setStyleSheet("font-size: 48px;")
|
|
|
|
def apply_theme(self):
|
|
"""Applique le thème actuel"""
|
|
theme = self.theme_manager.get_theme()
|
|
|
|
style = f"""
|
|
QWidget {{
|
|
background-color: {theme.get_color("background_color")};
|
|
border-radius: 15px;
|
|
border: 2px solid {theme.get_color("primary_color")};
|
|
}}
|
|
QLabel {{
|
|
color: {theme.get_color("text_color")};
|
|
background: transparent;
|
|
border: none;
|
|
}}
|
|
"""
|
|
self.setStyleSheet(style)
|
|
|
|
def center_on_screen(self):
|
|
"""Centre la fenêtre sur l'écran"""
|
|
from PyQt6.QtWidgets import QApplication
|
|
screen = QApplication.primaryScreen()
|
|
screen_geometry = screen.geometry()
|
|
|
|
x = (screen_geometry.width() - self.width()) // 2
|
|
y = (screen_geometry.height() - self.height()) // 2
|
|
self.move(x, y)
|
|
|
|
def setup_timer(self):
|
|
"""Configure le timer pour fermer automatiquement le splash screen"""
|
|
self.timer = QTimer()
|
|
self.timer.timeout.connect(self.close_splash)
|
|
self.timer.start(self.duration)
|
|
|
|
def close_splash(self):
|
|
"""Ferme le splash screen et émet le signal"""
|
|
if hasattr(self, 'spinner'):
|
|
self.spinner.stop()
|
|
self.timer.stop()
|
|
self.hide()
|
|
self.finished.emit()
|
|
|
|
def show_splash(self):
|
|
"""Affiche le splash screen"""
|
|
self.show()
|
|
self.raise_()
|
|
self.activateWindow() |