From b8996b1f0357043cc74a0218acc8b6cb70317a8b Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 13 Jul 2023 13:40:55 +0200 Subject: [PATCH] Compatibility with Cinnamon 4.8 and higher --- CHANGELOG | 3 + .../4.8/icon.png | 2 +- cinnamon-dynamic-wallpaper@TobiZog/4.8/icons | 1 - .../4.8/image-configurator/data | 1 + .../4.8/image-configurator/data/routes.py | 1 - .../image-configurator/image-configurator.py | 7 +- .../4.8/image-configurator/windowHandler.py | 1 + .../5.4/icon.png | 1 - .../5.4/image-configurator/data/routes.py | 1 - .../image-configurator.glade | 2 +- .../image-configurator/image-configurator.py | 376 +----------------- .../5.4/image-configurator/windowHandler.py | 367 +++++++++++++++++ .../{5.4/icons => }/icon.png | Bin .../metadata.json | 3 + 14 files changed, 387 insertions(+), 379 deletions(-) delete mode 120000 cinnamon-dynamic-wallpaper@TobiZog/4.8/icons create mode 120000 cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/data delete mode 100644 cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/data/routes.py mode change 120000 => 100644 cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/image-configurator.py create mode 120000 cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/windowHandler.py delete mode 120000 cinnamon-dynamic-wallpaper@TobiZog/5.4/icon.png delete mode 100644 cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/data/routes.py create mode 100644 cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/windowHandler.py rename cinnamon-dynamic-wallpaper@TobiZog/{5.4/icons => }/icon.png (100%) diff --git a/CHANGELOG b/CHANGELOG index a2509e7..3d147bd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +# Version 1.2 +- Compatibility with Cinnamon 4.8 and higher + # Version 1.1 - Compatibility with Cinnamon 5.4 and 5.8 - Two new image sets diff --git a/cinnamon-dynamic-wallpaper@TobiZog/4.8/icon.png b/cinnamon-dynamic-wallpaper@TobiZog/4.8/icon.png index 3f28e94..0dba589 120000 --- a/cinnamon-dynamic-wallpaper@TobiZog/4.8/icon.png +++ b/cinnamon-dynamic-wallpaper@TobiZog/4.8/icon.png @@ -1 +1 @@ -../5.4/icon.png \ No newline at end of file +../icon.png \ No newline at end of file diff --git a/cinnamon-dynamic-wallpaper@TobiZog/4.8/icons b/cinnamon-dynamic-wallpaper@TobiZog/4.8/icons deleted file mode 120000 index bc358a2..0000000 --- a/cinnamon-dynamic-wallpaper@TobiZog/4.8/icons +++ /dev/null @@ -1 +0,0 @@ -../5.4/icons/ \ No newline at end of file diff --git a/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/data b/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/data new file mode 120000 index 0000000..bed5c10 --- /dev/null +++ b/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/data @@ -0,0 +1 @@ +../../5.4/image-configurator/data/ \ No newline at end of file diff --git a/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/data/routes.py b/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/data/routes.py deleted file mode 100644 index 4d07e26..0000000 --- a/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/data/routes.py +++ /dev/null @@ -1 +0,0 @@ -pref_path = "/.cinnamon/configs/cinnamon-dynamic-wallpaper@TobiZog/cinnamon-dynamic-wallpaper@TobiZog.json" \ No newline at end of file diff --git a/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/image-configurator.py b/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/image-configurator.py deleted file mode 120000 index e48c899..0000000 --- a/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/image-configurator.py +++ /dev/null @@ -1 +0,0 @@ -../../5.4/image-configurator/image-configurator.py \ No newline at end of file diff --git a/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/image-configurator.py b/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/image-configurator.py new file mode 100644 index 0000000..d444587 --- /dev/null +++ b/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/image-configurator.py @@ -0,0 +1,6 @@ +import os +import windowHandler + +if __name__ == "__main__": + wh = windowHandler.WindowHandler(os.path.expanduser("~") + "/.cinnamon/configs/cinnamon-dynamic-wallpaper@TobiZog/cinnamon-dynamic-wallpaper@TobiZog.json") + wh.showMainWindow() diff --git a/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/windowHandler.py b/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/windowHandler.py new file mode 120000 index 0000000..16cad97 --- /dev/null +++ b/cinnamon-dynamic-wallpaper@TobiZog/4.8/image-configurator/windowHandler.py @@ -0,0 +1 @@ +../../5.4/image-configurator/windowHandler.py \ No newline at end of file diff --git a/cinnamon-dynamic-wallpaper@TobiZog/5.4/icon.png b/cinnamon-dynamic-wallpaper@TobiZog/5.4/icon.png deleted file mode 120000 index 9db683c..0000000 --- a/cinnamon-dynamic-wallpaper@TobiZog/5.4/icon.png +++ /dev/null @@ -1 +0,0 @@ -icons/icon.png \ No newline at end of file diff --git a/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/data/routes.py b/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/data/routes.py deleted file mode 100644 index 04fb47a..0000000 --- a/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/data/routes.py +++ /dev/null @@ -1 +0,0 @@ -pref_path = "/.config/cinnamon/spices/cinnamon-dynamic-wallpaper@TobiZog/cinnamon-dynamic-wallpaper@TobiZog.json" \ No newline at end of file diff --git a/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/image-configurator.glade b/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/image-configurator.glade index cf140af..35d9abb 100644 --- a/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/image-configurator.glade +++ b/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/image-configurator.glade @@ -853,7 +853,7 @@ center 1024 768 - ../icons/icon.png + ../../icon.png diff --git a/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/image-configurator.py b/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/image-configurator.py index 14eb7fa..c305390 100644 --- a/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/image-configurator.py +++ b/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/image-configurator.py @@ -1,374 +1,6 @@ -import gi, os, glob, json, shutil, enum, threading, subprocess -from data.routes import pref_path -from data.enum import Source - -gi.require_version("Gtk", "3.0") -from gi.repository import Gtk, GdkPixbuf - -PROJECT_DIR = os.path.dirname(os.path.dirname(__file__)) + "/" -UI_PATH = PROJECT_DIR + "image-configurator/" + "image-configurator.glade" -PREF_PATH = os.path.expanduser("~") + pref_path - -IMAGE_DIR = PROJECT_DIR + "images/" -IMAGE_EXTRACT_DIR = IMAGE_DIR + "extracted/" -IMAGE_SETS_DIR = IMAGE_DIR + "included_image_sets/" -IMAGE_SELECTED_DIR = IMAGE_DIR + "selected/" - - -class ImageConfigurator: - def __init__(self) -> None: - ########### Class variables ########### - self.pref_vars = [ - "etr_img_morning_twilight", - "etr_img_sunrise", - "etr_img_morning", - "etr_img_noon", - "etr_img_afternoon", - "etr_img_evening", - "etr_img_sunset", - "etr_img_night_twilight", - "etr_img_night" - ] - - self.img_sets = [ - "aurora", - "beach", - "bitday", - "cliffs", - "gradient", - "lakeside", - "mountains", - "sahara" - ] - - ########### Create the folder ########### - try: - os.mkdir(IMAGE_EXTRACT_DIR) - except: - pass - - try: - os.mkdir(IMAGE_SELECTED_DIR) - except: - pass - - ########### GTK stuff ########### - self.builder = Gtk.Builder() - self.builder.add_from_file(UI_PATH) - self.builder.connect_signals(self) - - ########### Glade Ressources ########### - self.rb_included_image_set = self.builder.get_object("rb_included_image_set") - self.rb_external_image_set = self.builder.get_object("rb_external_image_set") - - self.lb_image_set = self.builder.get_object("lb_image_set") - self.cb_image_set = self.builder.get_object("cb_image_set") - - self.lb_heic_file = self.builder.get_object("lb_heic_file") - self.fc_heic_file = self.builder.get_object("fc_heic_file") - - self.img_previews = [ - self.builder.get_object("img_preview_1"), - self.builder.get_object("img_preview_2"), - self.builder.get_object("img_preview_3"), - self.builder.get_object("img_preview_4"), - self.builder.get_object("img_preview_5"), - self.builder.get_object("img_preview_6"), - self.builder.get_object("img_preview_7"), - self.builder.get_object("img_preview_8"), - self.builder.get_object("img_preview_9") - ] - - self.cb_previews = [ - self.builder.get_object("cb_preview_1"), - self.builder.get_object("cb_preview_2"), - self.builder.get_object("cb_preview_3"), - self.builder.get_object("cb_preview_4"), - self.builder.get_object("cb_preview_5"), - self.builder.get_object("cb_preview_6"), - self.builder.get_object("cb_preview_7"), - self.builder.get_object("cb_preview_8"), - self.builder.get_object("cb_preview_9") - ] - - # The GtkStack - self.stack_main = self.builder.get_object("stack_main") - self.stack_main.add_named(self.builder.get_object("page_config"), "config") - self.stack_main.add_named(self.builder.get_object("page_load"), "load") - self.stack_main.set_visible_child_name("config") - - - ########### Load predefinitions and settings ########### - for set in self.img_sets: - self.cb_image_set.append_text(set) - - self.image_source = Source.SELECTED - - - # Check for Cinnamon version - # With version 5.6+, the folder of the configuration file was changed - version = subprocess.check_output(["cinnamon", "--version"]) - version = version.decode() - version = version[version.find(" "):version.rfind("\n")].strip() - - # Load preferences - self.loadFromSettings() - - - def showMainWindow(self): - """ Opens the main window, starts the Gtk main routine - """ - window = self.builder.get_object("main_window") - window.show_all() - - self.imageSetVisibility(self.image_source) - self.rb_external_image_set.set_active(self.image_source == Source.EXTRACT) - - Gtk.main() - - - def loadFromSettings(self): - """ Load preferences from the Cinnamon preference file - """ - # Load the settings - with open(PREF_PATH, "r") as pref_file: - pref_data = json.load(pref_file) - - - # Get all images in the "selected" folder - choosable_images = os.listdir(IMAGE_SELECTED_DIR) - choosable_images.sort() - - - # Add the founded image names to the ComboBoxes - if pref_data["etr_choosen_image_set"]["value"] == "custom": - for combobox in self.cb_previews: - for option in choosable_images: - combobox.append_text(option) - else: - for i, set in enumerate(self.img_sets): - if set == pref_data["etr_choosen_image_set"]["value"]: - self.cb_image_set.set_active(i) - - - for i, val in enumerate(self.pref_vars): - # Set the preview image - self.changePreviewImage(i, IMAGE_SELECTED_DIR + pref_data[val]['value']) - - # Set the ComboBox selection - if pref_data["etr_choosen_image_set"]["value"] == "custom": - self.image_source = Source.EXTRACT - - for j, set in enumerate(choosable_images): - if set == pref_data[val]["value"]: - self.cb_previews[i].set_active(j) - else: - self.image_source = Source.SET - - - def writeToSettings(self): - """ Save preferences to the Cinnamon preference file - """ - # Load the settings - with open(PREF_PATH, "r") as pref_file: - pref_data = json.load(pref_file) - - - # Update the settings - if self.image_source == Source.SET: - pref_data["etr_choosen_image_set"]["value"] = self.cb_image_set.get_active_text() - - for i, val in enumerate(self.pref_vars): - pref_data[val]['value'] = str(i + 1) + ".jpg" - else: - pref_data["etr_choosen_image_set"]["value"] = "custom" - - for i, val in enumerate(self.pref_vars): - pref_data[val]['value'] = self.cb_previews[i].get_active_text() - - - # Write the settings - with open(PREF_PATH, "w") as pref_file: - json.dump(pref_data, pref_file, separators=(',', ':'), indent=4) - - - def changePreviewImage(self, imageId: int, imageURI: str): - """ Exchanges the image in the preview - - Args: - imageId (int): The number of the preview (0-8) - imageURI (str): URI to the new image - """ - try: - pixbuf = GdkPixbuf.Pixbuf.new_from_file(imageURI) - pixbuf = pixbuf.scale_simple(300, 200, GdkPixbuf.InterpType.BILINEAR) - - self.img_previews[imageId].set_from_pixbuf(pixbuf) - except: - pass - - - def extractHeifImages(self, imageURI: str): - """ Extract all images in a heif file - - Args: - imageURI (str): URI to the heif file - """ - imageURI = imageURI.replace("%20", "\ ") - - filename = imageURI[imageURI.rfind("/") + 1:imageURI.rfind(".")] - - self.image_source = Source.EXTRACT - - self.wipeImages(Source.EXTRACT) - os.system("heif-convert " + imageURI + " " + IMAGE_EXTRACT_DIR + "/" + filename + ".jpg") - - self.createExtracted() - - - def wipeImages(self, source: Source): - """ Removes all image of a folder - - Args: - source (Source): Choose the folder by selecting the Source - """ - if source == Source.EXTRACT: - dir = IMAGE_EXTRACT_DIR + "*" - elif source == Source.SELECTED: - dir = IMAGE_SELECTED_DIR + "*" - - for file in glob.glob(dir): - os.remove(file) - - - def createExtracted(self): - """ Create the extracted images array - """ - try: - if self.image_source == Source.SELECTED: - self.extracted = os.listdir(IMAGE_SELECTED_DIR) - elif self.image_source == Source.EXTRACT: - self.extracted = os.listdir(IMAGE_EXTRACT_DIR) - - self.extracted.sort() - - for combobox in self.cb_previews: - for option in self.extracted: - combobox.append_text(option) - except: - pass - - self.stack_main.set_visible_child_name("config") - - - def copyToSelected(self, source: Source): - """ Copies the extracted images to "res/" - """ - # Clean the "selected folder up" - self.wipeImages(Source.SELECTED) - - # Estimate the source folder - if source == Source.EXTRACT: - source_folder = IMAGE_EXTRACT_DIR - else: - source_folder = IMAGE_SETS_DIR + self.cb_image_set.get_active_text() + "/" - - # Copy it to "selected/" - for image in os.listdir(source_folder): - shutil.copy(source_folder + image, IMAGE_SELECTED_DIR + image) - - - def imageSetVisibility(self, source: Source): - """ Toggle the visibility of the option in the "Image set" box - - Args: - source (Source): Toggle by type of Source - """ - self.image_source = source - - self.lb_image_set.set_visible(source == Source.SET) - self.cb_image_set.set_visible(source == Source.SET) - - self.lb_heic_file.set_visible(source != Source.SET) - self.fc_heic_file.set_visible(source != Source.SET) - - for i in range(0, 9): - self.cb_previews[i].set_visible(source != Source.SET) - - - - ########## UI Signals ########## - - def onImageSetSelected(self, cb): - """ UI signal if the image set combo box value changed - - Args: - cb (GtkComboBox): The active ComboBox - """ - if self.image_source != Source.SELECTED: - set_name = cb.get_active_text() - - for i, _ in enumerate(self.img_previews): - self.changePreviewImage(i, IMAGE_SETS_DIR + set_name + "/" + str(i + 1) + ".jpg") - - - def onRadioImageSet(self, rb): - """ UI signal if the radio buttons are toggled - - Args: - rb (GtkRadioButton): The toggled RadioButton - """ - if rb.get_active(): - self.imageSetVisibility(Source.SET) - else: - self.imageSetVisibility(Source.EXTRACT) - - - def onHeifSelected(self, fc): - """ UI signal if the filechooser has a file selected - - Args: - fc (filechooser): The selected filechooser - """ - # Get the URI to the file - uri = fc.get_file().get_uri() - uri = uri[7:] - - self.stack_main.set_visible_child_name("load") - - thread = threading.Thread(target=self.extractHeifImages, args=(uri, )) - thread.daemon = True - thread.start() - - - def onPreviewComboboxSelected(self, cb): - """ UI signal if one of the preview combobox is selected - - Args: - cb (ComboBox): The selected combobox - """ - number = Gtk.Buildable.get_name(cb) - number = number[number.rfind("_") + 1:] - - if self.image_source == Source.EXTRACT: - self.changePreviewImage(int(number) - 1, IMAGE_EXTRACT_DIR + cb.get_active_text()) - - - def onApply(self, *args): - """ UI signal if the user presses the "Apply" button - """ - self.writeToSettings() - self.copyToSelected(self.image_source) - - Gtk.main_quit() - - - def onDestroy(self, *args): - """ UI signal if the window is closed by the user - """ - Gtk.main_quit() - +import os +import windowHandler if __name__ == "__main__": - ic = ImageConfigurator() - ic.showMainWindow() + wh = windowHandler.WindowHandler(os.path.expanduser("~") + "/.config/cinnamon/spices/cinnamon-dynamic-wallpaper@TobiZog/cinnamon-dynamic-wallpaper@TobiZog.json") + wh.showMainWindow() diff --git a/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/windowHandler.py b/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/windowHandler.py new file mode 100644 index 0000000..4668d0d --- /dev/null +++ b/cinnamon-dynamic-wallpaper@TobiZog/5.4/image-configurator/windowHandler.py @@ -0,0 +1,367 @@ +import gi, os, glob, json, shutil, threading, subprocess +from data.enum import Source + +gi.require_version("Gtk", "3.0") +from gi.repository import Gtk, GdkPixbuf + +CONFIGURATOR_DIR = os.path.dirname(os.path.abspath(__file__)) +PROJECT_DIR = os.path.dirname(CONFIGURATOR_DIR) + "/" +UI_PATH = CONFIGURATOR_DIR + "/" + "image-configurator.glade" + +IMAGE_DIR = PROJECT_DIR + "images/" +IMAGE_EXTRACT_DIR = IMAGE_DIR + "extracted/" +IMAGE_SETS_DIR = IMAGE_DIR + "included_image_sets/" +IMAGE_SELECTED_DIR = IMAGE_DIR + "selected/" + + +class WindowHandler: + def __init__(self, pref_path: str) -> None: + + ########### Class variables ########### + self.pref_path = pref_path + + self.pref_vars = [ + "etr_img_morning_twilight", + "etr_img_sunrise", + "etr_img_morning", + "etr_img_noon", + "etr_img_afternoon", + "etr_img_evening", + "etr_img_sunset", + "etr_img_night_twilight", + "etr_img_night" + ] + + self.img_sets = [ + "aurora", + "beach", + "bitday", + "cliffs", + "gradient", + "lakeside", + "mountains", + "sahara" + ] + + ########### Create the folder ########### + try: + os.mkdir(IMAGE_EXTRACT_DIR) + except: + pass + + try: + os.mkdir(IMAGE_SELECTED_DIR) + except: + pass + + ########### GTK stuff ########### + self.builder = Gtk.Builder() + self.builder.add_from_file(UI_PATH) + self.builder.connect_signals(self) + + ########### Glade Ressources ########### + self.rb_included_image_set = self.builder.get_object("rb_included_image_set") + self.rb_external_image_set = self.builder.get_object("rb_external_image_set") + + self.lb_image_set = self.builder.get_object("lb_image_set") + self.cb_image_set = self.builder.get_object("cb_image_set") + + self.lb_heic_file = self.builder.get_object("lb_heic_file") + self.fc_heic_file = self.builder.get_object("fc_heic_file") + + self.img_previews = [ + self.builder.get_object("img_preview_1"), + self.builder.get_object("img_preview_2"), + self.builder.get_object("img_preview_3"), + self.builder.get_object("img_preview_4"), + self.builder.get_object("img_preview_5"), + self.builder.get_object("img_preview_6"), + self.builder.get_object("img_preview_7"), + self.builder.get_object("img_preview_8"), + self.builder.get_object("img_preview_9") + ] + + self.cb_previews = [ + self.builder.get_object("cb_preview_1"), + self.builder.get_object("cb_preview_2"), + self.builder.get_object("cb_preview_3"), + self.builder.get_object("cb_preview_4"), + self.builder.get_object("cb_preview_5"), + self.builder.get_object("cb_preview_6"), + self.builder.get_object("cb_preview_7"), + self.builder.get_object("cb_preview_8"), + self.builder.get_object("cb_preview_9") + ] + + # The GtkStack + self.stack_main = self.builder.get_object("stack_main") + self.stack_main.add_named(self.builder.get_object("page_config"), "config") + self.stack_main.add_named(self.builder.get_object("page_load"), "load") + self.stack_main.set_visible_child_name("config") + + + ########### Load predefinitions and settings ########### + for set in self.img_sets: + self.cb_image_set.append_text(set) + + self.image_source = Source.SELECTED + + # Load preferences + self.loadFromSettings() + + + def showMainWindow(self): + """ Opens the main window, starts the Gtk main routine + """ + window = self.builder.get_object("main_window") + window.show_all() + + self.imageSetVisibility(self.image_source) + self.rb_external_image_set.set_active(self.image_source == Source.EXTRACT) + + Gtk.main() + + + def loadFromSettings(self): + """ Load preferences from the Cinnamon preference file + """ + #try: + # Load the settings + with open(self.pref_path, "r") as pref_file: + pref_data = json.load(pref_file) + + + # Get all images in the "selected" folder + choosable_images = os.listdir(IMAGE_SELECTED_DIR) + choosable_images.sort() + + + # Add the founded image names to the ComboBoxes + if pref_data["etr_choosen_image_set"]["value"] == "custom": + for combobox in self.cb_previews: + for option in choosable_images: + combobox.append_text(option) + else: + for i, set in enumerate(self.img_sets): + if set == pref_data["etr_choosen_image_set"]["value"]: + self.cb_image_set.set_active(i) + + + for i, val in enumerate(self.pref_vars): + # Set the preview image + self.changePreviewImage(i, IMAGE_SELECTED_DIR + pref_data[val]['value']) + + # Set the ComboBox selection + if pref_data["etr_choosen_image_set"]["value"] == "custom": + self.image_source = Source.EXTRACT + + for j, set in enumerate(choosable_images): + if set == pref_data[val]["value"]: + self.cb_previews[i].set_active(j) + else: + self.image_source = Source.SET + #except: + # pass + + + def writeToSettings(self): + """ Save preferences to the Cinnamon preference file + """ + # Load the settings + with open(self.pref_path, "r") as pref_file: + pref_data = json.load(pref_file) + + + # Update the settings + if self.image_source == Source.SET: + pref_data["etr_choosen_image_set"]["value"] = self.cb_image_set.get_active_text() + + for i, val in enumerate(self.pref_vars): + pref_data[val]['value'] = str(i + 1) + ".jpg" + else: + pref_data["etr_choosen_image_set"]["value"] = "custom" + + for i, val in enumerate(self.pref_vars): + pref_data[val]['value'] = self.cb_previews[i].get_active_text() + + + # Write the settings + with open(self.pref_path, "w") as pref_file: + json.dump(pref_data, pref_file, separators=(',', ':'), indent=4) + + + def changePreviewImage(self, imageId: int, imageURI: str): + """ Exchanges the image in the preview + + Args: + imageId (int): The number of the preview (0-8) + imageURI (str): URI to the new image + """ + try: + pixbuf = GdkPixbuf.Pixbuf.new_from_file(imageURI) + pixbuf = pixbuf.scale_simple(300, 200, GdkPixbuf.InterpType.BILINEAR) + + self.img_previews[imageId].set_from_pixbuf(pixbuf) + except: + pass + + + def extractHeifImages(self, imageURI: str): + """ Extract all images in a heif file + + Args: + imageURI (str): URI to the heif file + """ + imageURI = imageURI.replace("%20", "\ ") + + filename = imageURI[imageURI.rfind("/") + 1:imageURI.rfind(".")] + + self.image_source = Source.EXTRACT + + self.wipeImages(Source.EXTRACT) + os.system("heif-convert " + imageURI + " " + IMAGE_EXTRACT_DIR + "/" + filename + ".jpg") + + self.createExtracted() + + + def wipeImages(self, source: Source): + """ Removes all image of a folder + + Args: + source (Source): Choose the folder by selecting the Source + """ + if source == Source.EXTRACT: + dir = IMAGE_EXTRACT_DIR + "*" + elif source == Source.SELECTED: + dir = IMAGE_SELECTED_DIR + "*" + + for file in glob.glob(dir): + os.remove(file) + + + def createExtracted(self): + """ Create the extracted images array + """ + try: + if self.image_source == Source.SELECTED: + self.extracted = os.listdir(IMAGE_SELECTED_DIR) + elif self.image_source == Source.EXTRACT: + self.extracted = os.listdir(IMAGE_EXTRACT_DIR) + + self.extracted.sort() + + for combobox in self.cb_previews: + for option in self.extracted: + combobox.append_text(option) + except: + pass + + self.stack_main.set_visible_child_name("config") + + + def copyToSelected(self, source: Source): + """ Copies the extracted images to "res/" + """ + # Clean the "selected folder up" + self.wipeImages(Source.SELECTED) + + # Estimate the source folder + if source == Source.EXTRACT: + source_folder = IMAGE_EXTRACT_DIR + else: + source_folder = IMAGE_SETS_DIR + self.cb_image_set.get_active_text() + "/" + + # Copy it to "selected/" + for image in os.listdir(source_folder): + shutil.copy(source_folder + image, IMAGE_SELECTED_DIR + image) + + + def imageSetVisibility(self, source: Source): + """ Toggle the visibility of the option in the "Image set" box + + Args: + source (Source): Toggle by type of Source + """ + self.image_source = source + + self.lb_image_set.set_visible(source == Source.SET) + self.cb_image_set.set_visible(source == Source.SET) + + self.lb_heic_file.set_visible(source != Source.SET) + self.fc_heic_file.set_visible(source != Source.SET) + + for i in range(0, 9): + self.cb_previews[i].set_visible(source != Source.SET) + + + + ########## UI Signals ########## + + def onImageSetSelected(self, cb): + """ UI signal if the image set combo box value changed + + Args: + cb (GtkComboBox): The active ComboBox + """ + if self.image_source != Source.SELECTED: + set_name = cb.get_active_text() + + for i, _ in enumerate(self.img_previews): + self.changePreviewImage(i, IMAGE_SETS_DIR + set_name + "/" + str(i + 1) + ".jpg") + + + def onRadioImageSet(self, rb): + """ UI signal if the radio buttons are toggled + + Args: + rb (GtkRadioButton): The toggled RadioButton + """ + if rb.get_active(): + self.imageSetVisibility(Source.SET) + else: + self.imageSetVisibility(Source.EXTRACT) + + + def onHeifSelected(self, fc): + """ UI signal if the filechooser has a file selected + + Args: + fc (filechooser): The selected filechooser + """ + # Get the URI to the file + uri = fc.get_file().get_uri() + uri = uri[7:] + + self.stack_main.set_visible_child_name("load") + + thread = threading.Thread(target=self.extractHeifImages, args=(uri, )) + thread.daemon = True + thread.start() + + + def onPreviewComboboxSelected(self, cb): + """ UI signal if one of the preview combobox is selected + + Args: + cb (ComboBox): The selected combobox + """ + number = Gtk.Buildable.get_name(cb) + number = number[number.rfind("_") + 1:] + + if self.image_source == Source.EXTRACT: + self.changePreviewImage(int(number) - 1, IMAGE_EXTRACT_DIR + cb.get_active_text()) + + + def onApply(self, *args): + """ UI signal if the user presses the "Apply" button + """ + self.writeToSettings() + self.copyToSelected(self.image_source) + + Gtk.main_quit() + + + def onDestroy(self, *args): + """ UI signal if the window is closed by the user + """ + Gtk.main_quit() \ No newline at end of file diff --git a/cinnamon-dynamic-wallpaper@TobiZog/5.4/icons/icon.png b/cinnamon-dynamic-wallpaper@TobiZog/icon.png similarity index 100% rename from cinnamon-dynamic-wallpaper@TobiZog/5.4/icons/icon.png rename to cinnamon-dynamic-wallpaper@TobiZog/icon.png diff --git a/cinnamon-dynamic-wallpaper@TobiZog/metadata.json b/cinnamon-dynamic-wallpaper@TobiZog/metadata.json index 65e9206..b8ea4b4 100644 --- a/cinnamon-dynamic-wallpaper@TobiZog/metadata.json +++ b/cinnamon-dynamic-wallpaper@TobiZog/metadata.json @@ -5,6 +5,9 @@ "version": "1.1", "multiversion": true, "cinnamon-version": [ + "4.8", + "5.0", + "5.2", "5.4", "5.6", "5.8"