Added Settings options

This commit is contained in:
2025-12-17 23:16:54 -05:00
parent 28fd5cba5e
commit 249723a2e0
2 changed files with 71 additions and 3 deletions

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()

View File

@@ -1,6 +1,9 @@
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("NoteNook"),
bgcolor='#CC8B65',
@@ -8,8 +11,9 @@ def create_menubar(page: ft.Page, selector, builder):
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'