Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse external tool for Qt .ui to .py with pyuic

I use PyDev in Eclipse with the Qt integration. With an external tool I can create python source in a .py from a qt .ui file. This is the external tool: http://permalink.gmane.org/gmane.comp.python.xy.devel/413 The problem is that the generated python .py file has a name like MyGeneratedFile.ui.py. How can I adapt the external tool to have the extension of the generated file without .ui thus MyGeneratedFile.py ?

like image 445
ArtDijk Avatar asked Apr 04 '11 15:04

ArtDijk


3 Answers

So it seems the problem boils down to ${resource_loc}, since this gives you the full path name /path/to/file/filename.ui - Yes, it does include the .ui hence when you say ${resource_loc}.py this translates into /path/to/file/filename.ui.py

So probably the simplest way to correct this problem since I couldn't find a way to make eclipse remove the file extension for me was making a very small script to do work.

You might need to modify it slightly to work for your pyuic installation.

/usr/bin/pyuicEclipse:

#!/bin/bash
pyUICCommand="/usr/bin/pyuic" # change this per your installation
x=$1
f=`basename $x`
d=`dirname $x`
fNoUI="`echo $f | sed 's/\.ui$//'`" # removes .ui extension from file basename
$pyUICCommand -o ${d}/${fNoUI}.py $x

make it executable and the eclipse configuration I used was much simpler:

  • PyUIC->Main->Location: /usr/bin/pyuicEclipse ---obviously change this to yours
  • PyUIC->Main->Arguments: ${resource_loc}
  • PyUIC->Refresh - check "Refresh Resources upon Completion"
  • PyUIC->Build - uncheck "Build before Launch"
  • PyUIC->Common - don't do the File option that was mentioned in that article

This works on linux, so if you're on another OS it may need some slight modification, but I hope this solves your problem :)

like image 143
platinummonkey Avatar answered Oct 21 '22 23:10

platinummonkey


In the interests of maintaining the cross-platform nature of Eclipse, I've knocked up a DOS equivalent of platinummonkey's bash script. It's not quite so robust, but it does the job:

@echo off
set pyUICCommand="pyuic"
set fname=%1
set fname=%fname:.ui=.py%
%pyUICCommand% -o %fname% %1
like image 42
MerseyViking Avatar answered Oct 21 '22 22:10

MerseyViking


There is an easy solution to this problem that requires no scripting at all.

  1. Install pathtools plugin either through Eclipse updates or via the Eclipse marketplace:

  2. Setup an External Tools Configurations option in Eclipse as follows

In Main:

  1. Name: pyuic_run. (or something similar)
  2. Location: path to the python interpreter (or pyside-uic.exe if you use this)
  3. Arguments: On the first line, put the path to pyuic.py (not needed if you use pyside-uic.exe as it will be above). Use double quotes around the path if it contains spaces. On the second line put "${resource_loc}" (this will set the name of the resource file)
  4. In refresh: Enable "Refresh resources upon completion" (to see the final file)
  5. In Build: Disable "Build before launch" #not necessary here
  6. In Environment: No changes
  7. In Common: Activate the "File" option and set the path to be: ${parent-path}/${name-sans-extension}.py

Note that ${parent-path} and ${name-sans-extension} are arguments made available through the pathtools plugin.

If you apply this and then run the configuration on a .ui resource file, you'll see a new .py file created.

like image 34
Lozzer Avatar answered Oct 21 '22 23:10

Lozzer