Loading screen, documentation
This commit is contained in:
@@ -19,20 +19,12 @@
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkWindow" id="main_window">
|
||||
<property name="can-focus">False</property>
|
||||
<property name="window-position">center</property>
|
||||
<property name="default-height">768</property>
|
||||
<property name="icon">../icons/icon.png</property>
|
||||
<signal name="destroy" handler="onDestroy" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<object class="GtkScrolledWindow" id="page_config">
|
||||
<property name="width-request">100</property>
|
||||
<property name="height-request">80</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="hscrollbar-policy">never</property>
|
||||
<property name="shadow-type">in</property>
|
||||
<property name="overlay-scrolling">False</property>
|
||||
<property name="propagate-natural-width">True</property>
|
||||
<child>
|
||||
<object class="GtkViewport">
|
||||
<property name="visible">True</property>
|
||||
@@ -949,6 +941,22 @@
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkWindow" id="main_window">
|
||||
<property name="can-focus">False</property>
|
||||
<property name="window-position">center</property>
|
||||
<property name="default-width">1024</property>
|
||||
<property name="default-height">768</property>
|
||||
<property name="icon">../icons/icon.png</property>
|
||||
<signal name="destroy" handler="onDestroy" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkStack" id="stack_main">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="transition-type">crossfade</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar">
|
||||
@@ -971,4 +979,40 @@
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkBox" id="page_load">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="margin-start">8</property>
|
||||
<property name="margin-end">8</property>
|
||||
<property name="margin-top">8</property>
|
||||
<property name="margin-bottom">8</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">8</property>
|
||||
<child>
|
||||
<object class="GtkSpinner">
|
||||
<property name="height-request">64</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="active">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Proceeding...</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ic = ImageConfigurator()
|
||||
ic.showMainWindow()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user