keyboard element for non-English language (Hebrew) or unicode variables for text element

271 views
Skip to first unread message

Ilya Mark

unread,
Apr 26, 2015, 11:04:31 AM4/26/15
to psychop...@googlegroups.com
Hello all!

We are building an experiment in which subjects need to write a short essay in Hebrew. I understand that PsychoPy is not optimized for that, but I trying to get it working...
My first guess was recording the keystrokes, translating them into Hebrew, and and then showing the final result as a textStim. But the textStim shows the string as unicodes and not the chars. 
Suggestions on how I can make this easier or at least get it to work?

Thanks,
Ilya.

Michael MacAskill

unread,
Apr 29, 2015, 1:16:19 AM4/29/15
to psychop...@googlegroups.com
Hi Ilya,

I was holding back on answering this in case someone more knowledgable piped up :-)

This isn't a problem of PsychoPy per se, but of the underlying Python text libraries we rely upon. International text display is not a trivial topic, so it isn't easy to fix, but we're aware of some of the issues, and I found a work-around for Arabic/Farsi users at least (see discussion here):
<https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/psychopy-users/HJgyKNaSlKQ/xGyKXrw4e1wJ>

If you can find a Hebrew equivalent to that Python Arabic 'reshaper' function, it presumably could be used to allow PsychoPy to properly display Hebrew right-to-left. If so, we could (and should) incorporate it into PsychoPy so that this functionality gets built-in.

But as I don't think any of the (current) main developers of PsychoPy have much direct comprehension of the issues, I don't think we could implement an equivalent 'reshaping' function for Hebrew ourselves (although if an open-source solution exists out there, we could probably incorporate it).

But in the meantime, if you could better describe your issue, that would help. If the problem isn't actually right-to-left display, but instead text appearing as codes rather than characters, that we could probably help with. It would be necessary for you to show us what code you are currently using.

Lastly, I'm not really sure what "recording the keystrokes, translating them into Hebrew" means. If the computer's OS is set up to have Hebrew keyboard input, don't you receive Hebrew characters directly?

Regards,

Michael




--
Michael R. MacAskill, PhD michael....@nzbri.org
Research Director,
New Zealand Brain Research Institute

66 Stewart St http://www.nzbri.org/macaskill
Christchurch 8011 http://twitter.com/Sakkaden
NEW ZEALAND Ph: +64 3 3786 072










Michael MacAskill

unread,
Apr 29, 2015, 1:35:29 AM4/29/15
to psychop...@googlegroups.com
Just a follow-up (both for Ilya but also a heads-up for developers):

The situation for Hebrew seems to be simpler than for Arabic/Farsi, as the 'reshaping' function isn't necessary.

What is needed is support for bi-directional text. This remains on the wishlist for the pyglet developers (<https://code.google.com/p/pyglet/wiki/ReleaseSchedule>) and realistically isn't going to happen anytime soon.

But there seem to be pure Python implementations of the bi-directional algorithm (e.g. <https://pypi.python.org/pypi/python-bidi/> which might be easy for us to use within PsychoPy)

Ideally this would need someone more familiar with the issues to drive, in terms of giving us some specific examples of text to work with.

Regards,

Michael
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph: +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill



Jeremy Gray

unread,
Apr 29, 2015, 8:26:01 AM4/29/15
to psychop...@googlegroups.com
The bidi package is good to know about. However, I thought Ilya's question was how to get something that looks like this on the pyglet window:

u'\u05ea\u05d9\u05e8\u05d1\u05e2'

instead to look like this when displayed from a TextStim:

עברית

To do that, it works for me if I make a TextStim like this:

s = u'\u05ea\u05d9\u05e8\u05d1\u05e2'
t = visual.TextStim(win, text=s)


If the directionality is backwards, you can reverse a string, s, by asking for s[::-1]

It looks like the bidi package is for supporting text with both LTR and RTL within the same string. If that is what's needed, simple reversing will not work. It looks relatively easy (with some effort) to use bidi from within psychopy:

First install bidi (from command line or however you usually install python packages):
pip install python-bidi

Then from inside PsychoPy / python (this is their default example--there are several options, not just upper_is_rtl):

from bidi.algorithm import get_display
s = get_display(u'car is THE CAR in arabic', upper_is_rtl=True)

t = visual.TextStim(win, text=s)


--Jeremy





--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/AAF4DE50-8C04-4E16-A1B8-B8F8552F359E%40otago.ac.nz.
For more options, visit https://groups.google.com/d/optout.

Ilya Mark

unread,
May 11, 2015, 3:54:47 AM5/11/15
to psychop...@googlegroups.com
Thanks, that worked!

fate...@gmail.com

unread,
Mar 19, 2017, 4:10:42 PM3/19/17
to psychopy-users

fate...@gmail.com

unread,
Mar 19, 2017, 4:14:10 PM3/19/17
to psychopy-users

Hello all,
Can anybody help me with Persian stimuli for a stroop task and slfpaced reading task that gets the data from an excel file. I have typed in the commands
 from bidi.algorithm import get_display
s = get_displays=get_display(unicode_or_str, encoding='utf-8', upper_is_rtl=True, base_dir=L, debug=True)
t = visual.TextStim(win, text=s)
in the shell of psychopy and also in the coder pane of psychopy for the experiment, but it still shows Persian letters separate. Can anybody help?
On Sunday, April 26, 2015 at 7:34:31 PM UTC+4:30, Ilya Mark wrote:
Reply all
Reply to author
Forward
0 new messages