Made Flet 1.0 changes
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
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()
|
||||||
|
|
||||||
def get_meal_names():
|
def get_meal_names():
|
||||||
meal_list = list(meal_json.keys())
|
meal_list = list(meal_json.keys())
|
||||||
@@ -62,6 +62,7 @@ def builder(page):
|
|||||||
# Doesn't work yet
|
# Doesn't work yet
|
||||||
|
|
||||||
# if not self.new_ingredient or not self.new_quantity or not is_number(self.new_quantity):
|
# 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
|
# return
|
||||||
|
|
||||||
# ingredient = {
|
# ingredient = {
|
||||||
@@ -86,9 +87,9 @@ def builder(page):
|
|||||||
auto_scroll=False,
|
auto_scroll=False,
|
||||||
),
|
),
|
||||||
ft.Row(controls=[
|
ft.Row(controls=[
|
||||||
ft.ElevatedButton(text="Add Ingredient", on_click=lambda e: self.append_new_ingredient_row(selector_body)),
|
ft.Button(content=ft.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.Button(content=ft.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("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
|
# Don't add a new row if the last one is blank
|
||||||
if selector_body.controls[1].controls[-1].controls[0].value == "" or \
|
if selector_body.controls[1].controls[-1].controls[0].value == "" or \
|
||||||
selector_body.controls[1].controls[-1].controls[1].value == "":
|
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
|
return
|
||||||
|
|
||||||
selector_body.controls[1].controls.append(ft.Row(self.create_new_ingredient_row(),
|
selector_body.controls[1].controls.append(ft.Row(self.create_new_ingredient_row(),
|
||||||
@@ -118,7 +119,7 @@ def builder(page):
|
|||||||
if meal == "" or \
|
if meal == "" or \
|
||||||
selector_body.controls[1].controls.controls[0].value == "" or \
|
selector_body.controls[1].controls.controls[0].value == "" or \
|
||||||
selector_body.controls[1].controls.controls[1].value == "":
|
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
|
return
|
||||||
|
|
||||||
for row in selector_body.controls[1].controls:
|
for row in selector_body.controls[1].controls:
|
||||||
@@ -141,14 +142,17 @@ def builder(page):
|
|||||||
expanded_meal = []
|
expanded_meal = []
|
||||||
|
|
||||||
if (selector_body.controls[0].controls[0].value == None):
|
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
|
return
|
||||||
|
|
||||||
meal_name = selector_body.controls[0].controls[0].value
|
meal_name = selector_body.controls[0].controls[0].value
|
||||||
|
|
||||||
for details in meal_json[meal_name].items():
|
for details in meal_json[meal_name].items():
|
||||||
expanded_meal.append(
|
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,
|
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -163,8 +167,8 @@ def builder(page):
|
|||||||
auto_scroll=False,
|
auto_scroll=False,
|
||||||
),
|
),
|
||||||
ft.Row(controls=[
|
ft.Row(controls=[
|
||||||
ft.ElevatedButton(text="Save Changes", on_click=lambda e: self.update_ingredients(selector_body.controls[0].value)),
|
ft.Button(content=ft.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("Back"), on_click=lambda e: self.show_meal_selection(selector_body, page)),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
@@ -187,9 +191,9 @@ def builder(page):
|
|||||||
),
|
),
|
||||||
ft.Row(
|
ft.Row(
|
||||||
controls=[
|
controls=[
|
||||||
ft.ElevatedButton(text="Update Meal",
|
ft.Button(content=ft.Text("Update Meal"),
|
||||||
on_click=lambda e: self.show_meal_details(selector_body, page)),
|
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
|
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):
|
||||||
@@ -14,7 +14,7 @@ def selector(page: ft.Page):
|
|||||||
else:
|
else:
|
||||||
selected_meals[meal.label] = meal_json[meal.label]
|
selected_meals[meal.label] = meal_json[meal.label]
|
||||||
if selected_meals == {}:
|
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
|
return
|
||||||
|
|
||||||
write_checklist(combine_ingredients(selected_meals))
|
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(
|
page.controls[0].content = ft.Column(
|
||||||
controls = [
|
controls = [
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import flet as ft
|
import flet as ft
|
||||||
from MealBuilder import builder
|
|
||||||
from MealSelector import selector
|
from MealSelector import selector
|
||||||
from models.MenuBar import create_menubar
|
from models.MenuBar import create_menubar
|
||||||
|
|
||||||
@@ -8,11 +7,11 @@ def main(page: ft.Page):
|
|||||||
page.window.width = 750
|
page.window.width = 750
|
||||||
page.window.height = 900
|
page.window.height = 900
|
||||||
page.window.top = 10
|
page.window.top = 10
|
||||||
page.appbar = create_menubar(page, selector, builder)
|
page.appbar = create_menubar(page)
|
||||||
page.bgcolor = '#013328'
|
page.bgcolor = '#013328'
|
||||||
|
|
||||||
page.add(ft.Pagelet(content=ft.Text()))
|
page.add(ft.Pagelet(content=ft.Text(), expand=True, bgcolor='#013328'))
|
||||||
selector(page)
|
selector(page)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
ft.app(main)
|
ft.run(main)
|
||||||
Reference in New Issue
Block a user