2025-12-18 20:30:09 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import toga
|
2025-12-20 06:10:30 +00:00
|
|
|
|
2025-12-18 20:30:09 +00:00
|
|
|
from .data.db import init_database
|
2025-12-20 06:10:30 +00:00
|
|
|
from .ui.main_window import build_main_window
|
2025-12-18 20:30:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class FunkyJuiceRecipesApp(toga.App):
|
2025-12-20 06:10:30 +00:00
|
|
|
def __init__(self, name: str, identifier: str):
|
|
|
|
|
# Debug prints to verify lifecycle entry
|
|
|
|
|
print("FunkyJuiceRecipesApp.__init__ starting", flush=True)
|
|
|
|
|
# Important: call super().__init__ so Toga can wire up lifecycle hooks
|
|
|
|
|
super().__init__(name, identifier)
|
|
|
|
|
print("FunkyJuiceRecipesApp.__init__ finished", flush=True)
|
|
|
|
|
|
2025-12-18 20:30:09 +00:00
|
|
|
def startup(self) -> None:
|
|
|
|
|
# Initialize database and run migrations before showing UI
|
2025-12-20 06:10:30 +00:00
|
|
|
print("startup() entered", flush=True)
|
|
|
|
|
self._db = init_database(self)
|
|
|
|
|
print("db initialized; building window…", flush=True)
|
|
|
|
|
|
|
|
|
|
# Build the main window with a simple content-switching layout
|
|
|
|
|
self.main_window = build_main_window(self)
|
|
|
|
|
print("showing window…", flush=True)
|
2025-12-18 20:30:09 +00:00
|
|
|
self.main_window.show()
|
2025-12-20 06:10:30 +00:00
|
|
|
# def startup(self) -> None:
|
|
|
|
|
# # Initialize database and run migrations before showing UI
|
|
|
|
|
# # Keep a handle so we can close it on exit
|
|
|
|
|
# self._db = init_database(self)
|
|
|
|
|
#
|
|
|
|
|
# # Build the main window with a simple content-switching layout
|
|
|
|
|
# self.main_window = build_main_window(self)
|
|
|
|
|
# print("about to show main window")
|
|
|
|
|
# self.main_window.show()
|
|
|
|
|
|
|
|
|
|
def on_exit(self) -> None:
|
|
|
|
|
# Close DB connection cleanly to avoid resource warnings
|
|
|
|
|
db = getattr(self, "_db", None)
|
|
|
|
|
try:
|
|
|
|
|
if db is not None:
|
|
|
|
|
db.close()
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
2025-12-18 20:30:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> FunkyJuiceRecipesApp:
|
|
|
|
|
"""Entry point for Briefcase and CLI execution.
|
|
|
|
|
|
|
|
|
|
Returns a constructed, not-yet-started app instance.
|
|
|
|
|
"""
|
2025-12-20 06:10:30 +00:00
|
|
|
print("main() starting")
|
|
|
|
|
return FunkyJuiceRecipesApp("funkyjuicerecipes", "com.targonproducts.funkyjuicerecipes")
|
2025-12-18 20:30:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
app = main()
|
|
|
|
|
app.main_loop()
|