Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Cyrillic characters

edited June 2013 in OpenSesame

I wrote simple script based on this post: http://forum.cogsci.nl/index.php?p=/discussion/469/open-selective-sampling-with-a-ratio-help-please/p1 (many thanks :) )
But my script's outcome is squares. I use Cyrillic characters. I've read forum's post about Farsi, but I don't want use PyGame back-end. I'd prefer PsychoPy. Can you help me?
Here the link on archive with script and files http://www.filedropper.com/word_1

Comments

  • edited 1:28AM

    Hi,

    In principle, you should be able to use Cyrillic text without any problems, because (unlike Farsi, which is a whole different story) Cyrillic is part of most standard fonts. However, I noticed that under Windows 7 you see only question marks. I imagine that's what you get as well, right?

    I'm not completely sure what the underlying problem is, but it has something to do with how OpenSesame represents text internally, which apparently depends on the operating system. For now, you'll have to work around it.

    The easy-but-not-so-convenient way

    You could create bitmaps for all your text, and present them like that. This will of course solve all font-related issues, but it might be very inconvenient.

    The clever way

    You could save your Cyrillic words in separate text files and read them into OpenSesame at runtime. This way they are not part of the experiment script, and do not suffer from the encoding issue. For example, the following script reads text from a file and sets it as the variable [word]. You can then use this variable to show text in a sketchpad, just like you normally would.

    # The path to a file containing a word
    path = exp.get_file('word.txt')
    # A file object
    f = open(path)
    # Reads the contents of the file into a string
    s = f.read()
    # Sets the string as variable [word]
    exp.set('word', s)
    

    The exact way to go about this depends on your experiment, of course, and you'll have to use a bit of Python (but nothing too complicated).

    Cheers!
    Sebastiaan

  • edited June 2013

    @sebastiaan Thank you for response, but "clever way" is exactly what I am doing in my script. And it doesn't work. By the way if I write Cyrillic text in sketchpad it's work:

    draw textline 0 0 "тест" center=1 color=white font_family="mono" font_size=18 font_italic=no font_bold=no show_if="always"
    # edit:
    # s = 'тест'
    # exp.set('word', s)
    # draw textline 0 0 "[word]" center=1 color=white font_family="mono" font_size=18 font_italic=no font_bold=no show_if="always"
    # also works
    

    but if I use your script and:

    draw textline 0 0 "[word]" center=1 color=white font_family="mono" font_size=18 font_italic=no font_bold=no show_if="always"
    

    it shows question marks.
    So maybe it's Python related problems? (I use opensesame_0.27.3~pre1-win32-1 and Windows XP / Windows 7)

  • edited June 2013

    Ok, well you're getting into messy character-encoding territory here ... I don't have a full grasp on it myself (otherwise I would've have fixed it in OpenSesame), but I can give you some tips for this specific case.

    The first thing is to realize that not all files are created equal: Text files have a specific character encoding, in your case Windows-1251, or cp1251 as Python calls it. Therefore, when you read this data in, you have to tell Python what the encoding is, otherwise it won't work.

    Like so:

    # Assuming that stim is a cp1251 encoded str. What we want to do is
    # decode stim into a unicode object, like so:
    stim = stim.decode('cp1251')
    exp.set("stim", stim)
    

    You may want to take a look at this page, which outlines the (subtle) difference between the Python unicode and str objects:

  • edited 1:28AM

    Yes, it's working. Thanks.

Sign In or Register to comment.