From e0091c3e3f647ef9961bbd9ee61a0ad070fd2350 Mon Sep 17 00:00:00 2001 From: TobiZog Date: Fri, 26 Jan 2024 19:02:18 +0100 Subject: [PATCH] cinnamon-dynamic-wallpaper v.2.1 --- .../5.4/extension.js | 3 - .../5.4/preferences.glade | 26 +- .../5.4/preferences.py | 391 +++++++----------- .../5.4/scripts/display.py | 20 + .../5.4/scripts/ui.py | 147 +++++++ .../5.4/settings-schema.json | 2 +- 6 files changed, 331 insertions(+), 258 deletions(-) create mode 100644 cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/scripts/display.py create mode 100644 cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/scripts/ui.py diff --git a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/extension.js b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/extension.js index d5936145..0fd8ab68 100644 --- a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/extension.js +++ b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/extension.js @@ -33,9 +33,6 @@ const PATH = DIRECTORY.path; // The extension object let extension; -// Time and date of the last location update -let lastLocationUpdate = -1 - // Loop state let looping = true diff --git a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/preferences.glade b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/preferences.glade index 46b06de3..e5144a3e 100644 --- a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/preferences.glade +++ b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/preferences.glade @@ -107,8 +107,8 @@ False center - 1024 - 400 + 800 + 600 ../icon.svg center @@ -167,7 +167,7 @@ vertical 4 - + True False applications-graphics @@ -217,7 +217,7 @@ vertical 4 - + True False preferences-desktop-wallpaper @@ -267,7 +267,7 @@ vertical 4 - + True False folder-open @@ -585,7 +585,6 @@ - 200 True False gtk-missing-image @@ -598,7 +597,6 @@ - 200 True False gtk-missing-image @@ -611,7 +609,6 @@ - 200 True False gtk-missing-image @@ -624,7 +621,6 @@ - 200 True False gtk-missing-image @@ -637,7 +633,6 @@ - 200 True False gtk-missing-image @@ -732,7 +727,6 @@ True - 200 True False gtk-missing-image @@ -745,7 +739,6 @@ - 200 True False gtk-missing-image @@ -758,7 +751,6 @@ - 200 True False gtk-missing-image @@ -771,7 +763,6 @@ - 200 True False gtk-missing-image @@ -784,7 +775,6 @@ - 200 True False gtk-missing-image @@ -992,7 +982,7 @@ vertical 4 - + True False network-wireless @@ -1042,7 +1032,7 @@ vertical 4 - + True False preferences-desktop-keyboard @@ -1094,7 +1084,7 @@ vertical 4 - + True False document-open-recent diff --git a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/preferences.py b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/preferences.py index 3192ff97..80f1a071 100755 --- a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/preferences.py +++ b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/preferences.py @@ -1,17 +1,18 @@ #!/usr/bin/python3 -# Imports +############################################################ +# Imports # +############################################################ + +# Packages import gi, os, subprocess, time from datetime import timedelta -from scripts.time_bar_chart import Time_Bar_Chart -from scripts.cinnamon_pref_handler import * -from scripts.suntimes import * -from scripts.location import * -from scripts.images import * -from scripts.dialogs import * + +# Local scripts +from scripts import cinnamon_pref_handler, dialogs, display, images, location, suntimes, time_bar_chart, ui +from loop import * from enums.ImageSourceEnum import ImageSourceEnum from enums.PeriodSourceEnum import PeriodSourceEnum -from loop import * gi.require_version("Gtk", "3.0") from gi.repository import Gtk, GdkPixbuf @@ -32,113 +33,24 @@ class Preferences: def __init__(self) -> None: # Objects from external scripts - self.time_bar_chart = Time_Bar_Chart() - self.prefs = Cinnamon_Pref_Handler() - self.suntimes = Suntimes() - self.images = Images() - self.location = Location() - self.dialogs = Dialogs() + self.prefs = cinnamon_pref_handler.Cinnamon_Pref_Handler() + self.dialogs = dialogs.Dialogs() + self.display = display.Display() + self.images = images.Images() + self.location = location.Location() + self.suntimes = suntimes.Suntimes() + self.time_bar_chart = time_bar_chart.Time_Bar_Chart() # Glade self.builder = Gtk.Builder() self.builder.add_from_file(GLADE_URI) self.builder.connect_signals(self) - - ########## UI objects ########## - - #### Page 1: Image Configuration - self.tb_image_set: Gtk.ToggleButton = self.builder.get_object("tb_image_set") - self.tb_heic_file: Gtk.ToggleButton = self.builder.get_object("tb_heic_file") - self.tb_source_folder: Gtk.ToggleButton = self.builder.get_object("tb_source_folder") - - # Image set - self.lbr_image_set: Gtk.ListBoxRow = self.builder.get_object("lbr_image_set") - self.cb_image_set: Gtk.ComboBox = self.builder.get_object("cb_image_set") - - # HEIC file - self.lbr_heic_file: Gtk.ListBoxRow = self.builder.get_object("lbr_heic_file") - - # Source folder - self.lbr_source_folder: Gtk.ListBoxRow = self.builder.get_object("lbr_source_folder") - self.btn_source_folder: Gtk.Button = self.builder.get_object("btn_source_folder") - self.lbl_source_folder: Gtk.Label = self.builder.get_object("lbl_source_folder") - - # Time bar chart - self.img_bar_images: Gtk.Image = self.builder.get_object("img_bar_images") - self.etr_periods: list[Gtk.Entry] = [ - self.builder.get_object("etr_period_1"), self.builder.get_object("etr_period_2"), - self.builder.get_object("etr_period_3"), self.builder.get_object("etr_period_4"), - self.builder.get_object("etr_period_5"), self.builder.get_object("etr_period_6"), - self.builder.get_object("etr_period_7"), self.builder.get_object("etr_period_8"), - self.builder.get_object("etr_period_9"), self.builder.get_object("etr_period_10"), - ] - - self.img_periods: list[Gtk.Image] = [ - self.builder.get_object("img_period_0"), self.builder.get_object("img_period_1"), - self.builder.get_object("img_period_2"), self.builder.get_object("img_period_3"), - self.builder.get_object("img_period_4"), self.builder.get_object("img_period_5"), - self.builder.get_object("img_period_6"), self.builder.get_object("img_period_7"), - self.builder.get_object("img_period_8"), self.builder.get_object("img_period_9"), - ] - - self.cb_periods: list[Gtk.ComboBox] = [ - self.builder.get_object("cb_period_0"), self.builder.get_object("cb_period_1"), - self.builder.get_object("cb_period_2"), self.builder.get_object("cb_period_3"), - self.builder.get_object("cb_period_4"), self.builder.get_object("cb_period_5"), - self.builder.get_object("cb_period_6"), self.builder.get_object("cb_period_7"), - self.builder.get_object("cb_period_8"), self.builder.get_object("cb_period_9"), - ] - - - - #### Page 2: Location & Times - self.tb_network_location: Gtk.ToggleButton = self.builder.get_object("tb_network_location") - self.lb_current_location: Gtk.Label = self.builder.get_object("lb_current_location") - self.lbr_current_location: Gtk.ListBoxRow = self.builder.get_object("lbr_current_location") - self.tb_custom_location: Gtk.ToggleButton = self.builder.get_object("tb_custom_location") - self.tb_time_periods: Gtk.ToggleButton = self.builder.get_object("tb_time_periods") - self.lbr_network_location: Gtk.ListBoxRow = self.builder.get_object("lbr_network_location") - self.spb_network_location_refresh_time: Gtk.SpinButton = self.builder.get_object("spb_network_location_refresh_time") - self.lbr_custom_location_longitude: Gtk.ListBoxRow = self.builder.get_object("lbr_custom_location_longitude") - self.lbr_custom_location_latitude: Gtk.ListBoxRow = self.builder.get_object("lbr_custom_location_latitude") - self.lbr_time_periods: Gtk.ListBoxRow = self.builder.get_object("lbr_time_periods") - self.etr_longitude: Gtk.Entry = self.builder.get_object("etr_longitude") - self.etr_latitude: Gtk.Entry = self.builder.get_object("etr_latitude") - self.img_bar_times: Gtk.Image = self.builder.get_object("img_bar_times") - self.spb_periods_hour: list[Gtk.SpinButton] = [ - self.builder.get_object("spb_period_1_hour"), - self.builder.get_object("spb_period_2_hour"), - self.builder.get_object("spb_period_3_hour"), - self.builder.get_object("spb_period_4_hour"), - self.builder.get_object("spb_period_5_hour"), - self.builder.get_object("spb_period_6_hour"), - self.builder.get_object("spb_period_7_hour"), - self.builder.get_object("spb_period_8_hour"), - self.builder.get_object("spb_period_9_hour"), - ] - self.spb_periods_minute: list[Gtk.SpinButton] = [ - self.builder.get_object("spb_period_1_minute"), - self.builder.get_object("spb_period_2_minute"), - self.builder.get_object("spb_period_3_minute"), - self.builder.get_object("spb_period_4_minute"), - self.builder.get_object("spb_period_5_minute"), - self.builder.get_object("spb_period_6_minute"), - self.builder.get_object("spb_period_7_minute"), - self.builder.get_object("spb_period_8_minute"), - self.builder.get_object("spb_period_9_minute") - ] - self.lb_period_end: list[Gtk.Label] = [ - self.builder.get_object("lb_period_0_end"), self.builder.get_object("lb_period_1_end"), - self.builder.get_object("lb_period_2_end"), self.builder.get_object("lb_period_3_end"), - self.builder.get_object("lb_period_4_end"), self.builder.get_object("lb_period_5_end"), - self.builder.get_object("lb_period_6_end"), self.builder.get_object("lb_period_7_end"), - self.builder.get_object("lb_period_8_end"), self.builder.get_object("lb_period_9_end"), - ] - - - # Page 3: Behaviour - self.cb_picture_aspect: Gtk.ComboBox = self.builder.get_object("cb_picture_aspect") - self.sw_dynamic_background_color: Gtk.Switch = self.builder.get_object("sw_dynamic_background_color") + + self.ui = ui.UI(self.builder) + + + # Local Config + self.smaller_ui_height = 1000 def show(self): @@ -149,26 +61,36 @@ def show(self): # Load from preferences if self.prefs.image_source == ImageSourceEnum.IMAGESET: - self.tb_image_set.set_active(True) + self.ui.tb_image_set.set_active(True) elif self.prefs.image_source == ImageSourceEnum.HEICFILE: - self.tb_heic_file.set_active(True) + self.ui.tb_heic_file.set_active(True) elif self.prefs.image_source == ImageSourceEnum.SOURCEFOLDER: - self.tb_source_folder.set_active(True) + self.ui.tb_source_folder.set_active(True) + + + # Remove icons in the ToggleButtons if the screen height resolution < 1000 px + if self.display.get_screen_height() < self.smaller_ui_height: + self.ui.img_tb_image_set.clear() + self.ui.img_tb_heic_file.clear() + self.ui.img_tb_source_folder.clear() + self.ui.img_tb_network_location.clear() + self.ui.img_tb_custom_location.clear() + self.ui.img_tb_time_periods.clear() picture_aspects = ["centered", "scaled", "stretched", "zoom", "spanned"] - self.add_items_to_combo_box(self.cb_picture_aspect, picture_aspects) - self.set_active_combobox_item(self.cb_picture_aspect, self.prefs.picture_aspect) + self.ui.add_items_to_combo_box(self.ui.cb_picture_aspect, picture_aspects) + self.ui.set_active_combobox_item(self.ui.cb_picture_aspect, self.prefs.picture_aspect) - self.sw_dynamic_background_color.set_active(self.prefs.dynamic_background_color) + self.ui.sw_dynamic_background_color.set_active(self.prefs.dynamic_background_color) if self.prefs.period_source == PeriodSourceEnum.NETWORKLOCATION: - self.tb_network_location.set_active(True) + self.ui.tb_network_location.set_active(True) elif self.prefs.period_source == PeriodSourceEnum.CUSTOMLOCATION: - self.tb_custom_location.set_active(True) + self.ui.tb_custom_location.set_active(True) elif self.prefs.period_source == PeriodSourceEnum.CUSTOMTIMEPERIODS: - self.tb_time_periods.set_active(True) + self.ui.tb_time_periods.set_active(True) # Time diagram @@ -207,7 +129,7 @@ def refresh_chart(self): if self.prefs.period_source == PeriodSourceEnum.NETWORKLOCATION: self.suntimes.calc_suntimes(float(self.prefs.latitude_auto), float(self.prefs.longitude_auto)) else: - self.suntimes.calc_suntimes(float(self.etr_latitude.get_text()), float(self.etr_longitude.get_text())) + self.suntimes.calc_suntimes(float(self.ui.etr_latitude.get_text()), float(self.ui.etr_longitude.get_text())) # Get all time periods. Store the minutes to the list and print the values to the text views @@ -219,22 +141,30 @@ def refresh_chart(self): else: time_range_next = time(hour=23, minute=59) - self.etr_periods[i].set_text( + self.ui.etr_periods[i].set_text( str(time_range_now.hour).rjust(2, '0') + ":" + str(time_range_now.minute).rjust(2, '0') + \ " - " + str(time_range_next.hour).rjust(2, '0') + ":" + str(time_range_next.minute).rjust(2, '0')) time_periods_min.append(time_range_now.hour * 60 + time_range_now.minute) # Create time bar - self.time_bar_chart.create_bar_chart_with_polylines(PREFERENCES_URI, 1300, 150, time_periods_min) - self.time_bar_chart.create_bar_chart(PREFERENCES_URI, 1300, 150, time_periods_min) + # Reduce size for small displays + if self.display.get_screen_height() < self.smaller_ui_height: + bar_width = 1150 + bar_height = 110 + else: + bar_width = 1300 + bar_height = 150 + + self.time_bar_chart.create_bar_chart_with_polylines(PREFERENCES_URI, bar_width, bar_height, time_periods_min) + self.time_bar_chart.create_bar_chart(PREFERENCES_URI, bar_width, bar_height, time_periods_min) # Load to the views pixbuf = GdkPixbuf.Pixbuf.new_from_file(PREFERENCES_URI + "/time_bar_polylines.svg") - self.img_bar_images.set_from_pixbuf(pixbuf) + self.ui.img_bar_images.set_from_pixbuf(pixbuf) pixbuf2 = GdkPixbuf.Pixbuf.new_from_file(PREFERENCES_URI + "/time_bar.svg") - self.img_bar_times.set_from_pixbuf(pixbuf2) + self.ui.img_bar_times.set_from_pixbuf(pixbuf2) def load_image_options_to_combo_boxes(self, options: list): @@ -245,8 +175,8 @@ def load_image_options_to_combo_boxes(self, options: list): """ options.insert(0, "") - for combobox in self.cb_periods: - self.add_items_to_combo_box(combobox, options) + for combobox in self.ui.cb_periods: + self.ui.add_items_to_combo_box(combobox, options) def load_image_to_preview(self, image_preview: Gtk.Image, image_src: str): @@ -258,54 +188,20 @@ def load_image_to_preview(self, image_preview: Gtk.Image, image_src: str): """ try: pixbuf = GdkPixbuf.Pixbuf.new_from_file(image_src) - pixbuf = pixbuf.scale_simple(260, 150, GdkPixbuf.InterpType.BILINEAR) + + screen_height = self.display.get_screen_height() + + # Scaling the images smaller for screens + if screen_height < self.smaller_ui_height: + pixbuf = pixbuf.scale_simple(221, 128, GdkPixbuf.InterpType.BILINEAR) + else: + pixbuf = pixbuf.scale_simple(260, 150, GdkPixbuf.InterpType.BILINEAR) image_preview.set_from_pixbuf(pixbuf) except: pass - ############################################################ - # UI helper methods # - ############################################################ - - def set_active_combobox_item(self, combobox: Gtk.ComboBoxText, active_item: str): - """ Change active item in combobox by String value - - Args: - combobox (Gtk.ComboBoxText): ComboBox to set active - active_item (str): String item to set active - """ - list_store = combobox.get_model() - - for i in range(0, len(list_store)): - row = list_store[i] - if row[0] == active_item: - combobox.set_active(i) - - - def add_items_to_combo_box(self, combobox: Gtk.ComboBox, items: list): - """ Add items to a combo box - - Args: - combobox (Gtk.ComboBox): ComboBox where to add the options - items (list): Possible options - """ - model = combobox.get_model() - store = Gtk.ListStore(str) - - for image_set in items: - store.append([image_set]) - - combobox.set_model(store) - - if model == None: - renderer_text = Gtk.CellRendererText() - combobox.pack_start(renderer_text, True) - combobox.add_attribute(renderer_text, "text", 0) - - - ############################################################ # Callbacks # ############################################################ @@ -324,24 +220,30 @@ def on_toggle_button_image_set_clicked(self, button: Gtk.ToggleButton): """ if button.get_active(): self.prefs.image_source = ImageSourceEnum.IMAGESET - self.tb_heic_file.set_active(False) - self.tb_source_folder.set_active(False) + self.ui.tb_heic_file.set_active(False) + self.ui.tb_source_folder.set_active(False) - self.lbr_image_set.set_visible(True) - self.lbr_heic_file.set_visible(False) - self.lbr_source_folder.set_visible(False) + self.ui.lbr_image_set.set_visible(True) + self.ui.lbr_heic_file.set_visible(False) + self.ui.lbr_source_folder.set_visible(False) - image_set_choices = ["aurora", "beach", "bitday", "cliffs", "earth", "gradient", "lakeside", "mountains", "sahara"] - self.add_items_to_combo_box(self.cb_image_set, image_set_choices) + image_set_choices = [ + "aurora", "beach", + "bitday", "cliffs", + "earth", "gradient", + "lakeside", "mountains", + "sahara" + ] + self.ui.add_items_to_combo_box(self.ui.cb_image_set, image_set_choices) - self.set_active_combobox_item(self.cb_image_set, self.prefs.selected_image_set) + self.ui.set_active_combobox_item(self.ui.cb_image_set, self.prefs.selected_image_set) - for i, combobox in enumerate(self.cb_periods): + for i, combobox in enumerate(self.ui.cb_periods): selected_image_name = self.prefs.period_images[i] - self.set_active_combobox_item(combobox, selected_image_name) + self.ui.set_active_combobox_item(combobox, selected_image_name) # Make the comboboxes invisible - for combobox in self.cb_periods: + for combobox in self.ui.cb_periods: combobox.set_visible(False) @@ -353,15 +255,15 @@ def on_toggle_button_heic_file_clicked(self, button: Gtk.ToggleButton): """ if button.get_active(): self.prefs.image_source = ImageSourceEnum.HEICFILE - self.tb_image_set.set_active(False) - self.tb_source_folder.set_active(False) + self.ui.tb_image_set.set_active(False) + self.ui.tb_source_folder.set_active(False) - self.lbr_image_set.set_visible(False) - self.lbr_heic_file.set_visible(True) - self.lbr_source_folder.set_visible(False) + self.ui.lbr_image_set.set_visible(False) + self.ui.lbr_heic_file.set_visible(True) + self.ui.lbr_source_folder.set_visible(False) # Make the comboboxes visible - for combobox in self.cb_periods: + for combobox in self.ui.cb_periods: combobox.set_visible(True) # Load images from source folder @@ -372,7 +274,7 @@ def on_toggle_button_heic_file_clicked(self, button: Gtk.ToggleButton): # 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]) + self.ui.set_active_combobox_item(self.ui.cb_periods[i], self.prefs.period_images[i]) else: print("No image files!") @@ -385,20 +287,20 @@ def on_toggle_button_source_folder_clicked(self, button: Gtk.ToggleButton): """ if button.get_active(): self.prefs.image_source = ImageSourceEnum.SOURCEFOLDER - self.tb_image_set.set_active(False) - self.tb_heic_file.set_active(False) + self.ui.tb_image_set.set_active(False) + self.ui.tb_heic_file.set_active(False) - self.lbr_image_set.set_visible(False) - self.lbr_heic_file.set_visible(False) - self.lbr_source_folder.set_visible(True) + self.ui.lbr_image_set.set_visible(False) + self.ui.lbr_heic_file.set_visible(False) + self.ui.lbr_source_folder.set_visible(True) # Make the comboboxes visible - for combobox in self.cb_periods: + for combobox in self.ui.cb_periods: combobox.set_visible(True) # Load the source folder to the view # This will update the comboboxes in the preview to contain the right items - self.lbl_source_folder.set_label(self.prefs.source_folder) + self.ui.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) @@ -408,7 +310,7 @@ def on_toggle_button_source_folder_clicked(self, button: Gtk.ToggleButton): # 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]) + self.ui.set_active_combobox_item(self.ui.cb_periods[i], self.prefs.period_images[i]) else: print("No image files!") @@ -446,7 +348,7 @@ def on_cb_image_set_changed(self, combobox: Gtk.ComboBox): # 2.jpg = Period 2 # and so on.... for i in range(0, 10): - self.cb_periods[i].set_active(i + 1) + self.ui.cb_periods[i].set_active(i + 1) # +----------------------------------------------+ @@ -497,15 +399,14 @@ def on_btn_source_folder_clicked(self, button: Gtk.Button): self.prefs.source_folder = folder + "/" # Update the label - self.lbl_source_folder.set_label(folder) + self.ui.lbl_source_folder.set_label(folder) # Update the image comboboxes self.load_image_options_to_combo_boxes(files) # Load the values for the images from the preferences for i in range(0, 10): - self.cb_periods[i].set_active(0) - #self.set_active_combobox_item(self.cb_periods[i], "") #self.prefs.period_images[i]) + self.ui.cb_periods[i].set_active(0) if len(files) == 1: self.dialogs.message_dialog("No image files found!") @@ -533,29 +434,34 @@ def on_cb_period_preview_changed(self, combobox: Gtk.ComboBox): # Build up image path image_path = self.prefs.source_folder + image_file_name - self.load_image_to_preview(self.img_periods[period_index], image_path) + self.load_image_to_preview(self.ui.img_periods[period_index], image_path) ## Location & Times - def on_toggle_button_network_location_clicked(self, button: Gtk.Button): + def on_toggle_button_network_location_clicked(self, button: Gtk.ToggleButton): + """ User clicks on the ToggleButton for the network location + + Args: + button (Gtk.ToggleButton): Clicked ToggleButton + """ if button.get_active(): self.prefs.period_source = PeriodSourceEnum.NETWORKLOCATION - self.tb_custom_location.set_active(False) - self.tb_time_periods.set_active(False) + self.ui.tb_custom_location.set_active(False) + self.ui.tb_time_periods.set_active(False) - self.lbr_network_location.set_visible(True) - self.lbr_current_location.set_visible(True) - self.lbr_custom_location_longitude.set_visible(False) - self.lbr_custom_location_latitude.set_visible(False) - self.lbr_time_periods.set_visible(False) + self.ui.lbr_network_location.set_visible(True) + self.ui.lbr_current_location.set_visible(True) + self.ui.lbr_custom_location_longitude.set_visible(False) + self.ui.lbr_custom_location_latitude.set_visible(False) + self.ui.lbr_time_periods.set_visible(False) - self.spb_network_location_refresh_time.set_value(self.prefs.location_refresh_intervals) + self.ui.spb_network_location_refresh_time.set_value(self.prefs.location_refresh_intervals) # Display the location in the UI current_location = self.location.get_location() - self.lb_current_location.set_text("Latitude: " + current_location["latitude"] + \ + self.ui.lb_current_location.set_text("Latitude: " + current_location["latitude"] + \ ", Longitude: " + current_location["longitude"]) # Store the location to the preferences @@ -565,41 +471,41 @@ def on_toggle_button_network_location_clicked(self, button: Gtk.Button): self.refresh_chart() - def on_toggle_button_custom_location_clicked(self, button: Gtk.Button): + def on_toggle_button_custom_location_clicked(self, button: Gtk.ToggleButton): if button.get_active(): self.prefs.period_source = PeriodSourceEnum.CUSTOMLOCATION - self.tb_network_location.set_active(False) - self.tb_time_periods.set_active(False) + self.ui.tb_network_location.set_active(False) + self.ui.tb_time_periods.set_active(False) - self.lbr_network_location.set_visible(False) - self.lbr_current_location.set_visible(False) - self.lbr_custom_location_longitude.set_visible(True) - self.lbr_custom_location_latitude.set_visible(True) - self.lbr_time_periods.set_visible(False) + self.ui.lbr_network_location.set_visible(False) + self.ui.lbr_current_location.set_visible(False) + self.ui.lbr_custom_location_longitude.set_visible(True) + self.ui.lbr_custom_location_latitude.set_visible(True) + self.ui.lbr_time_periods.set_visible(False) - self.etr_latitude.set_text(str(self.prefs.latitude_custom)) - self.etr_longitude.set_text(str(self.prefs.longitude_custom)) + self.ui.etr_latitude.set_text(str(self.prefs.latitude_custom)) + self.ui.etr_longitude.set_text(str(self.prefs.longitude_custom)) - def on_toggle_button_time_periods_clicked(self, button: Gtk.Button): + def on_toggle_button_time_periods_clicked(self, button: Gtk.ToggleButton): if button.get_active(): self.prefs.period_source = PeriodSourceEnum.CUSTOMTIMEPERIODS - self.tb_network_location.set_active(False) - self.tb_custom_location.set_active(False) - - self.lbr_network_location.set_visible(False) - self.lbr_current_location.set_visible(False) - self.lbr_custom_location_longitude.set_visible(False) - self.lbr_custom_location_latitude.set_visible(False) - self.lbr_time_periods.set_visible(True) + self.ui.tb_network_location.set_active(False) + self.ui.tb_custom_location.set_active(False) + + self.ui.lbr_network_location.set_visible(False) + self.ui.lbr_current_location.set_visible(False) + self.ui.lbr_custom_location_longitude.set_visible(False) + self.ui.lbr_custom_location_latitude.set_visible(False) + self.ui.lbr_time_periods.set_visible(True) for i in range(0, 9): pref_value = self.prefs.period_custom_start_time[i + 1] time_parts = [int(pref_value[0:pref_value.find(":")]), int(pref_value[pref_value.find(":") + 1:])] - self.spb_periods_hour[i].set_value(time_parts[0]) - self.spb_periods_minute[i].set_value(time_parts[1]) + self.ui.spb_periods_hour[i].set_value(time_parts[0]) + self.ui.spb_periods_minute[i].set_value(time_parts[1]) @@ -619,14 +525,14 @@ def on_spb_period_value_changed(self, spin_button: Gtk.SpinButton): index = int(spin_button_name[11:12]) - 1 # Determe time string and store to prefs - time_current_start = datetime(2024,1,1, int(self.spb_periods_hour[index].get_value()), int(self.spb_periods_minute[index].get_value())) + time_current_start = datetime(2024,1,1, int(self.ui.spb_periods_hour[index].get_value()), int(self.ui.spb_periods_minute[index].get_value())) time_current_start_str = str(time_current_start.hour).rjust(2, '0') + ":" + str(time_current_start.minute).rjust(2, '0') self.prefs.period_custom_start_time[index + 1] = time_current_start_str time_previous_end = time_current_start - timedelta(minutes=1) - self.lb_period_end[index].set_text(str(time_previous_end.hour).rjust(2, '0') + ":" + str(time_previous_end.minute).rjust(2, '0')) + self.ui.lb_period_end[index].set_text(str(time_previous_end.hour).rjust(2, '0') + ":" + str(time_previous_end.minute).rjust(2, '0')) self.refresh_chart() @@ -641,7 +547,12 @@ def on_spb_network_location_refresh_time_changed(self, spin_button: Gtk.SpinButt self.prefs.location_refresh_intervals = spin_button.get_value() - def on_etr_longitude_changed(self, entry): + def on_etr_longitude_changed(self, entry: Gtk.Entry): + """ User changes the value of the longitude Entry + + Args: + entry (Gtk.Entry): The manipulated Entry object + """ try: self.prefs.longitude_custom = float(entry.get_text()) self.refresh_chart() @@ -649,7 +560,12 @@ def on_etr_longitude_changed(self, entry): pass - def on_etr_latitude_changed(self, entry): + def on_etr_latitude_changed(self, entry: Gtk.Entry): + """ User changes the value of the latitude Entry + + Args: + entry (Gtk.Entry): The manipulated Entry object + """ try: self.prefs.latitude_custom = float(entry.get_text()) self.refresh_chart() @@ -702,7 +618,10 @@ def on_create_issue_button_clicked(self, button): def on_ok(self, *args): """ Callback for the OK button in the top bar """ - self.on_apply() + try: + self.on_apply() + except: + pass # Close the window self.on_destroy() diff --git a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/scripts/display.py b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/scripts/display.py new file mode 100644 index 00000000..ddd22748 --- /dev/null +++ b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/scripts/display.py @@ -0,0 +1,20 @@ +import gi +gi.require_version("Gtk", "3.0") +from gi.repository import Gdk + +class Display: + """ Handling display informations and actions + """ + def __init__(self) -> None: + self.display = Gdk.Display.get_default() + + + def get_screen_height(self) -> int: + """ Estimate the height resolution of the primary display + + Returns: + int: Height in pixel + """ + geometry = self.display.get_monitor(0).get_geometry() + + return geometry.height diff --git a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/scripts/ui.py b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/scripts/ui.py new file mode 100644 index 00000000..daa0a695 --- /dev/null +++ b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/scripts/ui.py @@ -0,0 +1,147 @@ +import gi +gi.require_version("Gtk", "3.0") +from gi.repository import Gtk + +class UI: + """ Class to handle UI components and actions + """ + def __init__(self, builder: Gtk.Builder) -> None: + # Page 1 + self.tb_image_set: Gtk.ToggleButton = builder.get_object("tb_image_set") + self.tb_heic_file: Gtk.ToggleButton = builder.get_object("tb_heic_file") + self.tb_source_folder: Gtk.ToggleButton = builder.get_object("tb_source_folder") + self.img_tb_image_set: Gtk.Image = builder.get_object("img_tb_image_set") + self.img_tb_heic_file: Gtk.Image = builder.get_object("img_tb_heic_file") + self.img_tb_source_folder: Gtk.Image = builder.get_object("img_tb_source_folder") + + # Image set + self.lbr_image_set: Gtk.ListBoxRow = builder.get_object("lbr_image_set") + self.cb_image_set: Gtk.ComboBox = builder.get_object("cb_image_set") + + # HEIC file + self.lbr_heic_file: Gtk.ListBoxRow = builder.get_object("lbr_heic_file") + + # Source folder + self.lbr_source_folder: Gtk.ListBoxRow = builder.get_object("lbr_source_folder") + self.btn_source_folder: Gtk.Button = builder.get_object("btn_source_folder") + self.lbl_source_folder: Gtk.Label = builder.get_object("lbl_source_folder") + + # Time bar chart + self.img_bar_images: Gtk.Image = builder.get_object("img_bar_images") + self.etr_periods: list[Gtk.Entry] = [ + builder.get_object("etr_period_1"), builder.get_object("etr_period_2"), + builder.get_object("etr_period_3"), builder.get_object("etr_period_4"), + builder.get_object("etr_period_5"), builder.get_object("etr_period_6"), + builder.get_object("etr_period_7"), builder.get_object("etr_period_8"), + builder.get_object("etr_period_9"), builder.get_object("etr_period_10"), + ] + + self.img_periods: list[Gtk.Image] = [ + builder.get_object("img_period_0"), builder.get_object("img_period_1"), + builder.get_object("img_period_2"), builder.get_object("img_period_3"), + builder.get_object("img_period_4"), builder.get_object("img_period_5"), + builder.get_object("img_period_6"), builder.get_object("img_period_7"), + builder.get_object("img_period_8"), builder.get_object("img_period_9"), + ] + + self.cb_periods: list[Gtk.ComboBox] = [ + builder.get_object("cb_period_0"), builder.get_object("cb_period_1"), + builder.get_object("cb_period_2"), builder.get_object("cb_period_3"), + builder.get_object("cb_period_4"), builder.get_object("cb_period_5"), + builder.get_object("cb_period_6"), builder.get_object("cb_period_7"), + builder.get_object("cb_period_8"), builder.get_object("cb_period_9"), + ] + + + + #### Page 2: Location & Times + self.tb_network_location: Gtk.ToggleButton = builder.get_object("tb_network_location") + self.tb_custom_location: Gtk.ToggleButton = builder.get_object("tb_custom_location") + self.tb_time_periods: Gtk.ToggleButton = builder.get_object("tb_time_periods") + self.img_tb_network_location: Gtk.Image = builder.get_object("img_tb_network_location") + self.img_tb_custom_location: Gtk.Image = builder.get_object("img_tb_custom_location") + self.img_tb_time_periods: Gtk.Image = builder.get_object("img_tb_time_periods") + + # Network Location + self.lb_current_location: Gtk.Label = builder.get_object("lb_current_location") + self.lbr_current_location: Gtk.ListBoxRow = builder.get_object("lbr_current_location") + self.lbr_network_location: Gtk.ListBoxRow = builder.get_object("lbr_network_location") + self.spb_network_location_refresh_time: Gtk.SpinButton = builder.get_object("spb_network_location_refresh_time") + + # Custom location + self.lbr_custom_location_longitude: Gtk.ListBoxRow = builder.get_object("lbr_custom_location_longitude") + self.lbr_custom_location_latitude: Gtk.ListBoxRow = builder.get_object("lbr_custom_location_latitude") + self.lbr_time_periods: Gtk.ListBoxRow = builder.get_object("lbr_time_periods") + self.etr_longitude: Gtk.Entry = builder.get_object("etr_longitude") + self.etr_latitude: Gtk.Entry = builder.get_object("etr_latitude") + self.img_bar_times: Gtk.Image = builder.get_object("img_bar_times") + self.spb_periods_hour: list[Gtk.SpinButton] = [ + builder.get_object("spb_period_1_hour"), + builder.get_object("spb_period_2_hour"), + builder.get_object("spb_period_3_hour"), + builder.get_object("spb_period_4_hour"), + builder.get_object("spb_period_5_hour"), + builder.get_object("spb_period_6_hour"), + builder.get_object("spb_period_7_hour"), + builder.get_object("spb_period_8_hour"), + builder.get_object("spb_period_9_hour"), + ] + self.spb_periods_minute: list[Gtk.SpinButton] = [ + builder.get_object("spb_period_1_minute"), + builder.get_object("spb_period_2_minute"), + builder.get_object("spb_period_3_minute"), + builder.get_object("spb_period_4_minute"), + builder.get_object("spb_period_5_minute"), + builder.get_object("spb_period_6_minute"), + builder.get_object("spb_period_7_minute"), + builder.get_object("spb_period_8_minute"), + builder.get_object("spb_period_9_minute") + ] + self.lb_period_end: list[Gtk.Label] = [ + builder.get_object("lb_period_0_end"), builder.get_object("lb_period_1_end"), + builder.get_object("lb_period_2_end"), builder.get_object("lb_period_3_end"), + builder.get_object("lb_period_4_end"), builder.get_object("lb_period_5_end"), + builder.get_object("lb_period_6_end"), builder.get_object("lb_period_7_end"), + builder.get_object("lb_period_8_end"), builder.get_object("lb_period_9_end"), + ] + + + # Page 3: Behaviour + self.cb_picture_aspect: Gtk.ComboBox = builder.get_object("cb_picture_aspect") + self.sw_dynamic_background_color: Gtk.Switch = builder.get_object("sw_dynamic_background_color") + + + def set_active_combobox_item(self, combobox: Gtk.ComboBoxText, active_item: str): + """ Change active item in combobox by String value + + Args: + combobox (Gtk.ComboBoxText): ComboBox to set active + active_item (str): String item to set active + """ + list_store = combobox.get_model() + + for i in range(0, len(list_store)): + row = list_store[i] + if row[0] == active_item: + combobox.set_active(i) + + + def add_items_to_combo_box(self, combobox: Gtk.ComboBox, items: list): + """ Add items to a combo box + + Args: + combobox (Gtk.ComboBox): ComboBox where to add the options + items (list): Possible options + """ + model = combobox.get_model() + store = Gtk.ListStore(str) + + for image_set in items: + store.append([image_set]) + + combobox.set_model(store) + + if model == None: + renderer_text = Gtk.CellRendererText() + combobox.pack_start(renderer_text, True) + combobox.add_attribute(renderer_text, "text", 0) diff --git a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/settings-schema.json b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/settings-schema.json index 2c3aac88..94b2cf08 100644 --- a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/settings-schema.json +++ b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/5.4/settings-schema.json @@ -5,7 +5,7 @@ }, "picture_aspect": { "type": "generic", - "default": "Scaled" + "default": "scaled" }, "dynamic_background_color": { "type": "generic",