HEIC import

This commit is contained in:
2024-01-17 20:04:12 +01:00
parent d97ec091c5
commit e1b464e36c
3 changed files with 92 additions and 34 deletions

View File

@@ -79,23 +79,27 @@ class Loop():
""" Setting a gradient background to hide images, which are not high enough """ Setting a gradient background to hide images, which are not high enough
""" """
# Load the image # Load the image
im = Image.open(self.current_image_uri) try:
pix = im.load() im = Image.open(self.current_image_uri)
pix = im.load()
# Width and height of the current setted image # Width and height of the current setted image
width, height = im.size width, height = im.size
# Color of the top and bottom pixel in the middle of the image # Color of the top and bottom pixel in the middle of the image
top_color = pix[width / 2,0] top_color = pix[width / 2,0]
bottom_color = pix[width / 2, height - 1] bottom_color = pix[width / 2, height - 1]
# Create the gradient # Create the gradient
self.background_settings['color-shading-type'] = "vertical" self.background_settings['color-shading-type'] = "vertical"
if self.prefs.dynamic_background_color: if self.prefs.dynamic_background_color:
self.background_settings['primary-color'] = f"#{top_color[0]:x}{top_color[1]:x}{top_color[2]:x}" self.background_settings['primary-color'] = f"#{top_color[0]:x}{top_color[1]:x}{top_color[2]:x}"
self.background_settings['secondary-color'] = f"#{bottom_color[0]:x}{bottom_color[1]:x}{bottom_color[2]:x}" self.background_settings['secondary-color'] = f"#{bottom_color[0]:x}{bottom_color[1]:x}{bottom_color[2]:x}"
else: else:
self.background_settings['primary-color'] = "#000000"
self.background_settings['secondary-color'] = "#000000"
except:
self.background_settings['primary-color'] = "#000000" self.background_settings['primary-color'] = "#000000"
self.background_settings['secondary-color'] = "#000000" self.background_settings['secondary-color'] = "#000000"

View File

