Module saePisan.view.components.SplashScreen

Classes

class SplashScreen (pixmap)
Expand source code
class SplashScreen(QSplashScreen):
    """
    A custom splash screen class that displays a series of messages during application startup.
    Attributes:
        label (QLabel): A label to display the current message.
        progress_bar (QProgressBar): Progress bar to show progress.
        layout (QVBoxLayout): A vertical box layout to manage the label's position.
        messages (list): A list of messages to be displayed sequentially.
        current_message_index (int): The index of the current message being displayed.
    Methods:
        update_message():
            Updates the label and progress bar to display the next message in the sequence.
    """
    
    def __init__(self, pixmap):
        super().__init__(pixmap)
        self.setWindowFlags(Qt.WindowType.FramelessWindowHint | Qt.WindowType.WindowStaysOnTopHint)
        
        self.label = QLabel("Checking environment...", self)
        self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.label.setStyleSheet("color: black; font-size: 14px;")

        self.progress_bar = QProgressBar(self)
        self.progress_bar.setRange(0, 100)
        self.progress_bar.setValue(0)
        self.progress_bar.setTextVisible(True)
        self.progress_bar.setFormat("%p%")
        self.progress_bar.setFixedHeight(10)
        self.progress_anim = QPropertyAnimation(self.progress_bar, b"value")
        self.progress_anim.setDuration(400)
        self.progress_bar.setStyleSheet("""
            QProgressBar {
                border: 1px solid #bbb;
                border-radius: 5px;
                background: #eee;
                text-align: center;
                color: black;
                font-size: 8px;
            }
            QProgressBar::chunk {
                background-color: #4caf50;
                border-radius: 5px;
            }
        """)

        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.label)
        self.layout.addWidget(self.progress_bar)
        self.layout.setAlignment(Qt.AlignmentFlag.AlignBottom)

        self.messages = [
            "Checking environment...",
            "Checking and Loading R...",
            "Loading R Packages...",
            "Setup Environment...",
            "Loading Completed!"
        ]
        self.current_message_index = 0

    def update_message(self):
        self.current_message_index = (self.current_message_index + 1) % len(self.messages)
        self.label.setText(self.messages[self.current_message_index])
        last_idx = len(self.messages) - 1
        if self.current_message_index < last_idx:
            progress = int((self.current_message_index / (last_idx - 1)) * 99) if last_idx > 1 else 99
        else:
            progress = 100
        self.progress_anim.stop()
        self.progress_anim.setStartValue(self.progress_bar.value())
        self.progress_anim.setEndValue(progress)
        self.progress_anim.start()
        QApplication.processEvents()

A custom splash screen class that displays a series of messages during application startup.

Attributes

label : QLabel
A label to display the current message.
progress_bar : QProgressBar
Progress bar to show progress.
layout : QVBoxLayout
A vertical box layout to manage the label's position.
messages : list
A list of messages to be displayed sequentially.
current_message_index : int
The index of the current message being displayed.

Methods

update_message(): Updates the label and progress bar to display the next message in the sequence.

Ancestors

  • PyQt6.QtWidgets.QSplashScreen
  • PyQt6.QtWidgets.QWidget
  • PyQt6.QtCore.QObject
  • PyQt6.sip.wrapper
  • PyQt6.QtGui.QPaintDevice
  • PyQt6.sip.simplewrapper

Methods

def update_message(self)
Expand source code
def update_message(self):
    self.current_message_index = (self.current_message_index + 1) % len(self.messages)
    self.label.setText(self.messages[self.current_message_index])
    last_idx = len(self.messages) - 1
    if self.current_message_index < last_idx:
        progress = int((self.current_message_index / (last_idx - 1)) * 99) if last_idx > 1 else 99
    else:
        progress = 100
    self.progress_anim.stop()
    self.progress_anim.setStartValue(self.progress_bar.value())
    self.progress_anim.setEndValue(progress)
    self.progress_anim.start()
    QApplication.processEvents()