speed up mock

This commit is contained in:
2026-03-13 00:39:06 +01:00
parent bec76d6796
commit 80dccdb38a
4 changed files with 95 additions and 75 deletions

View File

@@ -1,8 +1,7 @@
import io
import tkinter as tk
from tkinter import Frame, Canvas, ttk, PhotoImage
from tkinter import Frame, Canvas, ttk
from PIL import ImageChops
from PIL import ImageChops, ImageTk
from ..config import DISPLAY_TYPES, DISPLAY_MODES
from .draw_utils import draw_clock, draw_bluetooth_icon
@@ -52,6 +51,7 @@ class MainView(tk.Frame, ButtonInterface):
self.buttons = ButtonsManager(self, self.im_size, self.center,
curr_view=self)
self.loading_view = LoadingView(self.im_size, self.center)
self._prev_frame_bytes = None
self.recipes_manager = RecipeManager()
self.current_steps = [None] * 3
self.tare_buffer = []
@@ -323,18 +323,18 @@ class MainView(tk.Frame, ButtonInterface):
ims.append(recipe_im)
self.canvas.delete("all")
# Combine images by logical_and
if ims:
combined_im = ims[0]
for im in ims[1:]:
combined_im = ImageChops.invert(ImageChops.logical_xor(combined_im, im))
# Convert PIL image to bytes
buffer = io.BytesIO()
combined_im.save(buffer, format='PNG')
buffer.seek(0)
# Load into PhotoImage and display on canvas
self.photo = PhotoImage(data=buffer.getvalue())
# Skip redraw if frame hasn't changed
frame_bytes = combined_im.tobytes()
if frame_bytes == self._prev_frame_bytes:
return
self._prev_frame_bytes = frame_bytes
self.canvas.delete("all")
self.photo = ImageTk.PhotoImage(combined_im)
self.canvas.create_image(0, 0, anchor="nw", image=self.photo)