add circleview

This commit is contained in:
2025-05-05 23:37:07 +02:00
parent f13149002f
commit 3e168d2074
5 changed files with 67 additions and 4 deletions

View File

@@ -7,12 +7,13 @@ from statistics import mean
from .serial_reader import SerialReader
from .config import DEFAULT_CALIB, DISPLAY_TYPES
from .views import NumberView
from .views import *
class WeightApp(tk.Tk):
def __init__(self, weight_reader: SerialReader):
super().__init__()
self.weight_reader = weight_reader
self.view = None
self.toolbar = tk.Frame(self, padx=10)
self.toolbar.pack(side=tk.LEFT)
@@ -51,9 +52,11 @@ class WeightApp(tk.Tk):
self.view_type.pack()
self.view_type_label = ttk.Label(self.view_type, text="Visual:")
self.view_type_label.pack(side=tk.LEFT)
self.view_type_select = ttk.Combobox(self.view_type, values=[t.value for t in DISPLAY_TYPES], postcommand=self.update_view)
self.view_type_select = ttk.Combobox(self.view_type, values=[t.value for t in DISPLAY_TYPES])
self.view_type_select.set(DISPLAY_TYPES.NUMBER.value)
self.view_type_select.pack(side=tk.LEFT)
self.view_type_update = ttk.Button(self.view_type, text="Refresh", command=self.update_view)
self.view_type_update.pack()
#### Display ####
self.update_view()
@@ -109,12 +112,23 @@ class WeightApp(tk.Tk):
def update_view(self):
selected_view = self.view_type_select.get()
if self.view is not None:
self.view.pack_forget()
if selected_view == DISPLAY_TYPES.NUMBER.value:
self.view = NumberView(self,
tare_command=self.weight_reader.tare,
calibrate_command=self.calibrate,
padx=50)
self.view.pack(side=tk.RIGHT)
elif selected_view == DISPLAY_TYPES.CIRCLE.value:
self.view = CircleView(self,
tare_command=self.weight_reader.tare,
calibrate_command=self.calibrate,
padx=50)
self.view.pack(side=tk.RIGHT)
else:
raise Exception(f"View {selected_view} not found.")