add edit name
This commit is contained in:
@@ -12,17 +12,17 @@ from .recipe import Recipe, Step, StepType
|
||||
|
||||
class EditStep(View, ButtonInterface):
|
||||
def __init__(self, parent, im_size, center,
|
||||
recipe: Recipe,
|
||||
recipe_id: int,
|
||||
step_index: int,
|
||||
recipe_manager: RecipeManager,
|
||||
deactivate_command):
|
||||
self.deactivate_command = deactivate_command
|
||||
self.recipe_manager = recipe_manager
|
||||
self.recipe = recipe
|
||||
self.recipe_id = recipe_id
|
||||
self.step_index = step_index
|
||||
if step_index == 0:
|
||||
self.step = recipe.name
|
||||
|
||||
self.step = recipe_manager.get_recipe(recipe_id).name
|
||||
|
||||
self.confirm_view = False
|
||||
self.edit_step = 0 # 0: type, 1: step/name value
|
||||
self.new_type = ''
|
||||
@@ -53,21 +53,37 @@ class EditStep(View, ButtonInterface):
|
||||
self.new_value += decode(self.morse_buffer, language=self.morse_code_language).upper()
|
||||
else:
|
||||
self.value_cursor -= 1
|
||||
self.value_cursor = max(0, self.value_cursor)
|
||||
self.new_value = self.new_value[:-1]
|
||||
# process morse buffer
|
||||
self.last_input = None
|
||||
self.morse_buffer = ''
|
||||
|
||||
if isinstance(self.step, str):
|
||||
draw.text((x, 10), "Name:", fill='black')
|
||||
draw.text((x, 30), self.new_value, fill='black')
|
||||
font_size = 16
|
||||
y_start = 30
|
||||
draw.text((x, y_start), "Name:", fill='black')
|
||||
draw.text((x, y_start + 20), self.new_value, fill='black', font_size=font_size)
|
||||
if self.value_cursor_pulse > 1.0:
|
||||
draw.rectangle((x + self.value_cursor * 8, 28, x + self.value_cursor * 8 + 8, 40), fill='black')
|
||||
draw.rectangle((x + self.value_cursor * 10,
|
||||
y_start + 20 - 2,
|
||||
x + self.value_cursor * 10 + 8,
|
||||
y_start + 34),
|
||||
fill='black')
|
||||
if self.value_cursor_pulse > 2.0:
|
||||
self.value_cursor_pulse = 0.0
|
||||
self.value_cursor_pulse += 0.1
|
||||
|
||||
draw.line((x, 45, x + 80, 45), fill='black')
|
||||
draw.line((x, y_start + 37, x + 80, y_start + 37), fill='black')
|
||||
|
||||
if self.morse_buffer != '':
|
||||
for i, suffix in enumerate(['']):#, '.', '-', '.' * 10]):
|
||||
letter = 'del'
|
||||
if len(suffix) != 10 and len(self.morse_buffer) + len(suffix) < 10:
|
||||
letter = decode(self.morse_buffer + suffix, language=self.morse_code_language)
|
||||
draw.text((x, y_start + 50 + i * 15),
|
||||
f'{self.morse_buffer + suffix} {letter}',
|
||||
fill='black', font_size=14)
|
||||
elif self.edit_step == 0:
|
||||
pass
|
||||
else:
|
||||
@@ -101,22 +117,18 @@ class EditStep(View, ButtonInterface):
|
||||
# draw.text((x + 30, y_pos - 5), step.value_str, fill='black')
|
||||
|
||||
return im
|
||||
|
||||
|
||||
def left_press(self):
|
||||
self.selected_field = (self.selected_field - 1) % (len(self.recipe.steps) + 3)
|
||||
self.deactivate_command()
|
||||
|
||||
def left_long_press(self):
|
||||
if self.selected_field == len(self.recipe.steps) + 2:
|
||||
# back
|
||||
if self.step_index == 0:
|
||||
# editing name
|
||||
if self.new_value:
|
||||
recipe = self.recipe_manager.get_recipe(self.recipe_id)
|
||||
recipe.name = self.new_value
|
||||
self.deactivate_command()
|
||||
elif self.selected_field == len(self.recipe.steps) + 1:
|
||||
# add step
|
||||
pass
|
||||
elif self.selected_field == 0:
|
||||
# edit name
|
||||
pass
|
||||
else:
|
||||
# edit entry
|
||||
pass
|
||||
|
||||
def right_press(self):
|
||||
@@ -128,11 +140,10 @@ class EditStep(View, ButtonInterface):
|
||||
self.morse_buffer += '-'
|
||||
|
||||
def has_button(self) -> Tuple[bool, bool, bool, bool]:
|
||||
return True, True, True, False
|
||||
|
||||
return True, True, True, False
|
||||
|
||||
def render_left_press(self, draw, x, y):
|
||||
draw.regular_polygon((x, y+2, 5), 3, fill='black')
|
||||
draw.text((x, y-5), 'Cancel', fill='black')
|
||||
|
||||
def render_left_long_press(self, draw, x, y):
|
||||
draw.text((x, y-5), 'Next', fill='black')
|
||||
|
||||
Reference in New Issue
Block a user