diff --git a/demo.py b/demo.py index 5281843..1b0396e 100644 --- a/demo.py +++ b/demo.py @@ -6,7 +6,8 @@ import tkinter as tk from tkinter import filedialog from PIL import Image, ImageTk -OPENED_IMAGE = None + +CURRENT_IMAGE_BASENAME = None # Track the basename of the currently opened image def padding(file_path, border_width): image = cv2.imread(file_path) @@ -145,9 +146,9 @@ def _open_image(file_path): # Update label inside frame with the correct dimensions image_label.config(image=tk_img, height=height, width=width) - global OPENED_IMAGE - OPENED_IMAGE = file_path # Store opened image in global variable, to access later if needed - + + global CURRENT_IMAGE_BASENAME + CURRENT_IMAGE_BASENAME = os.path.basename(file_path) print("Opened image:", file_path) @@ -168,20 +169,20 @@ if __name__ == "__main__": file_menu = tk.Menu(menu, tearoff=0) menu.add_cascade(label="File", menu=file_menu) file_menu.add_command(label="Open Image", command=open_image) - file_menu.add_command(label="Save Image", command=lambda: _save_image(OPENED_IMAGE)) + file_menu.add_command(label="Save Image", command=lambda: _save_image(f"cache/{CURRENT_IMAGE_BASENAME}") if CURRENT_IMAGE_BASENAME else print("No image opened.")) file_menu.add_command(label="Exit", command=root.quit) test_menu = tk.Menu(menu, tearoff=0) menu.add_cascade(label="Test", menu=test_menu) - test_menu.add_command(label="Padding", command=lambda: padding(OPENED_IMAGE, border_width=50) if OPENED_IMAGE is not None else print("No image opened.")) - test_menu.add_command(label="Crop", command=lambda: crop(OPENED_IMAGE) if OPENED_IMAGE is not None else print("No image opened.")) - test_menu.add_command(label="Resize", command=lambda: resize(OPENED_IMAGE) if OPENED_IMAGE is not None else print("No image opened.")) - test_menu.add_command(label="Copy", command=lambda: copy(OPENED_IMAGE) if OPENED_IMAGE is not None else print("No image opened.")) - test_menu.add_command(label="Greyscale", command=lambda: grayscale(OPENED_IMAGE) if OPENED_IMAGE is not None else print("No image opened.")) - test_menu.add_command(label="Hsv", command=lambda: hsv(OPENED_IMAGE) if OPENED_IMAGE is not None else print("No image opened.")) - test_menu.add_command(label="Hue Shifted", command=lambda: hue_shifted(OPENED_IMAGE, hue=50) if OPENED_IMAGE is not None else print("No image opened.")) - test_menu.add_command(label="Smoothed", command=lambda: smoothing(OPENED_IMAGE) if OPENED_IMAGE is not None else print("No image opened.")) - test_menu.add_command(label="Rotated", command=lambda: rotation(OPENED_IMAGE, rotation_angle=90) if OPENED_IMAGE is not None else print("No image opened.")) + test_menu.add_command(label="Padding", command=lambda: padding(f"cache/{CURRENT_IMAGE_BASENAME}", border_width=50) if CURRENT_IMAGE_BASENAME else print("No image opened.")) + test_menu.add_command(label="Crop", command=lambda: crop(f"cache/{CURRENT_IMAGE_BASENAME}") if CURRENT_IMAGE_BASENAME else print("No image opened.")) + test_menu.add_command(label="Resize", command=lambda: resize(f"cache/{CURRENT_IMAGE_BASENAME}") if CURRENT_IMAGE_BASENAME else print("No image opened.")) + test_menu.add_command(label="Copy", command=lambda: copy(f"cache/{CURRENT_IMAGE_BASENAME}") if CURRENT_IMAGE_BASENAME else print("No image opened.")) + test_menu.add_command(label="Greyscale", command=lambda: grayscale(f"cache/{CURRENT_IMAGE_BASENAME}") if CURRENT_IMAGE_BASENAME else print("No image opened.")) + test_menu.add_command(label="Hsv", command=lambda: hsv(f"cache/{CURRENT_IMAGE_BASENAME}") if CURRENT_IMAGE_BASENAME else print("No image opened.")) + test_menu.add_command(label="Hue Shifted", command=lambda: hue_shifted(f"cache/{CURRENT_IMAGE_BASENAME}", hue=50) if CURRENT_IMAGE_BASENAME else print("No image opened.")) + test_menu.add_command(label="Smoothed", command=lambda: smoothing(f"cache/{CURRENT_IMAGE_BASENAME}") if CURRENT_IMAGE_BASENAME else print("No image opened.")) + test_menu.add_command(label="Rotated", command=lambda: rotation(f"cache/{CURRENT_IMAGE_BASENAME}", rotation_angle=90) if CURRENT_IMAGE_BASENAME else print("No image opened.")) clipboard_menu = tk.Menu(menu, tearoff=0)