From a14a8a4231a9a33f52e9fd39b1f91b804dcfa5ce Mon Sep 17 00:00:00 2001 From: tanyar09 Date: Thu, 2 Oct 2025 13:31:33 -0400 Subject: [PATCH] Add quit button with unsaved changes warning in PhotoTagger This update introduces a new quit button that prompts users with a warning if there are unsaved changes before exiting the tagging dialog. The warning summarizes pending tag additions and removals, allowing users to choose to save changes, quit without saving, or cancel the action. Additionally, the tag selection combobox is now set to 'readonly' to prevent user modifications, enhancing the overall user experience in managing photo tags. --- photo_tagger.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/photo_tagger.py b/photo_tagger.py index b4108e6..80a8be5 100644 --- a/photo_tagger.py +++ b/photo_tagger.py @@ -4613,6 +4613,46 @@ class PhotoTagger: save_button = ttk.Button(bottom_frame, text="Save Tagging") save_button.pack(side=tk.RIGHT, padx=10, pady=5) + # Quit button with warning for pending changes + def quit_with_warning(): + """Quit the dialog, but warn if there are pending changes""" + # Check for pending changes + has_pending_changes = bool(pending_tag_changes or pending_tag_removals) + + if has_pending_changes: + total_additions = sum(len(tags) for tags in pending_tag_changes.values()) + total_removals = sum(len(tags) for tags in pending_tag_removals.values()) + + changes_text = [] + if total_additions > 0: + changes_text.append(f"{total_additions} tag addition(s)") + if total_removals > 0: + changes_text.append(f"{total_removals} tag removal(s)") + + changes_summary = " and ".join(changes_text) + + result = messagebox.askyesnocancel( + "Unsaved Changes", + f"You have unsaved changes: {changes_summary}.\n\n" + "Do you want to save your changes before quitting?\n\n" + "Yes = Save and quit\n" + "No = Quit without saving\n" + "Cancel = Stay in dialog" + ) + + if result is True: # Yes - Save and quit + save_tagging_changes() + root.destroy() + elif result is False: # No - Quit without saving + root.destroy() + # If result is None (Cancel), do nothing - stay in dialog + else: + # No pending changes, just quit + root.destroy() + + quit_button = ttk.Button(bottom_frame, text="Quit", command=quit_with_warning) + quit_button.pack(side=tk.RIGHT, padx=(0, 10), pady=5) + # Enable mouse scroll anywhere in the dialog def on_mousewheel(event): content_canvas.yview_scroll(int(-1*(event.delta/120)), "units") @@ -5153,7 +5193,7 @@ class PhotoTagger: # Top frame - dropdown to select tag to add ttk.Label(top_frame, text="Add tag:").grid(row=0, column=0, padx=(0, 8), sticky=tk.W) tag_var = tk.StringVar() - combo = ttk.Combobox(top_frame, textvariable=tag_var, values=available_tags, width=30) + combo = ttk.Combobox(top_frame, textvariable=tag_var, values=available_tags, width=30, state='readonly') combo.grid(row=0, column=1, padx=(0, 8), sticky=(tk.W, tk.E)) combo.focus_set()