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

后端 未结 3 1063
温柔的废话
温柔的废话 2020-12-19 10:49

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.gma

相关标签:
3条回答
  • 2020-12-19 11:14

    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
    
    0 讨论(0)
  • 2020-12-19 11:24

    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.

    0 讨论(0)
  • 2020-12-19 11:28

    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 :)

    0 讨论(0)
提交回复
热议问题