start implementing edit_recipe
This commit is contained in:
@@ -3,6 +3,8 @@ from typing import Union
|
||||
|
||||
from enum import Enum
|
||||
|
||||
from ..draw_utils import draw_clock
|
||||
|
||||
class Recipe:
|
||||
def __init__(self, name: str, steps: list[Step]):
|
||||
self.name = name
|
||||
@@ -19,6 +21,16 @@ class StepType(Enum):
|
||||
WAIT_TIME_FINISHED = 3
|
||||
TARE = 4
|
||||
|
||||
def render(self, draw, position, fill='black') -> str:
|
||||
if self == StepType.SECTION:
|
||||
draw.text(position, "T", fill=fill)
|
||||
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)
|
||||
elif self == StepType.TARE:
|
||||
draw.text(position, "0.0g", fill=fill)
|
||||
|
||||
class Step:
|
||||
|
||||
def __init__(self,
|
||||
@@ -26,6 +38,29 @@ class Step:
|
||||
value: float | str = None):
|
||||
self.step_type = step_type
|
||||
self.value = value
|
||||
|
||||
@property
|
||||
def value_str(self) -> str:
|
||||
if self.step_type in [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
|
||||
if minutes == 0:
|
||||
return f"{seconds}s"
|
||||
else:
|
||||
return f"{minutes}:{seconds:02d}"
|
||||
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 ""
|
||||
|
||||
|
||||
###### example recipes #########
|
||||
|
||||
Reference in New Issue
Block a user