Qt for Python .ui batch compiler shell script
-
Please read the updated version down below, as I made a mistake writing this first one. I'm just keeping that mistake here for posterity's sake.
This is ridiculously simple. All it does is loop through every .ui file (a form created in Qt Creator's Widgets Designer) in its current directory and runs the
pyside6-uiccommand on each of them, which converts them into equivalent Python scripts.for file in *.ui; do if [ -f "$file" ]; then echo "Processing file $file..." pyside6-uic "$file" -o "ui_$file.py" echo "done!" fi doneYou'll need Python installed of course, and make sure that you have PySide6 (Qt's official Python language bindings) by running
pip install pyside6in the command line. If it isn't already there, the command will install it for you.
Theif [ -f "$file" ];part checks if the file is actually a file and not a folder. -
UPDATE: I just realised that it outputs a
.ui.pyfile instead of a.pyfile. Here's the new shell script:for file in *.ui; do if [ -f "$file" ]; then echo "Processing file $file..." IFS='.' read -r -a separated <<< "$file" pyside6-uic "$file" -o "ui_${separated[0]}.py" echo "done!" fi doneIFS='.' read -r -a separated <<< "$file"is equivalent toseparated = file.split('.')in Python.