Compare commits

9 Commits

Author SHA1 Message Date
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
8 changed files with 174 additions and 142 deletions

4
.gitignore vendored
View File

@@ -163,4 +163,6 @@ cython_debug/
storage/
# Custom
ingredients.json
ingredients.json
checklist.md
.vscode/

View File

@@ -1,81 +1,38 @@
# 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
### 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
Install dependencies from `pyproject.toml`:
Run the flet app:
```
poetry install
flet run MealSelector.py
```
OR
```
flet run MealBuilder.py
```
Run as a desktop app:
```
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/).
For more details, go to the [Flet website](https://flet.dev/)

View File

@@ -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 = "shopping"
product = "Meal Picker"
# company name to display in about app dialogs
company = "Nick Kalar"

View File

@@ -5,30 +5,31 @@ from dotenv import load_dotenv
load_dotenv()
file_path = os.getenv("file_path") if os.getenv("file_path") else "./checklist.md"
file_path = os.getenv("FILE_PATH") + "/checklist.md" if os.getenv("FILE_PATH") else "./checklist.md"
def read_json() -> dict | None:
def read_json() -> dict:
try:
with open("./src/json/ingredients.json", "rt") as file:
return json.load(file)
except:
print("Could not find or read file.")
return {}
def update_json(meals: dict):
def update_json(meals: dict) -> None:
try:
with open("./src/json/ingredients.json", "w") as file:
json.dump(meals, file, indent=4)
except Exception as e:
print(f"Unable to write data to file. {e}")
def get_selected_meals(meals: dict) -> dict | None:
def get_selected_meals(meals: dict) -> dict:
meal_json = read_json()
selected_meals = {}
if meal_json:
for meal in meals:
if meal in meal_json:
selected_meals[meal] = meal_json[meal]
return selected_meals
return selected_meals
def combine_ingredients(meals: dict) -> dict:
combined_ingredients = {}
@@ -36,7 +37,7 @@ def combine_ingredients(meals: dict) -> dict:
for meal, ingredients in meals.items():
for ingredient, detail in ingredients.items():
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:
combined_ingredients[ingredient] = detail
return combined_ingredients

View File

@@ -3,10 +3,11 @@ from FileHandler import read_json, update_json
import flet as ft
meal_json = read_json()
global new_ingredient, new_quantity, new_units
new_ingredient = ""
new_quantity = ""
new_units = ""
def get_meal_names():
meal_list = list(meal_json.keys())
meal_list.sort()
return meal_list
def is_number(s):
try:
@@ -18,18 +19,15 @@ def is_number(s):
def builder(page):
class Meal():
meal_radios = []
new_ingredient = ""
new_quantity = ""
new_units = ""
def __init__(self):
def get_meal_radios(self):
self.meal_radios = []
for name in get_meal_names():
self.meal_radios.append(
ft.Radio(value=name, label=name),
)
def get_meal_radios(self):
def get_meal_radios_group(self):
return ft.RadioGroup(
content=ft.Column(
controls=self.meal_radios,
@@ -38,7 +36,6 @@ def builder(page):
def update_ingredient(self, e):
self.new_ingredient = e.control.value
print(self.new_ingredient)
def update_quantity(self, e):
self.new_quantity = e.control.value
@@ -52,30 +49,86 @@ def builder(page):
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))
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=""))
return row
def update_ingredients(self, name):
if not self.new_ingredient or not self.new_quantity or not is_number(self.new_quantity):
return
pass
# Doesn't work yet
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)
# if not self.new_ingredient or not self.new_quantity or not is_number(self.new_quantity):
# 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),
ft.ListView(controls=[ft.Row(self.create_new_ingredient_row(),
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
width=300,
height=100,
)],
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))
]
page.title = "Add New Meal"
page.update()
def append_new_ingredient_row(self, selector_body):
selector_body.controls[1].controls.append(ft.Row(self.create_new_ingredient_row(),
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
width=300,
height=100,))
page.update()
def add_new_meal(self, e):
print("Gonna add something good!")
def add_new_meal(self, selector_body):
meal = selector_body.controls[0].value
ing, qua, uni = [], [], []
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 = []
print(selector_body.controls[0].value)
meal_name = selector_body.controls[0].value
meal_name = selector_body.controls[0].controls[0].value
for details in meal_json[meal_name].items():
expanded_meal.append(
@@ -105,9 +158,19 @@ def builder(page):
return selector_body
def show_meal_selection(self, selector_body, page):
selector_body.controls = [self.get_meal_radios(),
ft.ElevatedButton(text="Update Meal", on_click=lambda e: self.show_meal_details(selector_body, page)),
ft.ElevatedButton(text="Add Meal", on_click=self.add_new_meal)
self.get_meal_radios()
selector_body.controls = [ft.ListView(
controls=[
self.get_meal_radios_group(),
],
expand=True,
spacing=5,
padding=5,
auto_scroll=False,
),
ft.ElevatedButton(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())
]
if page.title != "Create and Edit Meals!":
@@ -115,9 +178,6 @@ def builder(page):
page.update()
return selector_body
def get_meal_names():
return list(meal_json.keys())
@@ -130,13 +190,11 @@ def builder(page):
expand = False,
)
page.add(ft.Container(
content = meal.show_meal_selection(selector_body, page)
))
page.controls[0].content = meal.show_meal_selection(selector_body, page)
page.update()
# TODO add functionality to create new meals
# TODO add functionality to add ingredients to a meal
# TODO (Possible) add functionality to delete meals and ingredients
# TODO (Possible) add functionality to delete meals and/or ingredients
ft.app(builder)
if __name__ == "__main__":
ft.app(builder)

View File

@@ -1,4 +1,5 @@
from FileHandler import read_json, combine_ingredients, write_checklist
import flet as ft
selected_meals = {}
@@ -23,14 +24,20 @@ def selector(page: ft.Page):
submit_button = ft.ElevatedButton(text="Make Shopping List", on_click=update_meal_selection)
page.add(
ft.ListView(
controls=meal_list,
expand=True,
spacing=10,
padding=10,
),
submit_button,
)
page.controls[0].content = ft.Column(
controls = [
ft.ListView(
controls=meal_list,
expand=True,
spacing=10,
padding=10,
),
submit_button,
],
height = 500,
expand = False,
)
page.update()
ft.app(selector)
if __name__ == "__main__":
ft.app(selector)

View File

@@ -1,26 +1,16 @@
import flet as ft
from MealBuilder import builder
from MealSelector import selector
from models.MenuBar import create_menubar
def main(page: ft.Page):
counter = ft.Text("0", size=50, data=0)
page.appbar = create_menubar(page, selector, builder)
def increment_click(e):
counter.data += 1
counter.value = str(counter.data)
counter.update()
page.floating_action_button = ft.FloatingActionButton(
icon=ft.Icons.ADD, on_click=increment_click
)
page.add(
ft.SafeArea(
ft.Container(
counter,
alignment=ft.alignment.center,
),
expand=True,
)
page.add(ft.Pagelet(
content = ft.Text("Welcome to Meal Picker! Please select an option from the menu above to get started.")
)
)
ft.app(main)
if __name__ == "__main__":
ft.app(main)

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

@@ -0,0 +1,17 @@
import flet as ft
def create_menubar(page: ft.Page, selector, builder):
menu = ft.AppBar(
title=ft.Text("Meal Picker"),
bgcolor=ft.Colors.GREEN_700,
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)),
]
)
]
)
return menu