Source code for radioviz.views.loading_splash

#  Copyright 2026 European Union
#  Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
#  SPDX-License-Identifier: EUPL-1.2
"""
Loading splash screen module.

Provides the :class:`LoadingSplash` class, a custom splash screen widget that displays a
background pixmap, status text and a progress bar during application startup.
"""

from PySide6.QtCore import Qt
from PySide6.QtGui import QCursor, QPixmap
from PySide6.QtWidgets import QApplication, QLabel, QProgressBar, QSplashScreen, QVBoxLayout, QWidget


[docs] class LoadingSplash(QSplashScreen): """ Custom splash screen widget. Extends :class:`PySide6.QtWidgets.QSplashScreen` to include a transparent container with a status label and a progress bar, allowing dynamic updates of startup status. """ def __init__(self, pixmap: QPixmap) -> None: """ Initialize the loading splash screen. Creates the splash screen with the given background :class:`PySide6.QtGui.QPixmap` and sets up the status label and progress bar. :param pixmap: Background image for the splash screen. :type pixmap: PySide6.QtGui.QPixmap """ super().__init__(pixmap) self.setWindowFlags(self.windowFlags() | Qt.WindowType.FramelessWindowHint) container = QWidget(self) container.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents, True) layout = QVBoxLayout(container) layout.setContentsMargins(20, 20, 20, 20) layout.setSpacing(8) self.status_label = QLabel('Starting...', container) self.status_label.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignBottom) self.status_label.setStyleSheet('color: black; font-size: 12px;') self.status_label.setWordWrap(True) layout.addWidget(self.status_label) self.progress = QProgressBar(container) self.progress.setRange(0, 100) self.progress.setValue(0) self.progress.setTextVisible(False) self.progress.setFixedHeight(10) layout.addWidget(self.progress) container.setLayout(layout) container.setGeometry(self.rect())
[docs] def set_status(self, text: str, current: int, total: int) -> None: """ Update the status text and progress bar. Sets the status label to the provided text and updates the progress bar based on the current and total steps. If ``total`` is less than or equal to zero, the progress bar enters an indeterminate mode. :param text: Status message to display. :type text: str :param current: Current progress step. :type current: int :param total: Total number of steps; if <= 0, an indeterminate progress bar is shown. :type total: int :return: None :rtype: None """ self.status_label.setText(text) if total <= 0: self.progress.setRange(0, 0) else: self.progress.setRange(0, total) self.progress.setValue(current)
[docs] def show(self) -> None: """ Center the splash screen on the screen containing the mouse cursor and display it. The method determines the screen under the current cursor position; if none is found, it falls back to the primary screen. It then moves the splash window so that it is centered on that screen before invoking the base class ``show`` method. """ screen = QApplication.screenAt(QCursor.pos()) if not screen: screen = QApplication.primaryScreen() screen_geometry = screen.geometry() splash_rect = self.frameGeometry() center_point = screen_geometry.center() splash_rect.moveCenter(center_point) self.move(splash_rect.topLeft()) super().show()