Switch between Dark and Light theme at 7:00 and 19:00 for theme Automatic
This commit is contained in:
parent
a995942d25
commit
502406663e
68
clock.py
68
clock.py
|
@ -80,7 +80,7 @@ class Theme():
|
|||
f = open("themes/" + x + "/theme.json")
|
||||
j = json.load(f)
|
||||
f.close()
|
||||
self.name = j["name"]
|
||||
self.name = x
|
||||
self.color_background = j["color_background"]
|
||||
self.color_shade = j["color_shade"]
|
||||
self.color_clock_hands_hours = j["color_clock_hands_hours"]
|
||||
|
@ -267,11 +267,51 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
is_arm = is_arm()
|
||||
|
||||
def update_background_automatic_sunrise(self):
|
||||
background = self.ids["background"]
|
||||
self.draw_list_curr_frame.append(["canvas.clear()", background])
|
||||
with background.canvas:
|
||||
color = self.intensity_to_rgb(self.intensity_curr)
|
||||
|
||||
self.draw_list_curr_frame.append(["Color", background.canvas, color[0], color[1], color[2]])
|
||||
self.draw_list_curr_frame.append(["Rectangle", background.canvas, background.size, background.pos, None])
|
||||
|
||||
def update_background_automatic_no_sunrise(self):
|
||||
background = self.ids["background"]
|
||||
self.draw_list_curr_frame.append(["canvas.clear()", background])
|
||||
with background.canvas:
|
||||
color = self.theme.color_background
|
||||
|
||||
self.draw_list_curr_frame.append(["Color", background.canvas, color[0], color[1], color[2]])
|
||||
self.draw_list_curr_frame.append(["Rectangle", background.canvas, background.size, background.pos, None])
|
||||
|
||||
def apply_theme(self):
|
||||
if self.settings.theme_selected == "Automatic":
|
||||
self.theme = Theme("Dark")
|
||||
if (self.light_state != "sunrise") and (self.light_state != "on"):
|
||||
# switch to light theme after 7:00 AM, to dark theme after 19:00
|
||||
t = datetime.datetime.now()
|
||||
h = t.hour + t.minute / 60
|
||||
if (h >= 7) and (h < 19):
|
||||
if self.theme.name != "Light":
|
||||
self.theme = Theme("Light")
|
||||
else:
|
||||
if self.theme.name != "Dark":
|
||||
self.theme = Theme("Dark")
|
||||
|
||||
self.update_background_automatic_no_sunrise()
|
||||
|
||||
else:
|
||||
if self.intensity_curr >= 0.5:
|
||||
self.theme = Theme("Light")
|
||||
else:
|
||||
self.theme = Theme("Dark")
|
||||
|
||||
self.update_background_automatic_sunrise()
|
||||
|
||||
else:
|
||||
self.theme = Theme(self.settings.theme_selected)
|
||||
if self.theme.name != self.settings.theme_selected:
|
||||
self.theme = Theme(self.settings.theme_selected)
|
||||
self.update_background_automatic_no_sunrise()
|
||||
|
||||
self.ids["settings_menu_wake_up_sound_label_top"].color = self.theme.color_font
|
||||
self.settings_menu_wake_up_sound_Ok_button.color = self.theme.color_font
|
||||
|
@ -477,24 +517,7 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
def update_theme(self):
|
||||
if self.settings.theme_selected == "Automatic":
|
||||
if self.intensity_curr >= 0.5:
|
||||
if self.theme.name != "Light":
|
||||
self.theme = Theme("Light")
|
||||
else:
|
||||
if self.theme.name != "Dark":
|
||||
self.theme = Theme("Dark")
|
||||
|
||||
def update_background(self):
|
||||
background = self.ids["background"]
|
||||
self.draw_list_curr_frame.append(["canvas.clear()", background])
|
||||
with background.canvas:
|
||||
if self.settings.theme_selected == "Automatic":
|
||||
color = self.intensity_to_rgb(self.intensity_curr)
|
||||
else:
|
||||
color = self.theme.color_background
|
||||
|
||||
self.draw_list_curr_frame.append(["Color", background.canvas, color[0], color[1], color[2]])
|
||||
self.draw_list_curr_frame.append(["Rectangle", background.canvas, background.size, background.pos, None])
|
||||
self.apply_theme()
|
||||
|
||||
def update_face(self):
|
||||
face_plate = self.ids["face_plate"]
|
||||
|
@ -909,7 +932,6 @@ class MyClockWidget(FloatLayout):
|
|||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["settings_menu_theme"], True])
|
||||
|
||||
self.update_theme()
|
||||
self.update_background()
|
||||
self.update_light_button()
|
||||
self.update_play_button()
|
||||
self.update_set_alarm_button()
|
||||
|
@ -1021,8 +1043,8 @@ class MyClockWidget(FloatLayout):
|
|||
print("You deselected " + theme)
|
||||
|
||||
self.settings.theme_selected = theme
|
||||
|
||||
self.apply_theme()
|
||||
self.settings.write()
|
||||
|
||||
def volume_slider_value(self, *args):
|
||||
self.settings.wake_up_volume = int(args[1])
|
||||
|
|
Loading…
Reference in New Issue