Skip to content

Instantly share code, notes, and snippets.

@vermiceli
Created November 28, 2014 15:24
Show Gist options
  • Save vermiceli/108fec65759d19645ee3 to your computer and use it in GitHub Desktop.
Save vermiceli/108fec65759d19645ee3 to your computer and use it in GitHub Desktop.
# This is a powershell commandlet equivalent of build_ui.sh for installation on Windows
# Generate python files based on the designer ui files. pyrcc4 should be on the path.
# If you need to modify the python location or pyuic path, just change the 2 variables below
$pythonPath = "C:\Python27\"
$pyuicPath = "C:\Python27\Lib\site-packages\PyQt4\uic\pyuic.py"
If (!(Test-Path "designer")) {
Write-Host "Please run this from the project root"
Exit
}
# Create the directory. If it already exists, nothing will happen
Write-Host "Creating aqt\forms"
New-Item "aqt\forms" -ItemType "directory" -Force > $null
$init = "aqt\forms\__init__.py"
$temp = "aqt\forms\scratch"
If (Test-Path $init) {
Write-Host "Creating $($init)"
Remove-Item $init
}
If (Test-Path $temp) {
Write-Host "Creating $($temp)"
Remove-Item $temp
}
Write-Output "# This file auto-generated by build_ui.sh. Don't edit." | Out-File -Encoding "UTF8" $init
Write-Output "__all__ = [" | Out-File -Encoding "UTF8" -Append $init
Write-Host "Generating forms.."
Get-ChildItem "designer\*.ui" | Select BaseName | Foreach-Object {
$base = "$($_.BaseName)"
Write-Host " $($base)"
$py = Join-Path "aqt\forms\" ($base + ".py")
Write-Output " '$($base)'," | Out-File -Append -Encoding "UTF8" $init
Write-Output "import $($base)" | Out-File -Append -Encoding "UTF8" $temp
if(!(Test-Path $py) -or ((Get-Item "designer\$($base).ui").LastWriteTime -gt (Get-Item $py).LastWriteTime)) {
Write-Host " $($py)"
$pythonCommand = Join-Path $pythonPath "python.exe"
$command = "$($pythonCommand) $($pyuicPath) ""designer\$($base).ui"" -o $($py)"
Invoke-Expression $command
# munge the output to use gettext
# perl -pi.bak -e 's/(QtGui\.QApplication\.)?_?translate\(".*?", /_(/; s/, None.*/))/' $py
# rm $py.bak
}
}
Write-Output "]" | Out-File -Encoding "UTF8" -Append $init
Cat $temp | Out-File -Encoding "UTF8" -Append $init
Remove-Item $temp
Write-Host "Building resources..."
pyrcc4 designer\icons.qrc -o aqt\forms\icons_rc.py
Write-Host "Complete"
@tfer
Copy link

tfer commented Mar 2, 2016

After about six hours of messing with this I finally got this to work. Nothing to do with the script other than the changes needed to lines 5 and 6, rather my pain had to do with my use of the Anaconda distribution.

Points for Anaconda:

  1. the PyQt that comes with Anaconda is missing some of the dev tools needed, so do:
    conda remove pyqt
  2. get the windows pyqt4 installer from www.riverbankcomputing.com
  3. ran the installer, for some reason all this seems to do is put a tarball in the pkg directory
  4. so I did:
    conda install path-&-name-of-tarball
  5. last bit was to adjust the pyrcc.bat file so it called pyrcc.exe, (with parameters), which I found in /Library/bin instead on /Scripts
  6. Works! mostly... complains that it wants 'Mplayer' but thats for another day

@dlon
Copy link

dlon commented May 19, 2018

Updated this: https://gist.github.com/dlon/81ca304616ee4b03c58a11581a21d048
Works for pip-installed PyQt5, at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment