start implementation of recipe selection

This commit is contained in:
Jannes Magnusson
2025-10-18 17:26:46 +02:00
parent 7a3329e8f2
commit d619ec1859
7 changed files with 207 additions and 76 deletions

View File

@@ -6,22 +6,9 @@ from .draw_utils import draw_clock, draw_long_press
class ButtonsManager(View):
# left, left long, right, right long, both long
config = {
'default': {
'left_button_press': 'start_timer_command',
'left_button_long_press': 'reset_timer_command',
'right_button_press': 'tare_command',
'right_button_long_press': 'select_recipe_command',
'both_buttons_long_press': 'open_settings_command',
},
'select_recipe': {},
'settings': {},
}
def __init__(self, parent, im_size, center,
**actions):
self.current_config = self.config['default']
self.current_view = actions['default']
self.long_press_threshold = 1000 # milliseconds
self.left_press_start = None
self.right_press_start = None
@@ -61,57 +48,44 @@ class ButtonsManager(View):
im = self.bkg_im.copy()
draw = ImageDraw.Draw(im)
has_buttons = self.current_view.has_button()
# Draw left button
if self.current_config.get('left_button_press', None):
if has_buttons[0]:
draw.circle((10, 10), 2, fill='black')
if self.current_config['left_button_press'] == 'start_timer_command':
draw_clock(draw, (20, 10), radius=3)
if self.current_config.get('left_button_long_press', None):
self.current_view.render_left_press(draw, 20, 10)
if has_buttons[1]:
y = self.size[1] - 10
draw_long_press(draw, (10, y))
if self.current_config['left_button_long_press'] == 'reset_timer_command':
draw_clock(draw, (24, y), radius=3)
draw.text((30, y - 5), "R", fill='black')
self.current_view.render_left_long_press(draw, 24, y)
# Draw right button
if self.current_config.get('right_button_press', None):
if has_buttons[2]:
draw.circle((self.size[0] - 10, 10), 2, fill='black')
if self.current_config['right_button_press'] == 'tare_command':
draw.text((self.size[0] - 20, 4), "T", fill='black')
if self.current_config.get('right_button_long_press', None):
self.current_view.render_right_press(draw, self.size[0] - 20, 4)
if has_buttons[3]:
y = self.size[1] - 10
draw_long_press(draw, (self.size[0] - 10, y))
if self.current_config['right_button_long_press'] == 'select_recipe_command':
draw.text((self.size[0] - 22, y - 5), "R", fill='black')
self.current_view.render_right_long_press(draw, self.size[0] - 24, y)
return im
############ BUTTON ACTIONS ###########
def left_button_press(self):
action = self.current_config.get('left_button_press', None)
if action:
self.__getattribute__(action)()
self.current_view.left_press()
def left_button_long_press(self):
action = self.current_config.get('left_button_long_press', None)
if action:
self.__getattribute__(action)()
self.current_view.left_long_press()
def right_button_press(self):
action = self.current_config.get('right_button_press', None)
if action:
self.__getattribute__(action)()
self.current_view.right_press()
def right_button_long_press(self):
action = self.current_config.get('right_button_long_press', None)
if action:
self.__getattribute__(action)()
self.current_view.right_long_press()
def both_buttons_long_press(self):
action = self.current_config.get('both_buttons_long_press', None)
if action:
self.__getattribute__(action)()
self.current_view.both_long_press()
############ BUTTON PRESS HANDLERS ###########
def _left_button_press_start(self, event):
@@ -162,7 +136,7 @@ class ButtonsManager(View):
"""Handle both buttons press start"""
self.both_press_start = self.ui.after_idle(lambda: None) # Get current time reference
# Schedule long press detection
self.both_press_job = self.ui.after(self.long_press_threshold, self._both_long_press_detected)
self.both_press_job = self.ui.after(self.long_press_threshold, self._both_buttons_long_press_detected)
def _both_buttons_press_end(self, event):
"""Handle both buttons press end"""