View Single Post
Nyrath's Avatar
Posts: 92 | Thanked: 50 times | Joined on Jan 2006 @ the praeternatural tower
#5
Originally Posted by giannoug View Post
How can you use pyuic4 to output a file that you can include in your main python program?
From the command line, you have to invoke pyuic4 using the form:
pyuic4 uiFile -o pythonFile

For example, say in directory c:\myProjects\textEditor you had a Qt Designer file called myEdit.ui and you were developing in a Windows environment. You'd invoke the Windows Command Prompt, and type in the following:

Code:
cd c:\myProjects\textEditor
pyuic4 myEdit.ui -o myEditUI.py
You could then use myEditUI.py in your PyQt project. I use the name *UI.py out of habit because that was in the documentation, but you can use any name you want.

I sometimes use a little python program to automate this, if I have lots of *.ui files. Create the following python script
Code:
import os, sys, glob
    
fileList = glob.glob('*.ui')
for fileName in fileList:
    theCommand = "pyuic4 %s -o %sUI.py" % (fileName, fileName[:-3])
    os.system(theCommand)
and save it as BatchPyuic4.py
Copy it into the folder with your *.ui files. From the command line, type
Code:
cd c:\myProjects\textEditor
python BatchPyuic4.py
It will find all your *.ui files, run pyuic4 on them, and save them as *.ui.py

Last edited by Nyrath; 2010-05-20 at 18:39.