pyuic4

268 views
Skip to first unread message

Eric

unread,
Nov 14, 2008, 3:54:53 PM11/14/08
to python(x,y)
I tried generating a UI with QT Designer. I've searched, and can't
find pyuic4 anywhere. I thought I needed this to convert the ui file
to a python file. What am I missing here?

Thanks in advanced,

Eric

pierre semecurbe

unread,
Nov 14, 2008, 4:11:02 PM11/14/08
to pyth...@googlegroups.com
Hello,
 
         It's true, it is not pyuic4.py but pyuic.py.
You have just to copy your ui file in the same directory that the pyuic.py and execute with a dos console (cmd) this command :
python pyuic.py -o test.ui -x test.py
 
If you are interested, I have made an UI to help the conversion (you must copy the ui2py.py in the same directory that pyuic.py).
 
Pierre Semecurbe  
ui2py.py

Eric

unread,
Nov 14, 2008, 5:19:03 PM11/14/08
to python(x,y)
Thanks, that worked. Of course, I'll have to translate the French!

On Nov 14, 3:11 pm, "pierre semecurbe" <semecur...@gmail.com> wrote:
> Hello,
>
>          It's true, it is not pyuic4.py but pyuic.py.
> You have just to copy your ui file in the same directory that the pyuic.py
> and execute with a dos console (cmd) this command :
> python pyuic.py -o test.ui -x test.py
>
> If you are interested, I have made an UI to help the conversion (you must
> copy the ui2py.py in the same directory that pyuic.py).
>
> Pierre Semecurbe
>
> On Fri, Nov 14, 2008 at 9:54 PM, Eric <eric.sh...@gmail.com> wrote:
>
> > I tried generating a UI with QT Designer. I've searched, and can't
> > find pyuic4 anywhere. I thought I needed this to convert the ui file
> > to a python file. What am I missing here?
>
> > Thanks in advanced,
>
> > Eric
>
>
>
> [ui2py.py3K ]#!/usr/bin/env python
> """Utilitaire de conversion de fichier UI (Qt designer) en fichier Python"""
>
> import sys
> import os
> from PyQt4 import QtCore, QtGui
>
> class Dialog(QtGui.QDialog):
>
>     def __init__(self, parent=None):
>         QtGui.QDialog.__init__(self, parent)
>         frameStyle = QtGui.QFrame.Sunken | QtGui.QFrame.Panel
>         self.openFileNameLabel = QtGui.QLabel()
>         self.texte = QtGui.QLabel("Nom du fichier Python : ")
>         self.nom_sortie= QtGui.QLineEdit()
>         self.openFileNameLabel.setFrameStyle(frameStyle)
>         self.openFileNameButton = QtGui.QPushButton(self.tr("Selection du fichier a convertir"))
>         self.conversion = QtGui.QPushButton(self.tr("CONVERSION"))    
>         self.connect(self.openFileNameButton, QtCore.SIGNAL("clicked()"), self.setOpenFileName)    
>         self.connect(self.conversion, QtCore.SIGNAL("clicked()"), self.Conv)    
>         layout = QtGui.QGridLayout()
>         layout.setColumnStretch(1, 1)
>         layout.setColumnMinimumWidth(1, 150)
>         layout.addWidget(self.openFileNameButton, 0, 0)
>         layout.addWidget(self.texte, 1, 0)
>         layout.addWidget(self.nom_sortie, 1, 1)
>         layout.addWidget(self.openFileNameLabel, 0, 1)
>         layout.addWidget(self.conversion, 2, 0)
>         self.setLayout(layout)
>         self.setWindowTitle(self.tr("Ui2Py"))
>
>     def setOpenFileName(self):    
>         fileName = QtGui.QFileDialog.getOpenFileName(self,
>                                          self.tr("Selection du fichier UI a convertir"),
>                                          self.openFileNameLabel.text(),
>                                          self.tr("Fichier UI (*.ui)"))
>         if not fileName.isEmpty():
>             self.openFileNameLabel.setText(fileName)
>             chaine=self.openFileNameLabel.text()
>             r = str(chaine)
>             r = r.split("/")
>             long=len(r)
>             nom_ui=str(r[long-1])
>             nom_py=nom_ui.split('.')
>             self.nom_sortie.setText(str(nom_py[0]))    
>
>     def Conv(self):    
>         chaine=self.openFileNameLabel.text()
>         r = str(chaine)
>         r = r.split("/")
>         long=len(r)
>         nom_ui=str(r[long-1])
>         nom_py=nom_ui.split('.')
>         nom_py=str(self.nom_sortie.text())+ '.py'        
>         cmd = 'python pyuic.py -x ' + nom_ui + ' -o ' + nom_py
>         print cmd
>         os.popen(cmd)
>
> if __name__ == '__main__':
>     app = QtGui.QApplication(sys.argv)
>     dialog = Dialog()
>     sys.exit(dialog.exec_())

