From 9746f78d4509d4f717043e4de5776ceffce384e3 Mon Sep 17 00:00:00 2001 From: Vladislav Naumov Date: Tue, 11 Feb 2025 19:24:37 +0600 Subject: [PATCH] basic dnd catch --- modules/ui.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 94fa5cf..278637a 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -27,6 +27,8 @@ from modules.utilities import ( ) from modules.video_capture import VideoCapturer from modules.gettext import LanguageManager +from tkinterdnd2 import DND_FILES, TkinterDnD + import platform if platform.system() == "Windows": @@ -143,7 +145,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C ctk.set_appearance_mode("system") ctk.set_default_color_theme(resolve_relative_path("ui.json")) - root = ctk.CTk() + root = TkinterDnD.Tk() root.minsize(ROOT_WIDTH, ROOT_HEIGHT) root.title( f"{modules.metadata.name} {modules.metadata.version} {modules.metadata.edition}" @@ -153,9 +155,13 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C source_label = ctk.CTkLabel(root, text=None) source_label.place(relx=0.1, rely=0.1, relwidth=0.3, relheight=0.25) + source_label.drop_target_register(DND_FILES) + source_label.dnd_bind('<>', lambda e: print("SOURCE: ", e.data)) target_label = ctk.CTkLabel(root, text=None) target_label.place(relx=0.6, rely=0.1, relwidth=0.3, relheight=0.25) + target_label.drop_target_register(DND_FILES) + target_label.dnd_bind('<>', lambda e: print("TARGET: ", e.data)) select_face_button = ctk.CTkButton( root, text=_("Select a face"), cursor="hand2", command=lambda: select_source_path() @@ -705,7 +711,7 @@ def fit_image_to_size(image, width: int, height: int): ratio_h = height / h # Use the smaller ratio to ensure the image fits within the given dimensions ratio = min(ratio_w, ratio_h) - + # Compute new dimensions, ensuring they're at least 1 pixel new_width = max(1, int(ratio * w)) new_height = max(1, int(ratio * h))