start adding edit_step

This commit is contained in:
Jannes Magnusson
2025-10-19 11:00:28 +02:00
parent eb32f089ad
commit 1e62bd77d1
9 changed files with 204 additions and 24 deletions

View File

@@ -5,16 +5,18 @@ from ..base import View
from ..button_interface import ButtonInterface
from .recipe_manager import RecipeManager
from .recipe import Recipe
from .recipe import Recipe, Step
class EditRecipe(View, ButtonInterface):
def __init__(self, parent, im_size, center,
recipe_manager: RecipeManager,
edit_step_command,
deactivate_command,
recipe: Recipe = None):
self.deactivate_command = deactivate_command
self.recipe_manager = recipe_manager
self.recipe = recipe
self.edit_step_command = edit_step_command
if recipe is None:
self.recipe = Recipe("New", [])
@@ -24,7 +26,7 @@ class EditRecipe(View, ButtonInterface):
super().__init__(parent, im_size, center)
def _get_visual_steps(self):
steps = self.recipe.steps + ['+']
steps = self.recipe.steps + ['+', 'BACK']
if len(steps) < 4:
return steps, 0
@@ -60,13 +62,20 @@ class EditRecipe(View, ButtonInterface):
offset = 15
for i in range(0, 90, r // 2):
draw.circle((x + i, y_pos), r, fill='black')
if str(step) != '+':
if str(step) == '+':
draw.text((x, y_pos - 5), '+', fill='white')
elif str(step) == 'BACK':
draw.regular_polygon((x + 5, y_pos, 5), 3, fill='white', rotation=90)
else:
step.step_type.render(draw, (x, y_pos - 5), fill='white')
draw.text((x + 30, y_pos - 5), step.value_str, fill='white')
else:
draw.text((x, y_pos - 5), '+', fill='white')
elif str(step) == '+':
draw.text((x, y_pos - 5), '+', fill='black')
elif str(step) == 'BACK':
draw.regular_polygon((x + 5, y_pos, 5), 3, fill='black', rotation=90)
else:
step.step_type.render(draw, (x, y_pos - 5), fill='black')
draw.text((x + 30, y_pos - 5), step.value_str, fill='black')
@@ -74,31 +83,39 @@ class EditRecipe(View, ButtonInterface):
return im
def left_press(self):
# edit entry
pass
self.selected_field = (self.selected_field - 1) % (len(self.recipe.steps) + 3)
def left_long_press(self):
if self.selected_field == len(self.recipe.steps) + 2:
# back
self.deactivate_command()
elif self.selected_field == len(self.recipe.steps) + 1:
# add step
pass
else:
# edit name
self.edit_step_command(self.recipe, self.selected_field)
def right_press(self):
self.selected_field = (self.selected_field + 1) % (len(self.recipe.steps) + 3)
def right_long_press(self):
# save
self.recipe_manager.add_recipe(self.recipe)
self.deactivate_command()
def right_press(self):
self.selected_field += 1
if self.selected_field > len(self.recipe.steps) + 1:
self.selected_field = 0
def has_button(self) -> Tuple[bool, bool, bool, bool]:
return True, True, True, True
def render_left_press(self, draw, x, y):
draw.regular_polygon((x, y, 5), 3, fill='black', rotation=270)
draw.regular_polygon((x, y+2, 5), 3, fill='black')
def render_left_long_press(self, draw, x, y):
draw.text((x - 3, y - 5), 'Save', fill='black')
draw.text((x, y-5), 'Enter', fill='black')
def render_right_press(self, draw, x, y):
draw.regular_polygon((x, y + 6, 5), 3, fill='black', rotation=180)
draw.regular_polygon((x, y+4, 5), 3, fill='black', rotation=180)
def render_right_long_press(self, draw, x, y):
draw.text((x - 30, y - 5), 'Cancel', fill='black')
draw.text((x - 20, y-5), 'Save', fill='black')