Compare commits

25 Commits

Author SHA1 Message Date
1ff9b3c400 Merge pull request 'Formatting and Settings' (#2) from formatting into main
Reviewed-on: #2
2025-12-19 03:44:10 +00:00
a1d7afaad3 Merge branch 'main' into formatting 2025-12-19 03:44:00 +00:00
4a6bfec571 Made Flet 1.0 changes 2025-12-17 23:17:17 -05:00
249723a2e0 Added Settings options 2025-12-17 23:16:54 -05:00
28fd5cba5e Updated pathing 2025-12-17 23:16:29 -05:00
4a78a01ae3 Updated Flet version 2025-12-17 23:15:10 -05:00
c7faed0597 formatting and snackbar 2025-11-26 23:19:29 -05:00
290bed8198 formatting adjustments 2025-11-26 23:18:48 -05:00
3af9453260 Merge pull request 'Unifty-Apps' (#1) from Unifty-Apps into main
Reviewed-on: #1
2025-11-26 04:23:04 +00:00
3f10d8049a hamburger 2025-11-25 23:21:11 -05:00
8e9d57c5cb formatting changes 2025-11-25 23:20:57 -05:00
ff32de4ac0 formatting changes 2025-11-25 23:20:46 -05:00
b137fcb0f9 minor filepath changes 2025-11-25 23:20:25 -05:00
dfca9bf2ed Updated project name 2025-11-25 23:19:56 -05:00
027b245075 updated gitignore 2025-11-24 21:17:45 -05:00
ca3d0f8090 Moved menubar to own file 2025-11-24 21:17:35 -05:00
2d5d44cd21 Renamed product 2025-11-24 21:10:51 -05:00
66011974a3 Added app bar to select apps 2025-11-24 21:10:35 -05:00
61f1f6a711 Updated for unifying 2025-11-24 21:10:13 -05:00
fec8c05216 Fixed type issue 2025-11-22 16:23:19 -05:00
Nicholas
eb8dcc0f36 README updates 2025-11-22 16:07:56 -05:00
Nicholas
7347b53bfe minor changes 2025-11-22 16:00:23 -05:00
Nicholas
75cd42ed30 Add Meal Function 2025-11-22 15:50:48 -05:00
781a7eb89b OOP 2025-11-22 13:53:21 -05:00
f3467c879c Added update_json and refactor 2025-11-22 13:53:03 -05:00
11 changed files with 414 additions and 216 deletions

3
.gitignore vendored
View File

@@ -164,3 +164,6 @@ storage/
# Custom # Custom
ingredients.json ingredients.json
checklist.md
.vscode/
settings.json

View File

@@ -1,81 +1,38 @@
# Meal Picker app # Meal Picker app
An app made to help keep track of ingredients for meals, and to build markdown
checklists for shopping.
## Files:
### .env
A file containing the path you want to save the final checklist to. Defaults to current folder.
### src/json/ingredients.json
A file containing the JSON representation of meals and their ingredients. Will be created if one does not exist.
## Run the app ## Run the app
### uv ### CLI
Run as a desktop app: Create a virtual environment:
``` ```
uv run flet run source .venv/bin/activate
``` ```
Run as a web app: Install required packages:
``` ```
uv run flet run --web pip install -r requirements.txt
``` ```
### Poetry Run the flet app:
Install dependencies from `pyproject.toml`:
``` ```
poetry install flet run MealSelector.py
```
OR
```
flet run MealBuilder.py
``` ```
Run as a desktop app: For more details, go to the [Flet website](https://flet.dev/)
```
poetry run flet run
```
Run as a web app:
```
poetry run flet run --web
```
For more details on running the app, refer to the [Getting Started Guide](https://flet.dev/docs/getting-started/).
## Build the app
### Android
```
flet build apk -v
```
For more details on building and signing `.apk` or `.aab`, refer to the [Android Packaging Guide](https://flet.dev/docs/publish/android/).
### iOS
```
flet build ipa -v
```
For more details on building and signing `.ipa`, refer to the [iOS Packaging Guide](https://flet.dev/docs/publish/ios/).
### macOS
```
flet build macos -v
```
For more details on building macOS package, refer to the [macOS Packaging Guide](https://flet.dev/docs/publish/macos/).
### Linux
```
flet build linux -v
```
For more details on building Linux package, refer to the [Linux Packaging Guide](https://flet.dev/docs/publish/linux/).
### Windows
```
flet build windows -v
```
For more details on building Windows package, refer to the [Windows Packaging Guide](https://flet.dev/docs/publish/windows/).

View File

@@ -1,5 +1,5 @@
[project] [project]
name = "Meal Picker" name = "NoteNook"
version = "0.1.0" version = "0.1.0"
description = "An app designed to build, store, and select meals for shopping purposes." description = "An app designed to build, store, and select meals for shopping purposes."
readme = "README.md" readme = "README.md"
@@ -8,7 +8,7 @@ authors = [
{ name = "Nick Kalar", email = "nick@kalar.codes" } { name = "Nick Kalar", email = "nick@kalar.codes" }
] ]
dependencies = [ dependencies = [
"flet==0.28.3" "flet >=0.70.0.dev0",
] ]
[tool.flet] [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, # 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. # shown in window titles and about app dialogs on desktop.
product = "shopping" product = "NoteNook"
# company name to display in about app dialogs # company name to display in about app dialogs
company = "Nick Kalar" company = "Nick Kalar"
@@ -29,6 +29,9 @@ copyright = "Copyright (C) 2025 by Nick Kalar"
[tool.flet.app] [tool.flet.app]
path = "src" path = "src"
[tool.flet.macos]
entitlement."com.apple.security.files.user-selected.read-write" = true
[tool.uv] [tool.uv]
dev-dependencies = [ dev-dependencies = [
"flet[all]==0.28.3", "flet[all]==0.28.3",

View File

@@ -1,2 +1,2 @@
python-dotenv python-dotenv
flet[all] 'flet[all]>=0.70.0.dev0'

View File

@@ -1,25 +1,58 @@
import os from pathlib import Path
import json import json
from dotenv import load_dotenv working_directory = Path(__file__).parent
load_dotenv()
file_path = os.getenv("file_path")
def read_json() -> dict:
try: try:
with open("./src/json/ingredients.json", "rt") as file: 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"
def read_ingredient_json() -> dict:
try:
with open(ingredients_file_path, "rt") as file:
return json.load(file) return json.load(file)
except: except:
print("Could not find or read file.") print("Could not find or read ingredients file.")
return {}
def update_json(meals: dict): def read_json_file(filename: str) -> dict:
print("TODO: Add update logic") 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(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: def get_selected_meals(meals: dict) -> dict:
meal_json = read_json() meal_json = read_ingredient_json()
selected_meals = {} selected_meals = {}
if meal_json:
for meal in meals: for meal in meals:
if meal in meal_json: if meal in meal_json:
selected_meals[meal] = meal_json[meal] selected_meals[meal] = meal_json[meal]
@@ -31,17 +64,14 @@ def combine_ingredients(meals: dict) -> dict:
for meal, ingredients in meals.items(): for meal, ingredients in meals.items():
for ingredient, detail in ingredients.items(): for ingredient, detail in ingredients.items():
if ingredient in combined_ingredients: if ingredient in combined_ingredients:
combined_ingredients[ingredient]['quantity'] += detail['quantity'] combined_ingredients[ingredient]['quantity'] = str(float(combined_ingredients[ingredient]['quantity']) + float(detail['quantity']))
else: else:
combined_ingredients[ingredient] = detail combined_ingredients[ingredient] = detail
return combined_ingredients return combined_ingredients
def write_checklist(data: dict) -> None: def write_checklist(data: dict) -> None:
if os.path.exists(file_path):
os.remove(file_path)
try: try:
with open(file_path, 'w') as checklist: with open(checklist_file_path, 'w') as checklist:
for ingredient, details in data.items(): for ingredient, details in data.items():
s = ingredient + " - " + str(details['quantity']) s = ingredient + " - " + str(details['quantity'])
if details['units'] != None: if details['units'] != None:
@@ -52,7 +82,7 @@ def write_checklist(data: dict) -> None:
if __name__ == "__main__": if __name__ == "__main__":
meals = read_json() meals = read_ingredient_json()
if meals: if meals:
combined_ingredients = combine_ingredients(meals) combined_ingredients = combine_ingredients(meals)
write_checklist(combined_ingredients) write_checklist(combined_ingredients)

View File

@@ -1,12 +1,13 @@
from FileHandler import read_json, update_json from FileHandler import read_ingredient_json, update_json
import flet as ft import flet as ft
meal_json = read_json() meal_json = read_ingredient_json()
global new_ingredient, new_quantity, new_units
new_ingredient = "" def get_meal_names():
new_quantity = "" meal_list = list(meal_json.keys())
new_units = "" meal_list.sort()
return meal_list
def is_number(s): def is_number(s):
try: try:
@@ -15,99 +16,210 @@ def is_number(s):
except ValueError: except ValueError:
return False return False
def create_ingredient_row(ingredient, details):
row = []
row.append(ft.TextField(label="Ingredient", value=ingredient))
row.append(ft.TextField(label="Quantity", value=details['quantity']))
row.append(ft.TextField(label="Units (optional)", value=details['units']))
return row
def builder(page): def builder(page):
class Meal():
def update_ingredient(e): def get_meal_radios(self):
global new_ingredient self.meal_radios = []
new_ingredient = e.control.value for name in get_meal_names():
self.meal_radios.append(
ft.Radio(value=name, label=name),
)
def update_quantity(e): def get_meal_radios_group(self):
global new_quantity return ft.RadioGroup(
new_quantity = e.control.value content=ft.Column(
controls=self.meal_radios,
)
)
def update_units(e): def update_ingredient(self, e):
global new_units self.new_ingredient = e.control.value
new_units = e.control.value
def add_ingredient(e): def update_quantity(self, e):
global new_ingredient, new_quantity, new_units self.new_quantity = e.control.value
if not new_ingredient or not new_quantity or not is_number(new_quantity): def update_units(self, e):
return self.new_units = e.control.value
ingredient = { def create_ingredient_row(self, ingredient, details):
new_ingredient: row = []
{ row.append(ft.TextField(label="Ingredient", value=ingredient, on_change=self.update_ingredient, width=300))
"quantity":float(new_quantity), row.append(ft.TextField(label="Quantity", value=details['quantity'], on_change=self.update_quantity, width=200))
"units": new_units if new_units != "" else None row.append(ft.TextField(label="Units (optional)", value=details['units'], on_change=self.update_units, width=200))
} return row
}
meal_json[name] = ingredient def create_new_ingredient_row(self):
update_json(meal_json) row = []
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):
pass
# 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 = {
# self.new_ingredient:
# {
# "quantity":float(self.new_quantity),
# "units": self.new_units if self.new_units != "" else None
# }
# }
# meal_json[name] = ingredient
# update_json(meal_json)
# page.update()
def show_new_meal(self):
self.new_meal = {}
selector_body.controls = [
ft.TextField(label="Meal", value="", autofocus=True, width=720),
ft.ListView(controls=[ft.Row(self.create_new_ingredient_row(),
alignment=ft.MainAxisAlignment.START,
)],
expand=True,
auto_scroll=False,
),
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() 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(),
page.title = "Create and Edit Meals!"
meal_list = []
for name, ingredients in meal_json.items():
ingredients_list = []
for ingredient, details in ingredients.items():
ingredients_list.append(
ft.Row(create_ingredient_row(ingredient, details),
alignment=ft.MainAxisAlignment.SPACE_EVENLY, alignment=ft.MainAxisAlignment.SPACE_EVENLY,
width=300, width=300,
height=100, height=100,))
)
) page.update()
ingredients_list.append(
ft.Row( def add_new_meal(self, selector_body):
controls=[ meal = selector_body.controls[0].value
ft.TextField(label="Ingredient", on_change=update_ingredient), ing, qua, uni = [], [], []
ft.TextField(label="Quantity", on_change=update_quantity),
ft.TextField(label="Units (optional)", on_change=update_units), if meal == "" or \
ft.ElevatedButton(text="Update Ingredient", on_click=add_ingredient), 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
if row.controls[0].value == "" or row.controls[1].value == "":
continue
ing.append(row.controls[0].value)
qua.append(row.controls[1].value)
uni.append(row.controls[2].value if row.controls[2].value != "" else None)
meal_json[meal] = {}
for i in range(len(ing)):
meal_json[meal][ing[i]] = { 'quantity': qua[i], 'units': uni[i] }
#write changes to the ingredients.json file
update_json(meal_json)
self.show_new_meal()
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(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, alignment=ft.MainAxisAlignment.SPACE_EVENLY,
width=300,
height=100,
),
) )
meal_list.append( )
ft.Column(
controls=[ selector_body.controls = [
ft.TextField(label="Meal", value=name), ft.TextField(label="Meal", value=meal_name),
ft.ListView( ft.ListView(
controls=ingredients_list, controls=expanded_meal,
expand=True, expand=True,
spacing=10, spacing=10,
padding=10, padding=10,
auto_scroll=False, auto_scroll=False,
), ),
], 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()
page.add( return selector_body
ft.ListView(
controls=meal_list, def show_meal_selection(self, selector_body, page):
self.get_meal_radios()
selector_body.controls = [ft.ListView(
controls=[
self.get_meal_radios_group(),
],
expand=True, expand=True,
spacing=10, spacing=10,
padding=10, padding=10,
auto_scroll=False,
),
ft.Row(
controls=[
ft.Button(content=ft.Text("Update Meal"),
on_click=lambda e: self.show_meal_details(selector_body, page)),
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!"
page.update()
return selector_body
meal = Meal()
page.title = "Create and Edit Meals!"
selector_body = ft.Column(
controls = [],
height = 700,
expand = False,
) )
# TODO add functionality to create new meals page.controls[0].content = meal.show_meal_selection(selector_body, page)
# TODO add functionality to add ingredients to a meal (Mostly done) page.update()
# TODO (Possible) add functionality to delete meals and ingredients
# TODO add functionality to add ingredients to a meal
# TODO (Possible) add functionality to delete meals and/or ingredients
if __name__ == "__main__":
ft.app(builder) ft.app(builder)

View File

@@ -1,8 +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 import flet as ft
selected_meals = {} selected_meals = {}
meal_json = read_json() meal_json = read_ingredient_json()
def selector(page: ft.Page): def selector(page: ft.Page):
def update_meal_selection(event): def update_meal_selection(event):
@@ -12,18 +13,27 @@ def selector(page: ft.Page):
selected_meals.pop(meal.label) selected_meals.pop(meal.label)
else: else:
selected_meals[meal.label] = meal_json[meal.label] 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)) write_checklist(combine_ingredients(selected_meals))
page.title = "Select Some Meals" page.title = "Select Some Meals"
meal_list = [] meal_list = []
for name, _ in meal_json.items(): 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) )
)
page.add( submit_button = ft.Button(content=ft.Text("Make Shopping List"), on_click=update_meal_selection)
page.controls[0].content = ft.Column(
controls = [
ft.ListView( ft.ListView(
controls=meal_list, controls=meal_list,
expand=True, expand=True,
@@ -31,6 +41,11 @@ def selector(page: ft.Page):
padding=10, padding=10,
), ),
submit_button, submit_button,
],
height = 700,
expand = False,
) )
page.update()
if __name__ == "__main__":
ft.app(selector) ft.app(selector)

64
src/Settings.py Normal file
View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -1,26 +1,17 @@
import flet as ft import flet as ft
from MealSelector import selector
from models.MenuBar import create_menubar
def main(page: ft.Page): def main(page: ft.Page):
counter = ft.Text("0", size=50, data=0) page.window.width = 750
page.window.height = 900
page.window.top = 10
page.appbar = create_menubar(page)
page.bgcolor = '#013328'
def increment_click(e): page.add(ft.Pagelet(content=ft.Text(), expand=True, bgcolor='#013328'))
counter.data += 1 selector(page)
counter.value = str(counter.data)
counter.update()
page.floating_action_button = ft.FloatingActionButton( if __name__ == "__main__":
icon=ft.Icons.ADD, on_click=increment_click ft.run(main)
)
page.add(
ft.SafeArea(
ft.Container(
counter,
alignment=ft.alignment.center,
),
expand=True,
)
)
ft.app(main)

23
src/models/MenuBar.py Normal file
View File

@@ -0,0 +1,23 @@
import flet as ft
from MealBuilder import builder
from MealSelector import selector
from Settings import settings
def create_menubar(page: ft.Page):
menu = ft.AppBar(
title=ft.Text("NoteNook"),
bgcolor='#CC8B65',
center_title=False,
actions=[
ft.PopupMenuButton(
items=[
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'
)
]
)
return menu