@@ -147,9 +147,6 @@ class Preferences:
window = self.builder.get_object("window_main") window = self.builder.get_object("window_main")
window.show_all() window.show_all()
# todo: Remove after HEIC implementation
self.tb_heic_file.set_visible(False)
# Load from preferences # Load from preferences
if self.prefs.image_source == ImageSourceEnum.IMAGESET: if self.prefs.image_source == ImageSourceEnum.IMAGESET:
self.tb_image_set.set_active(True) self.tb_image_set.set_active(True)
@@ -253,7 +250,13 @@ class Preferences:
self.add_items_to_combo_box(combobox, options) self.add_items_to_combo_box(combobox, options)
def load_image_to_preview(self, image_preview: Gtk.Image, image_src: list): def load_image_to_preview(self, image_preview: Gtk.Image, image_src: str):
""" Scales the image to a lower resoultion and put them into the time bar chart
Args:
image_preview (Gtk.Image): Gtk Image where it will be displayed
image_src (str): Absolute path to the image
"""
try: try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file(image_src) pixbuf = GdkPixbuf.Pixbuf.new_from_file(image_src)
pixbuf = pixbuf.scale_simple(260, 175, GdkPixbuf.InterpType.BILINEAR) pixbuf = pixbuf.scale_simple(260, 175, GdkPixbuf.InterpType.BILINEAR)
@@ -352,6 +355,19 @@ class Preferences:
for combobox in self.cb_periods: for combobox in self.cb_periods:
combobox.set_visible(True) combobox.set_visible(True)
# Load images from source folder
files = self.images.get_images_from_folder(self.prefs.source_folder)
if len(files) != 0:
self.load_image_options_to_combo_boxes(files)
# Load the values for the images from the preferences
for i in range(0, 10):
self.set_active_combobox_item(self.cb_periods[i], self.prefs.period_images[i])
else:
# todo: Message to user
print("No image files!")
def on_toggle_button_source_folder_clicked(self, button: Gtk.ToggleButton): def on_toggle_button_source_folder_clicked(self, button: Gtk.ToggleButton):
if button.get_active(): if button.get_active():
@@ -371,7 +387,24 @@ class Preferences:
# This will update the comboboxes in the preview to contain the right items # This will update the comboboxes in the preview to contain the right items
self.lbl_source_folder.set_label(self.prefs.source_folder) self.lbl_source_folder.set_label(self.prefs.source_folder)
# Load files from saved source folder
files = self.images.get_images_from_folder(self.prefs.source_folder)
if len(files) != 0:
self.load_image_options_to_combo_boxes(files)
# Load the values for the images from the preferences
for i in range(0, 10):
self.set_active_combobox_item(self.cb_periods[i], self.prefs.period_images[i])
else:
# todo: Message to user
print("No image files!")
# +------------------------------------+
# | Select an image set | aurora ▼ |
# +------------------------------------+
def on_cb_image_set_changed(self, combobox: Gtk.ComboBox): def on_cb_image_set_changed(self, combobox: Gtk.ComboBox):
tree_iter = combobox.get_active_iter() tree_iter = combobox.get_active_iter()
@@ -400,35 +433,44 @@ class Preferences:
self.cb_periods[i].set_active(i) self.cb_periods[i].set_active(i)
def on_fc_heic_file_file_set(self, fc_button: Gtk.FileChooser): # +----------------------------------------------+
file_path = fc_button.get_filename() # | Select a heic file to import | (None) 📄 |
extract_folder = os.path.abspath(os.path.join(PREFERENCES_URI, os.pardir)) + \ # +----------------------------------------------+
"/images/extracted_images/"
file_name = file_path[file_path.rfind("/") + 1:] def on_fc_heic_file_file_set(self, fc_button: Gtk.FileChooser):
file_path: str = fc_button.get_filename()
extract_folder: str = PREFERENCES_URI + "/images/extracted_images/"
file_name: str = file_path[file_path.rfind("/") + 1:]
file_name = file_name[:file_name.rfind(".")] file_name = file_name[:file_name.rfind(".")]
# Update the preferences # Update the preferences
self.prefs.selected_image_set = "" self.prefs.selected_image_set = ""
self.prefs.source_folder = extract_folder self.prefs.source_folder = extract_folder
# Create the buffer folder # Create the buffer folder if its not existing
try: try:
os.mkdir(extract_folder) os.mkdir(extract_folder)
except: except:
pass pass
# Extract the HEIC file # Cleanup the folder
for file in self.images.get_images_from_folder(extract_folder): for file in self.images.get_images_from_folder(extract_folder):
os.remove(extract_folder + file) os.remove(extract_folder + file)
os.system("heif-convert " + file_path + " " + extract_folder + file_name + ".jpg") # Extract the HEIC file
os.system("heif-convert '" + file_path + "' '" + extract_folder + file_name + ".jpg'")
# Collect all extracted images and push them to the comboboxes # Collect all extracted images and push them to the comboboxes
image_names = self.images.get_images_from_folder(self.prefs.source_folder) image_names = self.images.get_images_from_folder(self.prefs.source_folder)
self.load_image_options_to_combo_boxes(image_names) self.load_image_options_to_combo_boxes(image_names)
# +------------------------------------------------------------+
# | Select a source folder | 📂 Open file selection dialog |
# | /home/developer/Downloads/
# +------------------------------------------------------------+
def on_btn_source_folder_clicked(self, button: Gtk.Button): def on_btn_source_folder_clicked(self, button: Gtk.Button):
""" Button to choose an image source folder was clicked """ Button to choose an image source folder was clicked
@@ -442,18 +484,25 @@ class Preferences:
self.prefs.selected_image_set = "" self.prefs.selected_image_set = ""
self.prefs.source_folder = folder + "/" self.prefs.source_folder = folder + "/"
# Update the button # Update the label
button.set_label(folder) self.lbl_source_folder.set_label(folder)
# Update the image comboboxes # Update the image comboboxes
if len(files) != 0: self.load_image_options_to_combo_boxes(files)
self.load_image_options_to_combo_boxes(files)
# Load the values for the images from the preferences # Load the values for the images from the preferences
for i in range(0, 10): for i in range(0, 10):
self.set_active_combobox_item(self.cb_periods[i], self.prefs.period_images[i]) self.cb_periods[i].set_active(0)
else: #self.set_active_combobox_item(self.cb_periods[i], "") #self.prefs.period_images[i])
if len(files) != 0:
pass pass
else:
# todo: Message to user
print("No image files!")
def on_cb_period_preview_changed(self, combobox: Gtk.ComboBox): def on_cb_period_preview_changed(self, combobox: Gtk.ComboBox):

View File

@@ -5,6 +5,11 @@ class Images:
pass pass
def get_images_from_folder(self, URI: str) -> list: def get_images_from_folder(self, URI: str) -> list:
items = os.listdir(URI) items = []
for file in os.listdir(URI):
if file.endswith("jpg") or file.endswith("jpeg") or file.endswith("png") or file.endswith("bmp"):
items.append(file)
items.sort() items.sort()
return items return items