from __future__ import annotations import toga from .data.db import init_database from .ui.main_window import build_main_window class FunkyJuiceRecipesApp(toga.App): 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) def startup(self) -> None: # Initialize database and run migrations before showing UI 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) self.main_window.show() # 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 def main() -> FunkyJuiceRecipesApp: """Entry point for Briefcase and CLI execution. Returns a constructed, not-yet-started app instance. """ print("main() starting") return FunkyJuiceRecipesApp("funkyjuicerecipes", "com.targonproducts.funkyjuicerecipes") if __name__ == "__main__": app = main() app.main_loop()