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

Open Modal Window after Modal Window, does not open 2nd Window #1513

Closed
Mstpyt opened this issue Dec 30, 2021 · 2 comments
Closed

Open Modal Window after Modal Window, does not open 2nd Window #1513

Mstpyt opened this issue Dec 30, 2021 · 2 comments
Labels
priority: high high priority state: ready Fixed/Added and will be present in an upcoming release type: bug bug type: improvement improvements or optimizations are needed

Comments

@Mstpyt
Copy link
Collaborator

Mstpyt commented Dec 30, 2021

Version of Dear PyGui

Version: 1.1.3
Operating System: Windows 10

My Issue/Question

If you open a Modal Window and open another one after the first one, the 2nd Modal Window does not open till you delete the first window and sleep 0.1 Seconds

Expected behavior

Open a Modal Window on top of a Modal Window or not need to sleep before opening another modal Window

Screenshots/Video

XXX (you can drag files here)

Standalone, minimal, complete and verifiable example

from time import sleep

import dearpygui.dearpygui as dpg

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

def show_info(title, message, selection_callback):

    # guarantee these commands happen in the same frame

    viewport_width = dpg.get_viewport_client_width()
    viewport_height = dpg.get_viewport_client_height()

    with dpg.window(label=title, modal=True, no_close=True, tag="modal") as modal_id:
        dpg.add_text(message)
        with dpg.group(horizontal=True):
            dpg.add_button(label="Ok", width=75, user_data=(modal_id, True), callback=lambda: show_info_two())
            dpg.add_button(label="Cancel", width=75, user_data=(modal_id, False), callback=selection_callback)

    # guarantee these commands happen in another frame
    width = dpg.get_item_width(modal_id)
    height = dpg.get_item_height(modal_id)
    dpg.set_item_pos(modal_id, [viewport_width // 2 - width // 2, viewport_height // 2 - height // 2])


def show_info_two():
    """
    You have to delete the other modal window and after you delete it you have to sleep for 0.1 second otherwise it doesnt work
    """
    dpg.delete_item("modal")
    sleep(0.1)
    

    with dpg.window(label="Lade...", modal=True, no_close=True, tag="loading",
                    width=400, height=400, no_title_bar=True, no_background=True, no_resize=True,
                    no_move=False, pos=[int((dpg.get_viewport_width() // 2 - 400 // 2)),
                                                         int((dpg.get_viewport_height() / 2 - 400 / 2))]):
        dpg.add_loading_indicator(speed=1, radius=10, show=True, pos=[150, 150])

def on_selection(sender, unused, user_data):

    if user_data[1]:
        print("User selected 'Ok'")
    else:
        print("User selected 'Cancel'")

    # delete window
    dpg.delete_item(user_data[0])


with dpg.window(label="Example"):
    dpg.add_button(label="Open Messagebox", callback=lambda:show_info("Message Box", "Do you wish to proceed?", on_selection))
    dpg.add_button(label="2nd",
                   callback=lambda: show_info_two())


# main loop
dpg.show_viewport()
while dpg.is_dearpygui_running():
    dpg.render_dearpygui_frame()

dpg.destroy_context()
@Mstpyt Mstpyt added state: pending not addressed yet type: bug bug labels Dec 30, 2021
@hoffstadt hoffstadt added priority: high high priority and removed state: pending not addressed yet labels Dec 30, 2021
@hoffstadt hoffstadt added state: ready Fixed/Added and will be present in an upcoming release type: improvement improvements or optimizations are needed labels Dec 31, 2021
@hoffstadt
Copy link
Owner

1.2 has a new window keyword "no_open_over_existing_popup". You can do this now:

from time import sleep

import dearpygui.dearpygui as dpg

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

def show_info(title, message, selection_callback):

    # guarantee these commands happen in the same frame

    viewport_width = dpg.get_viewport_client_width()
    viewport_height = dpg.get_viewport_client_height()

    with dpg.window(label=title, no_open_over_existing_popup=False, modal=True, no_close=True, tag="modal") as modal_id:
        dpg.add_text(message)
        with dpg.group(horizontal=True):
            dpg.add_button(label="Ok", width=75, user_data=(modal_id, True), callback=lambda: show_info_two())
            dpg.add_button(label="Cancel", width=75, user_data=(modal_id, False), callback=selection_callback)

    # guarantee these commands happen in another frame
    width = dpg.get_item_width(modal_id)
    height = dpg.get_item_height(modal_id)
    dpg.set_item_pos(modal_id, [viewport_width // 2 - width // 2, viewport_height // 2 - height // 2])


def show_info_two():
    """
    You have to delete the other modal window and after you delete it you have to sleep for 0.1 second otherwise it doesnt work
    """
    #dpg.hide_item("modal")
    #dpg.delete_item("modal")
    #sleep(0.1)
    

    with dpg.window(label="Lade...", no_open_over_existing_popup=False, modal=True, tag="loading",
                    width=400, height=400, no_background=True, no_resize=True,
                    no_move=False, pos=[int((dpg.get_viewport_width() // 2 - 400 // 2)),
                                                         int((dpg.get_viewport_height() / 2 - 400 / 2))]):
        dpg.add_loading_indicator(speed=1, radius=10, show=True, pos=[150, 150])

def on_selection(sender, unused, user_data):

    if user_data[1]:
        print("User selected 'Ok'")
    else:
        print("User selected 'Cancel'")

    # delete window
    dpg.delete_item(user_data[0])


with dpg.window(label="Example"):
    dpg.add_button(label="Open Messagebox", callback=lambda:show_info("Message Box", "Do you wish to proceed?", on_selection))
    dpg.add_button(label="2nd",
                   callback=lambda: show_info_two())


# main loop
dpg.show_viewport()
while dpg.is_dearpygui_running():
    dpg.render_dearpygui_frame()

dpg.destroy_context()

hoffstadt added a commit that referenced this issue Dec 31, 2021
…#1513

* feat (mvWindow): added `no_open_over_existing_popup` keyword to window #1513

* feat (mvWindow): added `no_open_over_existing_popup` keyword to window #1513
@Mstpyt
Copy link
Collaborator Author

Mstpyt commented Dec 31, 2021

Great fix !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high high priority state: ready Fixed/Added and will be present in an upcoming release type: bug bug type: improvement improvements or optimizations are needed
Projects
None yet
Development

No branches or pull requests

2 participants