mirror of
https://github.com/nixietab/picodulce.git
synced 2025-04-10 10:28:56 +01:00
added animated themes support!
This commit is contained in:
parent
51dc126c8a
commit
8167462838
44
picodulce.py
44
picodulce.py
@ -173,6 +173,13 @@ class PicomcVersionSelector(QWidget):
|
|||||||
if os.path.isfile(dark_theme_file) and os.path.isfile(native_theme_file):
|
if os.path.isfile(dark_theme_file) and os.path.isfile(native_theme_file):
|
||||||
print("Theme Integrity OK")
|
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):
|
def init_ui(self):
|
||||||
self.setWindowTitle('PicoDulce Launcher') # Change window title
|
self.setWindowTitle('PicoDulce Launcher') # Change window title
|
||||||
current_date = datetime.now()
|
current_date = datetime.now()
|
||||||
@ -188,27 +195,44 @@ class PicomcVersionSelector(QWidget):
|
|||||||
with open("config.json", "r") as config_file:
|
with open("config.json", "r") as config_file:
|
||||||
config = json.load(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
|
# Get the base64 string for the background image from the theme file
|
||||||
theme_background_base64 = self.theme.get("background_image_base64", "")
|
theme_background_base64 = self.theme.get("background_image_base64", "")
|
||||||
if theme_background_base64:
|
if theme_background_base64:
|
||||||
try:
|
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())
|
background_image_data = QByteArray.fromBase64(theme_background_base64.encode())
|
||||||
pixmap = QPixmap()
|
temp_gif_path = "temp.gif" # Write the gif into a temp file because Qt stuff
|
||||||
if pixmap.loadFromData(background_image_data):
|
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)
|
self.setAutoFillBackground(True)
|
||||||
palette = self.palette()
|
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)
|
self.setPalette(palette)
|
||||||
|
|
||||||
|
# Adjust the QLabel size when the window is resized
|
||||||
|
self.movie_label.resizeEvent = self.resize_event
|
||||||
else:
|
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:
|
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:
|
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
|
# Create title label
|
||||||
title_label = QLabel('PicoDulce Launcher') # Change label text
|
title_label = QLabel('PicoDulce Launcher') # Change label text
|
||||||
|
Loading…
Reference in New Issue
Block a user