Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

maya can't recognize unicode if it's from PySide2?

maya can't recognize unicode if it's from PySide2?

Anonymous
Not applicable
2,166 Views
8 Replies
Message 1 of 9

maya can't recognize unicode if it's from PySide2?

Anonymous
Not applicable

Hi there.

The problem is the unicode text that come from "QtWidgets.QPlainTextEdit" is not recognized by Maya. it work fine in Windows or if it directly written. ( take a look at screenshot and you'll understand )

I posted this problem in here(Stack)

The code is here(Updated but no solution)

 

The output in Maya if I insert ↑ in the text field:

>>>not recognized

The output in Window if I insert ↑ in the text field:

>>>↑ is printed

0 Likes
Accepted solutions (1)
2,167 Views
8 Replies
Replies (8)
Message 2 of 9

teddude75
Collaborator
Collaborator

Hello, the code that's in maya has to have a purpose. The special characters like "↑" don't do anything and to say the least Maya doesn't recognize them. Your focusing on the details of the script ( "↑") when you should focus on your end goal for the script your trying to write. What is it your trying to do?

0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi,well that's true and thank you for reminding it, but I sort of need maya to accept unicode. The original plugin use these unicode character, for special command with the text I'm writing in that input. It would be a pain to replace this method as I use the same code in elswhere without problem...

0 Likes
Message 4 of 9

Anonymous
Not applicable

Note : Unfortunately this problem is only in Windows machine, So I'll accept this issue as solved and report it as a bug.

If someone have a solution to fix it, feel free to reply. Thanks

Tested in Maya 2019.1 in Windows 10

Message 5 of 9

zewt
Collaborator
Collaborator

(I'm not sure what Ted means, but this is a pretty straightforward question.)

 

The answer on StackOverflow is correct.  toPlainText() returns a Unicode string, but you're comparing against a non-Unicode string, and the conversion is failing.  All you need to do is compare against a Unicode string:

 

    def printIt(self):
        text = self.plainTextEdit.toPlainText()
        for i in text:
            print i.__class__
            if i == "a":
                print ('a is printed')
            elif i == "#":
                print ('# is printed')
            elif i == u"↑":
                print ('↑ is printed')
            else:
                print ('not recognized')

 

With that, the code works fine in Windows: paste in ↑ and click Test, and "↑ is printed" is printed.

 

0 Likes
Message 6 of 9

Anonymous
Not applicable

Hi, sry but seems like you didn't pay attention to my post and comments on Stack.(look at image). We already tried it. The problem is not windows itself, but Maya in windows.Did you tried this in Maya?

0 Likes
Message 7 of 9

zewt
Collaborator
Collaborator

I tested it in Maya, in Windows 10, and it worked fine.  (Please don't tell people they're not paying attention, it's quite rude.)

 

0 Likes
Message 8 of 9

Anonymous
Not applicable

@zewtI'm sorry, didn't want to be rude. Can you tell me witch maya version and update you tested on?

0 Likes
Message 9 of 9

zewt
Collaborator
Collaborator
Accepted solution

It happens in 2019.  I found the underlying issue.  Maya's script window appears to be a multibyte input rather than a Unicode input, converting to the Windows ANSI codepage.  (I'm not sure why, since Maya itself is a Unicode application in Windows.)  This means characters only work if they're in the ACP, and since ↑ is in my codepage (cp932), it works.  If your system is a default English installation, you're probably in cp1252, which doesn't.  You can test this by just running print "↑".  If your codepage doesn't have the character, it'll print ?.

 

The reason "elif i == "↑":" seems to work is because both cases of ↑ are being replaced with ?, so it's really comparing "?" == "?".  It looks like it works, but it's just wrong the same way in two places, so it's not actually working.

 

This is just the Maya script editor window, though.  If I save the file to Documents\maya\2019\scripts and import it, it works fine.  FWIW, I recommend doing this for any nontrivial script anyway (edit a standalone file), since it's very easy to lose edits in the script editor.

 

Note that it does need to use Unicode strings.  You might be able to just use "from __future__ import unicode_literals".