Bugfixing
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
*.glade~
|
*.glade~
|
||||||
*.glade#
|
*.glade#
|
||||||
extracted/
|
extracted/
|
||||||
|
custom_images/
|
||||||
*.txt
|
*.txt
|
||||||
@@ -1,11 +1,20 @@
|
|||||||
import gi, os, glob, json
|
import gi, os, glob, json, shutil, enum
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, GdkPixbuf
|
from gi.repository import Gtk, GdkPixbuf
|
||||||
|
|
||||||
DIR = os.path.dirname(os.path.abspath(__file__))
|
PROJECT_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||||
UI_FILE = DIR + "/image-configurator.glade"
|
PROG_DIR = PROJECT_DIR + "/image-configurator"
|
||||||
EXPORT_DIR = "extracted"
|
EXPORT_DIR = PROG_DIR + "/extracted"
|
||||||
|
RES_DIR = PROJECT_DIR + "/res"
|
||||||
|
UI_PATH = PROG_DIR + "/image-configurator.glade"
|
||||||
|
PREF_PATH = os.path.expanduser("~") + \
|
||||||
|
"/.config/cinnamon/spices/cinnamon-dynamic-wallpaper@TobiZog/cinnamon-dynamic-wallpaper@TobiZog.json"
|
||||||
|
|
||||||
|
class Source(enum.Enum):
|
||||||
|
RESSOURCES = 0
|
||||||
|
EXPORT = 1
|
||||||
|
SET = 2
|
||||||
|
|
||||||
|
|
||||||
class ImageConfigurator:
|
class ImageConfigurator:
|
||||||
@@ -23,27 +32,32 @@ class ImageConfigurator:
|
|||||||
"etr_img_night"
|
"etr_img_night"
|
||||||
]
|
]
|
||||||
|
|
||||||
self.pref_path = os.path.expanduser("~") + \
|
|
||||||
"/.config/cinnamon/spices/cinnamon-dynamic-wallpaper@TobiZog/cinnamon-dynamic-wallpaper@TobiZog.json"
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.mkdir(DIR + "/" + EXPORT_DIR)
|
os.mkdir(EXPORT_DIR)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.mkdir(RES_DIR + "/custom_images")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
########### GTK stuff ###########
|
########### GTK stuff ###########
|
||||||
self.builder = Gtk.Builder()
|
self.builder = Gtk.Builder()
|
||||||
self.builder.add_from_file(UI_FILE)
|
self.builder.add_from_file(UI_PATH)
|
||||||
self.builder.connect_signals(self)
|
self.builder.connect_signals(self)
|
||||||
|
|
||||||
########### Glade Ressources ###########
|
########### Glade Ressources ###########
|
||||||
self.imageSetText = self.builder.get_object("lb_image_set")
|
self.rb_included_image_set = self.builder.get_object("rb_included_image_set")
|
||||||
self.imageSetCb = self.builder.get_object("cb_image_set")
|
self.rb_external_image_set = self.builder.get_object("rb_external_image_set")
|
||||||
|
|
||||||
self.fileChooserText = self.builder.get_object("lb_heic_file")
|
self.lb_image_set = self.builder.get_object("lb_image_set")
|
||||||
self.fileChooserFc = self.builder.get_object("fc_heic_file")
|
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.image_set_list_store = self.builder.get_object("image_set_list_store")
|
self.image_set_list_store = self.builder.get_object("image_set_list_store")
|
||||||
self.ls_preview = self.builder.get_object("ls_preview")
|
self.ls_preview = self.builder.get_object("ls_preview")
|
||||||
|
|
||||||
@@ -78,9 +92,7 @@ class ImageConfigurator:
|
|||||||
self.image_set_list_store.append(["Lakeside"])
|
self.image_set_list_store.append(["Lakeside"])
|
||||||
# todo
|
# todo
|
||||||
|
|
||||||
|
|
||||||
# Load preferences
|
# Load preferences
|
||||||
self.createExtracted()
|
|
||||||
self.loadFromSettings()
|
self.loadFromSettings()
|
||||||
|
|
||||||
|
|
||||||
@@ -93,35 +105,54 @@ class ImageConfigurator:
|
|||||||
|
|
||||||
|
|
||||||
def loadFromSettings(self):
|
def loadFromSettings(self):
|
||||||
with open(self.pref_path, "r") as pref_file:
|
# Load the settings
|
||||||
|
with open(PREF_PATH, "r") as pref_file:
|
||||||
pref_data = json.load(pref_file)
|
pref_data = json.load(pref_file)
|
||||||
|
|
||||||
|
|
||||||
|
# Use the settings
|
||||||
|
if pref_data["etr_choosen_image_set"]["value"] == "custom":
|
||||||
|
self.image_source = Source.RESSOURCES
|
||||||
|
else:
|
||||||
|
#todo
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.createExtracted()
|
||||||
|
|
||||||
for i, val in enumerate(self.pref_vars):
|
for i, val in enumerate(self.pref_vars):
|
||||||
try:
|
try:
|
||||||
self.changePreviewImage(i, EXPORT_DIR + "/" + pref_data[val]['value'])
|
self.changePreviewImage(i, RES_DIR + "/custom_images/" + pref_data[val]['value'])
|
||||||
self.cb_previews[i].set_active(self.extracted.index(pref_data[val]['value']))
|
self.cb_previews[i].set_active(self.extracted.index(pref_data[val]['value']))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def writeToSettings(self):
|
def writeToSettings(self):
|
||||||
with open(self.pref_path, "r") as pref_file:
|
# Load the settings
|
||||||
|
with open(PREF_PATH, "r") as pref_file:
|
||||||
pref_data = json.load(pref_file)
|
pref_data = json.load(pref_file)
|
||||||
|
|
||||||
|
|
||||||
|
# Update the settings
|
||||||
for i, val in enumerate(self.pref_vars):
|
for i, val in enumerate(self.pref_vars):
|
||||||
pref_data[val]['value'] = self.extracted[self.cb_previews[i].get_active()]
|
pref_data[val]['value'] = self.extracted[self.cb_previews[i].get_active()]
|
||||||
|
|
||||||
|
|
||||||
|
if self.rb_included_image_set:
|
||||||
|
#pref_data["etr_choosen_image_set"]["value"] = self.cb_image_set.
|
||||||
|
# todo
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
pref_data["etr_choosen_image_set"]["value"] = "custom"
|
||||||
|
|
||||||
|
|
||||||
|
# Write the settings
|
||||||
with open(self.pref_path, "w") as pref_file:
|
with open(self.pref_path, "w") as pref_file:
|
||||||
json.dump(pref_data, pref_file, separators=(',', ':'), indent=4)
|
json.dump(pref_data, pref_file, separators=(',', ':'), indent=4)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def changePreviewImage(self, imageId: int, imageURI: str):
|
def changePreviewImage(self, imageId: int, imageURI: str):
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(DIR + "/" + 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)
|
||||||
|
|
||||||
self.img_previews[imageId].set_from_pixbuf(pixbuf)
|
self.img_previews[imageId].set_from_pixbuf(pixbuf)
|
||||||
@@ -130,27 +161,53 @@ class ImageConfigurator:
|
|||||||
def extractHeifImages(self, imageURI: str):
|
def extractHeifImages(self, imageURI: str):
|
||||||
imageURI = imageURI.replace("%20", "\ ")
|
imageURI = imageURI.replace("%20", "\ ")
|
||||||
|
|
||||||
filename = imageURI[imageURI.rfind("/"):imageURI.rfind(".")]
|
filename = imageURI[imageURI.rfind("/") + 1:imageURI.rfind(".")]
|
||||||
|
|
||||||
self.wipeImages()
|
self.image_source = Source.EXPORT
|
||||||
os.system("heif-convert " + imageURI + " " + DIR + "/" + EXPORT_DIR + filename + ".jpg")
|
|
||||||
|
self.wipeImages(Source.EXPORT)
|
||||||
|
os.system("heif-convert " + imageURI + " " + EXPORT_DIR + "/" + filename + ".jpg")
|
||||||
|
|
||||||
|
|
||||||
def wipeImages(self):
|
def wipeImages(self, source: Source):
|
||||||
for file in glob.glob(DIR + "/" + EXPORT_DIR + "/*"):
|
if source == Source.EXPORT:
|
||||||
|
dir = EXPORT_DIR + "/*"
|
||||||
|
elif source == Source.RESSOURCES:
|
||||||
|
dir = RES_DIR + "/custom_images/*"
|
||||||
|
|
||||||
|
for file in glob.glob(dir):
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
|
|
||||||
|
|
||||||
def createExtracted(self):
|
def createExtracted(self):
|
||||||
self.extracted = os.listdir(DIR + "/" + EXPORT_DIR)
|
if self.image_source == Source.RESSOURCES:
|
||||||
self.extracted.sort()
|
self.extracted = os.listdir(RES_DIR + "/custom_images")
|
||||||
|
elif self.image_source == Source.EXPORT:
|
||||||
|
self.extracted = os.listdir(EXPORT_DIR)
|
||||||
|
|
||||||
|
self.extracted.sort()
|
||||||
self.ls_preview.clear()
|
self.ls_preview.clear()
|
||||||
|
|
||||||
for option in self.extracted:
|
for option in self.extracted:
|
||||||
self.ls_preview.append([option])
|
self.ls_preview.append([option])
|
||||||
|
|
||||||
|
|
||||||
|
def copyToSource(self):
|
||||||
|
self.wipeImages(Source.RESSOURCES)
|
||||||
|
|
||||||
|
for image in os.listdir(EXPORT_DIR):
|
||||||
|
shutil.copy(EXPORT_DIR + "/" + image, RES_DIR + "/custom_images/" + image)
|
||||||
|
|
||||||
|
|
||||||
|
def imageSetVisibility(self, 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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
########## UI Signals ##########
|
########## UI Signals ##########
|
||||||
|
|
||||||
def onRadioImageSet(self, rb):
|
def onRadioImageSet(self, rb):
|
||||||
@@ -159,11 +216,10 @@ class ImageConfigurator:
|
|||||||
Args:
|
Args:
|
||||||
rb (GtkRadioButton): The toggled RadioButton
|
rb (GtkRadioButton): The toggled RadioButton
|
||||||
"""
|
"""
|
||||||
self.imageSetText.set_visible(rb.get_active())
|
if rb.get_active():
|
||||||
self.imageSetCb.set_visible(rb.get_active())
|
self.imageSetVisibility(Source.SET)
|
||||||
|
else:
|
||||||
self.fileChooserText.set_visible(not rb.get_active())
|
self.imageSetVisibility(Source.EXPORT)
|
||||||
self.fileChooserFc.set_visible(not rb.get_active())
|
|
||||||
|
|
||||||
|
|
||||||
def onHeifSelected(self, fc):
|
def onHeifSelected(self, fc):
|
||||||
@@ -179,11 +235,15 @@ class ImageConfigurator:
|
|||||||
number = Gtk.Buildable.get_name(cb)
|
number = Gtk.Buildable.get_name(cb)
|
||||||
number = number[number.rfind("_") + 1:]
|
number = number[number.rfind("_") + 1:]
|
||||||
|
|
||||||
self.changePreviewImage(int(number) - 1, EXPORT_DIR + "/" + self.extracted[cb.get_active()])
|
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:
|
||||||
|
self.changePreviewImage(int(number) - 1, EXPORT_DIR + "/" + self.extracted[cb.get_active()])
|
||||||
|
|
||||||
|
|
||||||
def onApply(self, *args):
|
def onApply(self, *args):
|
||||||
self.writeToSettings()
|
self.writeToSettings()
|
||||||
|
self.copyToSource()
|
||||||
|
|
||||||
Gtk.main_quit()
|
Gtk.main_quit()
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,11 @@
|
|||||||
"description": "Open the Repository",
|
"description": "Open the Repository",
|
||||||
"callback": "openRepoWebsite"
|
"callback": "openRepoWebsite"
|
||||||
},
|
},
|
||||||
|
"etr_choosen_image_set": {
|
||||||
|
"type": "entry",
|
||||||
|
"default": "",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
"etr_img_morning_twilight": {
|
"etr_img_morning_twilight": {
|
||||||
"type": "entry",
|
"type": "entry",
|
||||||
"default": "",
|
"default": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user