add Drag and drop functionality
parent
2b2caf6aba
commit
30ffbc1042
|
@ -80,7 +80,7 @@ target_label_dict_live = {}
|
|||
img_ft, vid_ft = modules.globals.file_types
|
||||
|
||||
|
||||
def init(start: Callable[[], None], destroy: Callable[[], None], lang: str) -> tkdnd.TkinterDnD.Tk:
|
||||
def init(start: Callable[[], None], destroy: Callable[[], None], lang: str) -> ctk.CTk:
|
||||
global ROOT, PREVIEW, _
|
||||
|
||||
lang_manager = LanguageManager(lang)
|
||||
|
@ -144,37 +144,31 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
ctk.set_appearance_mode("dark")
|
||||
ctk.set_default_color_theme(resolve_relative_path("ui.json"))
|
||||
|
||||
# Initialize TkinterDnD.Tk
|
||||
root = tkdnd.TkinterDnD.Tk()
|
||||
root.minsize(ROOT_WIDTH, ROOT_HEIGHT)
|
||||
root.title(
|
||||
f"{modules.metadata.name} {modules.metadata.version} {modules.metadata.edition}"
|
||||
)
|
||||
|
||||
# Set dark colors for the root window - universal approach
|
||||
root.configure(bg="#1a1a1a")
|
||||
|
||||
root.configure(bg="#050505")
|
||||
root.protocol("WM_DELETE_WINDOW", lambda: destroy())
|
||||
|
||||
# Create a single frame with dark color to contain everything
|
||||
content_frame = ctk.CTkFrame(root, fg_color="#1e1e1e", corner_radius=0)
|
||||
content_frame.pack(fill="both", expand=True, padx=10, pady=10)
|
||||
main_frame = ctk.CTkFrame(root, fg_color="#181818", corner_radius=0)
|
||||
main_frame.pack(fill="both", expand=True, padx=0, pady=0)
|
||||
|
||||
# Use content_frame as the parent for all UI elements
|
||||
source_label = ctk.CTkLabel(content_frame, text=None)
|
||||
source_label = ctk.CTkLabel(main_frame, text=None)
|
||||
source_label.place(relx=0.1, rely=0.1, relwidth=0.3, relheight=0.25)
|
||||
|
||||
source_label.drop_target_register(tkdnd.DND_FILES)
|
||||
source_label.dnd_bind("<<Drop>>", lambda event: handle_drop_source(event))
|
||||
|
||||
target_label = ctk.CTkLabel(content_frame, text=None)
|
||||
target_label = ctk.CTkLabel(main_frame, text=None)
|
||||
target_label.place(relx=0.6, rely=0.1, relwidth=0.3, relheight=0.25)
|
||||
|
||||
target_label.drop_target_register(tkdnd.DND_FILES)
|
||||
target_label.dnd_bind("<<Drop>>", lambda event: handle_drop_target(event))
|
||||
|
||||
select_face_button = ctk.CTkButton(
|
||||
content_frame, text=_("Select a face"), cursor="hand2", command=lambda: select_source_path()
|
||||
main_frame, text=_("Select a face"), cursor="hand2", command=lambda: select_source_path()
|
||||
)
|
||||
select_face_button.place(relx=0.1, rely=0.4, relwidth=0.3, relheight=0.1)
|
||||
|
||||
|
@ -182,12 +176,12 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
select_face_button.dnd_bind("<<Drop>>", lambda event: handle_drop_source(event))
|
||||
|
||||
swap_faces_button = ctk.CTkButton(
|
||||
content_frame, text="↔", cursor="hand2", command=lambda: swap_faces_paths()
|
||||
main_frame, text="↔", cursor="hand2", command=lambda: swap_faces_paths()
|
||||
)
|
||||
swap_faces_button.place(relx=0.45, rely=0.4, relwidth=0.1, relheight=0.1)
|
||||
|
||||
select_target_button = ctk.CTkButton(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Select a target"),
|
||||
cursor="hand2",
|
||||
command=lambda: select_target_path(),
|
||||
|
@ -199,7 +193,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
|
||||
keep_fps_value = ctk.BooleanVar(value=modules.globals.keep_fps)
|
||||
keep_fps_checkbox = ctk.CTkSwitch(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Keep fps"),
|
||||
variable=keep_fps_value,
|
||||
cursor="hand2",
|
||||
|
@ -212,7 +206,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
|
||||
keep_frames_value = ctk.BooleanVar(value=modules.globals.keep_frames)
|
||||
keep_frames_switch = ctk.CTkSwitch(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Keep frames"),
|
||||
variable=keep_frames_value,
|
||||
cursor="hand2",
|
||||
|
@ -225,7 +219,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
|
||||
enhancer_value = ctk.BooleanVar(value=modules.globals.fp_ui["face_enhancer"])
|
||||
enhancer_switch = ctk.CTkSwitch(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Face Enhancer"),
|
||||
variable=enhancer_value,
|
||||
cursor="hand2",
|
||||
|
@ -238,7 +232,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
|
||||
keep_audio_value = ctk.BooleanVar(value=modules.globals.keep_audio)
|
||||
keep_audio_switch = ctk.CTkSwitch(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Keep audio"),
|
||||
variable=keep_audio_value,
|
||||
cursor="hand2",
|
||||
|
@ -251,7 +245,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
|
||||
many_faces_value = ctk.BooleanVar(value=modules.globals.many_faces)
|
||||
many_faces_switch = ctk.CTkSwitch(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Many faces"),
|
||||
variable=many_faces_value,
|
||||
cursor="hand2",
|
||||
|
@ -264,7 +258,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
|
||||
color_correction_value = ctk.BooleanVar(value=modules.globals.color_correction)
|
||||
color_correction_switch = ctk.CTkSwitch(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Fix Blueish Cam"),
|
||||
variable=color_correction_value,
|
||||
cursor="hand2",
|
||||
|
@ -277,7 +271,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
|
||||
map_faces = ctk.BooleanVar(value=modules.globals.map_faces)
|
||||
map_faces_switch = ctk.CTkSwitch(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Map faces"),
|
||||
variable=map_faces,
|
||||
cursor="hand2",
|
||||
|
@ -291,7 +285,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
|
||||
show_fps_value = ctk.BooleanVar(value=modules.globals.show_fps)
|
||||
show_fps_switch = ctk.CTkSwitch(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Show FPS"),
|
||||
variable=show_fps_value,
|
||||
cursor="hand2",
|
||||
|
@ -304,7 +298,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
|
||||
mouth_mask_var = ctk.BooleanVar(value=modules.globals.mouth_mask)
|
||||
mouth_mask_switch = ctk.CTkSwitch(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Mouth Mask"),
|
||||
variable=mouth_mask_var,
|
||||
cursor="hand2",
|
||||
|
@ -314,7 +308,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
|
||||
show_mouth_mask_box_var = ctk.BooleanVar(value=modules.globals.show_mouth_mask_box)
|
||||
show_mouth_mask_box_switch = ctk.CTkSwitch(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Show Mouth Mask Box"),
|
||||
variable=show_mouth_mask_box_var,
|
||||
cursor="hand2",
|
||||
|
@ -325,22 +319,22 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
show_mouth_mask_box_switch.place(relx=0.6, rely=0.55)
|
||||
|
||||
start_button = ctk.CTkButton(
|
||||
content_frame, text=_("Start"), cursor="hand2", command=lambda: analyze_target(start, root)
|
||||
main_frame, text=_("Start"), cursor="hand2", command=lambda: analyze_target(start, root)
|
||||
)
|
||||
start_button.place(relx=0.15, rely=0.80, relwidth=0.2, relheight=0.05)
|
||||
|
||||
stop_button = ctk.CTkButton(
|
||||
content_frame, text=_("Destroy"), cursor="hand2", command=lambda: destroy()
|
||||
main_frame, text=_("Destroy"), cursor="hand2", command=lambda: destroy()
|
||||
)
|
||||
stop_button.place(relx=0.4, rely=0.80, relwidth=0.2, relheight=0.05)
|
||||
|
||||
preview_button = ctk.CTkButton(
|
||||
content_frame, text=_("Preview"), cursor="hand2", command=lambda: toggle_preview()
|
||||
main_frame, text=_("Preview"), cursor="hand2", command=lambda: toggle_preview()
|
||||
)
|
||||
preview_button.place(relx=0.65, rely=0.80, relwidth=0.2, relheight=0.05)
|
||||
|
||||
# --- Camera Selection ---
|
||||
camera_label = ctk.CTkLabel(content_frame, text=_("Select Camera:"))
|
||||
camera_label = ctk.CTkLabel(main_frame, text=_("Select Camera:"))
|
||||
camera_label.place(relx=0.1, rely=0.86, relwidth=0.2, relheight=0.05)
|
||||
|
||||
available_cameras = get_available_cameras()
|
||||
|
@ -349,7 +343,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
if not camera_names or camera_names[0] == "No cameras found":
|
||||
camera_variable = ctk.StringVar(value="No cameras found")
|
||||
camera_optionmenu = ctk.CTkOptionMenu(
|
||||
content_frame,
|
||||
main_frame,
|
||||
variable=camera_variable,
|
||||
values=["No cameras found"],
|
||||
state="disabled",
|
||||
|
@ -357,13 +351,13 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
else:
|
||||
camera_variable = ctk.StringVar(value=camera_names[0])
|
||||
camera_optionmenu = ctk.CTkOptionMenu(
|
||||
content_frame, variable=camera_variable, values=camera_names
|
||||
main_frame, variable=camera_variable, values=camera_names
|
||||
)
|
||||
|
||||
camera_optionmenu.place(relx=0.35, rely=0.86, relwidth=0.25, relheight=0.05)
|
||||
|
||||
live_button = ctk.CTkButton(
|
||||
content_frame,
|
||||
main_frame,
|
||||
text=_("Live"),
|
||||
cursor="hand2",
|
||||
command=lambda: webcam_preview(
|
||||
|
@ -383,11 +377,11 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> tkdnd
|
|||
live_button.place(relx=0.65, rely=0.86, relwidth=0.2, relheight=0.05)
|
||||
# --- End Camera Selection ---
|
||||
|
||||
status_label = ctk.CTkLabel(content_frame, text=None, justify="center")
|
||||
status_label = ctk.CTkLabel(main_frame, text=None, justify="center")
|
||||
status_label.place(relx=0.1, rely=0.9, relwidth=0.8)
|
||||
|
||||
donate_label = ctk.CTkLabel(
|
||||
content_frame, text="Deep Live Cam", justify="center", cursor="hand2"
|
||||
main_frame, text="Deep Live Cam", justify="center", cursor="hand2"
|
||||
)
|
||||
donate_label.place(relx=0.1, rely=0.95, relwidth=0.8)
|
||||
donate_label.configure(
|
||||
|
|
Loading…
Reference in New Issue