Advertisement
DaelonSuzuka

Untitled

Feb 17th, 2024
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.18 KB | None | 0 0
  1. import sys
  2. import signal
  3.  
  4. from PySide6.QtCore import Qt, QTimer
  5. from PySide6.QtWidgets import QApplication, QSplashScreen, QVBoxLayout, QLabel
  6. from PySide6.QtGui import QPixmap, QFont, QFontDatabase
  7.  
  8. class SplashScreen(QSplashScreen):
  9.     def __init__(self):
  10.         super().__init__()
  11.         self.setFixedSize(534, 300)
  12.  
  13.         # Define layout as an instance variable
  14.         self.vbox = QVBoxLayout()
  15.         self.setContentsMargins(0, 0, 0, 0)
  16.         self.vbox.setAlignment(Qt.AlignTop | Qt.AlignLeft)
  17.  
  18.         # Set the layout for the splash screen
  19.         self.setLayout(self.vbox)
  20.  
  21.         self.setWindowTitle("AppName")
  22.         self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
  23.         self.setWindowOpacity(1)
  24.  
  25.         # Add external fonts
  26.         # QFontDatabase.addApplicationFont("fonts/Aligator.otf")
  27.  
  28.         # Create a label to display the background image
  29.         self.splash_img = QLabel(self)
  30.         self.splash_img.setAlignment(Qt.AlignCenter | Qt.AlignTop)  # Center the image within the window
  31.         self.splash_img.setPixmap(QPixmap("icon.png"))
  32.         self.splash_img.setStyleSheet("padding: 0;")
  33.         self.splash_img.setScaledContents(True)
  34.  
  35.         # Create labels for text
  36.         app_name_label = QLabel("AppName", self)
  37.         # app_name_label.setFont(QFont("Aligator", 75))
  38.         app_name_label.setAlignment(Qt.AlignCenter | Qt.AlignTop)  # Center the text horizontally
  39.         app_name_label.setStyleSheet("color: black; padding: 0;")
  40.         self.vbox.addWidget(app_name_label)
  41.  
  42.         version_label = QLabel("Version Number", self)
  43.         version_label.setStyleSheet("color: black; padding: 0;")
  44.         version_label.setAlignment(Qt.AlignBottom)
  45.         self.vbox.addWidget(version_label)
  46.  
  47.         programmer_label = QLabel("Written by Name", self)
  48.         programmer_label.setStyleSheet("color: black; padding: 0;")
  49.         programmer_label.setAlignment(Qt.AlignBottom)
  50.         self.vbox.addWidget(programmer_label)
  51.  
  52.         copyright_label = QLabel("Copyright Year, Cute Saying Here", self)
  53.         copyright_label.setStyleSheet("color: black; padding: 0;")
  54.         copyright_label.setAlignment(Qt.AlignBottom)
  55.         self.vbox.addWidget(copyright_label)
  56.  
  57.     def showEvent(self, event):
  58.         super().showEvent(event)
  59.         # Resize the background label to fill the whole screen
  60.         self.splash_img.setFixedSize(self.size())
  61.  
  62.  
  63. def install_ctrlc_handler(app):
  64.     def ctrlc_handler(sig=None, frame=None):
  65.         app.closeAllWindows() # this makes sure the MainWindow's .close() method gets called
  66.         app.quit()
  67.        
  68.     # grab the keyboard interrupt signal
  69.     signal.signal(signal.SIGINT, ctrlc_handler)
  70.  
  71.     # empty timer callback
  72.     def update():
  73.         pass
  74.    
  75.     # create timer to force python interpreter to get some runtime
  76.     app._ctrlc_timer = QTimer()
  77.     app._ctrlc_timer.timeout.connect(update)
  78.     app._ctrlc_timer.start(10)
  79.  
  80.  
  81. if __name__ == "__main__":
  82.     app = QApplication(sys.argv)
  83.     install_ctrlc_handler(app)
  84.  
  85.     splash = SplashScreen()
  86.     splash.show()
  87.  
  88.     # Simulate some loading time
  89.     import time
  90.     time.sleep(1)
  91.  
  92.     sys.exit(app.exec())
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement