Tag Archives: encoding

Assigning UTF8 display strings in PythonOgre with CEGUI 0.6.2b

If you just do:

line=f.readline()
cegui.wm[“destination”][“Text”]=line
# Of course: cegui.wm=cegui.WindowManager.getSingleton()

then, despite “line” being UTF8, some piece of code will attempt to convert it into something “appropriate.” We don’t want that. We want our UTF8 string to be displayed with correct encoding, without guesses about what to convert it into — because the guess is incorrect! (It looks like it converts it into ascii or some Western European codepage).

So let’s force the wrapper to do the right thing:

line=f.readline()
line_cg=cegui.String(); line_cg.assign(line)
cegui.wm[“destination”][“Text”]=line_cg

Or you may prefer a utility function which does that:

def getDisplayString(txt):
  cg_string=cegui.String()
  cg_string.assign(line)
  return cg_string


line=f.readline()
cegui.wm[“destination”][“Text”]=getDisplayString(line)

This was necessary on PythonOgre SVN revision 996, wrapping Ogre 1.6.1 and CEGUI 0.6.2b for Python 2.5, on Mac. 
Image courtesy of Bart Simpson Chalkboard Generator from addletters.com