Skip to content

Instantly share code, notes, and snippets.

@dangreene0
Last active August 15, 2021 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dangreene0/328ea84a5c3187e87ad206f702731d52 to your computer and use it in GitHub Desktop.
Save dangreene0/328ea84a5c3187e87ad206f702731d52 to your computer and use it in GitHub Desktop.
pyuic5 drag and drop converter

pyuic5 Ui2Py.py

This is an open-source drag and drop solution for people using Qt Designer and PyQt5.

Features

  • Ease of use!!!!

How to install

  1. Just unzip Ui2Py.py

How to use

  • Drag your .ui file onto it, and presto!

Thank you!

Please comment below if you have anymore questions.

import sys
import os
try:
droppedFile = sys.argv[1]
input("Press any button begin conversion.")
print(f"Attempting to convert file located at {droppedFile}")
if droppedFile.endswith(".ui"):
fileName = os.path.basename(droppedFile)
asPy = f"{fileName[:-3]}.py"
for file in os.listdir("."):
if file == asPy:
print(f"\nThere is already a file named {asPy}")
answer = input("Do you wish to overwrite it?\nY/N\n")
if answer.lower() == "y":
os.system(f"pyuic5 -o {fileName[:-3]}.py {droppedFile}")
print(f"\n{fileName[:-3]} has been converted...\n")
else:
print("\nIncorrect file type.\nMust be a Qt Designer .ui file.\n")
input("Press any button to close this window")
except:
print("No file dropped...")
input("Press any button to close this window.")
# raw code that this basically accomplishes
# pyuic5 -o window.py untitled.ui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment