Eclipse PyQtDesigner pyuic4 code generation

537 views
Skip to first unread message

threader

unread,
Sep 23, 2009, 2:00:56 AM9/23/09
to python(x,y), thread...@gmail.com
Hello Everybody...

I have used Qt Designer to generate a basic GUI. The file saved from
Qt Designer I named it myGUI.ui .

Now, I have to generate from myGUI.ui the ui_myGUI.py, right? To get
this done, we must run pyuic4, directly or via mkpuqt.py or Make PyQt.
I tried to get it done, so went into the Py25 console:


>>> pyuic4 -o C:\dev\prgr\src\ui_myGUI.py C:\dev\prgr\src\myGUI.ui
SyntaxError: invalid syntax

I didn't figure out how to get it running.

I googled around and didn't find much useful material or any practical
example/setup on internet about how to put the pyuic4 to generate the
ui_myGUI.py.

Of course the better would be to run pyuic4 directly from the Eclipse
IDE, which I have integrated and compiling Python 2.5 and 2.6.
However, no way is working.

What I am doing wrong, or what is missing here?

Any comments or suggestions are mostly appreciated.

doc_brown

unread,
Oct 20, 2009, 4:54:10 PM10/20/09
to python(x,y)
Hi, I hope it's not too late :)

On Windows, you can go to Eclipse menu -> Run -> External Tools ->
Configure External Tools. Create a tool, say, "Compile UI", choose
Location as your pyuic path, normally "C:\Python26\Lib\site-packages
\PyQt4\pyuic4.bat", Working Directory - browse your src directory,
and parameters [resource-name] > [string-prompt]

Apply changes and run it (make sure to have your myGUI.ui file open).
You will be prompted to enter a value. Type myGUI.py and you are all
set. Newly generated myGUI.py will be in your src directory. After
modifying the form do it again, old .py file will be silently re-
written.

Worked perfectly for me.

Hope it will help.

Victor (doc_brown)

Joe Stenger

unread,
Oct 21, 2009, 11:22:07 AM10/21/09
to python(x,y)
Hi All QTDesigner Users,

I am a newbie to this forum and to Python, so I hope you don't mind
helping me out until I can contribute to the collective. I have been
using QTDesigner to create GUI's and would like to view the code.

From the QTDesigner Tool I should be able to select - Form -> View
Code....

However, when I do this, I get the following error; Code Generation
Failed "Unable to launch C:/Python26/Lib/site-packages/
PyQT4/./.\uic."

I did configure Eclipse to launch the conversion tool as doc_brown
states above, and also posted by Brendan in "HOWTO: Configure Eclipse
to run PyUIC". However, Eclipse will not open the myGui.ui file, and
throws the following error "Could not open the editor: An exception
was thrown during initialization"

Here is part of the the details;

java.lang.ClassCastException: org.eclipse.ui.ide.FileStoreEditorInput
cannot be cast to org.eclipse.ui.part.FileEditorInput
at com.trolltech.qtcppdesigner.editors.UiEditor.init(UiEditor.java:
82)
at org.eclipse.ui.internal.EditorManager.createSite
(EditorManager.java:798)
at org.eclipse.ui.internal.EditorReference.createPartHelper
(EditorReference.java:644)
......

Would anyone mind throwing me a bone to get moving again?

Thanks all,

Joe


doc_brown

unread,
Oct 21, 2009, 2:00:49 PM10/21/09
to python(x,y)
Hi, Joe,

I am also new to this forum and did not know about the Brendan's post.
I tried his solution also, it looks better than mine, except you seem
need to rename *.ui.py file to *.py every time you recompile it,
otherwise it is a problem to import it by the main script (correct me
someone if I am wrong).

You can also try for your External tool:

Location: C:\Python26\Lib\site-packages\PyQt4\pyuic4.bat

Working directory: ${container_loc}

Arguments: ${resource_loc} > ${string_prompt}

In this case your *.ui file compiles automatically to *.py file you
type in the prompt. Next time you recompile, the file name will be
already in the prompt, just enter it, no typing again.

