DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

Presenting a modal window after a modal file dialog results in inconsistent behavior

Open keck-in-space opened this issue 2 years ago • 3 comments

Version of Dear PyGui

Version: 1.6.2 Operating System: Windows 10

My Issue/Question

When the callback for a modal file dialog also presents a modal window, the modal window does not always appear.

To Reproduce

Steps to reproduce the behavior:

  1. Create a modal file dialog with a callback
  2. In the callback, present a modal window
  3. Notice that the modal window does not always display

Expected behavior

The modal window should always display.

If a small delay is added prior to showing the modal window, the window always displays. (See example for context)

Standalone, minimal, complete and verifiable example

# Here's some code anyone can copy and paste to reproduce your issue
import dearpygui.dearpygui as dpg
import time

dpg.create_context()
dpg.create_viewport(title='Custom Title', width=800, height=600)


def set_path(_, app_data):
    # time.sleep(0.1)  # adding this delay allows the modal to present
    if app_data["file_name"] != "test_file":
        dpg.show_item("invalid_file_modal")
        print("here, but no modal")


dpg.add_file_dialog(label="Choose a valid file", height=int(dpg.get_viewport_height() / 2), modal=True, directory_selector=False,
                    callback=set_path)

with dpg.window(label="Invalid File", modal=True, show=False, tag="invalid_file_modal", no_title_bar=True):
    dpg.add_text("You have selected an invalid file. Please try again.", color=(255, 255, 0))
    dpg.add_separator()
    dpg.add_button(label="OK", width=250, callback=lambda: dpg.hide_item("invalid_file_modal"))

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

keck-in-space avatar Jun 02 '22 18:06 keck-in-space

very similar to #1393

keck-in-space avatar Jun 02 '22 18:06 keck-in-space

I have also run into various issues due to modal windows and how the states of items are updated (e.g. a new modal window not becoming visible, visibility checks not working). You should call the split_frame function between hiding/deleting a modal window and e.g. before showing another modal window or before checking if an item in another window, which had been blocked by the modal window, is now visible. Doing so forces at least one frame to be rendered and that seems to be enough time for the states of items to update (e.g. from not visible to visible).

vyrjana avatar Jun 04 '22 08:06 vyrjana

Thank you! This worked great. Faster rendering than my time.sleep(0.1) as well. Appreciate it!

keck-in-space avatar Jun 06 '22 14:06 keck-in-space

Thanks for sharing the workaround. Closing the issue.

bandit-masked avatar Jan 04 '23 22:01 bandit-masked