More work on themes
354
clock.py
|
@ -7,7 +7,7 @@ import traceback
|
|||
import copy
|
||||
import os
|
||||
from kivy.config import Config
|
||||
from kivy.properties import ListProperty
|
||||
from kivy.properties import ObjectProperty
|
||||
import time
|
||||
|
||||
def is_arm():
|
||||
|
@ -39,11 +39,14 @@ if is_arm():
|
|||
)
|
||||
pixels.fill((0, 0, 0, 0))
|
||||
pixels.show()
|
||||
|
||||
backlight = Backlight()
|
||||
else:
|
||||
Config.set('graphics', 'width', '1200')
|
||||
Config.set('graphics', 'height', '720')
|
||||
|
||||
pixels = None
|
||||
backlight = None
|
||||
|
||||
Config.set('graphics', 'maxfps', '60')
|
||||
|
||||
|
@ -54,7 +57,7 @@ from kivy.uix.slider import Slider
|
|||
from kivy.uix.button import Button
|
||||
from kivy.clock import Clock
|
||||
from kivy.lang import Builder
|
||||
from kivy.graphics import Color, Line, Rectangle
|
||||
from kivy.graphics import Color, Line, Rectangle, Ellipse
|
||||
from kivy.core.window import Window
|
||||
|
||||
if is_arm():
|
||||
|
@ -70,22 +73,40 @@ Builder.load_string('''
|
|||
|
||||
canvas:
|
||||
Color:
|
||||
rgb: root.color_background
|
||||
rgb: root.theme.color_background
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
|
||||
FloatLayout
|
||||
id: background
|
||||
size_hint: None, None
|
||||
pos_hint: {"center_x":0.5, "center_y":0.5}
|
||||
size: root.size
|
||||
canvas:
|
||||
Color:
|
||||
rgb: root.theme.color_background
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
|
||||
FloatLayout
|
||||
id: face_plate
|
||||
size_hint: None, None
|
||||
pos_hint: {"center_x":0.5, "center_y":0.5}
|
||||
size: 0.9*min(root.size), 0.9*min(root.size)
|
||||
canvas:
|
||||
Color:
|
||||
rgb: root.theme.color_shade
|
||||
Ellipse:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
|
||||
FloatLayout
|
||||
id: face
|
||||
size_hint: None, None
|
||||
pos_hint: {"center_x":0.5, "center_y":0.5}
|
||||
size: 0.9*min(root.size), 0.9*min(root.size)
|
||||
canvas:
|
||||
Color:
|
||||
rgb: root.color_shade
|
||||
Ellipse:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
|
||||
FloatLayout
|
||||
id: hands
|
||||
|
@ -124,12 +145,12 @@ Builder.load_string('''
|
|||
size: 0.8*min(root.size), 0.7*min(root.size)
|
||||
canvas:
|
||||
Color:
|
||||
rgb: root.color_shade
|
||||
rgb: root.theme.color_shade
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
GridLayout:
|
||||
rows: 8
|
||||
rows: 9
|
||||
cols: 2
|
||||
pos_hint: {"center_x":0.5, "center_y":0.5}
|
||||
Label:
|
||||
|
@ -138,7 +159,7 @@ Builder.load_string('''
|
|||
valign: "middle"
|
||||
font_size: root.height*0.05
|
||||
text_size: self.size
|
||||
color: root.color_font
|
||||
color: root.theme.color_font
|
||||
Slider:
|
||||
id: volume_slider
|
||||
min: 0
|
||||
|
@ -153,22 +174,22 @@ Builder.load_string('''
|
|||
valign: "middle"
|
||||
font_size: root.height*0.05
|
||||
text_size: self.size
|
||||
color: root.color_font
|
||||
color: root.theme.color_font
|
||||
Button:
|
||||
id: settings_menu_wake_up_sound_select_button
|
||||
on_press: root.settings_menu_wake_up_sound_select_button_cb()
|
||||
font_size: root.height*0.05
|
||||
text: str(app.alarm_settings.sound_selected)
|
||||
color: root.color_font
|
||||
color: root.theme.color_font
|
||||
background_normal: ''
|
||||
background_color: root.color_button
|
||||
background_color: root.theme.color_button
|
||||
Label:
|
||||
text:"Wake up brightness"
|
||||
halign: "left"
|
||||
valign: "middle"
|
||||
font_size: root.height*0.05
|
||||
text_size: self.size
|
||||
color: root.color_font
|
||||
color: root.theme.color_font
|
||||
Slider:
|
||||
id: wake_up_bightness_slider
|
||||
min: 0
|
||||
|
@ -183,7 +204,7 @@ Builder.load_string('''
|
|||
valign: "middle"
|
||||
font_size: root.height*0.05
|
||||
text_size: self.size
|
||||
color: root.color_font
|
||||
color: root.theme.color_font
|
||||
Slider:
|
||||
id: reading_light_brightness_slider
|
||||
min: 1
|
||||
|
@ -198,7 +219,7 @@ Builder.load_string('''
|
|||
valign: "middle"
|
||||
font_size: root.height*0.05
|
||||
text_size: self.size
|
||||
color: root.color_font
|
||||
color: root.theme.color_font
|
||||
Slider:
|
||||
id: display_brightness_slider
|
||||
min: 0
|
||||
|
@ -207,6 +228,21 @@ Builder.load_string('''
|
|||
on_value: root.display_brightness_slider_value(*args)
|
||||
value_track: True
|
||||
value_track_color: [1, 0, 0, 1]
|
||||
Label:
|
||||
text:"Theme"
|
||||
halign: "left"
|
||||
valign: "middle"
|
||||
font_size: root.height*0.05
|
||||
text_size: self.size
|
||||
color: root.theme.color_font
|
||||
Button:
|
||||
id: settings_menu_theme_select_button
|
||||
on_press: root.settings_menu_theme_select_button_cb()
|
||||
font_size: root.height*0.05
|
||||
text: str(root.theme.name)
|
||||
color: root.theme.color_font
|
||||
background_normal: ''
|
||||
background_color: root.theme.color_button
|
||||
FloatLayout
|
||||
id: settings_menu_wake_up_sound
|
||||
size_hint: None, None
|
||||
|
@ -214,7 +250,7 @@ Builder.load_string('''
|
|||
size: 0.8*min(root.size), 0.8*min(root.size)
|
||||
canvas:
|
||||
Color:
|
||||
rgb: root.color_shade
|
||||
rgb: root.theme.color_shade
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
|
@ -224,7 +260,7 @@ Builder.load_string('''
|
|||
Label:
|
||||
text: "Select wake up sound"
|
||||
font_size: root.height*0.05
|
||||
color: root.color_font
|
||||
color: root.theme.color_font
|
||||
GridLayout:
|
||||
cols: 2
|
||||
CheckBox:
|
||||
|
@ -237,7 +273,7 @@ Builder.load_string('''
|
|||
valign: "middle"
|
||||
text_size: self.size
|
||||
font_size: root.height*0.05
|
||||
color: root.color_font
|
||||
color: root.theme.color_font
|
||||
active: True
|
||||
CheckBox:
|
||||
group: "settings_menu_wake_up_sound"
|
||||
|
@ -249,19 +285,120 @@ Builder.load_string('''
|
|||
valign: "middle"
|
||||
text_size: self.size
|
||||
font_size: root.height*0.05
|
||||
color: root.color_font
|
||||
color: root.theme.color_font
|
||||
Button:
|
||||
id: settings_menu_wake_up_sound_Ok_button
|
||||
on_press: root.settings_menu_wake_up_sound_Ok_button_cb()
|
||||
text: "Ok"
|
||||
font_size: root.height*0.05
|
||||
color: root.color_font
|
||||
color: root.theme.color_font
|
||||
background_normal: ''
|
||||
background_color: root.color_button
|
||||
background_color: root.theme.color_button
|
||||
FloatLayout
|
||||
id: settings_menu_theme
|
||||
size_hint: None, None
|
||||
pos_hint: {"center_x":0.5, "center_y":0.5}
|
||||
size: 0.8*min(root.size), 0.8*min(root.size)
|
||||
canvas:
|
||||
Color:
|
||||
rgb: root.theme.color_shade
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
pos_hint: {"center_x":0.5, "center_y":0.5}
|
||||
Label:
|
||||
text: "Select theme"
|
||||
font_size: root.height*0.05
|
||||
color: root.theme.color_font
|
||||
GridLayout:
|
||||
cols: 2
|
||||
CheckBox:
|
||||
group: "settings_menu_theme"
|
||||
on_active: root.settings_menu_theme_cb(self, self.active, "Dark")
|
||||
id: settings_menu_theme_Dark
|
||||
Label:
|
||||
text: "Dark"
|
||||
halign: "left"
|
||||
valign: "middle"
|
||||
text_size: self.size
|
||||
font_size: root.height*0.05
|
||||
color: root.theme.color_font
|
||||
active: True
|
||||
CheckBox:
|
||||
group: "settings_menu_theme"
|
||||
on_active: root.settings_menu_theme_cb(self, self.active, "Light")
|
||||
id: settings_menu_theme_Light
|
||||
Label:
|
||||
text: "Light"
|
||||
halign: "left"
|
||||
valign: "middle"
|
||||
text_size: self.size
|
||||
font_size: root.height*0.05
|
||||
color: root.theme.color_font
|
||||
Button:
|
||||
id: settings_menu_theme_Ok_button
|
||||
on_press: root.settings_menu_theme_Ok_button_cb()
|
||||
text: "Ok"
|
||||
font_size: root.height*0.05
|
||||
color: root.theme.color_font
|
||||
background_normal: ''
|
||||
background_color: root.theme.color_button
|
||||
''')
|
||||
|
||||
Position = collections.namedtuple('Position', 'x y')
|
||||
|
||||
class Theme():
|
||||
def __init__(self, x="Dark"):
|
||||
self.name = x
|
||||
if x == "Dark":
|
||||
self.color_background = [0, 0, 0]
|
||||
self.color_shade = [.1, .1, .1]
|
||||
self.color_clock_hands_hours = [.9, .9, .9]
|
||||
self.color_clock_hands_minutes = [.8, .8, .8]
|
||||
self.color_clock_hands_seconds = [.7, .7, .7]
|
||||
self.color_alarm_hands_hours = [.9, .0, .0]
|
||||
self.color_alarm_hands_minutes = [.8, .0, .0]
|
||||
self.color_alarm_hands_seconds = [.7, .0, .0]
|
||||
self.color_font = [1, 1, 1]
|
||||
self.color_numbers = [1, 1, 1]
|
||||
self.color_button = [.2, .2, .2, 1]
|
||||
|
||||
self.icon_light_off = 'icons/dark/light_off.png'
|
||||
self.icon_light_reading = 'icons/dark/light_reading.png'
|
||||
self.icon_light_sunrise = 'icons/dark/light_sunrise.png'
|
||||
self.icon_light_on = 'icons/dark/light_on.png'
|
||||
self.icon_media_playing = 'icons/dark/media_playing.png'
|
||||
self.icon_media_stopped = 'icons/dark/media_stopped.png'
|
||||
self.icon_alarm_on = 'icons/dark/alarm_on.png'
|
||||
self.icon_alarm_off = 'icons/dark/alarm_off.png'
|
||||
self.icon_settings_visible = 'icons/dark/settings_visible.png'
|
||||
self.icon_settings_not_visible = 'icons/dark/settings_not_visible.png'
|
||||
elif x == "Light":
|
||||
self.color_background = [1, 1, 1]
|
||||
self.color_shade = [.9, .9, .9]
|
||||
self.color_clock_hands_hours = [.1, .1, .1]
|
||||
self.color_clock_hands_minutes = [.2, .2, .2]
|
||||
self.color_clock_hands_seconds = [.3, .3, .3]
|
||||
self.color_alarm_hands_hours = [.9, .0, .0]
|
||||
self.color_alarm_hands_minutes = [.8, .0, .0]
|
||||
self.color_alarm_hands_seconds = [.7, .0, .0]
|
||||
self.color_font = [0, 0, 0]
|
||||
self.color_numbers = [0, 0, 0]
|
||||
self.color_button = [.8, .8, .8, 1]
|
||||
|
||||
self.icon_light_off = 'icons/light/light_off.png'
|
||||
self.icon_light_reading = 'icons/light/light_reading.png'
|
||||
self.icon_light_sunrise = 'icons/light/light_sunrise.png'
|
||||
self.icon_light_on = 'icons/light/light_on.png'
|
||||
self.icon_media_playing = 'icons/light/media_playing.png'
|
||||
self.icon_media_stopped = 'icons/light/media_stopped.png'
|
||||
self.icon_alarm_on = 'icons/light/alarm_on.png'
|
||||
self.icon_alarm_off = 'icons/light/alarm_off.png'
|
||||
self.icon_settings_visible = 'icons/light/settings_visible.png'
|
||||
self.icon_settings_not_visible = 'icons/light/settings_not_visible.png'
|
||||
|
||||
class AlarmSettings():
|
||||
alarm_time = datetime.datetime(2022, 12, 10, 7, 30, 0, 0)
|
||||
alarm_activated = False
|
||||
|
@ -313,6 +450,8 @@ class TouchEvent():
|
|||
self.processed = False
|
||||
|
||||
class MyClockWidget(FloatLayout):
|
||||
theme = ObjectProperty(Theme("Light"))
|
||||
|
||||
grabbed = ""
|
||||
face_numbers = []
|
||||
|
||||
|
@ -343,6 +482,7 @@ class MyClockWidget(FloatLayout):
|
|||
# - "set_alarm"
|
||||
# - "settings_menu"
|
||||
# - "settings_menu_wake_up_sound"
|
||||
# - "settings_menu_theme"
|
||||
view = "clock"
|
||||
view_active_since = time.time()
|
||||
|
||||
|
@ -353,6 +493,7 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
# we need a dirty hack to sensure that radio button is always in sync with selected setting
|
||||
settings_menu_wake_up_sound_select_button_cb_hack = False
|
||||
settings_menu_theme_select_button_cb_hack = False
|
||||
|
||||
# defer drawing to improve application speed: if list of draw calls for
|
||||
# this frame is identical to list of previous frame then nothing needs to
|
||||
|
@ -367,59 +508,6 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
is_arm = is_arm()
|
||||
|
||||
if is_arm:
|
||||
backlight = Backlight()
|
||||
else:
|
||||
backlight = None
|
||||
|
||||
color_background = ListProperty([0, 0, 0])
|
||||
color_shade = ListProperty([.1, .1, .1])
|
||||
color_clock_hands_hours = ListProperty([.9, .9, .9])
|
||||
color_clock_hands_minutes = ListProperty([.8, .8, .8])
|
||||
color_clock_hands_seconds = ListProperty([.7, .7, .7])
|
||||
color_alarm_hands_hours = ListProperty([.9, .0, .0])
|
||||
color_alarm_hands_minutes = ListProperty([.8, .0, .0])
|
||||
color_alarm_hands_seconds = ListProperty([.7, .0, .0])
|
||||
color_font = ListProperty([1, 1, 1])
|
||||
color_numbers = ListProperty([1, 1, 1])
|
||||
color_button = ListProperty([.2, .2, .2, 1])
|
||||
|
||||
icon_light_off = 'icons/dark/light_off.png'
|
||||
icon_light_reading = 'icons/dark/light_reading.png'
|
||||
icon_light_sunrise = 'icons/dark/light_sunrise.png'
|
||||
icon_light_on = 'icons/dark/light_on.png'
|
||||
icon_media_playing = 'icons/dark/white_media_playing.png'
|
||||
icon_media_stopped = 'icons/dark/media_stopped.png'
|
||||
icon_alarm_on = 'icons/dark/alarm_on.png'
|
||||
icon_alarm_off = 'icons/dark/alarm_off.png'
|
||||
icon_settings_visible = 'icons/dark/settings_visible.png'
|
||||
icon_settings_not_visible = 'icons/dark/settings_not_visible.png'
|
||||
"""
|
||||
|
||||
color_background = ListProperty([1, 1, 1])
|
||||
color_shade = ListProperty([.9, .9, .9])
|
||||
color_clock_hands_hours = ListProperty([.1, .1, .1])
|
||||
color_clock_hands_minutes = ListProperty([.2, .2, .2])
|
||||
color_clock_hands_seconds = ListProperty([.3, .3, .3])
|
||||
color_alarm_hands_hours = ListProperty([.9, .0, .0])
|
||||
color_alarm_hands_minutes = ListProperty([.8, .0, .0])
|
||||
color_alarm_hands_seconds = ListProperty([.7, .0, .0])
|
||||
color_font = ListProperty([0, 0, 0])
|
||||
color_numbers = ListProperty([0, 0, 0])
|
||||
color_button = ListProperty([.8, .8, .8, 1])
|
||||
|
||||
icon_light_off = 'icons/light/light_off.png'
|
||||
icon_light_reading = 'icons/light/light_reading.png'
|
||||
icon_light_sunrise = 'icons/light/light_sunrise.png'
|
||||
icon_light_on = 'icons/light/light_on.png'
|
||||
icon_media_playing = 'icons/light/media_playing.png'
|
||||
icon_media_stopped = 'icons/light/media_stopped.png'
|
||||
icon_alarm_on = 'icons/light/alarm_on.png'
|
||||
icon_alarm_off = 'icons/light/alarm_off.png'
|
||||
icon_settings_visible = 'icons/light/settings_visible.png'
|
||||
icon_settings_not_visible = 'icons/light/settings_not_visible.png'
|
||||
"""
|
||||
|
||||
def play_sound(self, source):
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
|
@ -448,7 +536,8 @@ class MyClockWidget(FloatLayout):
|
|||
y = c**x + offset
|
||||
z = max(1, round(y))
|
||||
if self.is_arm:
|
||||
self.backlight.brightness = z
|
||||
if backlight.brightness != z:
|
||||
backlight.brightness = z
|
||||
|
||||
def hide_widget(self, widget, hide=True):
|
||||
if hasattr(widget, 'saved_attrs'):
|
||||
|
@ -480,7 +569,7 @@ class MyClockWidget(FloatLayout):
|
|||
self.face_numbers.append(Label(
|
||||
text=str(i + offset),
|
||||
font_size=float(Config.get('graphics', 'height'))*0.05,
|
||||
color=self.color_numbers,
|
||||
color=self.theme.color_numbers,
|
||||
pos_hint={
|
||||
# pos_hint is a fraction in range (0, 1)
|
||||
"center_x": 0.5 + 0.45*math.sin(2 * math.pi * i/12),
|
||||
|
@ -489,9 +578,22 @@ class MyClockWidget(FloatLayout):
|
|||
))
|
||||
self.ids["face"].add_widget(self.face_numbers[i - 1])
|
||||
|
||||
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]])
|
||||
self.draw_list_curr_frame.append(["Rectangle", background.canvas, background.size, background.pos, None])
|
||||
|
||||
def update_face(self):
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
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])
|
||||
|
||||
if self.view == "set_alarm":
|
||||
t = alarm_settings.alarm_time
|
||||
else:
|
||||
|
@ -503,6 +605,7 @@ class MyClockWidget(FloatLayout):
|
|||
else:
|
||||
offset = 12
|
||||
|
||||
self.face_numbers[i].color=self.theme.color_numbers
|
||||
self.face_numbers[i].text=str(i + 1 + offset)
|
||||
|
||||
|
||||
|
@ -522,16 +625,16 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
def update_light_button(self):
|
||||
if (self.light_state == "off"):
|
||||
source = self.icon_light_off
|
||||
source = self.theme.icon_light_off
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
elif (self.light_state == "reading"):
|
||||
source = self.icon_light_reading
|
||||
source = self.theme.icon_light_reading
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
elif (self.light_state == "sunrise"):
|
||||
source = self.light_sunrise
|
||||
source = self.theme.icon_light_sunrise
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
elif (self.light_state == "on"):
|
||||
source = self.light_on
|
||||
source = self.theme.icon_light_on
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
|
||||
light_button = self.ids["light_button"]
|
||||
|
@ -544,10 +647,10 @@ class MyClockWidget(FloatLayout):
|
|||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
if alarm_settings.alarm_playing:
|
||||
source = self.icon_media_playing
|
||||
source = self.theme.icon_media_playing
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
else:
|
||||
source = self.icon_media_stopped
|
||||
source = self.theme.icon_media_stopped
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
|
||||
play_button = self.ids["play_button"]
|
||||
|
@ -560,27 +663,26 @@ class MyClockWidget(FloatLayout):
|
|||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
if (self.view == "set_alarm") or alarm_settings.alarm_activated:
|
||||
source = self.icon_alarm_on
|
||||
source = self.theme.icon_alarm_on
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
else:
|
||||
source = self.icon_alarm_off
|
||||
source = self.theme.icon_alarm_off
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
|
||||
set_alarm_button = self.ids["set_alarm_button"]
|
||||
self.draw_list_curr_frame.append(["canvas.clear()", set_alarm_button])
|
||||
with set_alarm_button.canvas:
|
||||
self.draw_list_curr_frame.append(["Color", set_alarm_button.canvas, rgb[0], rgb[1], rgb[2]])
|
||||
# Rectangle(size=set_alarm_button.size, pos=set_alarm_button.pos, source=source)
|
||||
self.draw_list_curr_frame.append(["Rectangle", set_alarm_button.canvas, set_alarm_button.size, set_alarm_button.pos, source])
|
||||
|
||||
def update_settings_button(self):
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
if (self.view.startswith("settings_menu")):
|
||||
source = self.icon_settings_visible
|
||||
source = self.theme.icon_settings_visible
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
else:
|
||||
source = self.icon_settings_not_visible
|
||||
source = self.theme.icon_settings_not_visible
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
|
||||
settings_button = self.ids["settings_button"]
|
||||
|
@ -706,6 +808,7 @@ class MyClockWidget(FloatLayout):
|
|||
self.check_play_sound()
|
||||
|
||||
def update_clock(self):
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["face_plate"], False])
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["face"], False])
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["hands"], False])
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
@ -720,18 +823,15 @@ class MyClockWidget(FloatLayout):
|
|||
minutes_hand = self.position_on_clock(t.minute/60+t.second/3600, length=0.40*hands.size[0])
|
||||
hours_hand = self.position_on_clock(t.hour/12 + t.minute/720, length=0.35*hands.size[0])
|
||||
|
||||
self.update_face()
|
||||
|
||||
#hands.canvas.clear()
|
||||
self.draw_list_curr_frame.append(["canvas.clear()", hands])
|
||||
update_rate = App.get_running_app().update_rate
|
||||
with hands.canvas:
|
||||
if self.view == "set_alarm":
|
||||
if self.grabbed != "" or self.set_alarm_timeout_counter < 1 * update_rate or \
|
||||
self.set_alarm_timeout_counter % update_rate <= update_rate / 2 or alarm_settings.alarm_modified == False:
|
||||
self.draw_list_curr_frame.append(["Color", hands.canvas, self.color_alarm_hands_hours[0], self.color_alarm_hands_hours[1], self.color_alarm_hands_hours[2]])
|
||||
self.draw_list_curr_frame.append(["Color", hands.canvas, self.theme.color_alarm_hands_hours[0], self.theme.color_alarm_hands_hours[1], self.theme.color_alarm_hands_hours[2]])
|
||||
self.draw_list_curr_frame.append(["Line", hands.canvas, [hands.center_x, hands.center_y, hours_hand.x, hours_hand.y], 3, "round"])
|
||||
self.draw_list_curr_frame.append(["Color", hands.canvas, self.color_alarm_hands_minutes[0], self.color_alarm_hands_minutes[1], self.color_alarm_hands_minutes[2]])
|
||||
self.draw_list_curr_frame.append(["Color", hands.canvas, self.theme.color_alarm_hands_minutes[0], self.theme.color_alarm_hands_minutes[1], self.theme.color_alarm_hands_minutes[2]])
|
||||
self.draw_list_curr_frame.append(["Line", hands.canvas, [hands.center_x, hands.center_y, minutes_hand.x, minutes_hand.y], 2, "round"])
|
||||
|
||||
if self.grabbed == "":
|
||||
|
@ -746,18 +846,21 @@ class MyClockWidget(FloatLayout):
|
|||
alarm_settings.alarm_activated = True
|
||||
alarm_settings.alarm_modified = False
|
||||
else:
|
||||
self.draw_list_curr_frame.append(["Color", hands.canvas, self.color_clock_hands_hours[0], self.color_clock_hands_hours[1], self.color_clock_hands_hours[2]])
|
||||
self.draw_list_curr_frame.append(["Color", hands.canvas, self.theme.color_clock_hands_hours[0], self.theme.color_clock_hands_hours[1], self.theme.color_clock_hands_hours[2]])
|
||||
self.draw_list_curr_frame.append(["Line", hands.canvas, [hands.center_x, hands.center_y, hours_hand.x, hours_hand.y], 3, "round"])
|
||||
self.draw_list_curr_frame.append(["Color", hands.canvas, self.color_clock_hands_minutes[0], self.color_clock_hands_minutes[1], self.color_clock_hands_minutes[2]])
|
||||
self.draw_list_curr_frame.append(["Color", hands.canvas, self.theme.color_clock_hands_minutes[0], self.theme.color_clock_hands_minutes[1], self.theme.color_clock_hands_minutes[2]])
|
||||
self.draw_list_curr_frame.append(["Line", hands.canvas, [hands.center_x, hands.center_y, minutes_hand.x, minutes_hand.y], 2, "round"])
|
||||
self.draw_list_curr_frame.append(["Color", hands.canvas, self.color_clock_hands_seconds[0], self.color_clock_hands_seconds[1], self.color_clock_hands_seconds[2]])
|
||||
self.draw_list_curr_frame.append(["Color", hands.canvas, self.theme.color_clock_hands_seconds[0], self.theme.color_clock_hands_seconds[1], self.theme.color_clock_hands_seconds[2]])
|
||||
self.draw_list_curr_frame.append(["Line", hands.canvas, [hands.center_x, hands.center_y, seconds_hand.x, seconds_hand.y], 1, "round"])
|
||||
self.update_face()
|
||||
|
||||
def update_settings(self):
|
||||
if self.view == "settings_menu":
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["settings_menu"], False])
|
||||
elif self.view == "settings_menu_wake_up_sound":
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["settings_menu_wake_up_sound"], False])
|
||||
elif self.view == "settings_menu_theme":
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["settings_menu_theme"], False])
|
||||
|
||||
def draw_display(self):
|
||||
if self.draw_list_curr_frame != self.draw_list_last_frame:
|
||||
|
@ -772,6 +875,9 @@ class MyClockWidget(FloatLayout):
|
|||
elif i[0] == "Rectangle":
|
||||
with i[1]:
|
||||
Rectangle(size=i[2], pos=i[3], source=i[4])
|
||||
elif i[0] == "Ellipse":
|
||||
with i[1]:
|
||||
Ellipse(size=i[2], pos=i[3])
|
||||
elif i[0] == "Line":
|
||||
with i[1]:
|
||||
Line(points=i[2], width=i[3], cap=i[4])
|
||||
|
@ -808,11 +914,14 @@ class MyClockWidget(FloatLayout):
|
|||
self.check_alarm()
|
||||
|
||||
# Hide all dynamic widgets; will be enabled when updating respecive view
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["face_plate"], True])
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["face"], True])
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["hands"], True])
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["settings_menu"], True])
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["settings_menu_wake_up_sound"], True])
|
||||
self.draw_list_curr_frame.append(["self.hide_widget", self.ids["settings_menu_theme"], True])
|
||||
|
||||
self.update_background()
|
||||
self.update_light_button()
|
||||
self.update_play_button()
|
||||
self.update_set_alarm_button()
|
||||
|
@ -870,6 +979,43 @@ class MyClockWidget(FloatLayout):
|
|||
alarm_settings.sound_selected = sound
|
||||
alarm_settings.sound_source = "https://icecast.omroep.nl/radio1-bb-mp3"
|
||||
|
||||
def settings_menu_theme_select_button_cb(self):
|
||||
self.settings_menu_wake_up_theme_button_cb_hack = True
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
self.ids["settings_menu_theme_Dark"].active = False
|
||||
self.ids["settings_menu_theme_Light"].active = False
|
||||
print("theme selected: " + self.theme.name)
|
||||
if self.theme.name == "Dark":
|
||||
self.ids["settings_menu_theme_Dark"].active = True
|
||||
elif self.theme.name == "Light":
|
||||
self.ids["settings_menu_theme_Light"].active = True
|
||||
|
||||
self.view = "settings_menu_theme"
|
||||
self.view_active_since = time.time()
|
||||
|
||||
def settings_menu_theme_Ok_button_cb(self):
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
self.ids["settings_menu_theme_select_button"].text = self.theme.name
|
||||
self.view = "settings_menu"
|
||||
self.view_active_since = time.time()
|
||||
|
||||
def settings_menu_theme_cb(self, instance, value, theme):
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
if self.settings_menu_theme_select_button_cb_hack:
|
||||
self.settings_menu_theme_select_button_cb_hack = False
|
||||
if not (self.theme.name == "" and theme != ""):
|
||||
return
|
||||
|
||||
if value == True:
|
||||
print("You selected " + theme)
|
||||
else:
|
||||
print("You deselected " + theme)
|
||||
|
||||
self.theme = Theme(theme)
|
||||
|
||||
def volume_slider_value(self, *args):
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
|
@ -1132,6 +1278,8 @@ class MyClockWidget(FloatLayout):
|
|||
pass
|
||||
elif self.view == "settings_menu_wake_up_sound":
|
||||
pass
|
||||
elif self.view == "settings_menu_theme_select":
|
||||
pass
|
||||
elif self.view == "clock":
|
||||
self.stop_sound()
|
||||
|
||||
|
@ -1143,10 +1291,12 @@ class MyClockWidget(FloatLayout):
|
|||
if t - self.view_active_since <= self.time_to_ignore_inputs_after_view_change:
|
||||
return True
|
||||
|
||||
"""
|
||||
if self.touch_down_event_prev is None:
|
||||
print("touch down at " + str(t) + " on " + str(touch.spos) + ", after: " + str(after) + ", prev event: None")
|
||||
else:
|
||||
print("touch down at " + str(t) + " on " + str(touch.spos) + ", after: " + str(after) + ", prev event at " + str(self.touch_down_event_prev.time) + " on " + str(self.touch_down_event_prev.touch.spos))
|
||||
"""
|
||||
|
||||
if after:
|
||||
self.touch_down_event_curr = TouchEvent(touch)
|
||||
|
@ -1161,10 +1311,12 @@ class MyClockWidget(FloatLayout):
|
|||
if t - self.view_active_since <= self.time_to_ignore_inputs_after_view_change:
|
||||
return True
|
||||
|
||||
"""
|
||||
if self.touch_move_event_prev is None:
|
||||
print("touch move at " + str(t) + " on " + str(touch.spos) + ", after: " + str(after) + ", prev event: None")
|
||||
else:
|
||||
print("touch move at " + str(t) + " on " + str(touch.spos) + ", after: " + str(after) + ", prev event at " + str(self.touch_move_event_prev.time) + " on " + str(self.touch_move_event_prev.touch.spos))
|
||||
"""
|
||||
|
||||
if after:
|
||||
# Do not delay processing of move events
|
||||
|
@ -1180,10 +1332,12 @@ class MyClockWidget(FloatLayout):
|
|||
if t - self.view_active_since <= self.time_to_ignore_inputs_after_view_change:
|
||||
return True
|
||||
|
||||
"""
|
||||
if self.touch_up_event_prev is None:
|
||||
print("touch up at " + str(t) + " on " + str(touch.spos) + ", after: " + str(after) + ", prev event: None")
|
||||
else:
|
||||
print("touch up at " + str(t) + " on " + str(touch.spos) + ", after: " + str(after) + ", prev event at " + str(self.touch_up_event_prev.time) + " on " + str(self.touch_up_event_prev.touch.spos))
|
||||
"""
|
||||
|
||||
if after:
|
||||
self.touch_up_event_curr = TouchEvent(touch)
|
||||
|
@ -1222,8 +1376,10 @@ def except_hook(type, value, tb):
|
|||
if is_arm():
|
||||
pixels.fill((0, 0, 0, 0))
|
||||
pixels.show()
|
||||
backlight.brightness = 50
|
||||
return
|
||||
|
||||
if __name__ == '__main__':
|
||||
#sys.excepthook = except_hook
|
||||
if is_arm():
|
||||
sys.excepthook = except_hook
|
||||
MyApp().run()
|
||||
|
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 15 KiB |