Compare commits
No commits in common. "master" and "1.0" have entirely different histories.
10 changed files with 85 additions and 165 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -152,4 +152,9 @@ dmypy.json
|
|||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
app/saves/history.json
|
||||
# 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/
|
||||
|
|
49
app/main.py
49
app/main.py
|
@ -1,49 +0,0 @@
|
|||
import flet as ft
|
||||
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
|
||||
|
||||
history_instance = History() # Erstellen der History-Instanz
|
||||
|
||||
home = Home(history_instance) # Übergeben der History-Instanz an Home
|
||||
home.page = page
|
||||
|
||||
settings = Settings()
|
||||
settings.page = page
|
||||
|
||||
def on_navigation_change(e):
|
||||
page.controls.clear()
|
||||
if e.control.selected_index == 0:
|
||||
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()
|
||||
|
||||
#test = ft.NavigationBarDestination(icon=ft.icons.HOME, label="Home")
|
||||
page.navigation_bar = ft.NavigationBar(
|
||||
destinations=[
|
||||
ft.NavigationBarDestination(icon=ft.icons.HOME, label="Home"),
|
||||
ft.NavigationBarDestination(icon=ft.icons.HISTORY, label="History"),
|
||||
ft.NavigationBarDestination(icon=ft.icons.SETTINGS, label="Settings")
|
||||
],
|
||||
on_change=on_navigation_change,
|
||||
)
|
||||
|
||||
page.appbar = home.create_appbar()
|
||||
page.add(home)
|
||||
page.update()
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("run")
|
||||
app(target=main)
|
|
@ -1,60 +0,0 @@
|
|||
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")
|
|
@ -1,21 +0,0 @@
|
|||
import flet as ft
|
||||
class Settings(ft.Control):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
|
||||
# Initialize controls
|
||||
self.main_container = ft.Container(
|
||||
content=ft.Column([ft.Text("huhu")]),
|
||||
border_radius=10,
|
||||
padding=15
|
||||
)
|
||||
|
||||
def build(self):
|
||||
return ft.Column(self.controls)
|
||||
|
||||
def create_appbar(self):
|
||||
return ft.AppBar(
|
||||
title=ft.Text("Settings")
|
||||
)
|
||||
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
@ -1,5 +1,7 @@
|
|||
import json
|
||||
|
||||
|
||||
|
||||
def save(jsettings,jhisory):
|
||||
with open("saves/settings.json", "w") as data:
|
||||
data.write(json.dumps(jsettings,indent=4))
|
|
@ -1,8 +1,7 @@
|
|||
import flet as ft
|
||||
from random import choice
|
||||
import file_handler
|
||||
from datetime import datetime
|
||||
from pages import file_handler
|
||||
from .history import History
|
||||
from random import choice
|
||||
|
||||
def get_time():
|
||||
t = datetime.now()
|
||||
|
@ -11,16 +10,20 @@ def get_time():
|
|||
def random_emoji():
|
||||
return choice("🍎🍐🍊🍋🍌🍉🍇🍓🍈🍒🍑🍍🥝🥭🥑🍅🍆🥒🥕🥬🌽🥔🍠🌰🥜🍯🥐🍞🥖🥨🥯🧀🥚🍳🥓🧄🧅🥞🧇🍤🍗🍖🍕🌭🍔🍟🥙🌮🌯🥗🥘🍝🍜🦪🍲🍥🍣🍱🍛🍚🧆🍙🍘🍢🍡🍧🍨🍦🍰🎂🍮🍭🍬🍫🍿🍩🍪🥮🧁🥛🧈🍼☕🍵🍶🍺🍻🥂🍷🥃🍸🍹🍾🧉🧃🧊🧂🥄🍴")
|
||||
|
||||
class Home(ft.Control):
|
||||
def __init__(self, history_instance: History) -> None:
|
||||
class Nahrung(ft.UserControl):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.history_instance = history_instance
|
||||
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, on_change=self.reseterrorinkcaltextfield, on_submit=self.editkcal)
|
||||
self.snack_bar = ft.SnackBar(ft.Text("Hinzugefügt"))
|
||||
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(
|
||||
[
|
||||
|
@ -28,14 +31,14 @@ class Home(ft.Control):
|
|||
[
|
||||
ft.Text("kjoule:", size=20),
|
||||
self.kjtext,
|
||||
ft.Text(f"/{round(self.history_instance.settings['kcal_max'] * 4.184, 0)}", size=10)
|
||||
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.history_instance.settings['kcal_max']}", size=10)
|
||||
ft.Text(f"/{self.settings['kcal_max']}", size=10)
|
||||
]
|
||||
),
|
||||
ft.Row(
|
||||
|
@ -51,7 +54,13 @@ class Home(ft.Control):
|
|||
padding=15,
|
||||
)
|
||||
|
||||
self.controls = [self.main_container, self.snack_bar]
|
||||
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()
|
||||
|
||||
|
@ -65,29 +74,22 @@ class Home(ft.Control):
|
|||
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_instance.addkcal(emoji, self.kcaltextfield.value)
|
||||
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.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()
|
||||
|
||||
self.update()
|
||||
except ValueError:
|
||||
self.kcaltextfield.error_text = "\\(*O*)/ nicht verschreiben!!"
|
||||
self.page.update()
|
||||
self.update()
|
||||
|
||||
def create_appbar(self):
|
||||
return ft.AppBar(
|
||||
title=ft.Text("Home"),
|
||||
title=ft.Text("Nahrungstracker"),
|
||||
actions=[
|
||||
ft.PopupMenuButton(
|
||||
items=[ft.PopupMenuItem(text="Reset", on_click=self.resethistory)]
|
||||
|
@ -95,20 +97,45 @@ class Home(ft.Control):
|
|||
],
|
||||
)
|
||||
|
||||
def resethistory(self,e):
|
||||
print("reset button")
|
||||
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_instance.history = []
|
||||
file_handler.save(self.history_instance.settings, self.history_instance.history)
|
||||
self.history_instance.update_history_view() # Aktualisieren der History-Ansicht
|
||||
self.history = []
|
||||
file_handler.save(self.settings, self.history)
|
||||
self.update_history()
|
||||
self.history_container.content = ft.Column(self.historylist)
|
||||
self.dialog.open = False
|
||||
self.page.update()
|
||||
# beide updaten
|
||||
self.page.update()
|
||||
self.update()
|
||||
|
||||
def close(e):
|
||||
self.dialog.open = False
|
||||
self.page.update()
|
||||
# beide updaten
|
||||
self.page.update()
|
||||
self.update()
|
||||
|
||||
self.dialog = ft.AlertDialog(
|
||||
modal=True,
|
||||
|
@ -121,17 +148,33 @@ class Home(ft.Control):
|
|||
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_instance.history:
|
||||
entry_date = entry[2][:3]
|
||||
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)
|
Loading…
Reference in a new issue