basic dnd catch

pull/933/head
Vladislav Naumov 2025-02-11 19:24:37 +06:00
parent 2f67e2f159
commit 9746f78d45
1 changed files with 8 additions and 2 deletions

View File

@ -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('<<Drop>>', 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('<<Drop>>', 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))