When a Chinese characters included in the file_dialog filename, it crashed with code -1073740791 (0xC0000409).
- copy a file which filename include Chinese characters to the file_dialog default open path.
- run the dpg.file_dialog() to show the file dialog.
- Dearpygui crashed with code with code -1073740791 (0xC0000409).
- For example, the filename is 'test-副本.xml' Thank you!
Version of Dear PyGui
Version: 1.7.1 Operating System: win 10
with dpg.file_dialog(height=500,width=500,callback=open_file_callback):
dpg.add_file_extension(".xml",color=(0,255,0,255))
related to #299 https://github.com/hoffstadt/DearPyGui/issues/299#issuecomment-1305007580
from pathlib import Path import os import dearpygui.dearpygui as dpg
选项列表 =[]
def 过滤(sender, filter_string): # 设置值 标记 内容值 dpg.set_value("过滤器", filter_string)
def 双击文件夹(sender, app_data): # Double-click to open the next layer of the path and refresh the display window # 双击打开下一层路径 下一层路径 = Path(dpg.get_value("文件路径")) / Path(dpg.get_value(app_data[1])) if os.path.isdir(下一层路径): dpg.delete_item("过滤器") 选项列表.clear() print(下一层路径) dpg.set_value("文件路径",下一层路径) with dpg.filter_set(tag="过滤器",parent="角色目录"): for i in os.listdir(Path(下一层路径)): dpg.add_text(i,filter_key=i,tag=i) dpg.bind_item_handler_registry(i, "事件项目") else: return
def 后退(): # Back to top,It doesn't change when it's in the root directory. # 返回上一层目录,当处于根目录时不会发生变化 dpg.delete_item("过滤器") 文件夹路径 = dpg.get_value("文件路径") 上一层 = 文件夹路径.replace(Path(dpg.get_value("文件路径")).name,"") if 上一层.endswith("\"): 上一层 = 上一层[:-1] if 上一层.endswith(":"): 上一层 = f"{上一层}\" dpg.set_value("文件路径",上一层) print(上一层) # 创建过滤器 with dpg.filter_set(tag="过滤器", parent="角色目录"): for i in os.listdir(Path(上一层)): dpg.add_text(i, filter_key=i, tag=i) dpg.bind_item_handler_registry(i, "事件项目")
def 监听停留(sender, app_data): # For dynamic acquisition of the file where the cursor is located # 用于动态获取光标所在的文件 try: # 选项列表 -> list() if 选项列表: dpg.configure_item(选项列表.pop(), color=(255, 255, 255, 255)) 选项列表.append(app_data) dpg.configure_item(app_data, color=(255, 65, 65, 255)) else: dpg.configure_item(app_data, color=(255, 65, 65, 255)) 选项列表.append(app_data) except SystemError: pass
def 选择角色(sender, app_data): # Get the selected file directory when clicked # 单击时获取选择的文件目录 print("单击了") 选择的文件 = dpg.get_value(app_data[1]) print(选择的文件) dpg.set_value("当前选择",选择的文件) if os.path.isdir(Path(dpg.get_value("文件路径"))/Path(选择的文件)): dpg.set_value("后缀", "\t\t[ Dir ]") else: dpg.set_value("后缀", "\t\t[ File ]") # with dpg.popup(dpg.get_value(app_data[1]), mousebutton=dpg.mvMouseButton_Right, modal=False): # dpg.add_button(label="选项")
def 搜索(): # Get folder information when you click Search # 点击搜索时,获取文件夹信息 # try: dpg.delete_item("过滤器") # except AttributeError: # print("暂时没有控件") 文件夹路径 = dpg.get_value("文件路径") print(文件夹路径) # 创建过滤器 # dpg.add_text("aaa1.c", filter_key="aaa1.c", bullet=True) with dpg.filter_set(tag="过滤器",parent="角色目录"): for i in os.listdir(Path(文件夹路径)): dpg.add_text(i,filter_key=i,tag=i) dpg.bind_item_handler_registry(i, "事件项目") def ok(): # 点击确认后显示完整路径 print(Path(dpg.get_value("文件路径")) / Path(dpg.get_value("当前选择")))
if name == 'main':
dpg.create_context() # 必须放在第一行
dpg.show_metrics() # 能够看见当前设备的实时刷新率、各种设备监听
with dpg.item_handler_registry(tag="事件项目"):
# 添加各种类型的监听事件触发的函数
dpg.add_item_clicked_handler(callback=选择角色)
dpg.add_item_double_clicked_handler(callback=双击文件夹)
dpg.add_item_hover_handler(callback=监听停留)
# 想要显示非英文字符需要添加字体文件,请更换你本地的字体文件路径
with dpg.font_registry():
with dpg.font("./jp-Light.ttc", 15, tag="font"):
dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)
dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Simplified_Common)
dpg.add_font_range_hint(dpg.mvFontRangeHint_Japanese)
dpg.add_font_range_hint(dpg.mvFontRangeHint_Korean)
dpg.bind_font("font")
with dpg.window():
dpg.add_text("文件目录路径:")
with dpg.group(horizontal=True):
dpg.add_input_text(default_value=str(Path.cwd()),height=100,width=300,tag="文件路径")
dpg.add_button(label="后退",callback=后退,width=40,height=20)
dpg.add_button(label="搜索", callback=搜索, width=40, height=20)
dpg.add_input_text(hint="人物搜索", callback=过滤,width=400)
with dpg.child_window(width=400,height=100,tag="角色目录"):
pass
with dpg.group(horizontal=True):
dpg.add_input_text(readonly=True, label="", tag="当前选择", width=200)
dpg.add_input_text(readonly=True, label="", tag="后缀", width=85)
dpg.add_text()
dpg.add_text()
dpg.add_text()
dpg.add_button(label="确认(ok)",callback=ok,width=70)
# dpg.set_primary_window("主窗口", True)
# ------------------------------
dpg.create_viewport(title="test",width=500,height=500)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
#-------------------------------------------------------------------- #I simulated writing a file manager-like function, but there was a problem, I wanted to add a right-click pop-up function, but it would cause the next level of directory could not be opened.