'paste' in cyrillic encoding does not work

Asked by retano

Trying to paste any cyrillic string in LinuxMint 17 XFCE inside Firefox results in something like that:
paste('тест') => тест

Tried regional settings RU/ENG, Firefox RU/ENG. Tried solution from here:
t='somestring'
paste(t).encode("UTF-8")) # hand it over with utf-8 encoding
(https://answers.launchpad.net/sikuli/+question/169226)

did not work for me either...

What else can be done?

Question information

Language:
Spanish Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
retano
Solved:
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

Hi,

Can you try and use "type(тест)" instead of "paste(тест)"?

Revision history for this message
RaiMan (raimund-hocke) said :
#2

type does not work at all with UTF-8 characters, only letters, numbers and some special characters in the US-Keyboard layout.

what version of Sikuli?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

try the following:

paste(unicode("тест", "utf8"))

Revision history for this message
rss (rssdev10) said :
#4

Possibility of the unicode string pasting is available only from 1.1.0.

https://github.com/RaiMan/SikuliX-2014/commit/e05e9f2d5eb174fa0ef434d42781b04e9eafa8f3 - fixed an incorrect conversation from Java String.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

# comment #4 (rss)
At least for the Jython environment this is not true yet:
even with the mentioned patch in 1.1.0, simply
paste("тест")

does not work. you still need to use
paste(unicode("тест", "utf8"))

to hand over a unicode string down to the Java level, which then is pasted correctly.
… and this works in 1.0.1 as well, that does not have the patch.

I think I make it a bug and track it down further, when I get to the revision of the clipboard handling and the general use of unicode strings.

Revision history for this message
retano (retano) said :
#6

Hi RaiMan,
It is version 1.0.1 Java. Your workaround worked just fine:
paste(unicode("тест", "utf8"))

thank you for the quick solution!

Revision history for this message
rss (rssdev10) said :
#7

# comment #5 (RaiMan)

Checked in winxp, win7. With any BUFFER type it is really work in winxp.
But it does not work in win7 without CHAR_BUFFER.

BTW, there is a short form: paste( u"тест" )

Revision history for this message
RaiMan (raimund-hocke) said :
#8

# rss
thanks.

I will write a HowTo into the docs about unicode handling in Sikuli scripts using Python language.

A general rule for version 1.1.0+:
Despite the fact, that strings containing unicode characters are shown correctly in the IDE, the usage at runtime (string functions, image filenames, Sikuli features accepting strings as parameters (e.g. paste()), ...) might make problems.
To avoid these possible problems, one should always use this notation for strings containing unicode characters:
aUnicodeString = u"cyrillic: тест"

now this string will be handled correctly at runtime all over the place.

any string (e.g. text loaded from a file) can be marked as being a unicode string by using:
aUnicodeString = ucode(otherString)

which is a convenience shortcut for
aUnicodeString = unicode(otherString, "utf8")