Open nickosh opened 2 years ago
Similar issue: https://github.com/hoffstadt/DearPyGui/issues/1257
Looks like mine issue have more information and recreation way so I hope it will be more useful for fixing.
I have also found a similar issue. My method of operation is to press Ctrl to select two directories, but the returned path is incorrect and must be processed twice before it can be used
Hi a quick fix would be to use app_data["selections"].items()
and a custom function remove_penultimate_to_last()
inside
your directory_selector callback function
as follow:
import dearpygui.dearpygui as dpg
import os
import re
def remove_penultimate_to_last(text, pattern):
idx = text.rfind(pattern, 0, text.rfind(pattern))
return text[0:idx]
dpg.create_context()
def callback(sender, app_data):
print('OK was clicked.')
print("Sender: ", sender)
print("App Data: ", app_data)
print("\n")
for key, val in app_data["selections"].items():
print(" :: ", remove_penultimate_to_last(val,"/")+"/"+key)
def cancel_callback(sender, app_data):
print('Cancel was clicked.')
print("Sender: ", sender)
print("App Data: ", app_data)
dpg.add_file_dialog(
directory_selector=True, show=False, callback=callback, tag="file_dialog_id",
cancel_callback=cancel_callback, width=700 ,height=400)
with dpg.window(label="Tutorial", width=800, height=300):
dpg.add_button(label="Directory Selector", callback=lambda: dpg.show_item("file_dialog_id"))
dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
Version of Dear PyGui
Version: 1.8.0 Operating System: Windows 11 (Build 22621.674)
My Issue/Question
When I used Directory Selector component its duplicate name of the folder at the end of string in "selections" dict. So, instead of "C:\test" folder it always will be "C:\test\test".
To Reproduce
Use
dpg.add_file_dialog
withdirectory_selector=True
parameter.Expected behavior
Folder path without duplication. If I choose "C:\test" I expect same path.
Screenshots/Video
Standalone, minimal, complete and verifiable example