Skip to content
Snippets Groups Projects
Commit b8b970d0 authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

ui2py.py. Use space instead of tab to indent auto-generated code.

parent 957a6aaa
No related branches found
No related tags found
No related merge requests found
......@@ -8,21 +8,22 @@ import os
def create_window_file(base_name: str, dest_dir: str):
camel_basename = base_name.replace("_", " ").title().replace(" ", "")
content = "from PyQt5.QtWidgets import QDialog\n"
content += "from " + "gui.ui_" + base_name.lower() + " import Ui_" + camel_basename + "\n"
content += (
"from " + "gui.ui_" + base_name.lower() + " import Ui_" + camel_basename + "\n"
)
content += "\n"
content += "\n"
content += "class " + camel_basename + "(QDialog):\n"
content += "\tdef __init__(self, parent_window):\n"
content += "\t\tsuper(" + camel_basename + ", self).__init__(parent_window)\n"
content += "\t\tself.ui = Ui_" + camel_basename + "()\n"
content += "\t\tself.ui.setupUi(self)\n"
content += " def __init__(self, parent_window):\n"
content += " super(" + camel_basename + ", self).__init__(parent_window)\n"
content += " self.ui = Ui_" + camel_basename + "()\n"
content += " self.ui.setupUi(self)\n"
dest_filename = os.path.join(dest_dir, base_name + ".py")
with open(dest_filename, 'w') as out_file:
with open(dest_filename, "w") as out_file:
out_file.write(content)
# Determine the projects base path and the directory containing the .ui files.
possible_base_paths = ["../", "../../"]
pyqt_dir = None
......@@ -46,7 +47,9 @@ else:
# Build the path to the `pyuic` executable
pyuic_exec_path = os.path.join(base_path, "venv/bin", pyuic_exec_file)
if not os.path.exists(pyuic_exec_path):
raise FileNotFoundError("[" + pyuic_exec_path + "] not found. Please install PyQt5.")
raise FileNotFoundError(
"[" + pyuic_exec_path + "] not found. Please install PyQt5."
)
# Find destination folder for .py output files
possible_pkg_names = [os.path.basename(os.path.abspath(os.path.pardir)), "src"]
......@@ -65,9 +68,8 @@ for ui_file in os.listdir(pyqt_dir):
if ui_file.endswith(".ui"):
ui_file_basename = os.path.splitext(ui_file)[0]
py_file = os.path.join(dest_dir, "ui_" + ui_file_basename + ".py")
os.system(pyuic_exec_path + " " + os.path.join(pyqt_dir, ui_file) + " -o " + py_file)
os.system(
pyuic_exec_path + " " + os.path.join(pyqt_dir, ui_file) + " -o " + py_file
)
if ui_file.endswith("_dialog.ui"):
create_window_file(ui_file_basename, dest_dir)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment