import flet as ft from datetime import datetime from pages import file_handler def get_time(): t = datetime.now() return [t.year, t.month, t.day, t.hour, t.minute, t.second] class History(ft.Control): def __init__(self) -> None: super().__init__() self.settings, self.history = file_handler.load(self) self.historylist = [] self.update_history() self.history_container = ft.Container( content=ft.Column(controls=self.historylist) ) self.controls = [self.history_container] def build(self): return ft.Column(self.controls) def addkcal(self, emoji, kcal): self.history.append([emoji, kcal, get_time()]) file_handler.save(self.settings, self.history) self.update_history() def update_history(self): self.historylist.clear() for h in self.history: self.historylist.insert(0, ft.Container( content=ft.Column( controls=[ ft.Row( [ft.Text(str(f"{h[2][3]}:{h[2][4]}:{h[2][5]} {h[2][2]}.{h[2][1]}.{h[2][0]}"))], alignment=ft.MainAxisAlignment.END ), ft.Row( [ft.Text(str(f"({h[1]} kcal) {h[0]}"), size=20)], alignment=ft.MainAxisAlignment.START, ) ] ), bgcolor=ft.colors.INDIGO_600, border_radius=5, padding=6 ) ) def update_history_view(self): self.update_history() self.controls.clear() self.history_container = ft.Container( content=ft.Column(controls=self.historylist) ) self.controls = [self.history_container] print("reset history view")