Compare commits
13 Commits
3af9453260
...
1ff9b3c400
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ff9b3c400 | |||
| a1d7afaad3 | |||
| 4a6bfec571 | |||
| 249723a2e0 | |||
| 28fd5cba5e | |||
| 4a78a01ae3 | |||
| c7faed0597 | |||
| 290bed8198 | |||
| 3f10d8049a | |||
| 8e9d57c5cb | |||
| ff32de4ac0 | |||
| b137fcb0f9 | |||
| dfca9bf2ed |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -165,4 +165,5 @@ storage/
|
||||
# Custom
|
||||
ingredients.json
|
||||
checklist.md
|
||||
.vscode/
|
||||
.vscode/
|
||||
settings.json
|
||||
@@ -1,5 +1,5 @@
|
||||
[project]
|
||||
name = "Meal Picker"
|
||||
name = "NoteNook"
|
||||
version = "0.1.0"
|
||||
description = "An app designed to build, store, and select meals for shopping purposes."
|
||||
readme = "README.md"
|
||||
@@ -8,7 +8,7 @@ authors = [
|
||||
{ name = "Nick Kalar", email = "nick@kalar.codes" }
|
||||
]
|
||||
dependencies = [
|
||||
"flet==0.28.3"
|
||||
"flet >=0.70.0.dev0",
|
||||
]
|
||||
|
||||
[tool.flet]
|
||||
@@ -18,7 +18,7 @@ org = "codes.kalar"
|
||||
|
||||
# project display name that is used as an app title on Android and iOS home screens,
|
||||
# shown in window titles and about app dialogs on desktop.
|
||||
product = "Meal Picker"
|
||||
product = "NoteNook"
|
||||
|
||||
# company name to display in about app dialogs
|
||||
company = "Nick Kalar"
|
||||
@@ -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,29 +1,56 @@
|
||||
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"
|
||||
|
||||
file_path = os.getenv("FILE_PATH") + "/checklist.md" if os.getenv("FILE_PATH") else "./checklist.md"
|
||||
|
||||
def read_json() -> dict:
|
||||
def read_ingredient_json() -> dict:
|
||||
try:
|
||||
with open("./src/json/ingredients.json", "rt") as file:
|
||||
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:
|
||||
try:
|
||||
with open("./src/json/ingredients.json", "w") as file:
|
||||
with open(ingredients_file_path, "w") as file:
|
||||
json.dump(meals, file, indent=4)
|
||||
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:
|
||||
@@ -44,7 +71,7 @@ def combine_ingredients(meals: dict) -> dict:
|
||||
|
||||
def write_checklist(data: dict) -> None:
|
||||
try:
|
||||
with open(file_path, 'w') as checklist:
|
||||
with open(checklist_file_path, 'w') as checklist:
|
||||
for ingredient, details in data.items():
|
||||
s = ingredient + " - " + str(details['quantity'])
|
||||
if details['units'] != None:
|
||||
@@ -55,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())
|
||||
@@ -45,16 +45,16 @@ def builder(page):
|
||||
|
||||
def create_ingredient_row(self, ingredient, details):
|
||||
row = []
|
||||
row.append(ft.TextField(label="Ingredient", value=ingredient, on_change=self.update_ingredient))
|
||||
row.append(ft.TextField(label="Quantity", value=details['quantity'], on_change=self.update_quantity))
|
||||
row.append(ft.TextField(label="Units (optional)", value=details['units'], on_change=self.update_units))
|
||||
row.append(ft.TextField(label="Ingredient", value=ingredient, on_change=self.update_ingredient, width=300))
|
||||
row.append(ft.TextField(label="Quantity", value=details['quantity'], on_change=self.update_quantity, width=200))
|
||||
row.append(ft.TextField(label="Units (optional)", value=details['units'], on_change=self.update_units, width=200))
|
||||
return row
|
||||
|
||||
def create_new_ingredient_row(self):
|
||||
row = []
|
||||
row.append(ft.TextField(label="Ingredient", value=""))
|
||||
row.append(ft.TextField(label="Quantity", value=""))
|
||||
row.append(ft.TextField(label="Units (optional)", value=""))
|
||||
row.append(ft.TextField(label="Ingredient", value="", width=300))
|
||||
row.append(ft.TextField(label="Quantity", value="", width=200))
|
||||
row.append(ft.TextField(label="Units (optional)", value="", width=200))
|
||||
return row
|
||||
|
||||
def update_ingredients(self, name):
|
||||
@@ -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 = {
|
||||
@@ -78,26 +79,32 @@ def builder(page):
|
||||
def show_new_meal(self):
|
||||
self.new_meal = {}
|
||||
selector_body.controls = [
|
||||
ft.TextField(label="Meal", value="", autofocus=True),
|
||||
ft.TextField(label="Meal", value="", autofocus=True, width=720),
|
||||
ft.ListView(controls=[ft.Row(self.create_new_ingredient_row(),
|
||||
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
|
||||
width=300,
|
||||
height=100,
|
||||
alignment=ft.MainAxisAlignment.START,
|
||||
)],
|
||||
expand=True,
|
||||
spacing=5,
|
||||
padding=5,
|
||||
auto_scroll=False,
|
||||
),
|
||||
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.Row(controls=[
|
||||
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))
|
||||
]
|
||||
)
|
||||
|
||||
]
|
||||
|
||||
page.title = "Add New Meal"
|
||||
page.update()
|
||||
|
||||
def append_new_ingredient_row(self, selector_body):
|
||||
# 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.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(),
|
||||
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
|
||||
width=300,
|
||||
@@ -108,6 +115,12 @@ def builder(page):
|
||||
def add_new_meal(self, selector_body):
|
||||
meal = selector_body.controls[0].value
|
||||
ing, qua, uni = [], [], []
|
||||
|
||||
if meal == "" or \
|
||||
selector_body.controls[1].controls.controls[0].value == "" or \
|
||||
selector_body.controls[1].controls.controls[1].value == "":
|
||||
page.show_dialog(ft.SnackBar(ft.Text("Please fill out the meal information.")))
|
||||
return
|
||||
|
||||
for row in selector_body.controls[1].controls:
|
||||
#skip blank row
|
||||
@@ -127,15 +140,20 @@ def builder(page):
|
||||
|
||||
def show_meal_details(self, selector_body, page):
|
||||
expanded_meal = []
|
||||
|
||||
if (selector_body.controls[0].controls[0].value == None):
|
||||
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,
|
||||
width=300,
|
||||
height=100,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -144,13 +162,16 @@ def builder(page):
|
||||
ft.ListView(
|
||||
controls=expanded_meal,
|
||||
expand=True,
|
||||
spacing=5,
|
||||
padding=5,
|
||||
spacing=10,
|
||||
padding=10,
|
||||
auto_scroll=False,
|
||||
),
|
||||
ft.ElevatedButton(text="Update Meal", 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.Row(controls=[
|
||||
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)),
|
||||
]
|
||||
)
|
||||
]
|
||||
if page.title == "Create and Edit Meals!":
|
||||
page.title = f"Editing {meal_name}"
|
||||
page.update()
|
||||
@@ -164,14 +185,18 @@ def builder(page):
|
||||
self.get_meal_radios_group(),
|
||||
],
|
||||
expand=True,
|
||||
spacing=5,
|
||||
padding=5,
|
||||
spacing=10,
|
||||
padding=10,
|
||||
auto_scroll=False,
|
||||
),
|
||||
ft.ElevatedButton(text="Update Meal",
|
||||
ft.Row(
|
||||
controls=[
|
||||
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())
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
if page.title != "Create and Edit Meals!":
|
||||
page.title = f"Create and Edit Meals!"
|
||||
@@ -186,7 +211,7 @@ def builder(page):
|
||||
|
||||
selector_body = ft.Column(
|
||||
controls = [],
|
||||
height = 500,
|
||||
height = 700,
|
||||
expand = False,
|
||||
)
|
||||
|
||||
|
||||
@@ -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):
|
||||
@@ -13,16 +13,24 @@ def selector(page: ft.Page):
|
||||
selected_meals.pop(meal.label)
|
||||
else:
|
||||
selected_meals[meal.label] = meal_json[meal.label]
|
||||
print(selected_meals)
|
||||
if selected_meals == {}:
|
||||
page.show_dialog(ft.SnackBar(ft.Text("Please select at least one meal.")))
|
||||
return
|
||||
|
||||
write_checklist(combine_ingredients(selected_meals))
|
||||
|
||||
|
||||
page.title = "Select Some Meals"
|
||||
meal_list = []
|
||||
for name, _ in meal_json.items():
|
||||
meal_list.append(ft.Checkbox(label=name))
|
||||
meal_list.append(ft.Checkbox(
|
||||
label = name,
|
||||
active_color = '#6da0cd',
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
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 = [
|
||||
@@ -34,7 +42,7 @@ def selector(page: ft.Page):
|
||||
),
|
||||
submit_button,
|
||||
],
|
||||
height = 500,
|
||||
height = 700,
|
||||
expand = False,
|
||||
)
|
||||
page.update()
|
||||
|
||||
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()
|
||||
BIN
src/assets/hamburger.png
Normal file
BIN
src/assets/hamburger.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
15
src/main.py
15
src/main.py
@@ -1,16 +1,17 @@
|
||||
import flet as ft
|
||||
from MealBuilder import builder
|
||||
from MealSelector import selector
|
||||
from models.MenuBar import create_menubar
|
||||
|
||||
|
||||
def main(page: ft.Page):
|
||||
page.appbar = create_menubar(page, selector, builder)
|
||||
page.window.width = 750
|
||||
page.window.height = 900
|
||||
page.window.top = 10
|
||||
page.appbar = create_menubar(page)
|
||||
page.bgcolor = '#013328'
|
||||
|
||||
page.add(ft.Pagelet(
|
||||
content = ft.Text("Welcome to Meal Picker! Please select an option from the menu above to get started.")
|
||||
)
|
||||
)
|
||||
page.add(ft.Pagelet(content=ft.Text(), expand=True, bgcolor='#013328'))
|
||||
selector(page)
|
||||
|
||||
if __name__ == "__main__":
|
||||
ft.app(main)
|
||||
ft.run(main)
|
||||
@@ -1,16 +1,22 @@
|
||||
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("Meal Picker"),
|
||||
bgcolor=ft.Colors.GREEN_700,
|
||||
title=ft.Text("NoteNook"),
|
||||
bgcolor='#CC8B65',
|
||||
center_title=False,
|
||||
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