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
|
import time
|
||||||
from sounds import WakeUpSounds
|
from sounds import WakeUpSounds
|
||||||
import json
|
import json
|
||||||
|
from hsluv import hsluv_to_rgb
|
||||||
|
|
||||||
def is_arm():
|
def is_arm():
|
||||||
if (uname()[4][:3] == 'arm') or (uname()[4][:7] == 'aarch64'):
|
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
|
# 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 rpi_backlight import Backlight
|
||||||
from rgbw_colorspace_converter.colors.converters import HSV, RGB
|
from rgbw_colorspace_converter.colors.converters import HSV, RGB
|
||||||
from hsluv import hsluv_to_rgb
|
|
||||||
|
|
||||||
Config.set('graphics', 'width', '800')
|
Config.set('graphics', 'width', '800')
|
||||||
Config.set('graphics', 'height', '480')
|
Config.set('graphics', 'height', '480')
|
||||||
|
@ -187,8 +187,11 @@ class ClockSettings():
|
||||||
class MyClockWidget(FloatLayout):
|
class MyClockWidget(FloatLayout):
|
||||||
settings = ClockSettings()
|
settings = ClockSettings()
|
||||||
|
|
||||||
#theme_selected = "Dark"
|
if settings.theme_selected == "Automatic":
|
||||||
theme = ObjectProperty(Theme(settings.theme_selected))
|
theme_name = "Light"
|
||||||
|
else:
|
||||||
|
theme_name = settings.theme_selected
|
||||||
|
theme = ObjectProperty(Theme(theme_name))
|
||||||
|
|
||||||
for x in ('', 'PCM'):
|
for x in ('', 'PCM'):
|
||||||
try:
|
try:
|
||||||
|
@ -266,7 +269,7 @@ class MyClockWidget(FloatLayout):
|
||||||
|
|
||||||
def apply_theme(self):
|
def apply_theme(self):
|
||||||
if self.settings.theme_selected == "Automatic":
|
if self.settings.theme_selected == "Automatic":
|
||||||
self.theme = Theme("Light")
|
self.theme = Theme("Dark")
|
||||||
else:
|
else:
|
||||||
self.theme = Theme(self.settings.theme_selected)
|
self.theme = Theme(self.settings.theme_selected)
|
||||||
|
|
||||||
|
@ -472,19 +475,37 @@ class MyClockWidget(FloatLayout):
|
||||||
))
|
))
|
||||||
self.ids["face"].add_widget(self.face_numbers[i - 1])
|
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):
|
def update_background(self):
|
||||||
background = self.ids["background"]
|
background = self.ids["background"]
|
||||||
self.draw_list_curr_frame.append(["canvas.clear()", background])
|
self.draw_list_curr_frame.append(["canvas.clear()", background])
|
||||||
with background.canvas:
|
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])
|
self.draw_list_curr_frame.append(["Rectangle", background.canvas, background.size, background.pos, None])
|
||||||
|
|
||||||
def update_face(self):
|
def update_face(self):
|
||||||
face_plate = self.ids["face_plate"]
|
face_plate = self.ids["face_plate"]
|
||||||
self.draw_list_curr_frame.append(["canvas.clear()", face_plate])
|
self.draw_list_curr_frame.append(["canvas.clear()", face_plate])
|
||||||
with face_plate.canvas:
|
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]])
|
color = self.theme.color_numbers
|
||||||
self.draw_list_curr_frame.append(["Ellipse", face_plate.canvas, face_plate.size, face_plate.pos])
|
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":
|
if self.view == "set_alarm":
|
||||||
t = self.settings.alarm_time
|
t = self.settings.alarm_time
|
||||||
|
@ -497,8 +518,8 @@ class MyClockWidget(FloatLayout):
|
||||||
else:
|
else:
|
||||||
offset = 12
|
offset = 12
|
||||||
|
|
||||||
self.face_numbers[i].color=self.theme.color_numbers
|
self.face_numbers[i].color = self.theme.color_numbers
|
||||||
self.face_numbers[i].text=str(i + 1 + offset)
|
self.face_numbers[i].text = str(i + 1 + offset)
|
||||||
|
|
||||||
|
|
||||||
def on_parent(self, myclock, parent):
|
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(["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])
|
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:
|
if intensity < 0:
|
||||||
intensity = 0
|
intensity = 0
|
||||||
elif intensity > 1:
|
elif intensity > 1:
|
||||||
|
@ -588,6 +609,11 @@ class MyClockWidget(FloatLayout):
|
||||||
l = 100 * intensity
|
l = 100 * intensity
|
||||||
|
|
||||||
rgb = hsluv_to_rgb([h, s, l])
|
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)
|
led_color = RGB(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255)
|
||||||
|
|
||||||
return led_color
|
return led_color
|
||||||
|
@ -833,6 +859,9 @@ class MyClockWidget(FloatLayout):
|
||||||
elif i[0] == "Ellipse":
|
elif i[0] == "Ellipse":
|
||||||
with i[1]:
|
with i[1]:
|
||||||
Ellipse(size=i[2], pos=i[3])
|
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":
|
elif i[0] == "Line":
|
||||||
with i[1]:
|
with i[1]:
|
||||||
Line(points=i[2], width=i[3], cap=i[4])
|
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_background"], True])
|
||||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["settings_menu_theme"], True])
|
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["settings_menu_theme"], True])
|
||||||
|
|
||||||
|
self.update_theme()
|
||||||
self.update_background()
|
self.update_background()
|
||||||
self.update_light_button()
|
self.update_light_button()
|
||||||
self.update_play_button()
|
self.update_play_button()
|
||||||
|
|
Loading…
Reference in New Issue