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

Fix non English filepath error in windows #21

Merged
merged 4 commits into from
Oct 1, 2021
Merged

Conversation

atticus-lv
Copy link
Contributor

@atticus-lv atticus-lv commented Sep 30, 2021

add suppport for different encoding system(For Example,'GBK') in Windows using local.getdefaultlocale()
Now can import image like 测试图像.png and not raise Index Error again.

Proposed changes

Screenshots/Screencasts

2021-10-01.02-47-53.mp4

Further comments

add suppport for different encoding system(For Example,'GBK') in Windows using local.getdefaultlocale()
Now can import image like `测试图像.png` and not raise Index Error again.
@thanhph111
Copy link
Collaborator

thanhph111 commented Oct 1, 2021

And one more thing we should consider. On my machine, if we don't check this (in fact, users don't usually use it):

image

the Blender will get an error:

Error: Python: Traceback (most recent call last):
  File "C:\Users\thanh\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\ImagePaste\imagepaste\operators.py", line 188, in execute
    bpy.ops.object.load_reference_image(filepath=image.filepath)
  File "C:\Users\thanh\Documents\Blender\2.93\scripts\modules\bpy\ops.py", line 132, in __call__      
    ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Error: Error: Cannot read 'C:\Users\thanh\Desktop\????.jpg': Invalid argument

because the subprocess decode wrong from 测试图像.jpg to ????.jpg.

import locale
locale.getdefaultlocale()
# ('en_GB', 'cp1252')

Do you have any clue we can also solve that?

@atticus-lv
Copy link
Contributor Author

I think the cp1512 will not contain the Chinese char in its coding.So it works bad.
Chinese char is default set in coding cp936

locale.getdefaultlocale()
# ('zh_CN', 'cp936')
locale.getdefaultlocale()
# after toggle,support non Chinese ('zh_CN', 'cp65001')

May be we should set chcp 65001 to the powershell to change its coding before it runs. So we can default run 'utf-8'

@thanhph111
Copy link
Collaborator

Yeah, you're right. But we should force it to utf-8 even from PowerShell and then subprocess can read it also with utf-8, no matter what the system's encoding is.
I'm on it now.

@thanhph111
Copy link
Collaborator

Can you check that is OK on your side?

@atticus-lv
Copy link
Contributor Author

Can you check that is OK on your side?

Good, it works find.

@thanhph111
Copy link
Collaborator

Great! I think we can have the merge now. The patch will be release this weekend. Thanks for your contributions!

imagepaste/process.py Outdated Show resolved Hide resolved
@thanhph111 thanhph111 linked an issue Oct 1, 2021 that may be closed by this pull request
@thanhph111 thanhph111 merged commit 00f2249 into b-init:main Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQUEST] None English url support
2 participants