feat (mvFileDialog): cancel button callback
name: feat (mvFileDialog): cancel button callback
about: A cancel button callback can be provided to file_dialog() as an optional keyword argument
title: Cancel button callback
assignees: @hoffstadt
Fixes #1841. Replaces #1842.
Description:
A new optional keyword argument providing a callback function can be passed to file_dialog. The new keyword argument is cancel_callback. The callback will be run if the user clicks the file dialog's cancel button. Documentation has been updated. Previously, a callback was only called if OK was clicked, making it difficult to detect if the user clicked cancel.
Concerning Areas: My first dpg and C++ contribution so it's likely I've done something wrong.
Hi @hoffstadt and @Pcothren, I know it's the summer but just pinging in case this got missed - feel free to close it if its not appropriate!
Any chance of getting this reviewed @hoffstadt @Pcothren? If not I'll try again to look for a workaround
fixed build errors ( and, or)
fixed documentation style (spaces not tabs) cause problem with presentation as .rst in ReadTheDocs
only change was to go ahead and send data through the cancel callback incase the user wants to do something with it because why not.
@hoffstadt the file directory seems that it was never clean up like the rest of the widgets. Not a huge fan of how the code is implemented but it works and could be cleaned up when we get to clean up the rest of this widget.
Tested Case This is the test case that was use and it does run.
import dearpygui.dearpygui as dpg
dpg.create_context()
def callback(sender, app_data):
print('OK was clicked.')
print("Sender: ", sender)
print("App Data: ", app_data)
def cancel_callback1(sender, app_data):
print('Cancel was clicked 1.')
print("Sender: ", sender)
print("App Data: ", app_data)
def cancel_callback2(sender, app_data):
print('Cancel was clicked 2.')
print("Sender: ", sender)
print("App Data: ", app_data)
dpg.add_file_dialog(
directory_selector=True, show=False, callback=callback, tag="file_dialog_id1",
cancel_callback=cancel_callback)
dpg.add_file_dialog(
directory_selector=True, show=False, callback=callback, tag="file_dialog_id2",
cancel_callback=cancel_callback)
with dpg.window(label="Tutorial", width=800, height=300):
dpg.add_button(label="Directory Selector", callback=lambda: dpg.show_item("file_dialog_id1"))
dpg.add_button(label="Directory Selector", callback=lambda: dpg.show_item("file_dialog_id2"))
dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()