简体   繁体   English

用于Qt .ui到.py的Eclipse外部工具与pyuic

[英]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配置更简单:

  • PyUIC->Main->Location: /usr/bin/pyuicEclipse ---obviously change this to yours PyUIC-> Main-> Location: / usr / bin / pyuicEclipse ---显然改为你的
  • PyUIC->Main->Arguments: ${resource_loc} PyUIC-> Main->参数: $ {resource_loc}
  • PyUIC->Refresh - check "Refresh Resources upon Completion" PyUIC->刷新 - 选中“完成后刷新资源”
  • PyUIC->Build - uncheck "Build before Launch" PyUIC-> Build - 取消选中“在启动前构建”
  • PyUIC->Common - don't do the File option that was mentioned in that article PyUIC-> Common - 不要执行该文章中提到的F​​ile选项

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. 这个问题有一个简单的解决方案,根本不需要脚本。

  1. Install pathtools plugin either through Eclipse updates or via the Eclipse marketplace : 通过Eclipse更新或通过Eclipse市场安装pathtools插件:

  2. Setup an External Tools Configurations option in Eclipse as follows 在Eclipse中设置“外部工具配置”选项,如下所示

In Main: 在主要:

  1. Name: pyuic_run. 名称:pyuic_run。 (or something similar) (或类似的东西)
  2. Location: path to the python interpreter (or pyside-uic.exe if you use this) 位置:python解释器的路径(如果使用此命令,则为pyside-uic.exe)
  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). 参数:在第一行,将路径放到pyuic.py(如果您使用pyside-uic.exe,则不需要它)。 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) 在第二行放“$ {resource_loc}”(这将设置资源文件的名称)
  4. In refresh: Enable "Refresh resources upon completion" (to see the final file) 在刷新中:启用“完成后刷新资源”(查看最终文件)
  5. In Build: Disable "Build before launch" #not necessary here 在Build中:禁用“在启动之前构建”#not here 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 通用:激活“文件”选项并将路径设置为:$ {parent-path} / $ {name-sans-extension} .py

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM