Pasting text into text component properties changes language

Hello,

When I paste text from a text editor into the text component properties dialogue box it translates it into:

汐慥敳搠潹牵戠獥⁴潴氠獩整潴琠敨椠獮牴捵楴湯⁳湡⁤浩汰浥湥⁴慥档朠極敤⁤敭楤慴楴湯瀠慲瑣捩⁥獡戠獥⁴獡礠畯挠湡.

Is there a way to prevent this from happening?

Thank you.

1 Like

To better help you it would be helpful to have more information. What operating system are you using? What text editor are you using? What is the text supposed to look like?

I imagine the issue has to do with an encoding mixup. I would find a way to determine what encoding your file uses (this will depend on your editor), make a copy of your file, convert it into utf-8 (which I believe psychopy uses), and try to copy paste again.

Hi Daniel,

I am using OS X El Capitan 10.11.6. I am using TextEdit and have specified utf-8 in the preferences. The text should be english language characters/words. I have also tried converting english language text to utf-8 with an online converter and it too was changed to characters similar to that above. In addition, I have ensure that the computer preferences are set only to utf-8. Problem still occurs.

Well I would still guess that the file is not actually utf-8, and believe it more since when you “converted” it to utf-8 it came out wrong: you have to know the original encoding (and open the file in that encoding) before you can correctly convert it. What format did the online converter convert from? And changing the settings in the text editor won’t change the encoding of an individual file, it will change the format it writes to by default, I believe.

I haven’t used TextEdit for a long time, because it pulled some crap like this on me one time. If I remember correctly, Text Edit saves things by default as ‘rich text file’ (rtf) format, and makes it less than obvious to save as a more standard text file.

Knowing you use TextEdit, and knowing that it displays your text correctly, I would try these steps I found online to save as a more normal utf-8 text file from within TextEdit:
TextEdit (for Mac)

Go to 'Format' and select 'Make Plain Text'.
Click 'File' and choose 'Save...'.
From the 'Plain Text Encoding' dropdown choose 'Unicode (UTF-8)'.
Click 'Save'.

I would then open that file in a different (better :slight_smile: ) editor and copy from there. I like sublime text editor, I’ve seen others using Atom, seemed cool. Let us know if this works!

1 Like

Thank you for your guidance, Daniel! I am continuing to troubleshoot. I will post when I find a solution.

There was an issue with this on the mac (not sure whether OSX changed the way it pasted text with different encodings or if wxPython changed the way it received them) but I believe I fixed it already by doing some checking and converting of character encoding during paste. If this is still a problem for you n 1.84.3 (you didn’t specify your version) then post back here. If not then please click this as solved. Thanks

Thanks, Jon. I am running v1.84.2 (not aware that .3 is available) on OSX El Capitan 10.11.6. Still no luck but I will mark as solved.

Sorry, typo, you’re right it’s 1.84.2, not .3 yet :wink:
In 1.84.2 I can’t reproduce the problem so I’m guessing that Dan is right about this being an issue at the encoding end (TextEdit) rather than a problem with PsychoPy. Then again if you find steps for us to reproduce it on 1.84.2 then I’m happy to look some more.

cheers
Jon

Hi,

I am a newbie and trying to construct my first experiment in psychopy which helped me overcome my fear of coding.
I have the same problem with santiAllende. I am using v1.84.2 stand alone version on Macbook pro OSx with TextEdit. I tried the solution as daniel.riggs1 explained but it does not solve the problem.

I will be extremely happy if you could help me with this.

thanks

burcu

1 Like

Hi,
same problem here: OSX 10.12.1, PsychoPy v1.84.2. No matter what external editor I use, whenever I paste text into the PsychoPy Code Component it looks like converted in Chinese. This is a bit annoying, especially as the Code Component editor is rather limited, so I often work with an external editor.

Thanks for checking this,
LF.

I’ve also experienced this issue previously. If I remember correctly, a workaround was to paste the text into, ahem, MS Word first, before pasting it into PsychoPy…

Jan

1 Like

I’m having the same problem, Mac OS 10.11.6 El Capitan, PsychoPy 1.84.2. I try out my code in a Jupyter notebook, then try to paste into Builder. It changes to Chinese characters. It doesn’t seem like I have the option of changing the encoding in a jupyter notebook, and it shouldn’t be rtf like in the TextEdit example. Pasting into TextWrangler or SublimeText doesn’t fix it, but pasting into MS Word does.

Thanks!
Jason

Actually, the fix of pasting into Word only works sporadically. I copied the following code from Word and tried pasting into Coder.

coords_arr = np.vstack([x,y]).T
 

In the output, I got this error:

File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/app/coder/coder.py", line 2652, in paste
    foc.Paste()
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/app/coder/coder.py", line 1103, in Paste
    self.ReplaceSelection(txt)
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/wx/stc.py", line 3639, in ReplaceSelection
    return _stc.StyledTextCtrl_ReplaceSelection(*args, **kwargs)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

Not sure if this is helpful or not, but it would be great if this could be fixed!

I’m running OS X 10.11.6 El Capitan and have tried this from many different sources, including sublime text and Atom, and making sure that I’m really dealing with plain-text utf-8 files, and every time I get the same characters like in the original post. This really slows things down because I have to transcribe code snippets that I find online (including this forum). Pasting into the text editor first doesn’t make a difference. As I mentioned below, pasting into word kind of works-- it looks like it’s pasting the proper text, but when I try to run it I get errors about the ascii encoding.

Any progress on this would be much appreciated!

Hey guys,

After having a very similar problem again and again (and again) on macOS with pasting any piece of code that I was working on outside PsychoPy, I finally managed to find a workaround that actually seems to be working.

Whatever code or whatever text you want to paste into PsychoPy’s builder view, just save it with an IDE of your choice (PyCharm for me) as a .py file and the open it in PsychoPy with the coder view. After that you’re good to go, copy and paste works like a charm!

EDIT: Actually, you can just copy directly from PyCharm (other IDEs?).

Regards!