b-init / ImagePaste

A simple Blender addon to grab images from your clipboard and paste as a reference image in viewport or onto the image editor.
GNU General Public License v3.0
251 stars 9 forks source link

[REQUEST] None English url support #20

Closed atticus-lv closed 3 years ago

atticus-lv commented 3 years ago

Problem

when I copy a local image with Chinese name, it shows this error

Python: Traceback (most recent call last):
  File "C:\Users\atticus\AppData\Roaming\Blender Foundation\Blender\3.0\scripts\addons\ImagePaste\imagepaste\operators.py", line 183, in execute
    clipboard = Clipboard.push(get_save_directory())
  File "C:\Users\atticus\AppData\Roaming\Blender Foundation\Blender\3.0\scripts\addons\ImagePaste\imagepaste\clipboard\windows\windows.py", line 54, in push
    process = Process.execute(cls.get_powershell_args(file_script))
  File "C:\Users\atticus\AppData\Roaming\Blender Foundation\Blender\3.0\scripts\addons\ImagePaste\imagepaste\process.py", line 69, in execute
    popen, stdout, stderr = comunicate(process.parameters)
  File "C:\Users\atticus\AppData\Roaming\Blender Foundation\Blender\3.0\scripts\addons\ImagePaste\imagepaste\process.py", line 52, in comunicate
    stdout, stderr = popen.communicate()
  File "C:\Program Files\Blender Foundation\blender-3.0.0-alpha+master.c53ffda8a496-windows.amd64-release\3.0\python\lib\subprocess.py", line 1134, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "C:\Program Files\Blender Foundation\blender-3.0.0-alpha+master.c53ffda8a496-windows.amd64-release\3.0\python\lib\subprocess.py", line 1529, in _communicate
    stdout = stdout[0]
IndexError: list index out of range

Solution

Not yet

Screenshot/Screencast

Additional context

thanhph111 commented 3 years ago

Can I have your image path? I tried some unicode filenames but still can't reproduce on my end.

By the way it's an unexpected behavior so I think it should be a bug.

atticus-lv commented 3 years ago

You can try to rename the image as 测试图像.jpg I think it may cause to the encoding of the system. I am using windows with the Simple Chinese language. Its coding is GBK.

import locale
locale.getdefaultlocale()
# return ('zh_CN', 'cp936')
thanhph111 commented 3 years ago

I think the issue might related to the locale as you pointed out.

The error IndexError: list index out of range from subprocess module is very vague due to this Python issue. As we can see, the stdout and stderr could be empty during a timeout on Windows and then cause the error. So we should redirect towards the PowerShell scripts.

Could you help me collect the outputs from this PowerShell script (PowerShell 5.1 in C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe), running after copying an image, both in Chinese name and in another ASCII normalized name:

$files = Get-Clipboard -Format FileDropList
if ($files) { $files.fullname }
atticus-lv commented 3 years ago

it show the correct path of the image:

PS C:\Windows\System32\WindowsPowerShell\v1.0> $files = Get-Clipboard -Format FIleDropList
PS C:\Windows\System32\WindowsPowerShell\v1.0> if($files) { $files.fullname}
C:\Users\atticus\Desktop\啊啊.png
PS C:\Windows\System32\WindowsPowerShell\v1.0> $files = Get-Clipboard -Format FIleDropList
PS C:\Windows\System32\WindowsPowerShell\v1.0> if($files) { $files.fullname}
C:\Users\atticus\Desktop\aaa.png
thanhph111 commented 3 years ago

The output looks fine. I think the encoding is unlikely to be an issue since utf-8 has already been passed to subprocess. I suppose I have to go back and try to reproduce it first. I'll update you if I find something. Thank you for your support.

atticus-lv commented 3 years ago

21

Fix! After clone reading the code(I want to use it to import models, too), I find out that it is due to the coding system. Just get the coding of the shell then use it to encode the scripts

thanhph111 commented 3 years ago

Oh, it turns out that we should use the system encoding instead of forcing it to utf-8. I'm having a look to the PR now.