Implemented changing background for theme Automatic (WIP)
This commit is contained in:
parent
91f8c816c1
commit
3fc16bc752
50
clock.py
50
clock.py
|
@ -11,6 +11,7 @@ from kivy.properties import ObjectProperty
|
|||
import time
|
||||
from sounds import WakeUpSounds
|
||||
import json
|
||||
from hsluv import hsluv_to_rgb
|
||||
|
||||
def is_arm():
|
||||
if (uname()[4][:3] == 'arm') or (uname()[4][:7] == 'aarch64'):
|
||||
|
@ -23,7 +24,6 @@ if is_arm():
|
|||
# echo 'SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rules
|
||||
from rpi_backlight import Backlight
|
||||
from rgbw_colorspace_converter.colors.converters import HSV, RGB
|
||||
from hsluv import hsluv_to_rgb
|
||||
|
||||
Config.set('graphics', 'width', '800')
|
||||
Config.set('graphics', 'height', '480')
|
||||
|
@ -187,8 +187,11 @@ class ClockSettings():
|
|||
class MyClockWidget(FloatLayout):
|
||||
settings = ClockSettings()
|
||||
|
||||
#theme_selected = "Dark"
|
||||
theme = ObjectProperty(Theme(settings.theme_selected))
|
||||
if settings.theme_selected == "Automatic":
|
||||
theme_name = "Light"
|
||||
else:
|
||||
theme_name = settings.theme_selected
|
||||
theme = ObjectProperty(Theme(theme_name))
|
||||
|
||||
for x in ('', 'PCM'):
|
||||
try:
|
||||
|
@ -266,7 +269,7 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
def apply_theme(self):
|
||||
if self.settings.theme_selected == "Automatic":
|
||||
self.theme = Theme("Light")
|
||||
self.theme = Theme("Dark")
|
||||
else:
|
||||
self.theme = Theme(self.settings.theme_selected)
|
||||
|
||||
|
@ -472,19 +475,37 @@ class MyClockWidget(FloatLayout):
|
|||
))
|
||||
self.ids["face"].add_widget(self.face_numbers[i - 1])
|
||||
|
||||
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:
|
||||
self.draw_list_curr_frame.append(["Color", background.canvas, self.theme.color_background[0], self.theme.color_background[1], self.theme.color_background[2]])
|
||||
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])
|
||||
|
||||
def update_face(self):
|
||||
face_plate = self.ids["face_plate"]
|
||||
self.draw_list_curr_frame.append(["canvas.clear()", face_plate])
|
||||
with face_plate.canvas:
|
||||
self.draw_list_curr_frame.append(["Color", face_plate.canvas, self.theme.color_shade[0], self.theme.color_shade[1], self.theme.color_shade[2]])
|
||||
self.draw_list_curr_frame.append(["Ellipse", face_plate.canvas, face_plate.size, face_plate.pos])
|
||||
color = self.theme.color_numbers
|
||||
self.draw_list_curr_frame.append(["Color", face_plate.canvas, color[0], color[1], color[2]])
|
||||
r = face_plate.size[0] / 2
|
||||
p = [face_plate.pos[0] + r, face_plate.pos[1] + r]
|
||||
self.draw_list_curr_frame.append(["Circle", face_plate.canvas, p, r])
|
||||
#self.draw_list_curr_frame.append(["Ellipse", face_plate.canvas, face_plate.size, face_plate.pos])
|
||||
|
||||
if self.view == "set_alarm":
|
||||
t = self.settings.alarm_time
|
||||
|
@ -497,8 +518,8 @@ class MyClockWidget(FloatLayout):
|
|||
else:
|
||||
offset = 12
|
||||
|
||||
self.face_numbers[i].color=self.theme.color_numbers
|
||||
self.face_numbers[i].text=str(i + 1 + offset)
|
||||
self.face_numbers[i].color = self.theme.color_numbers
|
||||
self.face_numbers[i].text = str(i + 1 + offset)
|
||||
|
||||
|
||||
def on_parent(self, myclock, parent):
|
||||
|
@ -577,7 +598,7 @@ class MyClockWidget(FloatLayout):
|
|||
self.draw_list_curr_frame.append(["Color", settings_button.canvas, rgb[0], rgb[1], rgb[2]])
|
||||
self.draw_list_curr_frame.append(["Rectangle", settings_button.canvas, settings_button.size, settings_button.pos, source])
|
||||
|
||||
def intensity_to_rgbw(self, intensity):
|
||||
def intensity_to_rgb(self, intensity):
|
||||
if intensity < 0:
|
||||
intensity = 0
|
||||
elif intensity > 1:
|
||||
|
@ -588,6 +609,11 @@ class MyClockWidget(FloatLayout):
|
|||
l = 100 * intensity
|
||||
|
||||
rgb = hsluv_to_rgb([h, s, l])
|
||||
|
||||
return rgb
|
||||
|
||||
def intensity_to_rgbw(self, intensity):
|
||||
rgb = self.intensity_to_rgb(intensity)
|
||||
led_color = RGB(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255)
|
||||
|
||||
return led_color
|
||||
|
@ -833,6 +859,9 @@ class MyClockWidget(FloatLayout):
|
|||
elif i[0] == "Ellipse":
|
||||
with i[1]:
|
||||
Ellipse(size=i[2], pos=i[3])
|
||||
elif i[0] == "Circle":
|
||||
with i[1]:
|
||||
Line(circle=(i[2][0], i[2][1], i[3]), width=4)
|
||||
elif i[0] == "Line":
|
||||
with i[1]:
|
||||
Line(points=i[2], width=i[3], cap=i[4])
|
||||
|
@ -879,6 +908,7 @@ class MyClockWidget(FloatLayout):
|
|||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["settings_menu_theme_background"], True])
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue