Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Chinese path support for select_directory_dialog #299

Open
hpp0hpp opened this issue Nov 1, 2020 · 15 comments
Open

Chinese path support for select_directory_dialog #299

hpp0hpp opened this issue Nov 1, 2020 · 15 comments
Assignees
Labels
priority: high high priority state: ready Fixed/Added and will be present in an upcoming release type: bug bug

Comments

@hpp0hpp
Copy link

hpp0hpp commented Nov 1, 2020

Version of Dear PyGui:
[DearPyGui Version] 0.5.53
[Python Version] 3.9.0
[DearImGui Version] 1.79
[Compiler] MSVC version 1927

OS

Operating System: Windows 10

My Issue/Question
You can see the path with Chinese character is appear as ?? even I tried
add_additional_font('WeiRuanYaHei.ttf', 18, glyph_ranges='chinese_simplified_common')
which only solve the main interface supporting not the select_directory_dialog.

if path with this is selected, DPG will exit without raising any Exception.

I try to dig into the source code of select_directory_dialog in dearpygui, but could not found it.

image

A clear and concise description of what the issue/question is. Please provide as much context as possible.

To Reproduce

try to create a director with charactor "我的程序", and using select_directory_dialog to select it and press OK.

Expected behavior

normal

Screenshots/Video

see above

Standalone, minimal, complete and verifiable example:

# Here's some code anyone can copy and paste to reproduce your issue
def directory_picker(sender, data):
    select_directory_dialog(callback=apply_selected_directory)

