使用pyuic将Qt .ui转换为.py的Eclipse外部工具 [英] Eclipse external tool for Qt .ui to .py with pyuic

查看:177
本文介绍了使用pyuic将Qt .ui转换为.py的Eclipse外部工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在带有Qt集成的Eclipse中使用PyDev。使用外部工具,我可以从qt .ui文件在.py中创建python源。这是外部工具:
http://permalink.gmane.org/gmane。 comp.python.xy.devel / 413
问题是生成的python .py文件的名称类似于MyGeneratedFile.ui.py。
如何修改外部工具以使生成的文件扩展名不带有.ui,因此不包含MyGeneratedFile.py?

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 ?

推荐答案

所以看来问题归结为 $ {resource_loc} ,因为这为您提供了完整的路径名 /path/to/file/filename.ui -是的,它确实包含 .ui ,因此当您说 $ {resource_loc} .py 时,它会转换为 /path/to/file/filename.ui.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

所以可能更正此问题的最简单方法是,因为我找不到让eclipse删除文件扩展名的方法,因此我编写了一个非常小的脚本来可以正常工作。

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.

您可能需要对其稍加修改以适用于pyuic安装。

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

使其可执行,而我使用的eclipse配置要简单得多:

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


  • PyUIC-> Main->位置: / usr / bin / pyuicEclipse ---显然将其更改为您的

  • PyUIC-> Main->参数: $ {resource_loc}

  • PyUIC->刷新-选中完成时刷新资源

  • PyUIC->构建-取消选中启动前构建

  • PyUIC->常见-不t做该文章中提到的文件选项

  • 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

这在Linux上有效,因此,如果您使用的是其他操作系统,则可能需要稍作修改,但我希望这可以解决您的问题:)

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

这篇关于使用pyuic将Qt .ui转换为.py的Eclipse外部工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