Pierre Raybaut

unread,
Nov 15, 2008, 1:51:28 PM11/15/08
to python(x,y)
Hi,

Note that you can also use the .ui file dynamically in your Python
code, without having to generate the .py file.
(see xyhome.pyw and xyhome.ui for example)

Also, Mark Summerfield has wrote a very useful tool to convert -among
other things- .ui to .py (see http://www.qtrac.eu/pyqtbook.zip).

Cheers,
Pierre

Eric

unread,
Nov 18, 2008, 10:12:47 AM11/18/08
to python(x,y)
Pierre,

Are there any simple examples to do this? I can create a .ui in
Eclipse, but at that point, I can't figure out what to do. Even a
simple tutorial would be helpful. Ultimately purchasing the
Summerfield book would be an option, but I'd like to try it out first.

Eric

On Nov 15, 12:51 pm, Pierre Raybaut <cont...@pythonxy.com> wrote:
> Hi,
>
> Note that you can also use the .ui file dynamically in your Python
> code, without having to generate the .py file.
> (see xyhome.pyw and xyhome.ui for example)
>
> Also, Mark Summerfield has wrote a very useful tool to convert -among
> other things- .ui to .py (seehttp://www.qtrac.eu/pyqtbook.zip).

Pierre Raybaut

unread,
Nov 18, 2008, 11:18:41 AM11/18/08
to python(x,y)
On Nov 18, 4:12 pm, Eric <eric.sh...@gmail.com> wrote:
> Pierre,

Which one? ;)

> Are there any simple examples to do this? I can create a .ui in
> Eclipse, but at that point, I can't figure out what to do. Even a

As I said, you may take a look at "xyhome.pyw" (even if this script is
not intended to be an example as a lot of things were wrote in a
hurry). This script is located in "C:\Program Files\pythonxy\python\Lib
\site-packages\xy".
After loading "xyhome.ui", it's filling some text in QLabel objets,
and connecting signals to QPushButton and QComboBox objects. In
between, it's also creating lists and dictionnaries with data around
Python(x,y) shortuts and documentation: that is the part which is very
poorly written code - thus you may ignore this part.

If you still can't figure it out, I'll write a simpler example code to
help you out.

> simple tutorial would be helpful. Ultimately purchasing the
> Summerfield book would be an option, but I'd like to try it out first.

If you're beginning with Python and PyQt, Summerfield's book is *the*
book to purchase. The introduction to Python is very original and easy
to read, and the PyQt part comes with intereting and not-trivial
examples which are a good start to write complex applications.

Pierre

Eric

unread,
Nov 18, 2008, 11:33:35 AM11/18/08
to python(x,y)
I guess I'm unclear on the process of using QT in Eclipse. What I've
done is as follows:

1) Created a new project
2) Created a QT widget (right click on the project
folder>New...>Other...>QT Designer Form followed the wizard)
3) Placed some widgets on the form connected some with the Signal Slot
Editor
4) Previewed the form (looks good)

At this point, I don't know what to do. Does a Python file get
automatically generated? I seem to have issues with configuration also
with Eclipse when I try to run. I've searched the web, and while I can
find tutorials using the stand alone QTDesigner, I can't find any
working within Eclipse.

Regards,

Eric

sach...@gmail.com

unread,
Nov 18, 2008, 11:27:15 AM11/18/08
to python(x,y)
Hi all,
I wrote a small script which I put in the external tools of eclipse
so I can create .py files from eclipse editor. This will create .py
files for .uic and .qrc files in the workspace. I've uploaded the Jpeg
of external tools
configuration settings as uic_rc.jpg in the files section of the
group.
This worked for me.
Also thanks Pierre for python x,y

Regards
--Sachin


#######=======uic_rc2py.py=======================
import sys
import os
import glob
import re