def apply_selected_directory(sender, data):
    # log_debug(data)  # so we can see what is inside of data
    directory = data[0]
    folder = data[1]
    set_value("directory", directory)
    set_value("folder", folder)
    set_value("folder_path", f"{directory}\\{folder}")`

with window('test):
    add_button("Folder", callback=directory_picker)

start_dearpygui()
@hpp0hpp
Copy link
Author

hpp0hpp commented Nov 1, 2020

add_additional_font('WeiRuanYaHei.ttf', 18, glyph_ranges='chinese_simplified_common')

to clarify. I've add this in front of all my code.

this seems to be the problem of ImGui, I found a solution of this from :https://www.joven.top/archives/192

But I don't know how to implement this.

ImGuiIO& io = ImGui::GetIO();
ImFont* font = io.Fonts->AddFontFromFileTTF("Resources/Fonts/zhankuwenyiti.ttf", 22.0f, NULL, io.Fonts->GetGlyphRangesChineseFull());

@hoffstadt
Copy link
Owner

Looking into it but we already do the solution you mentioned.

@hoffstadt
Copy link
Owner

This appears to be an issue related to ImGuiFileDialog. Still looking into it more.

@hoffstadt
Copy link
Owner

Should work in 0.7!

@gold0827
Copy link

gold0827 commented Jun 28, 2021

Unfortunately, I think it remains 0.8.0.

file_dialog_bug

My system info is

DearPyGui Version: 0.8.0 (pip install)
Operating System: macOs Big Sur 11.4

To reproduce, share my code

import os
import dearpygui.dearpygui as dpg

dir_name = os.path.dirname(__file__)[:-7]

def update_file_list(sender, data):
    pass

def file_upload(sender, data):
    os.chdir(dir_name) # Due to working directory problem on macOS, change working directory to path of current source file
    dpg.add_file_dialog(callback=update_file_list, directory_selector=True)

with dpg.font_registry():
    with dpg.font(f'{dir_name}/resource/fonts/NotoSansCJKkr-DemiLight.otf', size=25, default_font=True):
        dpg.add_font_range_hint(dpg.mvFontRangeHint_Default)
        dpg.add_font_range_hint(dpg.mvFontRangeHint_Korean)

with dpg.window(label = 'test') as window:
    dpg.set_primary_window(window, True)
    with dpg.menu_bar():
        with dpg.menu(label = 'Data'):
            dpg.add_menu_item(label = '파일 업로드', callback=file_upload)

if __name__ == '__main__':
    dpg.start_dearpygui()

I think i used "font", "font_registry" and "add_font_range_hint" to use Korean characters properly.

But the Korean characters disappeared in "add_file_dialog".

ttf or otf formats had a same issue.

@hoffstadt hoffstadt reopened this Jun 28, 2021
@hoffstadt
Copy link
Owner

Will look into it again!

@hoffstadt
Copy link
Owner

Switched to high priority.

@Pcothren
Copy link
Collaborator

Pcothren commented Nov 7, 2022

changing this

auto fileName = file.path().filename().string();

to this
auto fileName = file.path().filename().u8string();

solves the issue although we have to make the decision to fix it on our branch or do a PR on ImGuiFileDialog.

example code

with dpg.font_registry():
    with dpg.font("../../assets/NotoSerifCJKjp-Medium.otf", 20, tag="custom font"):
        dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)
    dpg.bind_font(dpg.last_container())

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

with dpg.file_dialog(directory_selector=False, show=False, callback=callbackhere, id="file_dialog_id"):
    dpg.add_file_extension(".*")
    dpg.add_file_extension("", color=(150, 255, 150, 255))
    dpg.add_file_extension("Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp}", color=(0, 255, 255, 255))
    dpg.add_file_extension(".h", color=(255, 0, 255, 255), custom_text="[header]")
    dpg.add_file_extension(".py", color=(0, 255, 0, 255), custom_text="[Python]")

with dpg.window(label="Tutorial 我是中文", width=800, height=300):
    dpg.add_text("我是中文")
    dpg.add_button(label="File Selector", callback=lambda: dpg.show_item("file_dialog_id"))
    dpg.add_button(label="Directory Selector", callback=lambda: dpg.show_item("file_dialog_id"))

and youll have to make a text file somewhere in your directory to navigate to "test-副本.txt"
working directory selector

@MrChinR
Copy link

MrChinR commented Nov 25, 2022

@Pcothren
Thanks for your solution. When I modify it in your way, the FileDialog can display the Chinese language normally. But when I went into a folder with Chinese characters it still crashed. I guess it's because the path above the FileDialog contains Chinese charactor.

@MrChinR
Copy link

MrChinR commented Dec 8, 2022

@hoffstadt
Thanks for @Pcothren 's solution. When I modify it in your way, the FileDialog can display the Chinese language normally. But when I went into a folder with Chinese characters it still crashed. I guess it's because the path above the FileDialog contains Chinese charactor.
Could you check it for me?Thx

@hoffstadt hoffstadt reopened this Jan 4, 2023
@MrChinR
Copy link

MrChinR commented May 8, 2023

@hoffstadt
Thank you for reopening this issue.Is there any chance to solve this now? I am really appreciated.

@MrChinR
Copy link

MrChinR commented Oct 10, 2023

I now using xdialog as an instead method.Those who has the same problem can check this.
https://github.com/xMGZx/xdialog

@v-ein
Copy link
Contributor

v-ein commented Dec 1, 2023

Regarding the crashes I've added some info to #2057.

@cleverpig
Copy link

@hoffstadt Thanks for @Pcothren 's solution. When I modify it in your way, the FileDialog can display the Chinese language normally. But when I went into a folder with Chinese characters it still crashed. I guess it's because the path above the FileDialog contains Chinese charactor. Could you check it for me?Thx

MARK! Waiting for response...

@0313johnny
Copy link

@hoffstadt Thanks for @Pcothren 's solution. When I modify it in your way, the FileDialog can display the Chinese language normally. But when I went into a folder with Chinese characters it still crashed. I guess it's because the path above the FileDialog contains Chinese charactor. Could you check it for me?Thx

Waiting for solution too.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
priority: high high priority state: ready Fixed/Added and will be present in an upcoming release type: bug bug
Projects
None yet
Development

No branches or pull requests

8 participants