[Maya 2015] Compile PyQt or convert to PySide?

I am writing this post because I’ve seen virtually no discussion of it on the internet after extensive searching.

We have some gui code written in PyQt for our Maya 2011 tools. Obviously these can’t be used directly in Maya 2015, so I have the option of either compiling PyQt4 myself or converting the code to PySide. Now I’ve spent a few hours trying to compile these, but Autodesk’s instructions are terrible and their example code is set up to use an older version of Visual Studio and PyQt than they tell you to use in the introduction. Is it worth all the hassle or should I just convert our code to PySide which comes bundled with Maya 2015? The later option sounds more appealing to me.

Side note: I have also tried downloading the latest version of PyQt4 (PyQt4-4.11.3-gpl-Py2.7-Qt4.8.6-x64) from riverbankcomputing.com and moved the PyQt folder from site-packages to Maya 2015 site packages folder, and it imported fine. So why is autodesk telling us we have to compile it ourselves? I have yet to try it with our tools, so I don’t know if it actually works well yet.

Thoughts?

switch to pyside, it’s pretty easy. there are only a few things syntax differences.

Seconded. PySide is where the inertia is headed. The only catch is that PySide doesn’t support the loadui() command well, and it is probably a better choice to compile your .ui files to .py files using pysideuic. The good news is that without the need to parse your .ui files every time they are opened, everything loads faster.

EDIT: BTW, the “syntactic changes” mentioned by rgkovach123 are largely improvements, such as the consistent use of native Python strings where previously you had to cast to a QT string type.

Cool, this seems to work well. I will need to recompile the ui files, but for now editing them manually worked just to get everything loaded. :slight_smile:
Just wish I had thought of asking about this before installing Visual Studio!

It is very possible to load .ui files in PySide too though. As for the question, yes PySide.

You can load the contents of a page from a .ui file, but you can’t derive an instance of an entire window. At least, you can’t do it in the same way that we were doing it with PyQT.

Heya,

not to derail this thread, but here’s a quick example (from here due to lack of time right now):

from PySide import QtCore, QtGui, QtUiTools


def loadUiWidget(uifilename, parent=None):
    loader = QtUiTools.QUiLoader()
    uifile = QtCore.QFile(uifilename)
    uifile.open(QtCore.QFile.ReadOnly)
    ui = loader.load(uifile, parent)
    uifile.close()
    return ui


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = loadUiWidget(":/forms/myform.ui")
    MainWindow.show()
    sys.exit(app.exec_())

Right, now create a derived class of the window you loaded.

Am a tad off the shelf it seems. I see what you mean now and you are of course right. Would something like this work? (Have not looked at it really)

Last reply here: http://stackoverflow.com/questions/14892713/how-do-you-load-ui-files-onto-python-classes-with-pyside
and:
https://github.com/lunaryorn/snippets/blob/master/qt4/designer/pyside_dynamic.py

Cheers,
Thorsten

Yup, this exactly. You have to extend PySide to add support for PyQT style loadui behavior. I haven’t been able to make this work reliably, and with the speed improvements of the pysideuic compiled code, this is why I recommend that approach. Rather than extend the loadui command, I’d rather wrap the import command with code that does a datestamp check and recompiles from the .ui file if I really want something like the PyQT setup.

we had to write our own loader that uses a combination of pysideuic.Compiler.compiler and StringIO. It works exactly like PyQt.

I believe portions of it were cobbled together from various Stack Overflow and blog posts, i’ll see if I can track them down (I didn’t personally write the function)…

And then there’s Rob’s recent post and it haed me wonder and question some of my tools hehe

Cheers,
Thorsten

heh, yea, personally I don’t use Qt Designer, but a lot of our tools do.
I like Qt Designer to mock up something, but then i’ll recreate it in code.

I’m having some trouble with adding a menu to Maya during my conversion.


    def _createMenu(self, name, tearable, parentId):
        """        Add menu        """

        mayaHwnd = MUtil.GetMayaMainWindow()

        """ create menu """
        menu = QtGui.QMenu(name, parent=mayaHwnd)
        menu.setTearOffEnabled(tearable)

        if parentId == -1:
            print type(mayaHwnd)
            mayaHwnd.menuBar().addMenu( menu )
        else:
            parentMenu = MenuFactory.menues[parentId]
            parentMenu.addMenu( menu )

        return menu

// Error: TypeError: ‘PySide.QtGui.QMenu’ called with wrong argument types:
PySide.QtGui.QMenu(str)
Supported signatures:
PySide.QtGui.QMenu(PySide.QtGui.QWidget = None)
PySide.QtGui.QMenu(unicode, PySide.QtGui.QWidget = None) //

Edit:
Got around the problem by returning QtGui.QMainWindow instead of QtGui.QObject in my GetMayaWindow function!