Added play button

This commit is contained in:
Admar Schoonen 2023-04-09 15:00:04 +02:00
parent 7852b378db
commit 6b213a54b9
1 changed files with 43 additions and 4 deletions

View File

@ -60,17 +60,29 @@ Builder.load_string('''
pos_hint: {"center_x":0.5, "center_y":0.5}
size: 0.9*min(root.size), 0.9*min(root.size)
FloatLayout
id: play_button
size_hint: None, None
pos_hint: {"center_x":0.1, "center_y":0.1}
size: 0.1*min(root.size), 0.1*min(root.size)
FloatLayout
id: set_alarm_button
size_hint: None, None
pos_hint: {"center_x":0.9, "center_y":0.1}
size: 0.1*min(root.size), 0.1*min(root.size)
FloatLayout
id: light_button
size_hint: None, None
pos_hint: {"center_x":0.1, "center_y":0.9}
size: 0.1*min(root.size), 0.1*min(root.size)
FloatLayout
id: settings_button
size_hint: None, None
pos_hint: {"center_x":0.9, "center_y":0.9}
size: 0.1*310/560*min(root.size), 0.1*310/560*min(root.size)
size: 0.1*min(root.size), 0.1*min(root.size)
FloatLayout
id: settings_menu
@ -368,12 +380,28 @@ class MyClockWidget(FloatLayout):
center_y + round(length * math.cos(2 * math.pi * fraction)),
)
def update_play_button(self):
alarm_settings = App.get_running_app().alarm_settings
if alarm_settings.alarm_playing:
source = 'playing.png'
rgb = [0.9, 0.9, 0.9]
else:
source = 'stopped.png'
rgb = [1.0, 1.0, 1.0]
play_button = self.ids["play_button"]
self.draw_list_curr_frame.append(["canvas.clear()", play_button])
with play_button.canvas:
self.draw_list_curr_frame.append(["Color", play_button.canvas, rgb[0], rgb[1], rgb[2]])
self.draw_list_curr_frame.append(["Rectangle", play_button.canvas, play_button.size, play_button.pos, source])
def update_set_alarm_button(self):
alarm_settings = App.get_running_app().alarm_settings
if (self.view == "set_alarm") or alarm_settings.alarm_activated:
source = 'alarm_on.png'
rgb = [0.9, 0.0, 0.0]
rgb = [0.9, 0.9, 0.9]
else:
source = 'alarm_off.png'
rgb = [1.0, 1.0, 1.0]
@ -390,7 +418,7 @@ class MyClockWidget(FloatLayout):
if (self.view.startswith("settings_menu")):
source = 'settings_visible.png'
rgb = [0.9, 0.0, 0.0]
rgb = [0.9, 0.9, 0.9]
else:
source = 'settings_not_visible.png'
rgb = [1.0, 1.0, 1.0]
@ -544,6 +572,7 @@ class MyClockWidget(FloatLayout):
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.update_play_button()
self.update_set_alarm_button()
self.update_settings_button()
if self.view == "clock" or self.view == "set_alarm":
@ -632,6 +661,13 @@ class MyClockWidget(FloatLayout):
if self.is_arm:
self.set_backlight(alarm_settings.display_brightness)
def on_play_button_pressed(self):
alarm_settings = App.get_running_app().alarm_settings
if alarm_settings.alarm_playing:
self.stop_sound()
else:
self.play_sound(alarm_settings.sound_source)
def on_alarm_button_pressed(self):
alarm_settings = App.get_running_app().alarm_settings
@ -771,7 +807,10 @@ class MyClockWidget(FloatLayout):
minutes_hand = self.position_on_clock(time.minute/60+time.second/3600, length=0.40*hands.size[0])
hours_hand = self.position_on_clock(time.hour/12 + time.minute/720, length=0.35*hands.size[0])
if (0.85 <= touch.spos[0] <= 0.95) and (0.05 <= touch.spos[1] <= 0.15):
print(str(touch.spos))
if (0.05 <= touch.spos[0] <= 0.15) and (0.05 <= touch.spos[1] <= 0.15):
self.on_play_button_pressed()
elif (0.85 <= touch.spos[0] <= 0.95) and (0.05 <= touch.spos[1] <= 0.15):
self.on_alarm_button_pressed()
elif (0.85 <= touch.spos[0] <= 0.95) and (0.85 <= touch.spos[1] <= 0.95):
self.on_settings_button_pressed()