From cc92c5001bbfe85bc3a901ffe63b7a91384bf67b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 23 Mar 2021 11:24:35 +0100 Subject: [PATCH] Brush up the Python wizard code templates Fix the spacing and introduce pathlib. Change-Id: I240291d91cae7c233b2d3ec5c0dfaeede09ad47d Reviewed-by: Cristian Maureira-Fredes --- .../projects/qtforpythonapplication/main_qtquick.py | 7 ++++--- .../wizards/projects/qtforpythonapplication/main_widget.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_qtquick.py b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_qtquick.py index d0cc9680c0b..deff3ccd3d7 100644 --- a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_qtquick.py +++ b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_qtquick.py @@ -1,15 +1,16 @@ # This Python file uses the following encoding: utf-8 -import sys import os +from pathlib import Path +import sys from %{PySideVersion}.QtGui import QGuiApplication from %{PySideVersion}.QtQml import QQmlApplicationEngine + if __name__ == "__main__": app = QGuiApplication(sys.argv) engine = QQmlApplicationEngine() - engine.load(os.path.join(os.path.dirname(__file__), "main.qml")) - + engine.load(os.fspath(Path(__file__).resolve().parent / "main.qml")) if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec_()) diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget.py b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget.py index 2b02e34ac19..e00ab451e5d 100644 --- a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget.py +++ b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget.py @@ -1,7 +1,7 @@ # This Python file uses the following encoding: utf-8 -import sys import os - +from pathlib import Path +import sys @if '%{BaseCB}' === 'QWidget' from %{PySideVersion}.QtWidgets import QApplication, QWidget @@ -27,12 +27,13 @@ class %{Class}: def load_ui(self): loader = QUiLoader() - path = os.path.join(os.path.dirname(__file__), "form.ui") + path = os.fspath(Path(__file__).resolve().parent / "form.ui") ui_file = QFile(path) ui_file.open(QFile.ReadOnly) loader.load(ui_file, self) ui_file.close() + if __name__ == "__main__": app = QApplication([]) widget = %{Class}()