However, from the part of your error message, it looks like your
problem is not in running the pyic, but in running eclipse itself. You
probably need to re-install your python(x,y) or java, unfortunately, I
am not an expert in this.

BTW, does anyone knows how to display Qwt and matplotlib widgets in
the integrated designer?
It looks like you need to call external designer to use them...

doc_brown

Joseph D Stenger

unread,
Oct 21, 2009, 2:56:31 PM10/21/09
to pyth...@googlegroups.com
Doc,

Thanks for the response. So I am correct in thinking that Eclipse should
open the myGUI.ui? Or do I need to do some pre-setup to get QTDesigner to
open from within Eclipse?

I just reinstalled Pythonxy 2.6 for a second time, and I am running Java
version 6.15 (build 1.6.0_15-b03) which I think is pretty up to date.
However, myGUI.ui will not open from within Eclipse.

Any knowledge on why the "View Code" Feature in QTDesigner does not work?
It was broken on my pyxy.2.1.15 version as well. Maybe there something I
have not setup yet?

In the mean time, I'll try the batch option.

Thanks for the feedback.

Joe

Joseph D Stenger

unread,
Oct 21, 2009, 3:34:19 PM10/21/09
to pyth...@googlegroups.com
Doc,

I learned that if I import the myGUI.ui into the project before opening, it
will open fine with QTDesigner from within Eclipse. I was trying to open it
directly from an unrelated FileFolder. I told you I was a rookie.

I can now edit my GUI in QTDesigner, import it into Eclipse, and generate my
.py code to view, or edit.

I am still at a loss why I cannot simply view with the 'View Code' feature
in QTDesigner.

Thanks for all the help.

Joe

doc_brown

unread,
Oct 21, 2009, 4:16:21 PM10/21/09
to python(x,y)
You are welcome!

Is it correct that now you can create a myGUI.ui form and double-click
open it from inside eclipse?

As for the "View Code" Feature in QTDesigner, it never worked with
PyQt (at least on Windows). Standard Nokia Qt Designer generates C++
code normally, but I'm also baffled why that cannot be done for PyQt
for long time.

Cheers,

Victor (doc_brown)

doc_brown

unread,
Oct 21, 2009, 4:21:20 PM10/21/09
to python(x,y)
To generate .ui form inside Eclipse right-click your source folder,
choose New -> Other -> Qt Designer -> Qt Designer Form, click "Next",
and choose the name for the form. That's it!

Victor (doc_brown)

On Oct 21, 3:34 pm, "Joseph D Stenger" <jstengers...@gmail.com> wrote:

Joseph D Stenger

unread,
Oct 21, 2009, 4:27:26 PM10/21/09
to pyth...@googlegroups.com
Yes, I can create a myGui.ui from External QTDesigner session ( I do this
because QT external to Eclipse seems to have more features and it is easier
to create the initial design). Then import it to Eclipse Open and simple
edit it with built in QT and generate the code.

Glad to hear I am not crazy with regards to View Code option. When you are
new to something, these "known to everyone but me" bugs can really throw you
for a loop and cost a lot of time.

Cheers,

Joe

-----Original Message-----
From: pyth...@googlegroups.com [mailto:pyth...@googlegroups.com] On Behalf
Of doc_brown
Sent: Wednesday, October 21, 2009 1:16 PM
To: python(x,y)
Subject: [python(x,y)] Re: Eclipse PyQtDesigner pyuic4 code generation


Joseph D Stenger

unread,
Oct 21, 2009, 4:30:56 PM10/21/09
to pyth...@googlegroups.com
Excellent, I was not aware I could do that.

Joe

doc_brown

unread,
Oct 21, 2009, 4:48:17 PM10/21/09
to python(x,y)
Joe,

You're right, the integrated Qt Designer does not provide all
available widgets like Qwt and matplotlib, so the external Qt designer
is also very handy. I even made another External tool in eclipse to
link to it :)

Victor (doc_brown)
Reply all
Reply to author
Forward
0 new messages