DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

File Dialog Callback Data is Confusing

Open igor-martinovski opened this issue 3 years ago • 2 comments

Version: dearpygui 1.1.3 Operating System: Windows 10

My Issue/Question

File Dialog call back app_data is confusing. When one file is selected the app_data dict contains an incorrect filename, it includes the filter as the extension. The file_path_name also contains the filter as the extension.

When multiple files are selected, the file_name and file_path_name also append the filter but it makes no sense (see output below)

app_data with one file selected:
{'current_filter': '.*',
 'current_path': 'C:\\Users\\igor\\Desktop\\dearpygui',
 'file_name': 'out.*',
 'file_path_name': 'C:\\Users\\igor\\Desktop\\dearpygui\\out.*',
 'selections': {'out.csv': 'C:\\Users\\igor\\Desktop\\dearpygui\\out.csv'}}
app_data with two files selected:
{'current_filter': '.*',
 'current_path': 'C:\\Users\\igor\\Desktop\\dearpygui',
 'file_name': '2 files Selected.*',
 'file_path_name': 'C:\\Users\\igor\\Desktop\\dearpygui\\2 files Selected.*',
 'selections': {'main.py': 'C:\\Users\\igor\\Desktop\\dearpygui\\main.py',
                'out.csv': 'C:\\Users\\igor\\Desktop\\dearpygui\\out.csv'}}

Expected behavior

file_name should be the exact filename, file_path_name should be a list of paths (or something? not sure how useful it is given the selections dict.)

The selections dict can also leverage pathlib objects for additional flexibility

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

dpg.create_context()

def callback(sender, app_data):
    print("Sender: ", sender)
    print("App Data: ", app_data)

with dpg.file_dialog(directory_selector=False, show=False, 
                    callback=callback, 
                    height=300,     
                    width=600,      
                    tag="file_dialog_id") as file_dialog:
                    
    dpg.add_file_extension(".*")

with dpg.window(label="Tutorial", width=800, height=300):
    dpg.add_button(label="Directory Selector", callback=lambda: dpg.show_item("file_dialog_id"))
    print (dpg.get_item_configuration(file_dialog))
    
dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

igor-martinovski avatar Dec 18 '21 15:12 igor-martinovski

I just noticed this problem as well. Except my issue is slightly different. I am trying to select multiple directories. The main difference I see is that my 'selections' output is goofed up. But I managed to fix it with a little path splitting.

App Data: {
  'file_path_name': 'C:\\2 files Selected',
  'file_name': '',
  'current_path': 'C:\\2 files Selected',
  'current_filter': '', 
  'min_size': [100.0, 100.0],
  'max_size': [30000.0, 30000.0],
  'selections': {
    'Users': 'C:\\2 files Selected\\Users',
    'Windows': 'C:\\2 files Selected\\Windows'
  }
}

cyanochroite avatar Mar 18 '22 04:03 cyanochroite

See also my similar comment here. https://github.com/hoffstadt/DearPyGui/issues/1491

EmmaRenauld avatar Jul 21 '23 18:07 EmmaRenauld