on_close has no effect for popup windows
Version of Dear PyGui
Version: 1.11.1 Operating System: Arch Linux
My Issue/Question
I want to open a popup window on top of a plot in response to a click, and I need to be notified when the popup is closed.
A popup is closed by clicking outside the popup.
With current dpg, the on_close callback is never called for popup windows.
To Reproduce
import dearpygui.dearpygui as dpg
import time
dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()
def on_close_handler(sender, data):
print("In on_close_handler")
with dpg.window(tag="Primary Window"):
dpg.add_text("Hello")
with dpg.window(popup=True, autosize=True, on_close=on_close_handler):
dpg.add_text("Click outside me")
dpg.show_viewport()
dpg.set_primary_window("Primary Window", True)
dpg.start_dearpygui()
dpg.destroy_context()
In this example, clicking outside the popup will never call on_close_handler.
In the C++ code, we can see that there is code to handle on_close for modal windows, but not for popups. Copying the code for modal windows seems to work in my case. With that change, clicking outside the popup does trigger on_close. However I didn't find a way to properly 'close' the popup in response to some interaction inside the popup (delete_item doesn't trigger on_close, neither show=False). In this case my workaround was to called the on_close handler in the concerned handlers to complement clicking outside the popup.
I have a fix for this, but waiting for #2275 (I decided to "freeze" all my fixes until that giant PR gets merged).