From 710c865753283008cb0b81032adb1a9890aead0b Mon Sep 17 00:00:00 2001 From: megamichi Date: Sun, 23 Jun 2024 19:41:00 +0200 Subject: [PATCH] home,history und settings Tab --- .gitignore | 7 +- app/main.py | 33 +++--- app/pages/history.py | 60 +++++++++++ app/pages/{root.py => home.py} | 95 ++++++----------- app/saves/history.json | 30 ++++-- app/views.py | 4 - assets/icon.png | Bin 5889 -> 0 bytes file_handler.py | 16 --- main.py | 180 --------------------------------- requirements.txt | 1 - saves/history.json | 1 - saves/settings.json | 3 - 12 files changed, 134 insertions(+), 296 deletions(-) rename app/pages/{root.py => home.py} (61%) delete mode 100644 app/views.py delete mode 100644 assets/icon.png delete mode 100644 file_handler.py delete mode 100644 main.py delete mode 100644 requirements.txt delete mode 100644 saves/history.json delete mode 100644 saves/settings.json diff --git a/.gitignore b/.gitignore index 68bc17f..a786607 100644 --- a/.gitignore +++ b/.gitignore @@ -152,9 +152,4 @@ dmypy.json # Cython debug symbols cython_debug/ -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +app/saves/history.json diff --git a/app/main.py b/app/main.py index a85d5bb..7305e91 100644 --- a/app/main.py +++ b/app/main.py @@ -1,26 +1,31 @@ import flet as ft -from pages.root import Nahrung +from pages.home import Home +from pages.history import History from pages.settings import Settings +from flet import app def main(page: ft.Page): page.title = "Nahrungstracker" page.scroll = True - # Initialize views - nahrung = Nahrung() - settings = Settings() + history_instance = History() # Erstellen der History-Instanz - # Store reference to the page in instances - nahrung.page = page + home = Home(history_instance) # รœbergeben der History-Instanz an Home + home.page = page + + settings = Settings() settings.page = page - # Function to switch views def on_navigation_change(e): page.controls.clear() if e.control.selected_index == 0: - page.appbar = nahrung.create_appbar() - page.add(nahrung) + page.appbar = home.create_appbar() + page.add(home) elif e.control.selected_index == 1: + page.appbar = ft.AppBar(title=ft.Text("History")) + history_instance.update_history_view() + page.add(history_instance) # Hinzufรผgen der History-Instanz zur Seite + elif e.control.selected_index == 2: page.appbar = ft.AppBar(title=ft.Text("Settings")) page.add(settings) page.update() @@ -28,14 +33,16 @@ def main(page: ft.Page): page.navigation_bar = ft.NavigationBar( destinations=[ ft.NavigationDestination(icon=ft.icons.HOME, label="Home"), + ft.NavigationDestination(icon=ft.icons.HISTORY, label="History"), ft.NavigationDestination(icon=ft.icons.SETTINGS, label="Settings") ], on_change=on_navigation_change, ) - page.appbar = nahrung.create_appbar() - page.add(nahrung) - page.update() # Ensure the initial UI is updated + page.appbar = home.create_appbar() + page.add(home) + page.update() if __name__ == "__main__": - ft.app(target=main) + print("run") + app(target=main) diff --git a/app/pages/history.py b/app/pages/history.py index e69de29..a275bf2 100644 --- a/app/pages/history.py +++ b/app/pages/history.py @@ -0,0 +1,60 @@ +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.UserControl): + 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") diff --git a/app/pages/root.py b/app/pages/home.py similarity index 61% rename from app/pages/root.py rename to app/pages/home.py index a8676aa..a50aedf 100644 --- a/app/pages/root.py +++ b/app/pages/home.py @@ -1,7 +1,8 @@ import flet as ft -from datetime import datetime from random import choice +from datetime import datetime from pages import file_handler +from .history import History def get_time(): t = datetime.now() @@ -10,21 +11,16 @@ def get_time(): def random_emoji(): return choice("๐ŸŽ๐Ÿ๐ŸŠ๐Ÿ‹๐ŸŒ๐Ÿ‰๐Ÿ‡๐Ÿ“๐Ÿˆ๐Ÿ’๐Ÿ‘๐Ÿ๐Ÿฅ๐Ÿฅญ๐Ÿฅ‘๐Ÿ…๐Ÿ†๐Ÿฅ’๐Ÿฅ•๐Ÿฅฌ๐ŸŒฝ๐Ÿฅ”๐Ÿ ๐ŸŒฐ๐Ÿฅœ๐Ÿฏ๐Ÿฅ๐Ÿž๐Ÿฅ–๐Ÿฅจ๐Ÿฅฏ๐Ÿง€๐Ÿฅš๐Ÿณ๐Ÿฅ“๐Ÿง„๐Ÿง…๐Ÿฅž๐Ÿง‡๐Ÿค๐Ÿ—๐Ÿ–๐Ÿ•๐ŸŒญ๐Ÿ”๐ŸŸ๐Ÿฅ™๐ŸŒฎ๐ŸŒฏ๐Ÿฅ—๐Ÿฅ˜๐Ÿ๐Ÿœ๐Ÿฆช๐Ÿฒ๐Ÿฅ๐Ÿฃ๐Ÿฑ๐Ÿ›๐Ÿš๐Ÿง†๐Ÿ™๐Ÿ˜๐Ÿข๐Ÿก๐Ÿง๐Ÿจ๐Ÿฆ๐Ÿฐ๐ŸŽ‚๐Ÿฎ๐Ÿญ๐Ÿฌ๐Ÿซ๐Ÿฟ๐Ÿฉ๐Ÿช๐Ÿฅฎ๐Ÿง๐Ÿฅ›๐Ÿงˆ๐Ÿผโ˜•๐Ÿต๐Ÿถ๐Ÿบ๐Ÿป๐Ÿฅ‚๐Ÿท๐Ÿฅƒ๐Ÿธ๐Ÿน๐Ÿพ๐Ÿง‰๐Ÿงƒ๐ŸงŠ๐Ÿง‚๐Ÿฅ„๐Ÿด") - -class Nahrung(ft.UserControl): - def __init__(self) -> None: +class Home(ft.UserControl): + def __init__(self, history_instance: History) -> None: super().__init__() - self.settings, self.history = file_handler.load(self) + self.history_instance = history_instance self.kjtext = ft.Text("0", size=25) self.kcaltext = ft.Text("0", size=30) self.kcaltextfield = ft.TextField(keyboard_type="NUMBER", expand=True, on_change=self.reseterrorinkcaltextfield, on_submit=self.editkcal) + self.snack_bar = ft.SnackBar(ft.Text("Hinzugefรผgt")) - # Initialize history list - self.historylist = [] - self.update_history() - - # Initialize controls self.main_container = ft.Container( content=ft.Column( [ @@ -32,14 +28,14 @@ class Nahrung(ft.UserControl): [ ft.Text("kjoule:", size=20), self.kjtext, - ft.Text(f"/{round(self.settings['kcal_max'] * 4.184, 0)}", size=10) + ft.Text(f"/{round(self.history_instance.settings['kcal_max'] * 4.184, 0)}", size=10) ] ), ft.Row( [ ft.Text("kcal:", size=25), self.kcaltext, - ft.Text(f"/{self.settings['kcal_max']}", size=10) + ft.Text(f"/{self.history_instance.settings['kcal_max']}", size=10) ] ), ft.Row( @@ -55,13 +51,7 @@ class Nahrung(ft.UserControl): padding=15, ) - self.history_container = ft.Container( - content=ft.Column([ft.Text("Verlauf:"), - ft.Column(controls=self.historylist) - ]), - ) - - self.controls = [self.main_container, self.history_container] + self.controls = [self.main_container, self.snack_bar] self.load_todays_kcal() @@ -75,22 +65,29 @@ class Nahrung(ft.UserControl): def editkcal(self, e): try: emoji = random_emoji() + print(emoji) new_kcal = int(self.kcaltext.value) + int(self.kcaltextfield.value) self.kcaltext.value = str(new_kcal) self.kjtext.value = str(round(new_kcal * 4.184, 0)) - self.history.append([emoji, self.kcaltextfield.value, get_time()]) - file_handler.save(self.settings, self.history) - self.update_history() + self.history_instance.addkcal(emoji, self.kcaltextfield.value) self.reseterrorinkcaltextfield() self.kcaltextfield.value = "" - self.update() + + self.snack_bar.open = True + self.page.snack_bar = self.snack_bar + self.page.update() + self.snack_bar.open = False + self.page.snack_bar = None + + self.history_instance.update_history_view() + except ValueError: self.kcaltextfield.error_text = "\\(*O*)/ nicht verschreiben!!" - self.update() + self.page.update() def create_appbar(self): return ft.AppBar( - title=ft.Text("Nahrungstracker"), + title=ft.Text("Home"), actions=[ ft.PopupMenuButton( items=[ft.PopupMenuItem(text="Reset", on_click=self.resethistory)] @@ -98,45 +95,20 @@ class Nahrung(ft.UserControl): ], ) - 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, # "#226666", - border_radius=5, - padding=6 - ) - ) - - def resethistory(self, e): - print("pressed") + def resethistory(self,e): + print("reset button") def reset(e): self.kcaltext.value = "0" self.kjtext.value = "0" - self.history = [] - file_handler.save(self.settings, self.history) - self.update_history() - self.history_container.content = ft.Column(self.historylist) + self.history_instance.history = [] + file_handler.save(self.history_instance.settings, self.history_instance.history) + self.history_instance.update_history_view() # Aktualisieren der History-Ansicht self.dialog.open = False - # beide updaten - self.page.update() - self.update() + self.page.update() def close(e): self.dialog.open = False - # beide updaten - self.page.update() - self.update() + self.page.update() self.dialog = ft.AlertDialog( modal=True, @@ -149,20 +121,17 @@ class Nahrung(ft.UserControl): actions_alignment=ft.MainAxisAlignment.END, on_dismiss=lambda e: print("Modal dialog dismissed!"), ) - self.page.dialog = self.dialog + self.page.dialog = self.dialog self.dialog.open = True self.page.update() def load_todays_kcal(self): today_date = get_time()[:3] - print(today_date) - todays_kcal = 0 - for entry in self.history: - entry_date = entry[2][:3] # Year, Month, Day part of the entry's timestamp + for entry in self.history_instance.history: + entry_date = entry[2][:3] if entry_date == today_date: todays_kcal += int(entry[1]) self.kcaltext.value = str(todays_kcal) - diff --git a/app/saves/history.json b/app/saves/history.json index d154340..c7bf3e2 100644 --- a/app/saves/history.json +++ b/app/saves/history.json @@ -1,26 +1,38 @@ [ [ - "\ud83c\udf4b", - "8", + "\ud83e\uddc1", + "50", [ 2024, 6, 23, - 13, - 37, - 23 + 19, + 38, + 59 ] ], [ - "\ud83c\udf47", + "\ud83c\udf5d", + "800", + [ + 2024, + 6, + 23, + 19, + 39, + 6 + ] + ], + [ + "\ud83c\udf2d", "5", [ 2024, 6, 23, - 13, - 37, - 40 + 19, + 39, + 22 ] ] ] \ No newline at end of file diff --git a/app/views.py b/app/views.py deleted file mode 100644 index b03bf87..0000000 --- a/app/views.py +++ /dev/null @@ -1,4 +0,0 @@ -import flet as ft - -def get_views(page): - return {} \ No newline at end of file diff --git a/assets/icon.png b/assets/icon.png deleted file mode 100644 index 4e91dfe8cbda69078918715a7f55f0fedc880b6a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5889 zcmeHKdsGu=7N3-qXGJQu)mCX55N&P9%p`#%O%NpV4p5|G5GzAw5~Ac`GC)8SHj7rP zTdXJwi%_J3ZK>7=>lQ_^Lct=k*a{UCvEZT`5i3$E6zNQO1)*n;XSe^Eb0+y7_x|qh z{_g$0li3y);y1(gRa*c6W(4?)!U2HdMLyP+#7h0ngP#*W)hQ7x@o*%GrqQZpig=8M zCu=YordP-SK;NPa^R_=vd*M{?heFCO;3g06{&Xm&q2P_ewIz~o)^{|`u&L=9vdyFf z&T@%le7W1&Kg)Oi(xSr9kat}}Ys2rf%`EXgwBtKj+|k?>H-D(U zJr5Vwrd3Jlh98B8k{z<s>S-EQ*OOwP4!d`EQqc+PwTg9cp*euB%<*vLUy6Gm%|}!pA2pz{h7SAtH^u zjUNmB&wI_QUbDQ6{*u+=tz7g_NaD|SHBp=C5!Pi(zp!`RyUAMo>aN+Z_?;_jZ?B2H za;{nuX%*@1@Efo`Q4@}TJZpIG?5HZe=2~V_zf)2VQ24$q_sWY_?Cb8|U&z>3|K--g zNE`u>VDFtd*u}tb+cOI)FMw_vlQSJ(EA)Ez+K>QCO)<@HEw6nVfod3&Jx(c*-de`h_63fk^O z+1OfHoe;GAm-M>%G50U*6kpwAU~gVZ(Jv`de@7WQ>DBOg^D5ozB{RLYlm}i1tUjoW z`}kOMYTNbeZLMeJxkE$1)~nhh(eGuJ0D%1}1<_zD#ld{3TIq(M>R8N8uhbBo2LOU4 zdJQ67hvBqXOs-G~={={;(rF4*NRQ-*L9xaMi&OZgXtCufAraD)by6NmU*c&i(DMlZ zC59t3y)s^<9Mh>2v{GzYBBsKf%^^_fxW6Vr8*fSnl`^q-Oi7sPh^Ww{kbVK;uyGGk z0=Yt|F?kVUPqM@nvI(&!aU*w3>6jBC+{bYzS&!vzGA69VV!lW%O(5w7h=g=9J|9&} z6)4{{gfWok0kTmB4~7s18-h5DSSc4~V8j%GJYaV&h?zkJsB}1@l42wj0q&+CaM&IQ z2!pT(0|H?wgDnGj3@(a73=bXxu~83L#^pk05TRNH(UnNNIV%zhC7@8qT`EP~c?<~V z5^OL`O0tP%urQ94$L6qM4&-ivLZy6PwN{A`9E9{>g(^Wmu@RwAV#{%aR1@-mxI7Owo6Ch+FwEvm7_GpxI-(OvObB#ijZh%V z!Y7g;ghj|cB>+qwL@s7KFQk){Xr$-(wwO3hD1sv*1jh(a5N7j1cRmb7 zKx{sT&1Z8LgD@X7vsa@ES@M6gCJzryFj8`Vg^q}yY+4#QQOmLQBeRidyux&pXf)HI z;3LwJ6m&=;hMIU1SR-4~I7B7Kh}&bdUB}iH)3gF4Lop7@LKs{Q!eX#_QiKu9LlFkZ z;<_Vjo`;Obl1@g~sbzQ)qQ$)BgpPz(M0=XFqAfBN>dnd4NpToi1wt?e=+1yR5fIFW zd3=yJDj4(6PZ5koJ-8g6DLaV4hIvG?5CSm}E)*;CkaDH4J3N{6|B~X=o)}G0z$CB5 zv7!o?Q_4PKV0MoZ(u}MT_cL+bGso}yQO(Gk^-uhaw%eZ=fq;G%zP``+hA0;MOHvMO?nW!IcDTl>og zZV#so9VqS9-RocQF!_fl`@UpRGq(Em{_eeXFL2+YP^k`H0LA<(Cb~7$XEr7C_*_QKzLbKv_49wE zOkq#*`R!zZ*gzeYr&a9!SI4!S$MpmA;~&IiANM4R&@$J#vFB0vmf^!!DbH}J zX_cDyb*}zR`#YQ4dlNmA!R<}PYlEFZE&QIt@^_vjZ<@D*|Hx?z{`I3@gYF^@29?5w#6wjNHJI?k!OpVZ@n75H^9~Dz&Abpc{-td zHFIiyrhKiANequqc-kH4%P?%Sx;wS(WEbt)N2Qd1)m+{(y+(qVS!m3y<`gYVG}5WA-j<0cSb~&- z2wrY}!@yVOcoWdYoGKUp&o~eN85MZRs9RCJO4PhyAX)T!^I%uw;9RE-Uw$!t{mlg& zt353}8<=u#CPYbhQxfMmeBJH!WxId8F<5%o;hSdfp+(|?e(kA)r*HJ$L8m_l6P^9U z=zd=JRy98*(fWQxMbj1gX+yWyhcEPA`(|NH&b1iVy{(K}$qgl0)h9_Y#x)&x^zGj@ zd?$@@tL;G#CN_u`z852T;3_x}6>8u*Qm2|z9cbrdHfLVh?*&0iUF949s7qi%V*E1Q zc-O(vSy#t5p3nGTdQmIaG+kVHHd|YOyeKy8xR6oP{7Y1GQM5&3dU`?S)C&U4tDhxk z$naYetWWLscXUcLE6T*M@a+t+x}9pVT|Hf$wti_HF7Rf3U~2bJ^rAJ$*Va1 aua9Q%HY#8H)}@F_&I6W(hz>7}G5ijT&jWS< diff --git a/file_handler.py b/file_handler.py deleted file mode 100644 index 15c7473..0000000 --- a/file_handler.py +++ /dev/null @@ -1,16 +0,0 @@ -import json - - - -def save(jsettings,jhisory): - with open("saves/settings.json", "w") as data: - data.write(json.dumps(jsettings,indent=4)) - with open("saves/history.json", "w") as data: - data.write(json.dumps(jhisory,indent=4)) - -def load(self) -> list: - with open("saves/settings.json", "r") as data: - jsettings = json.load(data) - with open("saves/history.json", "r") as data: - jhistory = json.load(data) - return jsettings,jhistory diff --git a/main.py b/main.py deleted file mode 100644 index 15128ac..0000000 --- a/main.py +++ /dev/null @@ -1,180 +0,0 @@ -import flet as ft -import file_handler -from datetime import datetime -from random import choice - -def get_time(): - t = datetime.now() - return [t.year, t.month, t.day, t.hour, t.minute, t.second] - -def random_emoji(): - return choice("๐ŸŽ๐Ÿ๐ŸŠ๐Ÿ‹๐ŸŒ๐Ÿ‰๐Ÿ‡๐Ÿ“๐Ÿˆ๐Ÿ’๐Ÿ‘๐Ÿ๐Ÿฅ๐Ÿฅญ๐Ÿฅ‘๐Ÿ…๐Ÿ†๐Ÿฅ’๐Ÿฅ•๐Ÿฅฌ๐ŸŒฝ๐Ÿฅ”๐Ÿ ๐ŸŒฐ๐Ÿฅœ๐Ÿฏ๐Ÿฅ๐Ÿž๐Ÿฅ–๐Ÿฅจ๐Ÿฅฏ๐Ÿง€๐Ÿฅš๐Ÿณ๐Ÿฅ“๐Ÿง„๐Ÿง…๐Ÿฅž๐Ÿง‡๐Ÿค๐Ÿ—๐Ÿ–๐Ÿ•๐ŸŒญ๐Ÿ”๐ŸŸ๐Ÿฅ™๐ŸŒฎ๐ŸŒฏ๐Ÿฅ—๐Ÿฅ˜๐Ÿ๐Ÿœ๐Ÿฆช๐Ÿฒ๐Ÿฅ๐Ÿฃ๐Ÿฑ๐Ÿ›๐Ÿš๐Ÿง†๐Ÿ™๐Ÿ˜๐Ÿข๐Ÿก๐Ÿง๐Ÿจ๐Ÿฆ๐Ÿฐ๐ŸŽ‚๐Ÿฎ๐Ÿญ๐Ÿฌ๐Ÿซ๐Ÿฟ๐Ÿฉ๐Ÿช๐Ÿฅฎ๐Ÿง๐Ÿฅ›๐Ÿงˆ๐Ÿผโ˜•๐Ÿต๐Ÿถ๐Ÿบ๐Ÿป๐Ÿฅ‚๐Ÿท๐Ÿฅƒ๐Ÿธ๐Ÿน๐Ÿพ๐Ÿง‰๐Ÿงƒ๐ŸงŠ๐Ÿง‚๐Ÿฅ„๐Ÿด") - -class Nahrung(ft.UserControl): - def __init__(self) -> None: - super().__init__() - self.settings, self.history = file_handler.load(self) - - self.kjtext = ft.Text("0", size=25) - self.kcaltext = ft.Text("0", size=30) - self.kcaltextfield = ft.TextField(keyboard_type="NUMBER", expand=True, autofocus=True, on_change=self.reseterrorinkcaltextfield, on_submit=self.editkcal) - - # Initialize history list - self.historylist = [] - self.update_history() - - # Initialize controls - self.main_container = ft.Container( - content=ft.Column( - [ - ft.Row( - [ - ft.Text("kjoule:", size=20), - self.kjtext, - ft.Text(f"/{round(self.settings['kcal_max'] * 4.184, 0)}", size=10) - ] - ), - ft.Row( - [ - ft.Text("kcal:", size=25), - self.kcaltext, - ft.Text(f"/{self.settings['kcal_max']}", size=10) - ] - ), - ft.Row( - [ - self.kcaltextfield, - ft.FloatingActionButton(icon="add", on_click=self.editkcal) - ] - ), - ] - ), - bgcolor=ft.colors.INDIGO_400, - border_radius=10, - padding=15, - ) - - self.history_container = ft.Container( - content=ft.Column([ft.Text("Verlauf:"), - ft.Column(controls=self.historylist) - ]), - ) - - self.controls = [self.main_container, self.history_container] - - self.load_todays_kcal() - - def reseterrorinkcaltextfield(self, e=None): - self.kcaltextfield.error_text = "" - - def build(self): - self.kjtext.value = str(round(int(self.kcaltext.value) * 4.184, 0)) - return ft.Column(self.controls) - - def editkcal(self, e): - try: - emoji = random_emoji() - new_kcal = int(self.kcaltext.value) + int(self.kcaltextfield.value) - self.kcaltext.value = str(new_kcal) - self.kjtext.value = str(round(new_kcal * 4.184, 0)) - self.history.append([emoji, self.kcaltextfield.value, get_time()]) - file_handler.save(self.settings, self.history) - self.update_history() - self.reseterrorinkcaltextfield() - self.kcaltextfield.value = "" - self.update() - except ValueError: - self.kcaltextfield.error_text = "\\(*O*)/ nicht verschreiben!!" - self.update() - - def create_appbar(self): - return ft.AppBar( - title=ft.Text("Nahrungstracker"), - actions=[ - ft.PopupMenuButton( - items=[ft.PopupMenuItem(text="Reset", on_click=self.resethistory)] - ) - ], - ) - - 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, # "#226666", - border_radius=5, - padding=6 - ) - ) - - def resethistory(self, e): - print("pressed") - def reset(e): - self.kcaltext.value = "0" - self.kjtext.value = "0" - self.history = [] - file_handler.save(self.settings, self.history) - self.update_history() - self.history_container.content = ft.Column(self.historylist) - self.dialog.open = False - # beide updaten - self.page.update() - self.update() - - def close(e): - self.dialog.open = False - # beide updaten - self.page.update() - self.update() - - self.dialog = ft.AlertDialog( - modal=True, - title=ft.Text("Wirklich?"), - content=ft.Text("Alle Daten werden aus deinem Verlauf gelรถscht!!!"), - actions=[ - ft.TextButton("ja", on_click=reset), - ft.TextButton("nein", on_click=close), - ], - actions_alignment=ft.MainAxisAlignment.END, - on_dismiss=lambda e: print("Modal dialog dismissed!"), - ) - self.page.dialog = self.dialog - - self.dialog.open = True - self.page.update() - - def load_todays_kcal(self): - today_date = get_time()[:3] - print(today_date) - - todays_kcal = 0 - for entry in self.history: - entry_date = entry[2][:3] # Year, Month, Day part of the entry's timestamp - if entry_date == today_date: - todays_kcal += int(entry[1]) - - self.kcaltext.value = str(todays_kcal) - - -def main(page: ft.Page): - page.title = "Nahrungstracker" - page.scroll = True - - nahrung = Nahrung() - nahrung.page = page # Store reference to the page in Nahrung instance - page.appbar = nahrung.create_appbar() - page.add(nahrung) - page.update() # Ensure the initial UI is updated - -if __name__ == "__main__": - ft.app(target=main) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 7a82fda..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -flet==0.21.* \ No newline at end of file diff --git a/saves/history.json b/saves/history.json deleted file mode 100644 index 0637a08..0000000 --- a/saves/history.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/saves/settings.json b/saves/settings.json deleted file mode 100644 index 36310da..0000000 --- a/saves/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "kcal_max": 2000 -} \ No newline at end of file