drop_callback not working for 2nd and more axis since version 2.0.0 (working with 1.10.1)
Version of Dear PyGui
Version: 2.0.0 Operating System: Windows 11
My Issue/Question
When using multiple axis on a plot. The drop_callback is not working for 2nd and more axis since version 2.0.0 (working with 1.10.1)
To Reproduce
Simply put two axis with callback, drag an item into it. The 2nd axis isn't going yellow and no callback are call.
Expected behavior
Same script was working well with drop back with 1.10.1
Screenshots/Video
Standalone, minimal, complete and verifiable example
def new_axis_drop_callback(y: str):
def _callback(_s, app_data, _u):
dpg.add_text('new axis', indent=10, parent="Console")
ds: DataTable = app_data["dragged_data"]
if dpg.does_item_exist(ds.formatted_key):
return
if ds in {TimeseriesDataTables.FRINGE_EDGES}:
add_stem_series(ds, y)
else:
add_line_series(ds, y)
return _callback
with dpg.plot(
drop_callback=plot_drop, payload_type="plotting", width=-1, height=-1, tag="log view",
):
dpg.add_plot_legend(payload_type="plotting")
dpg.add_plot_axis(dpg.mvXAxis, tag="x_axis", label="t")
dpg.add_plot_axis(
dpg.mvYAxis,
tag="y1_axis",
label="y1",
drop_callback=new_axis_drop_callback("y1_axis"),
payload_type="plotting",
)
dpg.add_plot_axis(
dpg.mvYAxis,
tag="y2_axis",
label="y2",
drop_callback=new_axis_drop_callback("y2_axis"),
payload_type="plotting",
)
dpg.add_plot_axis(
dpg.mvYAxis,
tag="y3_axis",
label="y3",
drop_callback=new_axis_drop_callback("y3_axis"),
payload_type="plotting",
)
You need to change these 3 to another string: "y1_axis", "y2_axis", "y3_axis"
because the terminal says: Message: Alias already exists.
If drop_callback still not working, can you provide a short/reproducible example?
My bad about those string, I might forget to rename it - duplicate.
yes, The 2nd axis isn't going yellow and no callback are call. because of some related issue (#2409, #2459, #2387, #2502).
I see it worked by modifying mvPlotting.cpp line#513 - #2502.
import dearpygui.dearpygui as dpg
dpg.create_context()
with dpg.window(width=500, height=500):
def new_axis_drop_callback(y:str):
def _callback(sender, app_data, user_data):
try: # parent - y or sender
dpg.add_line_series([0, 1, 2, 3, 4], [4, 0, 3, 0, 4], parent=y, label=f"line_series: {y}")
except Exception as e:
print(f"{y} drop target not accepted")
finally:
pass # print(app_data)
return _callback
with dpg.plot(width=-1, height=-30, label="test"):
dpg.add_plot_legend(payload_type="plotting",
drop_callback=new_axis_drop_callback("legend"))
dpg.add_plot_axis(dpg.mvXAxis, tag="x_axis", label="t")
dpg.add_plot_axis(
dpg.mvYAxis,
tag="y1_axis",
label="y1",
drop_callback=new_axis_drop_callback("y1_axis"),
payload_type="plotting",
)
dpg.add_plot_axis(
dpg.mvYAxis,
tag="y2_axis",
label="y2",
drop_callback=new_axis_drop_callback("y2_axis"),
payload_type="plotting",
)
dpg.add_plot_axis(
dpg.mvYAxis,
tag="y3_axis",
label="y3",
drop_callback=new_axis_drop_callback("y3_axis"),
payload_type="plotting",
)
dpg.add_button(label=">> drag me")
with dpg.drag_payload(parent=dpg.last_item(), payload_type="plotting", drag_data="button ?"):
dpg.add_text("dragging")
dpg.create_viewport()
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()