Connect image set selection in preferences
This commit is contained in:
@@ -345,9 +345,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_image_set">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_image_set_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@@ -387,7 +388,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkFileChooserButton">
|
||||
<object class="GtkFileChooserButton" id="fc_heic_file">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="filter">filefilter1</property>
|
||||
@@ -431,7 +432,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkFileChooserButton">
|
||||
<object class="GtkFileChooserButton" id="fc_source_folder">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="action">select-folder</property>
|
||||
@@ -623,9 +624,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_period_0">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_period_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -633,9 +635,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_period_2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_period_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
@@ -643,9 +646,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_period_4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_period_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
@@ -653,9 +657,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_period_6">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_period_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">3</property>
|
||||
@@ -663,9 +668,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_period_8">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_period_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">4</property>
|
||||
@@ -835,9 +841,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_period_1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_period_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
@@ -845,9 +852,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_period_3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_period_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
@@ -855,9 +863,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_period_5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_period_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">3</property>
|
||||
@@ -865,9 +874,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_period_7">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_period_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
@@ -875,9 +885,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBox">
|
||||
<object class="GtkComboBox" id="cb_period_9">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="on_cb_period_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">4</property>
|
||||
|
||||
@@ -7,6 +7,7 @@ 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 enums.PreferenceEnums import PrefenceEnums
|
||||
from enums.ImageSourceEnum import ImageSourceEnum
|
||||
from enums.PeriodSourceEnum import PeriodSourceEnum
|
||||
@@ -20,8 +21,6 @@ PREFERENCES_URI = os.path.dirname(os.path.abspath(__file__))
|
||||
GLADE_URI = PREFERENCES_URI + "/preferences.glade"
|
||||
|
||||
|
||||
|
||||
|
||||
class Preferences:
|
||||
""" Preference window class
|
||||
"""
|
||||
@@ -33,21 +32,30 @@ class Preferences:
|
||||
self.builder.add_from_file(GLADE_URI)
|
||||
self.builder.connect_signals(self)
|
||||
|
||||
# Objects from external scripts
|
||||
self.time_bar_chart = Time_Bar_Chart()
|
||||
self.c_prefs = Cinnamon_Pref_Handler()
|
||||
|
||||
# Suntimes object
|
||||
self.suntimes = Suntimes()
|
||||
self.images = Images()
|
||||
|
||||
########## UI objects ##########
|
||||
|
||||
## Image Configuration
|
||||
#### Page 1: Image Configuration
|
||||
self.tb_image_set = self.builder.get_object("tb_image_set")
|
||||
self.tb_heic_file = self.builder.get_object("tb_heic_file")
|
||||
self.tb_source_folder = self.builder.get_object("tb_source_folder")
|
||||
|
||||
# Image set
|
||||
self.lbr_image_set = self.builder.get_object("lbr_image_set")
|
||||
self.cb_image_set = self.builder.get_object("cb_image_set")
|
||||
|
||||
# HEIC file
|
||||
self.lbr_heic_file = self.builder.get_object("lbr_heic_file")
|
||||
|
||||
# Source folder
|
||||
self.lbr_source_folder = self.builder.get_object("lbr_source_folder")
|
||||
|
||||
# Time bar chart
|
||||
self.img_bar_images = self.builder.get_object("img_bar_images")
|
||||
self.sw_expand_over_all_displays = self.builder.get_object("sw_expand_over_all_displays")
|
||||
self.sw_show_on_lock_screen = self.builder.get_object("sw_show_on_lock_screen")
|
||||
@@ -59,7 +67,17 @@ class Preferences:
|
||||
self.builder.get_object("etr_period_9"), self.builder.get_object("etr_period_10"),
|
||||
]
|
||||
|
||||
## Location & Times
|
||||
self.cb_periods = [
|
||||
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 = self.builder.get_object("tb_network_location")
|
||||
self.lb_current_location = self.builder.get_object("lb_current_location")
|
||||
self.lbr_current_location = self.builder.get_object("lbr_current_location")
|
||||
@@ -119,6 +137,16 @@ class Preferences:
|
||||
elif self.c_prefs.prefs[PrefenceEnums.IMAGE_SOURCE] == ImageSourceEnum.SOURCEFOLDER:
|
||||
self.tb_source_folder.set_active(True)
|
||||
|
||||
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.set_active_combobox_item(self.cb_image_set, self.c_prefs.prefs[PrefenceEnums.SELECTED_IMAGE_SET])
|
||||
|
||||
for i, combobox in enumerate(self.cb_periods):
|
||||
selected_image_name = self.c_prefs.prefs["period_%s_image" % (i)]
|
||||
self.set_active_combobox_item(combobox, selected_image_name)
|
||||
|
||||
|
||||
self.sw_expand_over_all_displays.set_active(self.c_prefs.prefs[PrefenceEnums.EXPAND_OVER_ALL_DISPLAY])
|
||||
self.sw_show_on_lock_screen.set_active(self.c_prefs.prefs[PrefenceEnums.SHOW_ON_LOCK_SCREEN])
|
||||
|
||||
@@ -130,6 +158,7 @@ class Preferences:
|
||||
elif self.c_prefs.prefs[PrefenceEnums.PERIOD_SOURCE] == PeriodSourceEnum.CUSTOMTIMEPERIODS:
|
||||
self.tb_time_periods.set_active(True)
|
||||
|
||||
|
||||
# Time diagram
|
||||
try:
|
||||
self.refresh_chart()
|
||||
@@ -150,6 +179,8 @@ class Preferences:
|
||||
|
||||
|
||||
def refresh_chart(self):
|
||||
""" Recomputes both time bar charts and load it to the UI
|
||||
"""
|
||||
# Stores the start times of the periods in minutes since midnight
|
||||
time_periods_min = []
|
||||
|
||||
@@ -193,6 +224,40 @@ class Preferences:
|
||||
self.img_bar_times.set_from_pixbuf(pixbuf2)
|
||||
|
||||
|
||||
def set_active_combobox_item(self, combobox: Gtk.ComboBoxText, active_item: str):
|
||||
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 load_image_options_to_combo_boxes(self, options: list):
|
||||
for combobox in self.cb_periods:
|
||||
self.add_items_to_combo_box(combobox, options)
|
||||
|
||||
|
||||
def load_images_to_preview(self, image_src: list):
|
||||
"""_summary_
|
||||
"""
|
||||
# todo
|
||||
pass
|
||||
|
||||
|
||||
def add_items_to_combo_box(self, combobox: Gtk.ComboBox, items: list):
|
||||
store = Gtk.ListStore(str)
|
||||
|
||||
for image_set in items:
|
||||
store.append([image_set])
|
||||
|
||||
combobox.set_model(store)
|
||||
renderer_text = Gtk.CellRendererText()
|
||||
combobox.pack_start(renderer_text, True)
|
||||
combobox.add_attribute(renderer_text, "text", 0)
|
||||
|
||||
|
||||
#################### Callbacks ####################
|
||||
|
||||
|
||||
@@ -227,6 +292,39 @@ class Preferences:
|
||||
self.lbr_image_set.set_visible(False)
|
||||
self.lbr_heic_file.set_visible(False)
|
||||
self.lbr_source_folder.set_visible(True)
|
||||
|
||||
def on_cb_image_set_changed(self, combobox):
|
||||
tree_iter = combobox.get_active_iter()
|
||||
|
||||
if tree_iter is not None:
|
||||
# Get the selected value
|
||||
model = combobox.get_model()
|
||||
selected_image_set = model[tree_iter][0]
|
||||
|
||||
# Store to the preferences
|
||||
self.c_prefs.prefs[PrefenceEnums.SELECTED_IMAGE_SET] = selected_image_set
|
||||
|
||||
# Update the ComboBoxes for image selection
|
||||
image_path = os.path.abspath(os.path.join(PREFERENCES_URI, os.pardir)) + \
|
||||
"/images/included_image_sets/" + selected_image_set + "/"
|
||||
|
||||
image_names = self.images.get_images_from_folder(image_path)
|
||||
|
||||
self.load_image_options_to_combo_boxes(image_names)
|
||||
|
||||
# todo: Load images to preview
|
||||
|
||||
|
||||
def on_cb_period_changed(self, combobox):
|
||||
tree_iter = combobox.get_active_iter()
|
||||
|
||||
combobox_name = Gtk.Buildable.get_name(combobox)
|
||||
period_index = int(combobox_name[10:12])
|
||||
|
||||
if tree_iter is not None:
|
||||
# Get the selected value
|
||||
model = combobox.get_model()
|
||||
self.c_prefs.prefs["period_%s_image" % (period_index)] = model[tree_iter][0]
|
||||
|
||||
|
||||
## Location & Times
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import os
|
||||
|
||||
class Images:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def get_images_from_folder(self, URI: str) -> list:
|
||||
items = os.listdir(URI)
|
||||
items.sort()
|
||||
return items
|
||||
@@ -1,38 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="150">
|
||||
<rect fill="#00193d" x="0" y="40" width="52" height="70"/>
|
||||
<rect fill="#05597f" x="52" y="40" width="51" height="70"/>
|
||||
<rect fill="#54babf" x="103" y="40" width="51" height="70"/>
|
||||
<rect fill="#bfe3c2" x="154" y="40" width="51" height="70"/>
|
||||
<rect fill="#ffbf6b" x="205" y="40" width="51" height="70"/>
|
||||
<rect fill="#fdb55c" x="256" y="40" width="51" height="70"/>
|
||||
<rect fill="#f37f73" x="307" y="40" width="51" height="70"/>
|
||||
<rect fill="#b45bbc" x="358" y="40" width="51" height="70"/>
|
||||
<rect fill="#7e38ce" x="409" y="40" width="501" height="70"/>
|
||||
<rect fill="#00285f" x="910" y="40" width="292" height="70"/>
|
||||
<polyline points="116.8,0 116.8,30 26.0,30 26.0,75.0" stroke="#00193d" fill="none" stroke-width="5" />
|
||||
<polyline points="116.8,150 116.8,120 77.5,120 77.5,75.0" stroke="#05597f" fill="none" stroke-width="5" />
|
||||
<polyline points="356.8,0 356.8,20 128.5,20 128.5,75.0" stroke="#54babf" fill="none" stroke-width="5" />
|
||||
<polyline points="356.8,150 356.8,130 179.5,130 179.5,75.0" stroke="#bfe3c2" fill="none" stroke-width="5" />
|
||||
<polyline points="596.8,0 596.8,10 230.5,10 230.5,75.0" stroke="#ffbf6b" fill="none" stroke-width="5" />
|
||||
<polyline points="596.8,150 596.8,140 281.5,140 281.5,75.0" stroke="#fdb55c" fill="none" stroke-width="5" />
|
||||
<polyline points="836.8,0 836.8,20 332.5,20 332.5,75.0" stroke="#f37f73" fill="none" stroke-width="5" />
|
||||
<polyline points="836.8,150 836.8,130 383.5,130 383.5,75.0" stroke="#b45bbc" fill="none" stroke-width="5" />
|
||||
<polyline points="1076.8,0 1076.8,30 659.5,30 659.5,75.0" stroke="#7e38ce" fill="none" stroke-width="5" />
|
||||
<polyline points="1076.8,150 1076.8,120 1055.0,120 1055.0,75.0" stroke="#00285f" fill="none" stroke-width="5" />
|
||||
<line x1="0" y1="40" x2="0" y2="110" stroke="gray" stroke-width="2" />
|
||||
<text x="5" y="105" fill="gray" font-size="20" font-family="Liberation Sans">0</text>
|
||||
<line x1="150" y1="40" x2="150" y2="110" stroke="gray" stroke-width="2" />
|
||||
<text x="155" y="105" fill="gray" font-size="20" font-family="Liberation Sans">3</text>
|
||||
<line x1="300" y1="40" x2="300" y2="110" stroke="gray" stroke-width="2" />
|
||||
<text x="305" y="105" fill="gray" font-size="20" font-family="Liberation Sans">6</text>
|
||||
<line x1="450" y1="40" x2="450" y2="110" stroke="gray" stroke-width="2" />
|
||||
<text x="455" y="105" fill="gray" font-size="20" font-family="Liberation Sans">9</text>
|
||||
<line x1="600" y1="40" x2="600" y2="110" stroke="gray" stroke-width="2" />
|
||||
<text x="605" y="105" fill="gray" font-size="20" font-family="Liberation Sans">12</text>
|
||||
<line x1="750" y1="40" x2="750" y2="110" stroke="gray" stroke-width="2" />
|
||||
<text x="755" y="105" fill="gray" font-size="20" font-family="Liberation Sans">15</text>
|
||||
<line x1="900" y1="40" x2="900" y2="110" stroke="gray" stroke-width="2" />
|
||||
<text x="905" y="105" fill="gray" font-size="20" font-family="Liberation Sans">18</text>
|
||||
<line x1="1050" y1="40" x2="1050" y2="110" stroke="gray" stroke-width="2" />
|
||||
<text x="1055" y="105" fill="gray" font-size="20" font-family="Liberation Sans">21</text>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 3.0 KiB |
Reference in New Issue
Block a user