diff --git a/cinnamon-dynamic-wallpaper@TobiZog/image-configurator/image-configurator.glade b/cinnamon-dynamic-wallpaper@TobiZog/image-configurator/image-configurator.glade index 4b04cc8..43cd9f0 100644 --- a/cinnamon-dynamic-wallpaper@TobiZog/image-configurator/image-configurator.glade +++ b/cinnamon-dynamic-wallpaper@TobiZog/image-configurator/image-configurator.glade @@ -19,934 +19,942 @@ + + 100 + 80 + True + True + in + + + True + False + natural + + + True + False + 8 + 8 + 8 + 8 + True + vertical + 4 + + + True + False + 0.009999999776482582 + in + + + True + False + 8 + 8 + + + + True + False + 8 + 8 + 8 + 8 + 8 + 8 + True + + + True + False + Use an included or a custom image set? + + + 0 + 0 + 2 + + + + + Use an included image set + True + True + False + True + True + + + + 1 + 0 + + + + + Import a heic-file + True + True + False + True + True + rb_included_image_set + + + 1 + 1 + + + + + + + + + True + False + 4 + 4 + Image Source + + + + + False + True + 0 + + + + + True + False + 0.009999999776482582 + in + + + True + False + 8 + 8 + + + + True + False + 8 + 8 + 8 + 8 + 8 + 8 + True + + + 36 + True + False + Select an image-set + + + 0 + 0 + + + + + False + True + filefilter1 + + + + + 1 + 1 + + + + + 36 + False + True + Choose the file, which you want to use + + + 0 + 1 + + + + + True + False + image_set_list_store + True + 0 + + + False + + + + + 1 + 0 + + + + + + + + + True + False + 4 + 4 + Image Set + + + + + False + True + 1 + + + + + True + False + True + 0.009999999776482582 + in + + + True + False + 8 + 8 + 8 + + + + True + False + 8 + 8 + True + True + + + True + False + 0.5 + in + + + True + False + 8 + 8 + 8 + 8 + + + True + False + vertical + 8 + + + 300 + 200 + True + False + True + gtk-missing-image + 30 + + + False + True + 0 + + + + + True + False + ls_preview + True + 0 + + + + False + + + + + False + True + 1 + + + + + + + + + True + False + 4 + 4 + Morning Twilight + + + + + 0 + 0 + + + + + True + False + 0.5 + in + + + True + False + 8 + 8 + 8 + 8 + + + True + False + vertical + 8 + + + 300 + 200 + True + False + True + gtk-missing-image + + + False + True + 0 + + + + + True + False + ls_preview + True + 0 + + + + False + + + + + False + True + 1 + + + + + + + + + True + False + 4 + 4 + Sunrise + + + + + 1 + 0 + + + + + True + False + 0.5 + in + + + True + False + 8 + 8 + 8 + 8 + + + True + False + vertical + 8 + + + 300 + 200 + True + False + True + gtk-missing-image + + + False + True + 0 + + + + + True + False + ls_preview + True + 0 + + + + False + + + + + False + True + 1 + + + + + + + + + True + False + 4 + 4 + Morning + + + + + 2 + 0 + + + + + True + False + 0.5 + in + + + True + False + 8 + 8 + 8 + 8 + + + True + False + vertical + 8 + + + 300 + 200 + True + False + True + gtk-missing-image + + + False + True + 0 + + + + + True + False + ls_preview + True + 0 + + + + False + + + + + False + True + 1 + + + + + + + + + True + False + 4 + 4 + Noon + + + + + 0 + 1 + + + + + True + False + 0.5 + in + + + True + False + 8 + 8 + 8 + 8 + + + True + False + vertical + 8 + + + 300 + 200 + True + False + True + gtk-missing-image + + + False + True + 0 + + + + + True + False + ls_preview + True + 0 + + + + False + + + + + False + True + 1 + + + + + + + + + True + False + 4 + 4 + Afternoon + + + + + 1 + 1 + + + + + True + False + 0.5 + in + + + True + False + 8 + 8 + 8 + 8 + + + True + False + vertical + 8 + + + 300 + 200 + True + False + True + gtk-missing-image + + + False + True + 0 + + + + + True + False + ls_preview + True + 0 + + + + False + + + + + False + True + 1 + + + + + + + + + True + False + 4 + 4 + Evening + + + + + 2 + 1 + + + + + True + False + 0.5 + in + + + True + False + 8 + 8 + 8 + 8 + + + True + False + vertical + 8 + + + 300 + 200 + True + False + True + gtk-missing-image + + + False + True + 0 + + + + + True + False + ls_preview + True + 0 + + + + False + + + + + False + True + 1 + + + + + + + + + True + False + 4 + 4 + Sunset + + + + + 0 + 2 + + + + + True + False + 0.5 + in + + + True + False + 8 + 8 + 8 + 8 + + + True + False + vertical + 8 + + + 300 + 200 + True + False + True + gtk-missing-image + + + False + True + 0 + + + + + True + False + ls_preview + True + 0 + + + + False + + + + + False + True + 1 + + + + + + + + + True + False + 4 + 4 + Night Twilight + + + + + 1 + 2 + + + + + True + False + 0.5 + in + + + True + False + 8 + 8 + 8 + 8 + + + True + False + vertical + 8 + + + 300 + 200 + True + False + True + gtk-missing-image + + + False + True + 0 + + + + + True + False + ls_preview + True + 0 + + + + False + + + + + False + True + 1 + + + + + + + + + True + False + 4 + 4 + Night + + + + + 2 + 2 + + + + + + + + + True + False + 4 + 4 + Preview + + + + + False + True + 2 + + + + + + + False center + 1024 768 ../icons/icon.png - + True - True - never - in - False - True + False + crossfade - - True - False - natural - - - True - False - 8 - 8 - 8 - 8 - True - vertical - 4 - - - True - False - 0.009999999776482582 - in - - - True - False - 8 - 8 - - - - True - False - 8 - 8 - 8 - 8 - 8 - 8 - True - - - True - False - Use an included or a custom image set? - - - 0 - 0 - 2 - - - - - Use an included image set - True - True - False - True - True - - - - 1 - 0 - - - - - Import a heic-file - True - True - False - True - True - rb_included_image_set - - - 1 - 1 - - - - - - - - - True - False - 4 - 4 - Image Source - - - - - False - True - 0 - - - - - True - False - 0.009999999776482582 - in - - - True - False - 8 - 8 - - - - True - False - 8 - 8 - 8 - 8 - 8 - 8 - True - - - 36 - True - False - Select an image-set - - - 0 - 0 - - - - - False - True - filefilter1 - - - - - 1 - 1 - - - - - 36 - False - True - Choose the file, which you want to use - - - 0 - 1 - - - - - True - False - image_set_list_store - True - 0 - - - False - - - - - 1 - 0 - - - - - - - - - True - False - 4 - 4 - Image Set - - - - - False - True - 1 - - - - - True - False - True - 0.009999999776482582 - in - - - True - False - 8 - 8 - 8 - - - - True - False - 8 - 8 - True - True - - - True - False - 0.5 - in - - - True - False - 8 - 8 - 8 - 8 - - - True - False - vertical - 8 - - - 300 - 200 - True - False - True - gtk-missing-image - 30 - - - False - True - 0 - - - - - True - False - ls_preview - True - 0 - - - - False - - - - - False - True - 1 - - - - - - - - - True - False - 4 - 4 - Morning Twilight - - - - - 0 - 0 - - - - - True - False - 0.5 - in - - - True - False - 8 - 8 - 8 - 8 - - - True - False - vertical - 8 - - - 300 - 200 - True - False - True - gtk-missing-image - - - False - True - 0 - - - - - True - False - ls_preview - True - 0 - - - - False - - - - - False - True - 1 - - - - - - - - - True - False - 4 - 4 - Sunrise - - - - - 1 - 0 - - - - - True - False - 0.5 - in - - - True - False - 8 - 8 - 8 - 8 - - - True - False - vertical - 8 - - - 300 - 200 - True - False - True - gtk-missing-image - - - False - True - 0 - - - - - True - False - ls_preview - True - 0 - - - - False - - - - - False - True - 1 - - - - - - - - - True - False - 4 - 4 - Morning - - - - - 2 - 0 - - - - - True - False - 0.5 - in - - - True - False - 8 - 8 - 8 - 8 - - - True - False - vertical - 8 - - - 300 - 200 - True - False - True - gtk-missing-image - - - False - True - 0 - - - - - True - False - ls_preview - True - 0 - - - - False - - - - - False - True - 1 - - - - - - - - - True - False - 4 - 4 - Noon - - - - - 0 - 1 - - - - - True - False - 0.5 - in - - - True - False - 8 - 8 - 8 - 8 - - - True - False - vertical - 8 - - - 300 - 200 - True - False - True - gtk-missing-image - - - False - True - 0 - - - - - True - False - ls_preview - True - 0 - - - - False - - - - - False - True - 1 - - - - - - - - - True - False - 4 - 4 - Afternoon - - - - - 1 - 1 - - - - - True - False - 0.5 - in - - - True - False - 8 - 8 - 8 - 8 - - - True - False - vertical - 8 - - - 300 - 200 - True - False - True - gtk-missing-image - - - False - True - 0 - - - - - True - False - ls_preview - True - 0 - - - - False - - - - - False - True - 1 - - - - - - - - - True - False - 4 - 4 - Evening - - - - - 2 - 1 - - - - - True - False - 0.5 - in - - - True - False - 8 - 8 - 8 - 8 - - - True - False - vertical - 8 - - - 300 - 200 - True - False - True - gtk-missing-image - - - False - True - 0 - - - - - True - False - ls_preview - True - 0 - - - - False - - - - - False - True - 1 - - - - - - - - - True - False - 4 - 4 - Sunset - - - - - 0 - 2 - - - - - True - False - 0.5 - in - - - True - False - 8 - 8 - 8 - 8 - - - True - False - vertical - 8 - - - 300 - 200 - True - False - True - gtk-missing-image - - - False - True - 0 - - - - - True - False - ls_preview - True - 0 - - - - False - - - - - False - True - 1 - - - - - - - - - True - False - 4 - 4 - Night Twilight - - - - - 1 - 2 - - - - - True - False - 0.5 - in - - - True - False - 8 - 8 - 8 - 8 - - - True - False - vertical - 8 - - - 300 - 200 - True - False - True - gtk-missing-image - - - False - True - 0 - - - - - True - False - ls_preview - True - 0 - - - - False - - - - - False - True - 1 - - - - - - - - - True - False - 4 - 4 - Night - - - - - 2 - 2 - - - - - - - - - True - False - 4 - 4 - Preview - - - - - False - True - 2 - - - - - + @@ -971,4 +979,40 @@ + + True + False + 8 + 8 + 8 + 8 + True + vertical + 8 + + + 64 + True + False + True + + + True + False + 0 + + + + + True + False + Proceeding... + + + False + True + 2 + + + diff --git a/cinnamon-dynamic-wallpaper@TobiZog/image-configurator/image-configurator.py b/cinnamon-dynamic-wallpaper@TobiZog/image-configurator/image-configurator.py index 295f939..8a2135c 100644 --- a/cinnamon-dynamic-wallpaper@TobiZog/image-configurator/image-configurator.py +++ b/cinnamon-dynamic-wallpaper@TobiZog/image-configurator/image-configurator.py @@ -1,4 +1,4 @@ -import gi, os, glob, json, shutil, enum +import gi, os, glob, json, shutil, enum, threading gi.require_version("Gtk", "3.0") from gi.repository import Gtk, GdkPixbuf @@ -32,7 +32,7 @@ class ImageConfigurator: "etr_img_night" ] - + ########### Create the folder ########### try: os.mkdir(EXPORT_DIR) except: @@ -43,7 +43,6 @@ class ImageConfigurator: except: pass - ########### GTK stuff ########### self.builder = Gtk.Builder() self.builder.add_from_file(UI_PATH) @@ -85,6 +84,12 @@ class ImageConfigurator: 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 ########### self.image_set_list_store.append(["Big Sur Beach 2"]) @@ -94,10 +99,11 @@ class ImageConfigurator: # 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() @@ -105,6 +111,8 @@ class ImageConfigurator: 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) @@ -128,6 +136,8 @@ class ImageConfigurator: 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) @@ -152,6 +162,12 @@ class ImageConfigurator: 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 + """ pixbuf = GdkPixbuf.Pixbuf.new_from_file(imageURI) pixbuf = pixbuf.scale_simple(300, 200, GdkPixbuf.InterpType.BILINEAR) @@ -159,6 +175,11 @@ class ImageConfigurator: 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(".")] @@ -168,8 +189,15 @@ class ImageConfigurator: self.wipeImages(Source.EXPORT) os.system("heif-convert " + imageURI + " " + EXPORT_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.EXPORT: dir = EXPORT_DIR + "/*" elif source == Source.RESSOURCES: @@ -180,6 +208,8 @@ class ImageConfigurator: def createExtracted(self): + """ Create the extracted images array + """ if self.image_source == Source.RESSOURCES: self.extracted = os.listdir(RES_DIR + "/custom_images") elif self.image_source == Source.EXPORT: @@ -191,8 +221,12 @@ class ImageConfigurator: for option in self.extracted: self.ls_preview.append([option]) + self.stack_main.set_visible_child_name("config") + def copyToSource(self): + """ Copies the extracted images to "res/" + """ self.wipeImages(Source.RESSOURCES) for image in os.listdir(EXPORT_DIR): @@ -200,6 +234,11 @@ class ImageConfigurator: 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.lb_image_set.set_visible(source == Source.SET) self.cb_image_set.set_visible(source == Source.SET) @@ -211,7 +250,7 @@ class ImageConfigurator: ########## UI Signals ########## def onRadioImageSet(self, rb): - """ UI Signal, if the radio buttons are toggled + """ UI signal if the radio buttons are toggled Args: rb (GtkRadioButton): The toggled RadioButton @@ -223,18 +262,32 @@ class ImageConfigurator: 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.extractHeifImages(uri) - self.createExtracted() + 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:] + # todo if self.image_source == Source.RESSOURCES: self.changePreviewImage(int(number) - 1, RES_DIR + "/custom_images/" + self.extracted[cb.get_active()]) elif self.image_source == Source.EXPORT: @@ -242,6 +295,8 @@ class ImageConfigurator: def onApply(self, *args): + """ UI signal if the user presses the "Apply" button + """ self.writeToSettings() self.copyToSource() @@ -249,9 +304,11 @@ class ImageConfigurator: def onDestroy(self, *args): + """ UI signal if the window is closed by the user + """ Gtk.main_quit() -ic = ImageConfigurator() -ic.showMainWindow() - +if __name__ == "__main__": + ic = ImageConfigurator() + ic.showMainWindow()