print os.path.exists(sys.argv[1])
p=os.path.dirname(sys.argv[1])
#new_str=sys.argv[1]
new_str= sys.argv[1]+"\src"

if os.path.exists(new_str):
print "User has src folder in pydev module"
os.path.isdir(new_str)
new_ui_dir=new_str;
print new_str
else:
print "No src DIR folder in pydev module"
print sys.argv[1]
new_ui_dir=sys.argv[1]


os.chdir(new_ui_dir)
print os.getcwd()

new_ui_files=new_ui_dir+"/*.ui"
new_rc_files=new_ui_dir+"/*.qrc"




for i in glob.glob(new_rc_files):
rcs=re.compile("\.qrc")
rc1=rcs.sub("_rc.py",i)
cmmdrc="pyrcc4 " + "\""+i +"\"" + " -o "+ "\"" +rc1 +"\""
os.system(cmmdrc)
print "finished generating", rc1


for i in glob.glob(new_ui_files):
p=re.compile("\.ui")
a=p.sub(".py",i)
#print a
cmmd= "pyuic4 " + "\""+i +"\"" + " -o "+ "\"" +a +"\""
os.system(cmmd)
print "finished generating", a

sach...@gmail.com

unread,
Nov 18, 2008, 11:10:58 AM11/18/08
to python(x,y)
Hi all,
I wrote a small script which I put in the external tools of eclipse
so can create .py files from eclipse editor. I will try to upload JPEG
uic_rc.JPG of external tool settings in the groups files.
You can keep uic_rc.py at any location and accordingly change the
path in external tools settings. This will create .py files for .uic
and .qrc files in the workspace. This worked for me.

Pierre Raybaut

unread,
Nov 18, 2008, 1:46:31 PM11/18/08
to python(x,y)
Ok, at step 2, you have created an .ui file containing an XML-like
description of your Qt widget.
Now you have two option:
a) use it as it is, i.e. directly open the .ui file in your script ->
see xyhome.pyw/xyhome.ui
b) convert it to a .py file (so a Python module), and then import this
module in your script
c) convert it to a .py file and directly edit this file becoming your
main script (not recommended as you'll not be able to come back to the
Qt Designer editing step)

I'm not sure if I answer your question even partly.

HTH,
Cheers
Pierre

Eric

unread,
Nov 18, 2008, 5:39:22 PM11/18/08
to python(x,y)
Thank you for your response. I think my issues stem from the fact that
1) I'm new to Python, 2) I'm new to Eclipse, 3) I'm new to Qt.

I have the most experience with MATLAB where there is a GUI designer
integrated which while limited works well enough. I've dabbled with
NetBeans, too. It has a really great GUI designer, but it's Java. I've
been looking for a really cohesive IDE for Python and what Python(x,y)
provides seems really close especially since I do number crunching.

It will take me a bit of time to figure this all out. I find following
a tutorial useful when learning new tools, so I encourage anyone using
QTDesigner within Eclipse to put one together if they have time.

Pierre Raybaut

unread,
Nov 19, 2008, 5:18:19 PM11/19/08
to python(x,y)
On 18 nov, 23:39, Eric <eric.sh...@gmail.com> wrote:
> Thank you for your response. I think my issues stem from the fact that
> 1) I'm new to Python, 2) I'm new to Eclipse, 3) I'm new to Qt.

-> Then, except for the Eclipse part which is the easiest one, you
really should consider purchasing Mark Summerfield's book. That is
without any doubt the best tutorial you'll ever find on this topic.

> I have the most experience with MATLAB where there is a GUI designer
> integrated which while limited works well enough. I've dabbled with
> NetBeans, too. It has a really great GUI designer, but it's Java. I've
> been looking for a really cohesive IDE for Python and what Python(x,y)
> provides seems really close especially since I do number crunching.
>
> It will take me a bit of time to figure this all out. I find following
> a tutorial useful when learning new tools, so I encourage anyone using
> QTDesigner within Eclipse to put one together if they have time.

The step is not so high from MATLAB to Python. Perhaps you're not
familiar with object-oriented programming. But even if you're not,
that's not very important to begin learning Python, as long as you
know what is a class and what are methods and attributes. For example,
when you create a Qt widget, you write a class (e.g. deriving from
QtGui.QDialog for a dialog box) and then you instantiate it.
Reply all
Reply to author
Forward
0 new messages