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")
|
||||
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"])
|
||||
@@ -96,8 +101,9 @@ class ImageConfigurator:
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user