french accent marks

Anonymous

french accent marks

Anonymous
Not applicable

Hi all,

following problem:

import maya.cmds as cmds

#    Create a window with a some fields for entering text.
#
window = cmds.window()
cmds.rowColumnLayout( numberOfColumns=2, columnAttach=(1, 'right', 0), columnWidth=[(1, 100), (2, 250)] )
cmds.text( label='Name' )
txt = "mais le premier de ces indigènes qui mit la main sur la rampe de l' escalier rejeté en arrière par je ne sais quelle force invisible s' enfuit poussant des cris affreux et faisant des gambades exorbitantes"
name = cmds.textField(tx = txt)
cmds.showWindow( window )

output_str = cmds.textField(name, q=True, tx=True)

how do i encode/decode the "output_str"?, because every approach failed inside maya.

thx

0 Likes
Reply
Accepted solutions (1)
626 Views
3 Replies
Replies (3)

zewt
Collaborator
Collaborator
Accepted solution

The problem isn't Python here, it's a bug in Maya's script editor.  It lets you enter Unicode, but it converts it to the Windows ANSI codepage before executing it, instead of to UTF-8.  Your system doesn't have those characters, so they get substituted.  You can see the problem by just running 

 

print "è"

 

and it'll just print "e", depending on your OS language.

 

Just write your script in a file instead of the script editor (prefixing "-*- coding: utf-8 -*-" if needed) and import it, so your code isn't going through the script editor.  It's safer that way anyway, I've lost a *lot* of scripts over the years to Maya crashing because I got lazy and prototyped too much in the script editor...

 

0 Likes

Anonymous
Not applicable

Thank you for your answer, I did not suspect that it is due to python. I assume this problem is related to Qt and not script editor itself, because the encoding failed in every layout inside maya. I do not necessarily have to show the content within maya, but how would the solution look like if I have to. Will the problem be solved if I install the French Maya version?

 

0 Likes

zewt
Collaborator
Collaborator

Qt handles it just fine, it's caused by the script editor's edit box (other editors probably do the same thing, like the script panel and script editor).  If you run it from a file instead of through the script editor, the text works fine.

 

It should also work if your Windows language is set to French (or any language that supports those characters), but I can't test this easily.

 

0 Likes