Loading screen, documentation
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -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")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, GdkPixbuf
|
from gi.repository import Gtk, GdkPixbuf
|
||||||
@@ -32,7 +32,7 @@ class ImageConfigurator:
|
|||||||
"etr_img_night"
|
"etr_img_night"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
########### Create the folder ###########
|
||||||
try:
|
try:
|
||||||
os.mkdir(EXPORT_DIR)
|
os.mkdir(EXPORT_DIR)
|
||||||
except:
|
except:
|
||||||
@@ -43,7 +43,6 @@ class ImageConfigurator:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
########### GTK stuff ###########
|
########### GTK stuff ###########
|
||||||
self.builder = Gtk.Builder()
|
self.builder = Gtk.Builder()
|
||||||
self.builder.add_from_file(UI_PATH)
|
self.builder.add_from_file(UI_PATH)
|
||||||
@@ -85,6 +84,12 @@ class ImageConfigurator:
|
|||||||
self.builder.get_object("cb_preview_9")
|
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 ###########
|
########### Load predefinitions and settings ###########
|
||||||
self.image_set_list_store.append(["Big Sur Beach 2"])
|
self.image_set_list_store.append(["Big Sur Beach 2"])
|
||||||
@@ -96,8 +101,9 @@ class ImageConfigurator:
|
|||||||
self.loadFromSettings()
|
self.loadFromSettings()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def showMainWindow(self):
|
def showMainWindow(self):
|
||||||
|
""" Opens the main window, starts the Gtk main routine
|
||||||
|
"""
|
||||||
window = self.builder.get_object("main_window")
|
window = self.builder.get_object("main_window")
|
||||||
window.show_all()
|
window.show_all()
|
||||||
|
|
||||||
@@ -105,6 +111,8 @@ class ImageConfigurator:
|
|||||||
|
|
||||||
|
|
||||||
def loadFromSettings(self):
|
def loadFromSettings(self):
|
||||||
|
""" Load preferences from the Cinnamon preference file
|
||||||
|
"""
|
||||||
# Load the settings
|
# Load the settings
|
||||||
with open(PREF_PATH, "r") as pref_file:
|
with open(PREF_PATH, "r") as pref_file:
|
||||||
pref_data = json.load(pref_file)
|
pref_data = json.load(pref_file)
|
||||||
@@ -128,6 +136,8 @@ class ImageConfigurator:
|
|||||||
|
|
||||||
|
|
||||||
def writeToSettings(self):
|
def writeToSettings(self):
|
||||||
|
""" Save preferences to the Cinnamon preference file
|
||||||
|
"""
|
||||||
# Load the settings
|
# Load the settings
|
||||||
with open(PREF_PATH, "r") as pref_file:
|
with open(PREF_PATH, "r") as pref_file:
|
||||||
pref_data = json.load(pref_file)
|
pref_data = json.load(pref_file)
|
||||||
@@ -152,6 +162,12 @@ class ImageConfigurator:
|
|||||||
|
|
||||||
|
|
||||||
def changePreviewImage(self, imageId: int, imageURI: str):
|
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 = GdkPixbuf.Pixbuf.new_from_file(imageURI)
|
||||||
pixbuf = pixbuf.scale_simple(300, 200, GdkPixbuf.InterpType.BILINEAR)
|
pixbuf = pixbuf.scale_simple(300, 200, GdkPixbuf.InterpType.BILINEAR)
|
||||||
|
|
||||||
@@ -159,6 +175,11 @@ class ImageConfigurator:
|
|||||||
|
|
||||||
|
|
||||||
def extractHeifImages(self, imageURI: str):
|
def extractHeifImages(self, imageURI: str):
|
||||||
|
""" Extract all images in a heif file
|
||||||
|
|
||||||
|
Args:
|
||||||
|
imageURI (str): URI to the heif file
|
||||||
|
"""
|
||||||
imageURI = imageURI.replace("%20", "\ ")
|
imageURI = imageURI.replace("%20", "\ ")
|
||||||
|
|
||||||
filename = imageURI[imageURI.rfind("/") + 1:imageURI.rfind(".")]
|
filename = imageURI[imageURI.rfind("/") + 1:imageURI.rfind(".")]
|
||||||
@@ -168,8 +189,15 @@ class ImageConfigurator:
|
|||||||
self.wipeImages(Source.EXPORT)
|
self.wipeImages(Source.EXPORT)
|
||||||
os.system("heif-convert " + imageURI + " " + EXPORT_DIR + "/" + filename + ".jpg")
|
os.system("heif-convert " + imageURI + " " + EXPORT_DIR + "/" + filename + ".jpg")
|
||||||
|
|
||||||
|
self.createExtracted()
|
||||||
|
|
||||||
|
|
||||||
def wipeImages(self, source: Source):
|
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:
|
if source == Source.EXPORT:
|
||||||
dir = EXPORT_DIR + "/*"
|
dir = EXPORT_DIR + "/*"
|
||||||
elif source == Source.RESSOURCES:
|
elif source == Source.RESSOURCES:
|
||||||
@@ -180,6 +208,8 @@ class ImageConfigurator:
|
|||||||
|
|
||||||
|
|
||||||
def createExtracted(self):
|
def createExtracted(self):
|
||||||
|
""" Create the extracted images array
|
||||||
|
"""
|
||||||
if self.image_source == Source.RESSOURCES:
|
if self.image_source == Source.RESSOURCES:
|
||||||
self.extracted = os.listdir(RES_DIR + "/custom_images")
|
self.extracted = os.listdir(RES_DIR + "/custom_images")
|
||||||
elif self.image_source == Source.EXPORT:
|
elif self.image_source == Source.EXPORT:
|
||||||
@@ -191,8 +221,12 @@ class ImageConfigurator:
|
|||||||
for option in self.extracted:
|
for option in self.extracted:
|
||||||
self.ls_preview.append([option])
|
self.ls_preview.append([option])
|
||||||
|
|
||||||
|
self.stack_main.set_visible_child_name("config")
|
||||||
|
|
||||||
|
|
||||||
def copyToSource(self):
|
def copyToSource(self):
|
||||||
|
""" Copies the extracted images to "res/"
|
||||||
|
"""
|
||||||
self.wipeImages(Source.RESSOURCES)
|
self.wipeImages(Source.RESSOURCES)
|
||||||
|
|
||||||
for image in os.listdir(EXPORT_DIR):
|
for image in os.listdir(EXPORT_DIR):
|
||||||
@@ -200,6 +234,11 @@ class ImageConfigurator:
|
|||||||
|
|
||||||
|
|
||||||
def imageSetVisibility(self, source: Source):
|
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.lb_image_set.set_visible(source == Source.SET)
|
||||||
self.cb_image_set.set_visible(source == Source.SET)
|
self.cb_image_set.set_visible(source == Source.SET)
|
||||||
|
|
||||||
@@ -211,7 +250,7 @@ class ImageConfigurator:
|
|||||||
########## UI Signals ##########
|
########## UI Signals ##########
|
||||||
|
|
||||||
def onRadioImageSet(self, rb):
|
def onRadioImageSet(self, rb):
|
||||||
""" UI Signal, if the radio buttons are toggled
|
""" UI signal if the radio buttons are toggled
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
rb (GtkRadioButton): The toggled RadioButton
|
rb (GtkRadioButton): The toggled RadioButton
|
||||||
@@ -223,18 +262,32 @@ class ImageConfigurator:
|
|||||||
|
|
||||||
|
|
||||||
def onHeifSelected(self, fc):
|
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
|
# Get the URI to the file
|
||||||
uri = fc.get_file().get_uri()
|
uri = fc.get_file().get_uri()
|
||||||
uri = uri[7:]
|
uri = uri[7:]
|
||||||
|
|
||||||
self.extractHeifImages(uri)
|
self.stack_main.set_visible_child_name("load")
|
||||||
self.createExtracted()
|
|
||||||
|
thread = threading.Thread(target=self.extractHeifImages, args=(uri, ))
|
||||||
|
thread.daemon = True
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
|
||||||
def onPreviewComboboxSelected(self, cb):
|
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 = Gtk.Buildable.get_name(cb)
|
||||||
number = number[number.rfind("_") + 1:]
|
number = number[number.rfind("_") + 1:]
|
||||||
|
|
||||||
|
# todo
|
||||||
if self.image_source == Source.RESSOURCES:
|
if self.image_source == Source.RESSOURCES:
|
||||||
self.changePreviewImage(int(number) - 1, RES_DIR + "/custom_images/" + self.extracted[cb.get_active()])
|
self.changePreviewImage(int(number) - 1, RES_DIR + "/custom_images/" + self.extracted[cb.get_active()])
|
||||||
elif self.image_source == Source.EXPORT:
|
elif self.image_source == Source.EXPORT:
|
||||||
@@ -242,6 +295,8 @@ class ImageConfigurator:
|
|||||||
|
|
||||||
|
|
||||||
def onApply(self, *args):
|
def onApply(self, *args):
|
||||||
|
""" UI signal if the user presses the "Apply" button
|
||||||
|
"""
|
||||||
self.writeToSettings()
|
self.writeToSettings()
|
||||||
self.copyToSource()
|
self.copyToSource()
|
||||||
|
|
||||||
@@ -249,9 +304,11 @@ class ImageConfigurator:
|
|||||||
|
|
||||||
|
|
||||||
def onDestroy(self, *args):
|
def onDestroy(self, *args):
|
||||||
|
""" UI signal if the window is closed by the user
|
||||||
|
"""
|
||||||
Gtk.main_quit()
|
Gtk.main_quit()
|
||||||
|
|
||||||
|
|
||||||
ic = ImageConfigurator()
|
if __name__ == "__main__":
|
||||||
ic.showMainWindow()
|
ic = ImageConfigurator()
|
||||||
|
ic.showMainWindow()
|
||||||
|
|||||||
Reference in New Issue
Block a user