Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

dpg.create_viewport(title='xxx'),Chinese coding problem #1760

Closed
monkeycc opened this issue May 10, 2022 · 5 comments
Closed

dpg.create_viewport(title='xxx'),Chinese coding problem #1760

monkeycc opened this issue May 10, 2022 · 5 comments
Labels
state: pending not addressed yet

Comments

@monkeycc
Copy link

monkeycc commented May 10, 2022

import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport(title='我是中文', width=600, height=200)
dpg.setup_dearpygui()



with dpg.font_registry():
    with dpg.font(r"D:\0SDXX\DearPyGui\MiSans-Medium.ttf", 20) as default_font:
        dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)
dpg.bind_font(default_font) # Binds the font globally


with dpg.window(label="我是中国文字"):
    dpg.add_text("你好, 世界")

dpg.show_viewport()

# below replaces, start_dearpygui()
while dpg.is_dearpygui_running():
    # insert here any code you would like to run in the render loop
    # you can manually stop by using stop_dearpygui()
    print("this will run every frame")
    dpg.render_dearpygui_frame()

dpg.destroy_context()

微信截图_20220511003735

@monkeycc monkeycc added the state: pending not addressed yet label May 10, 2022
@yhyu13
Copy link

yhyu13 commented Jun 30, 2022

The author probably does not convert unicode python str to wide char in the underlying windowing managment

@sedenka
Copy link

sedenka commented Aug 16, 2022

If you realy need that, you may try to modify the source (for Windows) as shown below. It is a dirty solution without knowledge of all consequences but it is working for me. Maybe the correct fix should modify also the CreateWindow() call in the mvShowViewport(). I do not know.

src\platform\Windows\mvViewport.cpp:

#include <locale>
#include <codecvt>
#include "mvWindowsSpecifics.h"
...
std::wstring convert_to_wstring(const std::string& str)
{
	std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conv;
	return conv.from_bytes(str);
}
...
mv_internal void
mvPrerender(mvViewport& viewport)
{
...
	if (viewport.titleDirty)
	{
		SetWindowTextW(viewportData->handle, convert_to_wstring(viewport.title).c_str());
		viewport.titleDirty = false;
	}
...
}

@sedenka
Copy link

sedenka commented Aug 26, 2022

Possible duplicate of #1667.

@bandit-masked
Copy link
Collaborator

Workaround provided and possibly a duplicate. Closing the issue.

@trancefer
Copy link

trancefer commented May 30, 2023

Hi, Why is this not included in the release? For me this is also a problem. And I have seen the same issues arise for other languages. Solution not actual for current 1.9.1/1.9.2 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: pending not addressed yet
Projects
None yet
Development

No branches or pull requests

5 participants