Compare commits
4 Commits
c7faed0597
...
4a6bfec571
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a6bfec571 | |||
| 249723a2e0 | |||
| 28fd5cba5e | |||
| 4a78a01ae3 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -165,4 +165,5 @@ storage/
|
||||
# Custom
|
||||
ingredients.json
|
||||
checklist.md
|
||||
.vscode/
|
||||
.vscode/
|
||||
settings.json
|
||||
@@ -8,7 +8,7 @@ authors = [
|
||||
{ name = "Nick Kalar", email = "nick@kalar.codes" }
|
||||
]
|
||||
dependencies = [
|
||||
"flet==0.28.3"
|
||||
"flet >=0.70.0.dev0",
|
||||
]
|
||||
|
||||
[tool.flet]
|
||||
@@ -29,6 +29,9 @@ copyright = "Copyright (C) 2025 by Nick Kalar"
|
||||
[tool.flet.app]
|
||||
path = "src"
|
||||
|
||||
[tool.flet.macos]
|
||||
entitlement."com.apple.security.files.user-selected.read-write" = true
|
||||
|
||||
[tool.uv]
|
||||
dev-dependencies = [
|
||||
"flet[all]==0.28.3",
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
python-dotenv
|
||||
flet[all]
|
||||
'flet[all]>=0.70.0.dev0'
|
||||
@@ -1,20 +1,38 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
from dotenv import load_dotenv
|
||||
working_directory = Path(__file__).parent
|
||||
|
||||
load_dotenv()
|
||||
try:
|
||||
with open(str(working_directory / "settings.json"), "rt") as settings_file:
|
||||
settings = json.load(settings_file)
|
||||
checklist_file_path = settings.get("checklist_storage_path", str(working_directory / "json")) + "/checklists.json"
|
||||
ingredients_file_path = settings.get("meal_storage_path", str(working_directory / "json")) + "/ingredients.json"
|
||||
except Exception as e:
|
||||
print(e)
|
||||
with open(str(working_directory / "settings.json"), "w") as settings_file:
|
||||
settings = {
|
||||
"meal_storage_path": str(working_directory / "json"),
|
||||
"checklist_storage_path": str(working_directory / "json")
|
||||
}
|
||||
json.dump(settings, settings_file, indent=4)
|
||||
checklist_file_path = settings["checklist_storage_path"] + "/checklists.json"
|
||||
ingredients_file_path = settings["meal_storage_path"] + "/ingredients.json"
|
||||
|
||||
checklist_file_path = os.getenv("FILE_PATH") + "/checklist.md" if os.getenv("FILE_PATH") else "./checklist.md"
|
||||
|
||||
ingredients_file_path = "./src/json/ingredients.json"
|
||||
|
||||
def read_json() -> dict:
|
||||
def read_ingredient_json() -> dict:
|
||||
try:
|
||||
with open(ingredients_file_path, "rt") as file:
|
||||
return json.load(file)
|
||||
except:
|
||||
print("Could not find or read file.")
|
||||
print("Could not find or read ingredients file.")
|
||||
return {}
|
||||
|
||||
def read_json_file(filename: str) -> dict:
|
||||
try:
|
||||
with open(filename, "rt") as file:
|
||||
return json.load(file)
|
||||
except:
|
||||
print(f"Could not find or read file.\n{filename=}")
|
||||
return {}
|
||||
|
||||
def update_json(meals: dict) -> None:
|
||||
@@ -24,8 +42,15 @@ def update_json(meals: dict) -> None:
|
||||
except Exception as e:
|
||||
print(f"Unable to write data to file. {e}")
|
||||
|
||||
def update_file(filename: str, content: dict) -> None:
|
||||
try:
|
||||
with open(filename, "w") as file:
|
||||
json.dump(content, file, indent=4)
|
||||
except Exception as e:
|
||||
print(f"Unable to write data to file. {e}")
|
||||
|
||||
def get_selected_meals(meals: dict) -> dict:
|
||||
meal_json = read_json()
|
||||
meal_json = read_ingredient_json()
|
||||
selected_meals = {}
|
||||
if meal_json:
|
||||
for meal in meals:
|
||||
@@ -57,7 +82,7 @@ def write_checklist(data: dict) -> None:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
meals = read_json()
|
||||
meals = read_ingredient_json()
|
||||
if meals:
|
||||
combined_ingredients = combine_ingredients(meals)
|
||||
write_checklist(combined_ingredients)
|
||||
@@ -1,8 +1,8 @@
|
||||
from FileHandler import read_json, update_json
|
||||
from FileHandler import read_ingredient_json, update_json
|
||||
|
||||
import flet as ft
|
||||
|
||||
meal_json = read_json()
|
||||
meal_json = read_ingredient_json()
|
||||
|
||||
def get_meal_names():
|
||||
meal_list = list(meal_json.keys())
|
||||
@@ -62,6 +62,7 @@ def builder(page):
|
||||
# Doesn't work yet
|
||||
|
||||
# if not self.new_ingredient or not self.new_quantity or not is_number(self.new_quantity):
|
||||
# page.show_dialog(ft.SnackBar(ft.Text("Please fill in the current ingredient before adding a new one.")))
|
||||
# return
|
||||
|
||||
# ingredient = {
|
||||
@@ -86,9 +87,9 @@ def builder(page):
|
||||
auto_scroll=False,
|
||||
),
|
||||
ft.Row(controls=[
|
||||
ft.ElevatedButton(text="Add Ingredient", on_click=lambda e: self.append_new_ingredient_row(selector_body)),
|
||||
ft.ElevatedButton(text="Add Meal", on_click=lambda e: self.add_new_meal(selector_body)),
|
||||
ft.ElevatedButton(text="Back", on_click=lambda e: self.show_meal_selection(selector_body, page))
|
||||
ft.Button(content=ft.Text("Add Ingredient"), on_click=lambda e: self.append_new_ingredient_row(selector_body)),
|
||||
ft.Button(content=ft.Text("Add Meal"), on_click=lambda e: self.add_new_meal(selector_body)),
|
||||
ft.Button(content=ft.Text("Back"), on_click=lambda e: self.show_meal_selection(selector_body, page))
|
||||
]
|
||||
)
|
||||
|
||||
@@ -101,7 +102,7 @@ def builder(page):
|
||||
# Don't add a new row if the last one is blank
|
||||
if selector_body.controls[1].controls[-1].controls[0].value == "" or \
|
||||
selector_body.controls[1].controls[-1].controls[1].value == "":
|
||||
page.open(ft.SnackBar(ft.Text("Please fill in the current ingredient before adding a new one.")))
|
||||
page.show_dialog(ft.SnackBar(ft.Text("Please fill in the current ingredient before adding a new one.")))
|
||||
return
|
||||
|
||||
selector_body.controls[1].controls.append(ft.Row(self.create_new_ingredient_row(),
|
||||
@@ -118,7 +119,7 @@ def builder(page):
|
||||
if meal == "" or \
|
||||
selector_body.controls[1].controls.controls[0].value == "" or \
|
||||
selector_body.controls[1].controls.controls[1].value == "":
|
||||
page.open(ft.SnackBar(ft.Text("Please fill out the meal information.")))
|
||||
page.show_dialog(ft.SnackBar(ft.Text("Please fill out the meal information.")))
|
||||
return
|
||||
|
||||
for row in selector_body.controls[1].controls:
|
||||
@@ -141,14 +142,17 @@ def builder(page):
|
||||
expanded_meal = []
|
||||
|
||||
if (selector_body.controls[0].controls[0].value == None):
|
||||
page.open(ft.SnackBar(ft.Text("Please select a meal to update.")))
|
||||
page.show_dialog(ft.SnackBar(ft.Text("Please select a meal to update.")))
|
||||
return
|
||||
|
||||
meal_name = selector_body.controls[0].controls[0].value
|
||||
|
||||
for details in meal_json[meal_name].items():
|
||||
expanded_meal.append(
|
||||
ft.Row(self.create_ingredient_row(details[0], details[1]),
|
||||
ft.Row(controls=[
|
||||
self.create_ingredient_row(details[0], details[1]),
|
||||
ft.Button(icon=ft.Icons.DELETE_FOREVER_ROUNDED, color=ft.Colors.RED_500, on_click=lambda e, d=details: expanded_meal.remove(e.control.parent)),
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
|
||||
)
|
||||
)
|
||||
@@ -163,8 +167,8 @@ def builder(page):
|
||||
auto_scroll=False,
|
||||
),
|
||||
ft.Row(controls=[
|
||||
ft.ElevatedButton(text="Save Changes", on_click=lambda e: self.update_ingredients(selector_body.controls[0].value)),
|
||||
ft.ElevatedButton(text="Back", on_click=lambda e: self.show_meal_selection(selector_body, page)),
|
||||
ft.Button(content=ft.Text("Save Changes"), on_click=lambda e: self.update_ingredients(selector_body.controls[0].value)),
|
||||
ft.Button(content=ft.Text("Back"), on_click=lambda e: self.show_meal_selection(selector_body, page)),
|
||||
]
|
||||
)
|
||||
]
|
||||
@@ -187,9 +191,9 @@ def builder(page):
|
||||
),
|
||||
ft.Row(
|
||||
controls=[
|
||||
ft.ElevatedButton(text="Update Meal",
|
||||
ft.Button(content=ft.Text("Update Meal"),
|
||||
on_click=lambda e: self.show_meal_details(selector_body, page)),
|
||||
ft.ElevatedButton(text="Add Meal", on_click=lambda e: self.show_new_meal())
|
||||
ft.Button(content=ft.Text("Add Meal"), on_click=lambda e: self.show_new_meal())
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from FileHandler import read_json, combine_ingredients, write_checklist
|
||||
from FileHandler import read_ingredient_json, combine_ingredients, write_checklist
|
||||
|
||||
import flet as ft
|
||||
|
||||
selected_meals = {}
|
||||
meal_json = read_json()
|
||||
meal_json = read_ingredient_json()
|
||||
|
||||
def selector(page: ft.Page):
|
||||
def update_meal_selection(event):
|
||||
@@ -14,7 +14,7 @@ def selector(page: ft.Page):
|
||||
else:
|
||||
selected_meals[meal.label] = meal_json[meal.label]
|
||||
if selected_meals == {}:
|
||||
page.open(ft.SnackBar(ft.Text("Please select at least one meal.")))
|
||||
page.show_dialog(ft.SnackBar(ft.Text("Please select at least one meal.")))
|
||||
return
|
||||
|
||||
write_checklist(combine_ingredients(selected_meals))
|
||||
@@ -30,7 +30,7 @@ def selector(page: ft.Page):
|
||||
)
|
||||
)
|
||||
|
||||
submit_button = ft.ElevatedButton(text="Make Shopping List", on_click=update_meal_selection)
|
||||
submit_button = ft.Button(content=ft.Text("Make Shopping List"), on_click=update_meal_selection)
|
||||
|
||||
page.controls[0].content = ft.Column(
|
||||
controls = [
|
||||
|
||||
64
src/Settings.py
Normal file
64
src/Settings.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import json
|
||||
import flet as ft
|
||||
from pathlib import Path
|
||||
from FileHandler import update_file, read_json_file
|
||||
|
||||
working_directory = Path(__file__).parent / 'settings.json'
|
||||
|
||||
def settings(page):
|
||||
file_picker = ft.FilePicker()
|
||||
page.services.append(file_picker)
|
||||
|
||||
def toggle_dark_mode(e):
|
||||
if dark_mode_switch.value:
|
||||
page.theme_mode = ft.ThemeMode.DARK
|
||||
else:
|
||||
page.theme_mode = ft.ThemeMode.LIGHT
|
||||
page.update()
|
||||
|
||||
async def set_meal_file_path(e):
|
||||
meal_directory_path.value = await file_picker.get_directory_path()
|
||||
if meal_directory_path.value:
|
||||
settings_data["meal_storage_path"] = meal_directory_path.value
|
||||
update_file(working_directory, settings_data)
|
||||
|
||||
async def set_checklist_file_path(e):
|
||||
checklist_directory_path.value = await file_picker.get_directory_path()
|
||||
if checklist_directory_path.value:
|
||||
settings_data["checklist_storage_path"] = checklist_directory_path.value
|
||||
update_file(working_directory, settings_data)
|
||||
|
||||
dark_mode_switch = ft.Switch(
|
||||
label="Dark Mode",
|
||||
value=False,
|
||||
on_change=toggle_dark_mode
|
||||
)
|
||||
|
||||
settings_data = read_json_file(working_directory)
|
||||
|
||||
page.title = "Settings"
|
||||
|
||||
page.controls[0].content = ft.Column(
|
||||
controls=[
|
||||
dark_mode_switch,
|
||||
ft.Row(controls=[
|
||||
ft.Button(
|
||||
"Set Meal Storage Path",
|
||||
icon=ft.Icons.FOLDER_OPEN,
|
||||
on_click=set_meal_file_path
|
||||
),
|
||||
meal_directory_path := ft.Text(settings_data.get("meal_storage_path", "Not Set")),
|
||||
],),
|
||||
ft.Row(controls=[
|
||||
ft.Button(
|
||||
"Set Checklist Storage Path",
|
||||
icon=ft.Icons.FOLDER_OPEN,
|
||||
on_click=set_checklist_file_path
|
||||
),
|
||||
checklist_directory_path := ft.Text(settings_data.get("checklist_storage_path", "Not Set")),
|
||||
]),
|
||||
],
|
||||
height=700,
|
||||
expand=False,
|
||||
)
|
||||
page.update()
|
||||
@@ -1,5 +1,4 @@
|
||||
import flet as ft
|
||||
from MealBuilder import builder
|
||||
from MealSelector import selector
|
||||
from models.MenuBar import create_menubar
|
||||
|
||||
@@ -8,11 +7,11 @@ def main(page: ft.Page):
|
||||
page.window.width = 750
|
||||
page.window.height = 900
|
||||
page.window.top = 10
|
||||
page.appbar = create_menubar(page, selector, builder)
|
||||
page.appbar = create_menubar(page)
|
||||
page.bgcolor = '#013328'
|
||||
|
||||
page.add(ft.Pagelet(content=ft.Text()))
|
||||
page.add(ft.Pagelet(content=ft.Text(), expand=True, bgcolor='#013328'))
|
||||
selector(page)
|
||||
|
||||
if __name__ == "__main__":
|
||||
ft.app(main)
|
||||
ft.run(main)
|
||||
@@ -1,6 +1,9 @@
|
||||
import flet as ft
|
||||
from MealBuilder import builder
|
||||
from MealSelector import selector
|
||||
from Settings import settings
|
||||
|
||||
def create_menubar(page: ft.Page, selector, builder):
|
||||
def create_menubar(page: ft.Page):
|
||||
menu = ft.AppBar(
|
||||
title=ft.Text("NoteNook"),
|
||||
bgcolor='#CC8B65',
|
||||
@@ -8,8 +11,9 @@ def create_menubar(page: ft.Page, selector, builder):
|
||||
actions=[
|
||||
ft.PopupMenuButton(
|
||||
items=[
|
||||
ft.PopupMenuItem(text="Meal Selector", on_click=lambda e: selector(page)),
|
||||
ft.PopupMenuItem(text="Meal Builder", on_click=lambda e: builder(page)),
|
||||
ft.PopupMenuItem(content=ft.Text("Meal Selector"), on_click=lambda e: selector(page)),
|
||||
ft.PopupMenuItem(content=ft.Text("Meal Builder"), on_click=lambda e: builder(page)),
|
||||
ft.PopupMenuItem(content=ft.Text("Settings"), on_click=lambda e: settings(page)),
|
||||
],
|
||||
icon = ft.Icons.FASTFOOD_OUTLINED,
|
||||
icon_color = '#E3DCD2'
|
||||
|
||||
Reference in New Issue
Block a user