add edit step + do recipe in main view, added carousel for recipe selection

This commit is contained in:
2026-03-12 22:57:15 +01:00
parent 90257a62a0
commit d5dacb8fc4
21 changed files with 1052 additions and 279 deletions

View File

@@ -8,7 +8,7 @@ from ..draw_utils import draw_clock
class Recipe:
def __init__(self, name: str, steps: list[Step]):
self.name = name
self.steps = steps + [Step(StepType.SECTION, "Enjoy")]
self.steps = steps
def __str__(self):
return self.name
@@ -19,48 +19,50 @@ class Recipe:
class StepType(Enum):
SECTION = 0
WEIGH = 1
START_TIME = 2
WAIT_TIME_FINISHED = 3
TARE = 4
WEIGH_WITH_TIMER = 2
TARE = 3
def render(self, draw, position, fill='black') -> str:
def render(self, draw, position, fill='black', **kwargs) -> str:
font_size = kwargs.get('font_size', 10)
if self == StepType.SECTION:
draw.text(position, "T", fill=fill)
draw.text(position, "T", fill=fill, **kwargs)
elif self == StepType.WEIGH:
draw.text(position, "W", fill=fill)
elif self == StepType.START_TIME or self == StepType.WAIT_TIME_FINISHED:
draw_clock(draw, (position[0] + 3, position[1] + 5), radius=3, color=fill)
draw.text(position, "W", fill=fill, **kwargs)
elif self == StepType.WEIGH_WITH_TIMER:
draw.text(position, "W", fill=fill, **kwargs)
r = max(3, font_size // 4)
draw_clock(draw, (position[0] + font_size + 2, position[1] + font_size // 2), radius=r, color=fill)
elif self == StepType.TARE:
draw.text(position, "0.0g", fill=fill)
draw.text(position, "0.0g", fill=fill, **kwargs)
class Step:
def __init__(self,
step_type: StepType,
value: float | str = None):
value: float | str = None,
goal_time: float = 0.0):
self.step_type = step_type
self.value = value
self.goal_time = goal_time
@property
def value_str(self) -> str:
if self.step_type in [StepType.WEIGH]:
if self.step_type == StepType.WEIGH:
return f"{self.value}g"
elif self.step_type == StepType.START_TIME:
if self.value == -1:
return "Start"
else:
minutes = self.value // 60
seconds = self.value % 60
elif self.step_type == StepType.WEIGH_WITH_TIMER:
s = f"{self.value}g"
if self.goal_time > 0:
minutes = int(self.goal_time) // 60
seconds = int(self.goal_time) % 60
if minutes == 0:
return f"{seconds}s"
s += f" {seconds}s"
else:
return f"{minutes}:{seconds:02d}"
s += f" {minutes}:{seconds:02d}"
return s
elif self.step_type == StepType.SECTION:
return str(self.value)
elif self.step_type == StepType.TARE:
return "Tare"
elif self.step_type == StepType.WAIT_TIME_FINISHED:
return "Wait"
else:
return ""
@@ -75,10 +77,7 @@ V60 = Recipe(
Step(StepType.SECTION, "Brew"),
Step(StepType.TARE),
Step(StepType.START_TIME, 45),
Step(StepType.WEIGH, 50),
Step(StepType.WAIT_TIME_FINISHED),
Step(StepType.START_TIME, -1),
Step(StepType.WEIGH_WITH_TIMER, 50, goal_time=45),
Step(StepType.WEIGH, 250),
]
)
@@ -92,7 +91,6 @@ ESPRESSO = Recipe(
Step(StepType.SECTION, "Brew"),
Step(StepType.TARE),
Step(StepType.START_TIME, -1),
Step(StepType.WEIGH, 40),
Step(StepType.WEIGH_WITH_TIMER, 40, goal_time=0.0),
]
)