DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

Sender forced to use IDs in 1.9.1

Open ChabaneAmaury opened this issue 2 years ago • 7 comments

Version of Dear PyGui

Version: 1.9.1 Operating System: Windows 10

My Issue/Question

Version 1.9.1 introduced a bug when triggering a callback. The sender is not returned the custom tag (if any), but the id instead. This force us to update the entire code to add get_item_alias to allow us to use custom tags on the sender (we use tags for naming conventions making it easier to go deeper i the objects procedurally)

To Reproduce

Steps to reproduce the behavior:

  1. Use version 1.9.0
  2. Execute the code below and click on the button (see how the tag is 'windowTuto')
  3. Install version 1.9.1
  4. Do the same as before (see how it is the ID now)

Expected behavior

Sender should return the custom tag as in 1.9.0.

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()

with dpg.window(label="tutorial", tag="windowTuto") as window:
    dpg.add_button(label="Press me", callback=lambda s: print(s))

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

ChabaneAmaury avatar Jun 28 '23 08:06 ChabaneAmaury

In your example, the button has a callback but does not have a tag, and there's a tag on the window but it doesn't have a callback.

with dpg.window(label="tutorial", tag="windowTuto") as window:
    dpg.add_button(tag="test-btn", label="Press me", callback=lambda s: print(s))

Works like a charm, printing "test-btn" each time I click the button.

v-ein avatar Jun 28 '23 09:06 v-ein

Well, my example is indeed not right, I have to setup a new one, but you can refer to this message on the discord server, where it is specified that I am not the only one : https://discord.com/channels/736279277242417272/736279277242417275/1105551843393818704

ChabaneAmaury avatar Jun 28 '23 11:06 ChabaneAmaury

import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()

with dpg.window(label="tutorial") as window:
    with dpg.node_editor(tag="NodeEditor",
                         # Function call for updating all nodes if a new link is created
                         callback=lambda s, a, u: print(s, a, u)):
        with dpg.node():
            dpg.add_node_attribute(label="1", attribute_type=dpg.mvNode_Attr_Output,tag="test1")
        with dpg.node():
            dpg.add_node_attribute(label="2", attribute_type=dpg.mvNode_Attr_Input,tag="test2")

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

This one is close to what I have currently

Results in 1.9.0: NodeEditor ('test1', 'test2') None

Results in 1.9.1: NodeEditor (24, 26) None

Note that this issue is known as well for the tab_bar's callback

ChabaneAmaury avatar Jun 28 '23 11:06 ChabaneAmaury

Yeah, this one breaks for me, too. It's a regression caused by commit 187c94e, which was done to fix the issue #2034.

v-ein avatar Jun 28 '23 15:06 v-ein

I'm also affected by this issue! My node editor becomes totally unmanageable without the named tags.

rdoursenaud avatar Jun 29 '23 12:06 rdoursenaud

I am still facing this issue in v2.0, here is workaround for now if someone needs

# callback runs when user attempts to connect attributes
def link_callback(sender, app_data, user_data):
    # app_data -> (link_id1, link_id2)
    source_link_tag = dpg.get_item_alias(app_data[0])
    destination_link_tag = dpg.get_item_alias(app_data[1])

Mr-MayankThakur avatar Jan 21 '25 17:01 Mr-MayankThakur

I found it to be working fine with: dpg.get_item_alias(sender)

but I use it in a rather simple context :)

Schnabelnane avatar Apr 24 '25 07:04 Schnabelnane