Compare commits
9 Commits
781a7eb89b
...
Unifty-App
| Author | SHA1 | Date | |
|---|---|---|---|
| 027b245075 | |||
| ca3d0f8090 | |||
| 2d5d44cd21 | |||
| 66011974a3 | |||
| 61f1f6a711 | |||
| fec8c05216 | |||
|
|
eb8dcc0f36 | ||
|
|
7347b53bfe | ||
|
|
75cd42ed30 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -164,3 +164,5 @@ storage/
|
||||
|
||||
# Custom
|
||||
ingredients.json
|
||||
checklist.md
|
||||
.vscode/
|
||||
85
README.md
85
README.md
@@ -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/)
|
||||
@@ -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"
|
||||
|
||||
@@ -5,23 +5,24 @@ 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:
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -53,29 +50,85 @@ def builder(page):
|
||||
row.append(ft.TextField(label="Units (optional)", value=details['units'], on_change=self.update_units))
|
||||
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
|
||||
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
|
||||
|
||||
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)
|
||||
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):
|
||||
# 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 add_new_meal(self, e):
|
||||
print("Gonna add something good!")
|
||||
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, 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!":
|
||||
@@ -116,9 +179,6 @@ def builder(page):
|
||||
|
||||
return selector_body
|
||||
|
||||
def get_meal_names():
|
||||
return list(meal_json.keys())
|
||||
|
||||
|
||||
|
||||
meal = Meal()
|
||||
@@ -130,13 +190,11 @@ def builder(page):
|
||||
expand = False,
|
||||
)
|
||||
|
||||
page.controls[0].content = meal.show_meal_selection(selector_body, page)
|
||||
page.update()
|
||||
|
||||
page.add(ft.Container(
|
||||
content = meal.show_meal_selection(selector_body, page)
|
||||
))
|
||||
|
||||
# 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
|
||||
|
||||
if __name__ == "__main__":
|
||||
ft.app(builder)
|
||||
@@ -1,4 +1,5 @@
|
||||
from FileHandler import read_json, combine_ingredients, write_checklist
|
||||
|
||||
import flet as ft
|
||||
|
||||
selected_meals = {}
|
||||
@@ -23,7 +24,8 @@ def selector(page: ft.Page):
|
||||
|
||||
submit_button = ft.ElevatedButton(text="Make Shopping List", on_click=update_meal_selection)
|
||||
|
||||
page.add(
|
||||
page.controls[0].content = ft.Column(
|
||||
controls = [
|
||||
ft.ListView(
|
||||
controls=meal_list,
|
||||
expand=True,
|
||||
@@ -31,6 +33,11 @@ def selector(page: ft.Page):
|
||||
padding=10,
|
||||
),
|
||||
submit_button,
|
||||
],
|
||||
height = 500,
|
||||
expand = False,
|
||||
)
|
||||
page.update()
|
||||
|
||||
if __name__ == "__main__":
|
||||
ft.app(selector)
|
||||
24
src/main.py
24
src/main.py
@@ -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.")
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ft.app(main)
|
||||
17
src/models/MenuBar.py
Normal file
17
src/models/MenuBar.py
Normal 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
|
||||
Reference in New Issue
Block a user