add a menu with bt pairing
This commit is contained in:
@@ -5,18 +5,23 @@ from tkinter import Frame, Canvas, ttk, PhotoImage
|
||||
from PIL import ImageChops
|
||||
|
||||
from ..config import DISPLAY_TYPES, DISPLAY_MODES
|
||||
from .draw_utils import draw_clock
|
||||
from .draw_utils import draw_clock, draw_bluetooth_icon
|
||||
from . import NumberView, CircleView, TimerView, TextView
|
||||
|
||||
from .button_interface import ButtonInterface
|
||||
from .buttons_manager import ButtonsManager
|
||||
|
||||
from .recipes import RecipeSelection, RecipeManager, EditRecipe, EditStep, StepType, Step
|
||||
from .menu import MenuView
|
||||
from .bluetooth_pairing import BluetoothPairingView
|
||||
|
||||
class MainView(tk.Frame, ButtonInterface):
|
||||
def __init__(self, parent,
|
||||
tare_command=None,
|
||||
calibrate_command=None,
|
||||
bt_connected_getter=None,
|
||||
bt_start_pairing_command=None,
|
||||
bt_stop_pairing_command=None,
|
||||
**kwargs):
|
||||
super().__init__(parent, **kwargs)
|
||||
self.curr_mode = DISPLAY_MODES.MAIN
|
||||
@@ -24,6 +29,9 @@ class MainView(tk.Frame, ButtonInterface):
|
||||
self.timer_view = None # Timer view is always active
|
||||
self.tare_command = tare_command
|
||||
self.calibrate_command = calibrate_command
|
||||
self.bt_connected_getter = bt_connected_getter
|
||||
self.bt_start_pairing_command = bt_start_pairing_command
|
||||
self.bt_stop_pairing_command = bt_stop_pairing_command
|
||||
|
||||
self.actions = Frame(self)
|
||||
self.actions.pack()
|
||||
@@ -75,6 +83,10 @@ class MainView(tk.Frame, ButtonInterface):
|
||||
return
|
||||
self.enter_recipe_selection()
|
||||
|
||||
def both_long_press(self):
|
||||
if self.curr_mode == DISPLAY_MODES.MAIN:
|
||||
self.enter_menu()
|
||||
|
||||
|
||||
def render_left_press(self, draw, x, y):
|
||||
if self.curr_mode == DISPLAY_MODES.MAIN:
|
||||
@@ -106,6 +118,32 @@ class MainView(tk.Frame, ButtonInterface):
|
||||
if self.curr_mode == DISPLAY_MODES.MAIN:
|
||||
draw.text((x, y - 5), "R", fill='black')
|
||||
|
||||
def render_both_long_press(self, draw, x, y):
|
||||
if self.curr_mode == DISPLAY_MODES.MAIN:
|
||||
draw.text((x - 12, y - 5), "Menu", fill='black')
|
||||
|
||||
def render_status_icons(self, draw):
|
||||
if self.bt_connected_getter and self.bt_connected_getter():
|
||||
draw_bluetooth_icon(draw, (self.im_size[0] - 8, 8), size=5)
|
||||
|
||||
|
||||
def enter_menu(self):
|
||||
self.curr_mode = DISPLAY_MODES.MENU
|
||||
self.buttons.current_view = MenuView(self,
|
||||
self.im_size, self.center,
|
||||
bluetooth_pair_command=self.start_bluetooth_pairing,
|
||||
deactivate_command=self.enter_main_mode)
|
||||
self.refresh(0.0)
|
||||
|
||||
def start_bluetooth_pairing(self):
|
||||
self.curr_mode = DISPLAY_MODES.BLUETOOTH_PAIRING
|
||||
self.buttons.current_view = BluetoothPairingView(
|
||||
self, self.im_size, self.center,
|
||||
start_command=self.bt_start_pairing_command,
|
||||
stop_command=self.bt_stop_pairing_command,
|
||||
deactivate_command=self.enter_menu,
|
||||
)
|
||||
self.refresh(0.0)
|
||||
|
||||
def enter_main_mode(self):
|
||||
self.curr_mode = DISPLAY_MODES.MAIN
|
||||
|
||||
Reference in New Issue
Block a user