drag-n-drop for source/target map
							parent
							
								
									df14b65c1b
								
							
						
					
					
						commit
						f7e309513b
					
				| 
						 | 
					@ -442,8 +442,8 @@ def create_source_target_popup(
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    scrollable_frame.grid(row=0, column=0, padx=0, pady=0, sticky="nsew")
 | 
					    scrollable_frame.grid(row=0, column=0, padx=0, pady=0, sticky="nsew")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def on_button_click(map, button_num):
 | 
					    def on_button_click(map, button_num, fname = None):
 | 
				
			||||||
        map = update_popup_source(scrollable_frame, map, button_num)
 | 
					        map = update_popup_source(scrollable_frame, map, button_num, fname)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for item in map:
 | 
					    for item in map:
 | 
				
			||||||
        id = item["id"]
 | 
					        id = item["id"]
 | 
				
			||||||
| 
						 | 
					@ -456,6 +456,8 @@ def create_source_target_popup(
 | 
				
			||||||
            height=DEFAULT_BUTTON_HEIGHT,
 | 
					            height=DEFAULT_BUTTON_HEIGHT,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        button.grid(row=id, column=0, padx=50, pady=10)
 | 
					        button.grid(row=id, column=0, padx=50, pady=10)
 | 
				
			||||||
 | 
					        button.drop_target_register(DND_FILES)
 | 
				
			||||||
 | 
					        button.dnd_bind('<<Drop>>', lambda e, id=id: on_button_click(map, id, e.data))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        x_label = ctk.CTkLabel(
 | 
					        x_label = ctk.CTkLabel(
 | 
				
			||||||
            scrollable_frame,
 | 
					            scrollable_frame,
 | 
				
			||||||
| 
						 | 
					@ -490,15 +492,19 @@ def create_source_target_popup(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def update_popup_source(
 | 
					def update_popup_source(
 | 
				
			||||||
        scrollable_frame: ctk.CTkScrollableFrame, map: list, button_num: int
 | 
					        scrollable_frame: ctk.CTkScrollableFrame, map: list, button_num: int, fname: str = None
 | 
				
			||||||
) -> list:
 | 
					) -> list:
 | 
				
			||||||
    global source_label_dict
 | 
					    global source_label_dict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # drag-n-drop target, no need to open file dialog
 | 
				
			||||||
 | 
					    if fname is None:
 | 
				
			||||||
        source_path = ctk.filedialog.askopenfilename(
 | 
					        source_path = ctk.filedialog.askopenfilename(
 | 
				
			||||||
            title=_("select an source image"),
 | 
					            title=_("select an source image"),
 | 
				
			||||||
            initialdir=RECENT_DIRECTORY_SOURCE,
 | 
					            initialdir=RECENT_DIRECTORY_SOURCE,
 | 
				
			||||||
            filetypes=[img_ft],
 | 
					            filetypes=[img_ft],
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        source_path = fname
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if "source" in map[button_num]:
 | 
					    if "source" in map[button_num]:
 | 
				
			||||||
        map[button_num].pop("source")
 | 
					        map[button_num].pop("source")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue