Rewrite preference system
This commit is contained in:
@@ -1,45 +0,0 @@
|
|||||||
from enum import Enum
|
|
||||||
|
|
||||||
class PrefenceEnums(enumerate):
|
|
||||||
PICTURE_ASPECT = "picture_aspect"
|
|
||||||
DYNAMIC_BACKGROUND_COLOR = "dynamic_background_color"
|
|
||||||
|
|
||||||
# Which type of image source will be used
|
|
||||||
# image_set, heic_file, source_folder
|
|
||||||
IMAGE_SOURCE = "image_source"
|
|
||||||
|
|
||||||
SELECTED_IMAGE_SET = "selected_image_set"
|
|
||||||
SOURCE_FOLDER = "source_folder"
|
|
||||||
|
|
||||||
PERIOD_0_IMAGE = "period_0_image"
|
|
||||||
PERIOD_1_IMAGE = "period_1_image"
|
|
||||||
PERIOD_2_IMAGE = "period_2_image"
|
|
||||||
PERIOD_3_IMAGE = "period_3_image"
|
|
||||||
PERIOD_4_IMAGE = "period_4_image"
|
|
||||||
PERIOD_5_IMAGE = "period_5_image"
|
|
||||||
PERIOD_6_IMAGE = "period_6_image"
|
|
||||||
PERIOD_7_IMAGE = "period_7_image"
|
|
||||||
PERIOD_8_IMAGE = "period_8_image"
|
|
||||||
PERIOD_9_IMAGE = "period_9_image"
|
|
||||||
|
|
||||||
|
|
||||||
# How the period will estimage
|
|
||||||
# network_location, custom_location, custom_time_periods
|
|
||||||
PERIOD_SOURCE = "period_source"
|
|
||||||
|
|
||||||
LOCATION_REFRESH_INTERVALS = "location_refresh_intervals"
|
|
||||||
LATITUDE_AUTO = "latitude_auto"
|
|
||||||
LONGITUDE_AUTO = "longitude_auto"
|
|
||||||
LATITUDE_CUSTOM = "latitude_custom"
|
|
||||||
LONGITUDE_CUSTOM = "longitude_custom"
|
|
||||||
|
|
||||||
PERIOD_0_STARTTIME = "period_0_custom_start_time"
|
|
||||||
PERIOD_1_STARTTIME = "period_1_custom_start_time"
|
|
||||||
PERIOD_2_STARTTIME = "period_2_custom_start_time"
|
|
||||||
PERIOD_3_STARTTIME = "period_3_custom_start_time"
|
|
||||||
PERIOD_4_STARTTIME = "period_4_custom_start_time"
|
|
||||||
PERIOD_5_STARTTIME = "period_5_custom_start_time"
|
|
||||||
PERIOD_6_STARTTIME = "period_6_custom_start_time"
|
|
||||||
PERIOD_7_STARTTIME = "period_7_custom_start_time"
|
|
||||||
PERIOD_8_STARTTIME = "period_8_custom_start_time"
|
|
||||||
PERIOD_9_STARTTIME = "period_9_custom_start_time"
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
from scripts.cinnamon_pref_handler import *
|
from scripts.cinnamon_pref_handler import *
|
||||||
from scripts.suntimes import *
|
from scripts.suntimes import *
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
from enums.PreferenceEnums import *
|
|
||||||
from enums.PeriodSourceEnum import *
|
from enums.PeriodSourceEnum import *
|
||||||
from scripts.location import *
|
from scripts.location import *
|
||||||
from gi.repository import Gio
|
from gi.repository import Gio
|
||||||
@@ -20,7 +19,7 @@ class Loop():
|
|||||||
self.prefs = Cinnamon_Pref_Handler()
|
self.prefs = Cinnamon_Pref_Handler()
|
||||||
|
|
||||||
# Position should estimate by network
|
# Position should estimate by network
|
||||||
if self.prefs.prefs[PrefenceEnums.PERIOD_SOURCE] == PeriodSourceEnum.NETWORKLOCATION:
|
if self.prefs.period_source == PeriodSourceEnum.NETWORKLOCATION:
|
||||||
location_thread.start()
|
location_thread.start()
|
||||||
location_thread.join()
|
location_thread.join()
|
||||||
|
|
||||||
@@ -31,7 +30,7 @@ class Loop():
|
|||||||
|
|
||||||
# Position is given by user
|
# Position is given by user
|
||||||
elif self.prefs.prefs[PrefenceEnums.PERIOD_SOURCE] == PeriodSourceEnum.CUSTOMLOCATION:
|
elif self.prefs.prefs[PrefenceEnums.PERIOD_SOURCE] == PeriodSourceEnum.CUSTOMLOCATION:
|
||||||
suntimes.calc_suntimes(float(self.prefs.prefs[PrefenceEnums.LATITUDE_CUSTOM]), float(self.prefs.prefs[PrefenceEnums.LONGITUDE_CUSTOM]))
|
suntimes.calc_suntimes(float(self.prefs.latitude_custom), float(self.prefs.longitude_custom))
|
||||||
self.start_times = suntimes.day_periods
|
self.start_times = suntimes.day_periods
|
||||||
|
|
||||||
# No position, concrete times
|
# No position, concrete times
|
||||||
@@ -43,16 +42,16 @@ class Loop():
|
|||||||
return time(hour=int(hour), minute=int(minute))
|
return time(hour=int(hour), minute=int(minute))
|
||||||
|
|
||||||
self.start_times = [
|
self.start_times = [
|
||||||
string_to_time_converter(self.prefs.prefs[PrefenceEnums.PERIOD_0_STARTTIME]),
|
string_to_time_converter(self.prefs.period_custom_start_time[0]),
|
||||||
string_to_time_converter(self.prefs.prefs[PrefenceEnums.PERIOD_1_STARTTIME]),
|
string_to_time_converter(self.prefs.period_custom_start_time[1]),
|
||||||
string_to_time_converter(self.prefs.prefs[PrefenceEnums.PERIOD_2_STARTTIME]),
|
string_to_time_converter(self.prefs.period_custom_start_time[2]),
|
||||||
string_to_time_converter(self.prefs.prefs[PrefenceEnums.PERIOD_3_STARTTIME]),
|
string_to_time_converter(self.prefs.period_custom_start_time[3]),
|
||||||
string_to_time_converter(self.prefs.prefs[PrefenceEnums.PERIOD_4_STARTTIME]),
|
string_to_time_converter(self.prefs.period_custom_start_time[4]),
|
||||||
string_to_time_converter(self.prefs.prefs[PrefenceEnums.PERIOD_5_STARTTIME]),
|
string_to_time_converter(self.prefs.period_custom_start_time[5]),
|
||||||
string_to_time_converter(self.prefs.prefs[PrefenceEnums.PERIOD_6_STARTTIME]),
|
string_to_time_converter(self.prefs.period_custom_start_time[6]),
|
||||||
string_to_time_converter(self.prefs.prefs[PrefenceEnums.PERIOD_7_STARTTIME]),
|
string_to_time_converter(self.prefs.period_custom_start_time[7]),
|
||||||
string_to_time_converter(self.prefs.prefs[PrefenceEnums.PERIOD_8_STARTTIME]),
|
string_to_time_converter(self.prefs.period_custom_start_time[8]),
|
||||||
string_to_time_converter(self.prefs.prefs[PrefenceEnums.PERIOD_9_STARTTIME])
|
string_to_time_converter(self.prefs.period_custom_start_time[9])
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -63,21 +62,21 @@ class Loop():
|
|||||||
time_now = time(datetime.now().hour, datetime.now().minute)
|
time_now = time(datetime.now().hour, datetime.now().minute)
|
||||||
|
|
||||||
# Assign the last image as fallback
|
# Assign the last image as fallback
|
||||||
self.current_image_uri = self.prefs.prefs[PrefenceEnums.SOURCE_FOLDER] + self.prefs.prefs[PrefenceEnums.PERIOD_9_IMAGE]
|
self.current_image_uri = self.prefs.source_folder + self.prefs.period_images[9]
|
||||||
|
|
||||||
for i in range(0, 9):
|
for i in range(0, 9):
|
||||||
# Replace the image URI, if it's not the last time period of the day
|
# Replace the image URI, if it's not the last time period of the day
|
||||||
if self.start_times[i] <= time_now and time_now < self.start_times[i + 1]:
|
if self.start_times[i] <= time_now and time_now < self.start_times[i + 1]:
|
||||||
self.current_image_uri = self.prefs.prefs[PrefenceEnums.SOURCE_FOLDER] + self.prefs.prefs["period_%d_image" % (i)]
|
self.current_image_uri = self.prefs.source_folder + self.prefs.period_images[i]
|
||||||
break
|
break
|
||||||
|
|
||||||
# Set the background
|
# Set the background
|
||||||
background_settings['picture-uri'] = "file://" + self.current_image_uri
|
background_settings['picture-uri'] = "file://" + self.current_image_uri
|
||||||
|
|
||||||
# Set background stretching
|
# Set background stretching
|
||||||
background_settings['picture-options'] = self.prefs.prefs[PrefenceEnums.PICTURE_ASPECT]
|
background_settings['picture-options'] = self.prefs.picture_aspect
|
||||||
|
|
||||||
if self.prefs.prefs[PrefenceEnums.DYNAMIC_BACKGROUND_COLOR]:
|
if self.prefs.dynamic_background_color:
|
||||||
self.set_background_gradient()
|
self.set_background_gradient()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ from scripts.cinnamon_pref_handler import *
|
|||||||
from scripts.suntimes import *
|
from scripts.suntimes import *
|
||||||
from scripts.location import *
|
from scripts.location import *
|
||||||
from scripts.images import *
|
from scripts.images import *
|
||||||
from enums.PreferenceEnums import PrefenceEnums
|
|
||||||
from enums.ImageSourceEnum import ImageSourceEnum
|
from enums.ImageSourceEnum import ImageSourceEnum
|
||||||
from enums.PeriodSourceEnum import PeriodSourceEnum
|
from enums.PeriodSourceEnum import PeriodSourceEnum
|
||||||
from loop import *
|
from loop import *
|
||||||
@@ -145,26 +144,26 @@ class Preferences:
|
|||||||
|
|
||||||
|
|
||||||
# Load from preferences
|
# Load from preferences
|
||||||
if self.c_prefs.prefs[PrefenceEnums.IMAGE_SOURCE] == ImageSourceEnum.IMAGESET:
|
if self.c_prefs.image_source == ImageSourceEnum.IMAGESET:
|
||||||
self.tb_image_set.set_active(True)
|
self.tb_image_set.set_active(True)
|
||||||
elif self.c_prefs.prefs[PrefenceEnums.IMAGE_SOURCE] == ImageSourceEnum.HEICFILE:
|
elif self.c_prefs.image_source == ImageSourceEnum.HEICFILE:
|
||||||
self.tb_heic_file.set_active(True)
|
self.tb_heic_file.set_active(True)
|
||||||
elif self.c_prefs.prefs[PrefenceEnums.IMAGE_SOURCE] == ImageSourceEnum.SOURCEFOLDER:
|
elif self.c_prefs.image_source == ImageSourceEnum.SOURCEFOLDER:
|
||||||
self.tb_source_folder.set_active(True)
|
self.tb_source_folder.set_active(True)
|
||||||
|
|
||||||
|
|
||||||
picture_aspects = ["mosaic", "centered", "scaled", "stretched", "zoom", "spanned"]
|
picture_aspects = ["mosaic", "centered", "scaled", "stretched", "zoom", "spanned"]
|
||||||
self.add_items_to_combo_box(self.cb_picture_aspect, picture_aspects)
|
self.add_items_to_combo_box(self.cb_picture_aspect, picture_aspects)
|
||||||
self.set_active_combobox_item(self.cb_picture_aspect, self.c_prefs.prefs[PrefenceEnums.PICTURE_ASPECT])
|
self.set_active_combobox_item(self.cb_picture_aspect, self.c_prefs.picture_aspect)
|
||||||
|
|
||||||
self.sw_dynamic_background_color.set_active(self.c_prefs.prefs[PrefenceEnums.DYNAMIC_BACKGROUND_COLOR])
|
self.sw_dynamic_background_color.set_active(self.c_prefs.dynamic_background_color)
|
||||||
|
|
||||||
|
|
||||||
if self.c_prefs.prefs[PrefenceEnums.PERIOD_SOURCE] == PeriodSourceEnum.NETWORKLOCATION:
|
if self.c_prefs.period_source == PeriodSourceEnum.NETWORKLOCATION:
|
||||||
self.tb_network_location.set_active(True)
|
self.tb_network_location.set_active(True)
|
||||||
elif self.c_prefs.prefs[PrefenceEnums.PERIOD_SOURCE] == PeriodSourceEnum.CUSTOMLOCATION:
|
elif self.c_prefs.period_source == PeriodSourceEnum.CUSTOMLOCATION:
|
||||||
self.tb_custom_location.set_active(True)
|
self.tb_custom_location.set_active(True)
|
||||||
elif self.c_prefs.prefs[PrefenceEnums.PERIOD_SOURCE] == PeriodSourceEnum.CUSTOMTIMEPERIODS:
|
elif self.c_prefs.period_source == PeriodSourceEnum.CUSTOMTIMEPERIODS:
|
||||||
self.tb_time_periods.set_active(True)
|
self.tb_time_periods.set_active(True)
|
||||||
|
|
||||||
|
|
||||||
@@ -195,15 +194,15 @@ class Preferences:
|
|||||||
# Stores the start times of the periods in minutes since midnight
|
# Stores the start times of the periods in minutes since midnight
|
||||||
time_periods_min = []
|
time_periods_min = []
|
||||||
|
|
||||||
if self.c_prefs.prefs[PrefenceEnums.PERIOD_SOURCE] == PeriodSourceEnum.CUSTOMTIMEPERIODS:
|
if self.c_prefs.period_source == PeriodSourceEnum.CUSTOMTIMEPERIODS:
|
||||||
for i in range(0, 10):
|
for i in range(0, 10):
|
||||||
time_str = self.c_prefs.prefs["period_%s_custom_start_time" % i]
|
time_str = self.c_prefs.period_custom_start_time[i]
|
||||||
|
|
||||||
time_periods_min.append(int(time_str[0:2]) * 60 + int(time_str[3:5]))
|
time_periods_min.append(int(time_str[0:2]) * 60 + int(time_str[3:5]))
|
||||||
else:
|
else:
|
||||||
if self.c_prefs.prefs[PrefenceEnums.PERIOD_SOURCE] == PeriodSourceEnum.NETWORKLOCATION:
|
if self.c_prefs.period_source == PeriodSourceEnum.NETWORKLOCATION:
|
||||||
self.suntimes.calc_suntimes(float(self.c_prefs.prefs[PrefenceEnums.LATITUDE_AUTO]),
|
self.suntimes.calc_suntimes(float(self.c_prefs.latitude_auto),
|
||||||
float(self.c_prefs.prefs[PrefenceEnums.LONGITUDE_AUTO]))
|
float(self.c_prefs.longitude_auto))
|
||||||
else:
|
else:
|
||||||
self.suntimes.calc_suntimes(float(self.etr_latitude.get_text()), float(self.etr_longitude.get_text()))
|
self.suntimes.calc_suntimes(float(self.etr_latitude.get_text()), float(self.etr_longitude.get_text()))
|
||||||
|
|
||||||
@@ -308,7 +307,7 @@ class Preferences:
|
|||||||
|
|
||||||
def on_toggle_button_image_set_clicked(self, button: Gtk.Button):
|
def on_toggle_button_image_set_clicked(self, button: Gtk.Button):
|
||||||
if button.get_active():
|
if button.get_active():
|
||||||
self.c_prefs.prefs[PrefenceEnums.IMAGE_SOURCE] = ImageSourceEnum.IMAGESET
|
self.c_prefs.image_source = ImageSourceEnum.IMAGESET
|
||||||
self.tb_heic_file.set_active(False)
|
self.tb_heic_file.set_active(False)
|
||||||
self.tb_source_folder.set_active(False)
|
self.tb_source_folder.set_active(False)
|
||||||
|
|
||||||
@@ -319,10 +318,10 @@ class Preferences:
|
|||||||
image_set_choices = ["aurora", "beach", "bitday", "cliffs", "gradient", "lakeside", "mountains", "sahara"]
|
image_set_choices = ["aurora", "beach", "bitday", "cliffs", "gradient", "lakeside", "mountains", "sahara"]
|
||||||
self.add_items_to_combo_box(self.cb_image_set, image_set_choices)
|
self.add_items_to_combo_box(self.cb_image_set, image_set_choices)
|
||||||
|
|
||||||
self.set_active_combobox_item(self.cb_image_set, self.c_prefs.prefs[PrefenceEnums.SELECTED_IMAGE_SET])
|
self.set_active_combobox_item(self.cb_image_set, self.c_prefs.selected_image_set)
|
||||||
|
|
||||||
for i, combobox in enumerate(self.cb_periods):
|
for i, combobox in enumerate(self.cb_periods):
|
||||||
selected_image_name = self.c_prefs.prefs["period_%s_image" % (i)]
|
selected_image_name = self.c_prefs.period_images[i]
|
||||||
self.set_active_combobox_item(combobox, selected_image_name)
|
self.set_active_combobox_item(combobox, selected_image_name)
|
||||||
|
|
||||||
# Make the comboboxes invisible
|
# Make the comboboxes invisible
|
||||||
@@ -332,7 +331,7 @@ class Preferences:
|
|||||||
|
|
||||||
def on_toggle_button_heic_file_clicked(self, button: Gtk.Button):
|
def on_toggle_button_heic_file_clicked(self, button: Gtk.Button):
|
||||||
if button.get_active():
|
if button.get_active():
|
||||||
self.c_prefs.prefs[PrefenceEnums.IMAGE_SOURCE] = ImageSourceEnum.HEICFILE
|
self.c_prefs.image_source = ImageSourceEnum.HEICFILE
|
||||||
self.tb_image_set.set_active(False)
|
self.tb_image_set.set_active(False)
|
||||||
self.tb_source_folder.set_active(False)
|
self.tb_source_folder.set_active(False)
|
||||||
|
|
||||||
@@ -347,7 +346,7 @@ class Preferences:
|
|||||||
|
|
||||||
def on_toggle_button_source_folder_clicked(self, button: Gtk.Button):
|
def on_toggle_button_source_folder_clicked(self, button: Gtk.Button):
|
||||||
if button.get_active():
|
if button.get_active():
|
||||||
self.c_prefs.prefs[PrefenceEnums.IMAGE_SOURCE] = ImageSourceEnum.SOURCEFOLDER
|
self.c_prefs.image_source = ImageSourceEnum.SOURCEFOLDER
|
||||||
self.tb_image_set.set_active(False)
|
self.tb_image_set.set_active(False)
|
||||||
self.tb_heic_file.set_active(False)
|
self.tb_heic_file.set_active(False)
|
||||||
|
|
||||||
@@ -361,25 +360,25 @@ class Preferences:
|
|||||||
|
|
||||||
# Load the source folder to the view
|
# Load the source folder to the view
|
||||||
# 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.fc_source_folder.set_filename(self.c_prefs.prefs[PrefenceEnums.SOURCE_FOLDER])
|
self.fc_source_folder.set_filename(self.c_prefs.source_folder)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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()
|
||||||
|
|
||||||
if tree_iter is not None and self.c_prefs.prefs[PrefenceEnums.IMAGE_SOURCE] == ImageSourceEnum.IMAGESET:
|
if tree_iter is not None and self.c_prefs.image_source == ImageSourceEnum.IMAGESET:
|
||||||
# Get the selected value
|
# Get the selected value
|
||||||
model = combobox.get_model()
|
model = combobox.get_model()
|
||||||
selected_image_set = model[tree_iter][0]
|
selected_image_set = model[tree_iter][0]
|
||||||
|
|
||||||
# Store to the preferences
|
# Store to the preferences
|
||||||
self.c_prefs.prefs[PrefenceEnums.SELECTED_IMAGE_SET] = selected_image_set
|
self.c_prefs.selected_image_set = selected_image_set
|
||||||
self.c_prefs.prefs[PrefenceEnums.SOURCE_FOLDER] = os.path.abspath(os.path.join(PREFERENCES_URI, os.pardir)) + \
|
self.c_prefs.source_folder = os.path.abspath(os.path.join(PREFERENCES_URI, os.pardir)) + \
|
||||||
"/5.4/images/included_image_sets/" + selected_image_set + "/"
|
"/5.4/images/included_image_sets/" + selected_image_set + "/"
|
||||||
|
|
||||||
# Load all possible options to the comboboxes
|
# Load all possible options to the comboboxes
|
||||||
image_names = self.images.get_images_from_folder(self.c_prefs.prefs[PrefenceEnums.SOURCE_FOLDER])
|
image_names = self.images.get_images_from_folder(self.c_prefs.source_folder)
|
||||||
self.load_image_options_to_combo_boxes(image_names)
|
self.load_image_options_to_combo_boxes(image_names)
|
||||||
|
|
||||||
# Image sets have the same names for the images:
|
# Image sets have the same names for the images:
|
||||||
@@ -401,8 +400,8 @@ class Preferences:
|
|||||||
file_name = file_name[:file_name.rfind(".")]
|
file_name = file_name[:file_name.rfind(".")]
|
||||||
|
|
||||||
# Update the preferences
|
# Update the preferences
|
||||||
self.c_prefs.prefs[PrefenceEnums.SELECTED_IMAGE_SET] = ""
|
self.c_prefs.selected_image_set = ""
|
||||||
self.c_prefs.prefs[PrefenceEnums.SOURCE_FOLDER] = extract_folder
|
self.c_prefs.source_folder = extract_folder
|
||||||
|
|
||||||
# Create the buffer folder
|
# Create the buffer folder
|
||||||
try:
|
try:
|
||||||
@@ -417,7 +416,7 @@ class Preferences:
|
|||||||
os.system("heif-convert " + file_path + " " + extract_folder + file_name + ".jpg")
|
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.c_prefs.prefs[PrefenceEnums.SOURCE_FOLDER])
|
image_names = self.images.get_images_from_folder(self.c_prefs.source_folder)
|
||||||
self.load_image_options_to_combo_boxes(image_names)
|
self.load_image_options_to_combo_boxes(image_names)
|
||||||
|
|
||||||
|
|
||||||
@@ -426,15 +425,15 @@ class Preferences:
|
|||||||
files = self.images.get_images_from_folder(fc_button.get_filename())
|
files = self.images.get_images_from_folder(fc_button.get_filename())
|
||||||
|
|
||||||
# Update the preferences
|
# Update the preferences
|
||||||
self.c_prefs.prefs[PrefenceEnums.SELECTED_IMAGE_SET] = ""
|
self.c_prefs.selected_image_set = ""
|
||||||
self.c_prefs.prefs[PrefenceEnums.SOURCE_FOLDER] = fc_button.get_filename() + "/"
|
self.c_prefs.source_folder = fc_button.get_filename() + "/"
|
||||||
|
|
||||||
if len(files) != 0:
|
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.c_prefs.prefs["period_%s_image" % (i)])
|
self.set_active_combobox_item(self.cb_periods[i], self.c_prefs.period_images[i])
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -451,10 +450,10 @@ class Preferences:
|
|||||||
image_file_name = model[tree_iter][0]
|
image_file_name = model[tree_iter][0]
|
||||||
|
|
||||||
# Store selection to preferences
|
# Store selection to preferences
|
||||||
self.c_prefs.prefs["period_%s_image" % (period_index)] = image_file_name
|
self.c_prefs.period_images[period_index] = image_file_name
|
||||||
|
|
||||||
# Build up image path
|
# Build up image path
|
||||||
image_path = self.c_prefs.prefs[PrefenceEnums.SOURCE_FOLDER] + image_file_name
|
image_path = self.c_prefs.source_folder + image_file_name
|
||||||
|
|
||||||
self.load_image_to_preview(self.img_periods[period_index], image_path)
|
self.load_image_to_preview(self.img_periods[period_index], image_path)
|
||||||
|
|
||||||
@@ -463,7 +462,7 @@ class Preferences:
|
|||||||
|
|
||||||
def on_toggle_button_network_location_clicked(self, button: Gtk.Button):
|
def on_toggle_button_network_location_clicked(self, button: Gtk.Button):
|
||||||
if button.get_active():
|
if button.get_active():
|
||||||
self.c_prefs.prefs[PrefenceEnums.PERIOD_SOURCE] = PeriodSourceEnum.NETWORKLOCATION
|
self.c_prefs.period_source = PeriodSourceEnum.NETWORKLOCATION
|
||||||
self.tb_custom_location.set_active(False)
|
self.tb_custom_location.set_active(False)
|
||||||
self.tb_time_periods.set_active(False)
|
self.tb_time_periods.set_active(False)
|
||||||
|
|
||||||
@@ -473,7 +472,7 @@ class Preferences:
|
|||||||
self.lbr_custom_location_latitude.set_visible(False)
|
self.lbr_custom_location_latitude.set_visible(False)
|
||||||
self.lbr_time_periods.set_visible(False)
|
self.lbr_time_periods.set_visible(False)
|
||||||
|
|
||||||
self.spb_network_location_refresh_time.set_value(self.c_prefs.prefs[PrefenceEnums.LOCATION_REFRESH_INTERVALS])
|
self.spb_network_location_refresh_time.set_value(self.c_prefs.location_refresh_intervals)
|
||||||
|
|
||||||
|
|
||||||
# Start a thread to get the current location
|
# Start a thread to get the current location
|
||||||
@@ -488,15 +487,15 @@ class Preferences:
|
|||||||
", Longitude: " + location["longitude"])
|
", Longitude: " + location["longitude"])
|
||||||
|
|
||||||
# Store the location to the preferences
|
# Store the location to the preferences
|
||||||
self.c_prefs.prefs[PrefenceEnums.LATITUDE_AUTO] = float(location["latitude"])
|
self.c_prefs.latitude_auto = float(location["latitude"])
|
||||||
self.c_prefs.prefs[PrefenceEnums.LONGITUDE_AUTO] = float(location["longitude"])
|
self.c_prefs.longitude_auto = float(location["longitude"])
|
||||||
|
|
||||||
self.refresh_chart()
|
self.refresh_chart()
|
||||||
|
|
||||||
|
|
||||||
def on_toggle_button_custom_location_clicked(self, button: Gtk.Button):
|
def on_toggle_button_custom_location_clicked(self, button: Gtk.Button):
|
||||||
if button.get_active():
|
if button.get_active():
|
||||||
self.c_prefs.prefs[PrefenceEnums.PERIOD_SOURCE] = PeriodSourceEnum.CUSTOMLOCATION
|
self.c_prefs.period_source = PeriodSourceEnum.CUSTOMLOCATION
|
||||||
self.tb_network_location.set_active(False)
|
self.tb_network_location.set_active(False)
|
||||||
self.tb_time_periods.set_active(False)
|
self.tb_time_periods.set_active(False)
|
||||||
|
|
||||||
@@ -506,13 +505,13 @@ class Preferences:
|
|||||||
self.lbr_custom_location_latitude.set_visible(True)
|
self.lbr_custom_location_latitude.set_visible(True)
|
||||||
self.lbr_time_periods.set_visible(False)
|
self.lbr_time_periods.set_visible(False)
|
||||||
|
|
||||||
self.etr_latitude.set_text(str(self.c_prefs.prefs[PrefenceEnums.LATITUDE_CUSTOM]))
|
self.etr_latitude.set_text(str(self.c_prefs.latitude_custom))
|
||||||
self.etr_longitude.set_text(str(self.c_prefs.prefs[PrefenceEnums.LONGITUDE_CUSTOM]))
|
self.etr_longitude.set_text(str(self.c_prefs.longitude_custom))
|
||||||
|
|
||||||
|
|
||||||
def on_toggle_button_time_periods_clicked(self, button: Gtk.Button):
|
def on_toggle_button_time_periods_clicked(self, button: Gtk.Button):
|
||||||
if button.get_active():
|
if button.get_active():
|
||||||
self.c_prefs.prefs[PrefenceEnums.PERIOD_SOURCE] = PeriodSourceEnum.CUSTOMTIMEPERIODS
|
self.c_prefs.period_source = PeriodSourceEnum.CUSTOMTIMEPERIODS
|
||||||
self.tb_network_location.set_active(False)
|
self.tb_network_location.set_active(False)
|
||||||
self.tb_custom_location.set_active(False)
|
self.tb_custom_location.set_active(False)
|
||||||
|
|
||||||
@@ -524,7 +523,7 @@ class Preferences:
|
|||||||
|
|
||||||
|
|
||||||
for i in range(0, 9):
|
for i in range(0, 9):
|
||||||
pref_value = self.c_prefs.prefs["period_%s_custom_start_time" % (i + 1)]
|
pref_value = self.c_prefs.period_custom_start_time[i + 1]
|
||||||
time_parts = [int(pref_value[0:pref_value.find(":")]), int(pref_value[pref_value.find(":") + 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_hour[i].set_value(time_parts[0])
|
||||||
@@ -551,7 +550,7 @@ class Preferences:
|
|||||||
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.spb_periods_hour[index].get_value()), int(self.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')
|
time_current_start_str = str(time_current_start.hour).rjust(2, '0') + ":" + str(time_current_start.minute).rjust(2, '0')
|
||||||
|
|
||||||
self.c_prefs.prefs["period_%s_custom_start_time" % (index + 1)] = time_current_start_str
|
self.c_prefs.period_custom_start_time[index + 1] = time_current_start_str
|
||||||
|
|
||||||
|
|
||||||
time_previous_end = time_current_start - timedelta(minutes=1)
|
time_previous_end = time_current_start - timedelta(minutes=1)
|
||||||
@@ -562,12 +561,12 @@ class Preferences:
|
|||||||
|
|
||||||
|
|
||||||
def on_spb_network_location_refresh_time_changed(self, spin_button):
|
def on_spb_network_location_refresh_time_changed(self, spin_button):
|
||||||
self.c_prefs.prefs[PrefenceEnums.LOCATION_REFRESH_INTERVALS] = spin_button.get_value()
|
self.c_prefs.location_refresh_intervals = spin_button.get_value()
|
||||||
|
|
||||||
|
|
||||||
def on_etr_longitude_changed(self, entry):
|
def on_etr_longitude_changed(self, entry):
|
||||||
try:
|
try:
|
||||||
self.c_prefs.prefs[PrefenceEnums.LONGITUDE_CUSTOM] = float(entry.get_text())
|
self.c_prefs.longitude_custom = float(entry.get_text())
|
||||||
self.refresh_chart()
|
self.refresh_chart()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@@ -575,7 +574,7 @@ class Preferences:
|
|||||||
|
|
||||||
def on_etr_latitude_changed(self, entry):
|
def on_etr_latitude_changed(self, entry):
|
||||||
try:
|
try:
|
||||||
self.c_prefs.prefs[PrefenceEnums.LATITUDE_CUSTOM] = float(entry.get_text())
|
self.c_prefs.latitude_custom = float(entry.get_text())
|
||||||
self.refresh_chart()
|
self.refresh_chart()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@@ -588,11 +587,10 @@ class Preferences:
|
|||||||
|
|
||||||
if tree_iter is not None:
|
if tree_iter is not None:
|
||||||
model = combobox.get_model()
|
model = combobox.get_model()
|
||||||
self.c_prefs.prefs[PrefenceEnums.PICTURE_ASPECT] = model[tree_iter][0]
|
self.c_prefs.picture_aspect = model[tree_iter][0]
|
||||||
print(self.c_prefs.prefs[PrefenceEnums.PICTURE_ASPECT])
|
|
||||||
|
|
||||||
def on_sw_dynamic_background_color_state_set(self, switch: Gtk.Switch, state):
|
def on_sw_dynamic_background_color_state_set(self, switch: Gtk.Switch, state):
|
||||||
self.c_prefs.prefs[PrefenceEnums.DYNAMIC_BACKGROUND_COLOR] = state
|
self.c_prefs.dynamic_background_color = state
|
||||||
|
|
||||||
|
|
||||||
# About
|
# About
|
||||||
|
|||||||
@@ -6,31 +6,92 @@ class Cinnamon_Pref_Handler:
|
|||||||
self.pref_location = os.path.expanduser("~") + \
|
self.pref_location = os.path.expanduser("~") + \
|
||||||
"/.config/cinnamon/spices/cinnamon-dynamic-wallpaper@TobiZog/cinnamon-dynamic-wallpaper@TobiZog.json"
|
"/.config/cinnamon/spices/cinnamon-dynamic-wallpaper@TobiZog/cinnamon-dynamic-wallpaper@TobiZog.json"
|
||||||
|
|
||||||
self.prefs = {}
|
|
||||||
|
|
||||||
self.load_preferences()
|
self.load_preferences()
|
||||||
|
|
||||||
|
|
||||||
def load_preferences(self):
|
def load_preferences(self):
|
||||||
|
""" Load the JSON preferences to the Preference object
|
||||||
|
"""
|
||||||
with open(self.pref_location, "r") as pref_file:
|
with open(self.pref_location, "r") as pref_file:
|
||||||
pref_data = json.load(pref_file)
|
pref_data = json.load(pref_file)
|
||||||
|
|
||||||
for i in pref_data:
|
self.picture_aspect = pref_data['picture_aspect']['value']
|
||||||
try:
|
self.dynamic_background_color = pref_data['dynamic_background_color']['value']
|
||||||
self.prefs[i] = pref_data[i]["value"]
|
self.image_source = pref_data['image_source']['value']
|
||||||
except:
|
self.selected_image_set = pref_data['selected_image_set']['value']
|
||||||
pass
|
self.source_folder = pref_data['source_folder']['value']
|
||||||
|
|
||||||
|
self.period_images = [
|
||||||
|
pref_data['period_0_image']['value'],
|
||||||
|
pref_data['period_1_image']['value'],
|
||||||
|
pref_data['period_2_image']['value'],
|
||||||
|
pref_data['period_3_image']['value'],
|
||||||
|
pref_data['period_4_image']['value'],
|
||||||
|
pref_data['period_5_image']['value'],
|
||||||
|
pref_data['period_6_image']['value'],
|
||||||
|
pref_data['period_7_image']['value'],
|
||||||
|
pref_data['period_8_image']['value'],
|
||||||
|
pref_data['period_9_image']['value']
|
||||||
|
]
|
||||||
|
|
||||||
|
self.period_source = pref_data['period_source']['value']
|
||||||
|
self.location_refresh_intervals = pref_data['location_refresh_intervals']['value']
|
||||||
|
self.latitude_auto = pref_data['latitude_auto']['value']
|
||||||
|
self.longitude_auto = pref_data['longitude_auto']['value']
|
||||||
|
self.latitude_custom = pref_data['latitude_custom']['value']
|
||||||
|
self.longitude_custom = pref_data['longitude_custom']['value']
|
||||||
|
|
||||||
|
self.period_custom_start_time = [
|
||||||
|
pref_data['period_0_custom_start_time']['value'],
|
||||||
|
pref_data['period_1_custom_start_time']['value'],
|
||||||
|
pref_data['period_2_custom_start_time']['value'],
|
||||||
|
pref_data['period_3_custom_start_time']['value'],
|
||||||
|
pref_data['period_4_custom_start_time']['value'],
|
||||||
|
pref_data['period_5_custom_start_time']['value'],
|
||||||
|
pref_data['period_6_custom_start_time']['value'],
|
||||||
|
pref_data['period_7_custom_start_time']['value'],
|
||||||
|
pref_data['period_8_custom_start_time']['value'],
|
||||||
|
pref_data['period_9_custom_start_time']['value']
|
||||||
|
]
|
||||||
|
|
||||||
def store_preferences(self):
|
def store_preferences(self):
|
||||||
|
""" Store the values of the Preference object to the JSON file
|
||||||
|
"""
|
||||||
with open(self.pref_location, "r") as pref_file:
|
with open(self.pref_location, "r") as pref_file:
|
||||||
pref_data = json.load(pref_file)
|
pref_data = json.load(pref_file)
|
||||||
|
|
||||||
for i in pref_data:
|
pref_data['picture_aspect']['value'] = self.picture_aspect
|
||||||
try:
|
pref_data['dynamic_background_color']['value'] = self.dynamic_background_color
|
||||||
pref_data[i]["value"] = self.prefs[i]
|
pref_data['image_source']['value'] = self.image_source
|
||||||
except:
|
pref_data['selected_image_set']['value'] = self.selected_image_set
|
||||||
pass
|
pref_data['source_folder']['value'] = self.source_folder
|
||||||
|
pref_data['period_0_image']['value'] = self.period_images[0]
|
||||||
|
pref_data['period_1_image']['value'] = self.period_images[1]
|
||||||
|
pref_data['period_2_image']['value'] = self.period_images[2]
|
||||||
|
pref_data['period_3_image']['value'] = self.period_images[3]
|
||||||
|
pref_data['period_4_image']['value'] = self.period_images[4]
|
||||||
|
pref_data['period_5_image']['value'] = self.period_images[5]
|
||||||
|
pref_data['period_6_image']['value'] = self.period_images[6]
|
||||||
|
pref_data['period_7_image']['value'] = self.period_images[7]
|
||||||
|
pref_data['period_8_image']['value'] = self.period_images[8]
|
||||||
|
pref_data['period_9_image']['value'] = self.period_images[9]
|
||||||
|
pref_data['period_source']['value'] = self.period_source
|
||||||
|
pref_data['location_refresh_intervals']['value'] = self.location_refresh_intervals
|
||||||
|
pref_data['latitude_auto']['value'] = self.latitude_auto
|
||||||
|
pref_data['longitude_auto']['value'] = self.longitude_auto
|
||||||
|
pref_data['latitude_custom']['value'] = self.latitude_custom
|
||||||
|
pref_data['longitude_custom']['value'] = self.longitude_custom
|
||||||
|
pref_data['period_0_custom_start_time']['value'] = self.period_custom_start_time[0]
|
||||||
|
pref_data['period_1_custom_start_time']['value'] = self.period_custom_start_time[1]
|
||||||
|
pref_data['period_2_custom_start_time']['value'] = self.period_custom_start_time[2]
|
||||||
|
pref_data['period_3_custom_start_time']['value'] = self.period_custom_start_time[3]
|
||||||
|
pref_data['period_4_custom_start_time']['value'] = self.period_custom_start_time[4]
|
||||||
|
pref_data['period_5_custom_start_time']['value'] = self.period_custom_start_time[5]
|
||||||
|
pref_data['period_6_custom_start_time']['value'] = self.period_custom_start_time[6]
|
||||||
|
pref_data['period_7_custom_start_time']['value'] = self.period_custom_start_time[7]
|
||||||
|
pref_data['period_8_custom_start_time']['value'] = self.period_custom_start_time[8]
|
||||||
|
pref_data['period_9_custom_start_time']['value'] = self.period_custom_start_time[9]
|
||||||
|
|
||||||
|
# Write to file
|
||||||
with open(self.pref_location, "w") as pref_file:
|
with open(self.pref_location, "w") as pref_file:
|
||||||
json.dump(pref_data, pref_file, separators=(',', ':'), indent=4)
|
json.dump(pref_data, pref_file, separators=(',', ':'), indent=4)
|
||||||
|
|||||||
Reference in New Issue
Block a user