diff --git a/photo_tagger.py b/photo_tagger.py index ff6c6e2..787e616 100644 --- a/photo_tagger.py +++ b/photo_tagger.py @@ -2848,8 +2848,93 @@ class PhotoTagger: current_matched_index -= 1 update_display() + def has_unsaved_changes(): + """Check if there are any unsaved changes in checkbox_states_per_person""" + return len(checkbox_states_per_person) > 0 + def on_quit_auto_match(): nonlocal window_destroyed + + # Check for unsaved changes before quitting + if has_unsaved_changes(): + # Show warning dialog with custom width + from tkinter import messagebox + + # Create a custom dialog for better width control + dialog = tk.Toplevel(root) + dialog.title("Unsaved Changes") + dialog.geometry("500x250") + dialog.resizable(True, True) + dialog.transient(root) + dialog.grab_set() + + # Center the dialog + dialog.geometry("+%d+%d" % (root.winfo_rootx() + 50, root.winfo_rooty() + 50)) + + # Main message + message_frame = ttk.Frame(dialog, padding="20") + message_frame.pack(fill=tk.BOTH, expand=True) + + # Warning icon and text + icon_label = ttk.Label(message_frame, text="⚠️", font=("Arial", 16)) + icon_label.pack(anchor=tk.W) + + main_text = ttk.Label(message_frame, + text="You have unsaved changes that will be lost if you quit.", + font=("Arial", 10)) + main_text.pack(anchor=tk.W, pady=(5, 10)) + + # Options + options_text = ttk.Label(message_frame, + text="• Yes: Save current changes and quit\n" + "• No: Quit without saving\n" + "• Cancel: Return to auto-match", + font=("Arial", 9)) + options_text.pack(anchor=tk.W, pady=(0, 10)) + + + # Buttons + button_frame = ttk.Frame(dialog) + button_frame.pack(fill=tk.X, padx=20, pady=(0, 20)) + + result = None + + def on_yes(): + nonlocal result + result = True + dialog.destroy() + + def on_no(): + nonlocal result + result = False + dialog.destroy() + + def on_cancel(): + nonlocal result + result = None + dialog.destroy() + + yes_btn = ttk.Button(button_frame, text="Yes", command=on_yes) + no_btn = ttk.Button(button_frame, text="No", command=on_no) + cancel_btn = ttk.Button(button_frame, text="Cancel", command=on_cancel) + + yes_btn.pack(side=tk.LEFT, padx=(0, 5)) + no_btn.pack(side=tk.LEFT, padx=5) + cancel_btn.pack(side=tk.RIGHT, padx=(5, 0)) + + # Wait for dialog to close + dialog.wait_window() + + if result is None: # Cancel - don't quit + return + elif result: # Yes - save changes first + # Save current checkbox states before quitting + save_current_checkbox_states() + # Note: We don't actually save to database here, just preserve the states + # The user would need to click Save button for each person to persist changes + print("⚠️ Warning: Changes are preserved but not saved to database.") + print(" Click 'Save Changes' button for each person to persist changes.") + if not window_destroyed: window_destroyed = True try: