start implementation of recipe selection
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import io
|
||||
import tkinter as tk
|
||||
from tkinter import Frame, Canvas, ttk, PhotoImage
|
||||
from enum import Enum
|
||||
|
||||
from PIL import ImageChops
|
||||
|
||||
from ..config import DISPLAY_TYPES
|
||||
from ..config import DISPLAY_TYPES, DISPLAY_MODES
|
||||
from . import NumberView, CircleView, TimerView
|
||||
from .button_interface import ButtonInterface
|
||||
from .buttons_manager import ButtonsManager
|
||||
from .recipe_selection import RecipeSelection
|
||||
from .draw_utils import draw_clock
|
||||
|
||||
class MainView(tk.Frame):
|
||||
class MainView(tk.Frame, ButtonInterface):
|
||||
def __init__(self, parent,
|
||||
tare_command=None,
|
||||
calibrate_command=None,
|
||||
@@ -23,24 +27,59 @@ class MainView(tk.Frame):
|
||||
self.actions.pack()
|
||||
self.calibrate_button = ttk.Button(self.actions, text="Calibrate", command=calibrate_command)
|
||||
self.calibrate_button.pack()
|
||||
|
||||
# self.tare_button = ttk.Button(self.actions, text="Tare", command=tare_command)
|
||||
# self.tare_button.pack()
|
||||
|
||||
self.im_size = (168, 144)
|
||||
self.center = (168 // 2, 144 // 2)
|
||||
|
||||
# Create timer view that's always active
|
||||
self.timer_view = TimerView(self.actions, self.im_size, self.center)
|
||||
|
||||
self.canvas = Canvas(self, width=168, height=144, background='white',
|
||||
highlightthickness=1, highlightbackground="black")
|
||||
self.canvas.pack()
|
||||
|
||||
|
||||
self.timer_view = TimerView(self.actions, self.im_size, self.center)
|
||||
self.recipe_selection = RecipeSelection(self, self.im_size, self.center)
|
||||
self.buttons = ButtonsManager(self, self.im_size, self.center,
|
||||
tare_command=self.tare_command,
|
||||
start_timer_command=self.timer_view.toggle_timer,
|
||||
reset_timer_command=self.timer_view.reset_timer)
|
||||
default=self,
|
||||
select_recipe=self.recipe_selection)
|
||||
|
||||
self.curr_mode = DISPLAY_MODES.MAIN
|
||||
|
||||
def has_button(self):
|
||||
return True, True, True, True
|
||||
|
||||
def left_press(self):
|
||||
self.timer_view.toggle_timer()
|
||||
|
||||
def left_long_press(self):
|
||||
self.timer_view.reset_timer()
|
||||
|
||||
def right_press(self):
|
||||
self.tare_command()
|
||||
|
||||
def right_long_press(self):
|
||||
self.enter_recipe_selection()
|
||||
|
||||
|
||||
def render_left_press(self, draw, x, y):
|
||||
draw_clock(draw, (x, y), radius=3)
|
||||
|
||||
def render_left_long_press(self, draw, x, y):
|
||||
draw_clock(draw, (x, y), radius=3)
|
||||
draw.text((x + 6, y - 5), "R", fill='black')
|
||||
|
||||
def render_right_press(self, draw, x, y):
|
||||
draw.text((x, y), "T", fill='black')
|
||||
|
||||
def render_right_long_press(self, draw, x, y):
|
||||
draw.text((x, y - 5), "R", fill='black')
|
||||
|
||||
|
||||
|
||||
def enter_recipe_selection(self):
|
||||
self.curr_mode = DISPLAY_MODES.RECIPE_SELECTION
|
||||
self.buttons.current_view = self.recipe_selection
|
||||
self.refresh(0.0)
|
||||
|
||||
|
||||
################ VIEW MANAGEMENT ################
|
||||
@@ -63,19 +102,27 @@ class MainView(tk.Frame):
|
||||
|
||||
def refresh(self, weight: float):
|
||||
ims = []
|
||||
|
||||
if self.curr_mode == DISPLAY_MODES.MAIN:
|
||||
# Always include timer and button view
|
||||
if self.timer_view:
|
||||
timer_im = self.timer_view.update_weight(weight)
|
||||
button_im = self.buttons.update_weight(weight)
|
||||
ims.append(timer_im)
|
||||
ims.append(button_im)
|
||||
|
||||
# Add other selected views
|
||||
for view in self.views:
|
||||
im = view.update_weight(weight)
|
||||
ims.append(im)
|
||||
|
||||
# Always include timer and button view
|
||||
if self.timer_view:
|
||||
timer_im = self.timer_view.update_weight(weight)
|
||||
elif self.curr_mode == DISPLAY_MODES.RECIPE_SELECTION:
|
||||
button_im = self.buttons.update_weight(weight)
|
||||
ims.append(timer_im)
|
||||
ims.append(button_im)
|
||||
|
||||
# Add other selected views
|
||||
for view in self.views:
|
||||
im = view.update_weight(weight)
|
||||
ims.append(im)
|
||||
|
||||
recipe_im = self.recipe_selection.update_weight(weight)
|
||||
ims.append(recipe_im)
|
||||
|
||||
|
||||
self.canvas.delete("all")
|
||||
# Combine images by logical_and
|
||||
if ims:
|
||||
@@ -91,10 +138,3 @@ class MainView(tk.Frame):
|
||||
# Load into PhotoImage and display on canvas
|
||||
self.photo = PhotoImage(data=buffer.getvalue())
|
||||
self.canvas.create_image(0, 0, anchor="nw", image=self.photo)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
########### BUTTON PRESS HANDLING ###########
|
||||
|
||||
|
||||
Reference in New Issue
Block a user