[英]Eclipse external tool for Qt .ui to .py with pyuic
I use PyDev in Eclipse with the Qt integration. 我在Eclipse中使用PyDev和Qt集成。 With an external tool I can create python source in a .py from a qt .ui file.
使用外部工具,我可以从qt .ui文件中创建.py中的python源代码。 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.
这是外部工具: http : //permalink.gmane.org/gmane.comp.python.xy.devel/413问题是生成的python .py文件的名称类似于MyGeneratedFile.ui.py。 How can I adapt the external tool to have the extension of the generated file without .ui thus MyGeneratedFile.py ?
如何在不使用.ui的情况下调整外部工具以获得生成文件的扩展名MyGeneratedFile.py?
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 因此,问题似乎归结为$ {resource_loc} ,因为这会为您提供完整的路径名/path/to/file/filename.ui - 是的,它确实包含.ui因此当您说$ {resource_loc} .py时这转换为/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. 所以可能最简单的方法来纠正这个问题因为我找不到让eclipse为我删除文件扩展名的方法是制作一个非常小的脚本来完成工作。
You might need to modify it slightly to work for your pyuic installation. 您可能需要稍微修改它以适合您的pyuic安装。
/usr/bin/pyuicEclipse: 在/ 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: 使它可执行,我使用的eclipse配置更简单:
This works on linux, so if you're on another OS it may need some slight modification, but I hope this solves your problem :) 这适用于linux,所以如果你在另一个操作系统上它可能需要稍微修改,但我希望这可以解决你的问题:)
In the interests of maintaining the cross-platform nature of Eclipse, I've knocked up a DOS equivalent of platinummonkey's bash script. 为了维护Eclipse的跨平台性质,我敲了一下DOS等价的platinummonkey的bash脚本。 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
There is an easy solution to this problem that requires no scripting at all. 这个问题有一个简单的解决方案,根本不需要脚本。
Install pathtools plugin either through Eclipse updates or via the Eclipse marketplace : 通过Eclipse更新或通过Eclipse市场安装pathtools插件:
Setup an External Tools Configurations option in Eclipse as follows 在Eclipse中设置“外部工具配置”选项,如下所示
In Main: 在主要:
Note that ${parent-path} and ${name-sans-extension} are arguments made available through the pathtools plugin. 请注意,$ {parent-path}和$ {name-sans-extension}是通过pathtools插件提供的参数。
If you apply this and then run the configuration on a .ui resource file, you'll see a new .py file created. 如果应用此选项然后在.ui资源文件上运行配置,您将看到创建了一个新的.py文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.