diff --git a/picodulce.py b/picodulce.py index 363f528..bae6253 100644 --- a/picodulce.py +++ b/picodulce.py @@ -173,6 +173,13 @@ class PicomcVersionSelector(QWidget): if os.path.isfile(dark_theme_file) and os.path.isfile(native_theme_file): print("Theme Integrity OK") + + def resize_event(self, event): + if hasattr(self, 'movie_label'): + self.movie_label.setGeometry(0, 0, self.width(), self.height()) + event.accept() # Accept the resize event + + def init_ui(self): self.setWindowTitle('PicoDulce Launcher') # Change window title current_date = datetime.now() @@ -188,27 +195,44 @@ class PicomcVersionSelector(QWidget): with open("config.json", "r") as config_file: config = json.load(config_file) - if config.get("ThemeBackground", False): # Default to False if ThemeBackground is missing + if self.config.get("ThemeBackground", False): # Default to False if ThemeBackground is missing # Get the base64 string for the background image from the theme file theme_background_base64 = self.theme.get("background_image_base64", "") if theme_background_base64: try: - # Decode the base64 string and create a QPixmap + # Decode the base64 string to get the binary data background_image_data = QByteArray.fromBase64(theme_background_base64.encode()) - pixmap = QPixmap() - if pixmap.loadFromData(background_image_data): + temp_gif_path = "temp.gif" # Write the gif into a temp file because Qt stuff + with open(temp_gif_path, 'wb') as temp_gif_file: + temp_gif_file.write(background_image_data) + + # Create a QMovie object from the temporary file + movie = QMovie(temp_gif_path) + if movie.isValid(): self.setAutoFillBackground(True) palette = self.palette() - palette.setBrush(QPalette.Window, QBrush(pixmap.scaled( - self.size(), Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation - ))) + + # Set the QMovie to a QLabel + self.movie_label = QLabel(self) + self.movie_label.setMovie(movie) + self.movie_label.setGeometry(0, 0, movie.frameRect().width(), movie.frameRect().height()) + self.movie_label.setScaledContents(True) # Ensure the QLabel scales its contents + movie.start() + + # Use the QLabel pixmap as the brush texture + brush = QBrush(QPixmap(movie.currentPixmap())) + brush.setStyle(Qt.TexturePattern) + palette.setBrush(QPalette.Window, brush) self.setPalette(palette) + + # Adjust the QLabel size when the window is resized + self.movie_label.resizeEvent = self.resize_event else: - print("Error: Failed to load background image from base64 string.") + print("Error: Failed to load background GIF from base64 string.") except Exception as e: - print(f"Error: Failed to decode and set background image. {e}") + print(f"Error: Failed to decode and set background GIF. {e}") else: - print("No background image base64 string found in the theme file.") + print("No background GIF base64 string found in the theme file.") # Create title label title_label = QLabel('PicoDulce Launcher') # Change label text