Пробовал:
dpg.add_node_link(app_data[0], app_data[1], parent=sender, tag=f"{app_data[0]}_{app_data[1]}")
dpg.add_mouse_click_handler(button=1, callback=delink_callback, user_data=f"{app_data[0]}_{app_data[1]}")
И так
dpg.add_node_link(app_data[0], app_data[1], parent=sender, tag=f"{app_data[0]}_{app_data[1]}")
dpg.handler_registry(user_data=f"{app_data[0]}_{app_data[1]}", tag=f"{app_data[0]}_{app_data[1]}_handler")
dpg.add_mouse_click_handler(button=1, callback=delink_callback, user_data=f"{app_data[0]}_{app_data[1]}", parent=f"{app_data[0]}_{app_data[1]}_handler")
В парент так же сам Node Editor прописывал
пишет Parent could not be deduced.
В любом случае. Чтоже тут не так?
Код:
import dearpygui.dearpygui as dpg
import pdb
dpg.create_context()
# Define your functions here
def function1():
print("Executing Function 1")
def function2():
print("Executing Function 2")
def function3():
print("Executing Function 3")
# callback runs when user attempts to connect attributes
def link_callback(sender, app_data):
# app_data -> (link_id1, link_id2)
dpg.add_node_link(app_data[0], app_data[1], parent=sender, tag=f"{app_data[0]}_{app_data[1]}")
dpg.handler_registry(user_data=f"{app_data[0]}_{app_data[1]}", tag=f"{app_data[0]}_{app_data[1]}_handler")
dpg.add_mouse_click_handler(button=1, callback=delink_callback, user_data=f"{app_data[0]}_{app_data[1]}", parent=f"{app_data[0]}_{app_data[1]}_handler")
function1() # Call Function 1
# callback runs when user attempts to disconnect attributes
def delink_callback(sender, app_data):
print(sender, app_data)
# app_data -> link_id
dpg.delete_item(app_data)
function2() # Call Function 2
with dpg.window(label="Tutorial", width=400, height=400):
with dpg.node_editor(callback=link_callback, delink_callback=delink_callback, tag="123123"):
with dpg.node(label="Node 1"):
with dpg.node_attribute(label="Node A1"):
dpg.add_input_float(label="F1", width=150)
with dpg.node_attribute(label="Node A2", attribute_type=dpg.mvNode_Attr_Output):
dpg.add_input_float(label="F2", width=150)
with dpg.node(label="Node 2", ):
with dpg.node_attribute(label="Node A3"):
dpg.add_input_float(label="F3", width=200)
with dpg.node_attribute(label="Node A4", attribute_type=dpg.mvNode_Attr_Output):
dpg.add_input_float(label="F4", width=200)
function3() # Call Function 3
dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
Лог:
C:\Users\sadab\miniconda3\envs\UniversalAutomator\python.exe C:\Users\sadab\PycharmProjects\UniversalAutomator\main.py
Executing Function 3
Exception:
Error: [1011]
Command: add_*
Item: 34
Label:
Item Type: mvAppItemType::mvMouseClickHandler
Message: Parent could not be deduced.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\sadab\PycharmProjects\UniversalAutomator\main.py", line 23, in link_callback
dpg.add_mouse_click_handler(button=1, callback=delink_callback, user_data=f"{app_data[0]}_{app_data[1]}", parent=f"{app_data[0]}_{app_data[1]}_handler")
File "C:\Users\sadab\miniconda3\envs\UniversalAutomator\lib\site-packages\dearpygui\dearpygui.py", line 5624, in add_mouse_click_handler
return internal_dpg.add_mouse_click_handler(button, label=label, user_data=user_data, use_internal_label=use_internal_label, tag=tag, callback=callback, show=show, parent=parent, **kwargs)
SystemError: <built-in function add_mouse_click_handler> returned a result with an exception set
Process finished with exit code 1
Уже не нужно, оказывается ctrl+клик делинкит узлы