Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python code generation with pyside-uic

Tags:

python

pyside

How can I generate python code from a QtDesigner file ? I found pyside-uic but I can't find an example for the syntax. I run win7 and pythonxy with spyder.

like image 271
ArtDijk Avatar asked Dec 14 '10 17:12

ArtDijk


3 Answers

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
like image 83
FrederikNS Avatar answered Nov 03 '22 22:11

FrederikNS


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.

like image 25
Sven Avatar answered Nov 03 '22 22:11

Sven


pyside-uic.exe MyWindow.ui -o MyWindow.py 

is what I've been doing and it's working fine (as far as I know)

like image 6
Mike Avatar answered Nov 03 '22 22:11

Mike