Python code generation with pyside-uic

Solution 1:

pyside-uic is more or less identical to pyuic4, as such the man page specifies:

Usage:
        pyside-uic [options] <ui-file>

Options:
    --version
        show program's version number and exit

    -h,--help
        show this help message and exit

    -oFILE,--output=FILE
        write generated code to FILE instead of stdout

    -x,--execute
        generate extra code to test and display the class

    -d,--debug
        show debug output

    -iN,--ident=N
        set indent width to N spaces, tab if N is 0 (default: 4)

I usually use it like this:

pyside-uic -o output.py input.ui

Solution 2:

Just tried Pyside's QUILoader, works fine:

from PySide import QtGui  
from PySide import QtCore
from PySide import QtUiTools

class MyWidget(QtGui.QMainWindow):
    def __init__(self, *args):  
       apply(QtGui.QMainWindow.__init__, (self,) + args)

       loader = QtUiTools.QUiLoader()
       file = QtCore.QFile("pyside_ui_qtdesigner_form_test.ui")
       file.open(QtCore.QFile.ReadOnly)
       self.myWidget = loader.load(file, self)
       file.close()

       self.setCentralWidget(self.myWidget)

if __name__ == '__main__':  
   import sys  
   import os
   print("Running in " + os.getcwd() + " .\n")

   app = QtGui.QApplication(sys.argv)  

   win  = MyWidget()  
   win.show()

   app.connect(app, QtCore.SIGNAL("lastWindowClosed()"),
               app, QtCore.SLOT("quit()"))
   app.exec_()

I used Eclipse and QTDesigner to create the .ui file (right-click on module, "New -> Other..", choose "Qt Designer -> Qt Designer Form"). No explicit uic call is needed.