Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_value() to a button in a file_dilaog callback doesn't work #2421

Open
chesterrc opened this issue Nov 17, 2024 · 3 comments
Open

set_value() to a button in a file_dilaog callback doesn't work #2421

chesterrc opened this issue Nov 17, 2024 · 3 comments
Labels
state: pending not addressed yet type: bug bug

Comments

@chesterrc
Copy link

chesterrc commented Nov 17, 2024

Version of Dear PyGui

Version: 1.11.1
Operating System: Windows 10

My Issue/Question

When I try to use set_value() to a button within a callback for a file_dialog(), the button's value is not set.

To Reproduce

Steps to reproduce the behavior:

  1. Create a button
  2. Create a hidden file_dialog window
  3. Create a file_select function with the arguments of sender and app_data to set the value of the button to app_data["file_path_name"] then print the get_value of the button
  4. Set a callback on the button to show file_dialog window
  5. Set the file_dialog function as the callback to the file_dialog
  6. Run the python script, click the button, select a file, and check on the print statements.

Expected behavior

The print statement will have an output of "None"

Screenshots/Video

dearpygui_issue

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg


def file_select(sender, app_data):
    print(app_data)
    dpg.set_value("button", app_data["file_path_name"])
    print(dpg.get_value("button"))


dpg.create_context()
dpg.create_viewport(title='Test For Set Value', width=600, height=200)
dpg.setup_dearpygui()

with dpg.window(label="Test"):
    dpg.add_button(
                    label="button",
                    tag="button",
                    callback=lambda: dpg.show_item("file_dialog")
                    )

with dpg.file_dialog(show=False, label="choose a file",
                    tag="file_dialog", callback=file_select):
    dpg.add_file_extension(".*")


dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
@chesterrc chesterrc added state: pending not addressed yet type: bug bug labels Nov 17, 2024
@v-ein
Copy link
Contributor

v-ein commented Nov 17, 2024

What do you expect to get by setting a value on a button?

@chesterrc
Copy link
Author

I expected to get the path to a .csv file. I'm essentially creating a config window that has several other items, and when a user presses the "run" button, I expected to get the values of all the child items of the window.

@v-ein
Copy link
Contributor

v-ein commented Nov 19, 2024

So did I get it correctly that you're trying to save values obtained via the file_select callback in order to access them later? If so,

  1. You can use dpg.set_item_user_data() instead of set_value(). This way you'll be able to retrieve the value later with dpg.get_item_user_data().
  2. You can store the value in a global variable or a class member. This will probably be more convenient (especially with a class member) than set_item_user_data. BTW if you specify a member function as a DPG callback, that function does receive self and can therefore access member fields. That is, storing or retrieving the value is just one line like this:
class MyConfigDialog:
    selected_file: str = ""

    def file_select(self, sender, app_data):
        self.selected_file = app_data["file_path_name"]

Buttons, as well as some other widgets, do not have a value, and set_value is just ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: pending not addressed yet type: bug bug
Projects
None yet
Development

No branches or pull requests

2 participants