Maya 2017 switching to PySide2
In order to support Qt 5 Maya 2017 now uses the PySide2 module and shiboken2. While this is supposed to bring a lot of improvements into Maya’s UI, including speed and new functions, it also breaks a lot of old scripts. Including my BroDynamics and other tools. I though about using Qt.py, but that would require me to include it with all my scripts, and really it was too complex for a lot of my tools, especially those shipped as one file.
At first I was a bit terrified, thinking that I’ll have to re-write a lot of code. But in fact I was able to adapt all of my scripts in few minutes.
So, the biggest changes in PySide2 are:
– Some widgets moved from QtGui to QtWidgets
– shiboken is also changed to shiboken2
Before the change I was using PySide like this:
from PySide import QtCore, QtGui someWidget = QtGui.QWidget()
The biggest change is to switch to another method of importing PySide:
from PySide.QtCore import * from PySide.QtGui import *
This way you import all modules directly, and instead of writing QtGui.QWidget you can just use QWidget. Obvious but very handy in this case.
Without any further speculation, here is my final PySide import code.
try: from PySide2.QtGui import * from PySide2.QtCore import * from PySide2.QtWidgets import * from shiboken2 import wrapInstance print 'Using PySide2' except: from PySide.QtGui import * from PySide.QtCore import * from shiboken import wrapInstance print 'Using PySide'
And then using simple Replace, available in any text editor, change all “QtGui.” and “QtCore.” to “”. Just remove them.
I will test BroDynamics and other scripts for some time, before making new versions available to the public. Stay tuned 🙂
Here are a few links you may find useful as well:
Maya Help – PyQt and PySide Widget Best Practices