python: update wizard code style

- Updated the current code to use recommended code style
- Modify description of current wizards
- Adapt the documentation to reflect the new names of the applications
- Adapt exec() call for PySide6 (and leave exec_() for PySide2)

Change-Id: Iad662523b8a0e56ac622b21cee60f7928d419354
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Cristián Maureira-Fredes
2021-12-17 09:40:21 +01:00
committed by Cristian Maureira-Fredes
parent 345c8caa03
commit c926ca2321
10 changed files with 45 additions and 24 deletions

View File

@@ -122,20 +122,20 @@
to desktop, embedded, and mobile target platforms.
\row
\li {1,4} Application (Qt for Python)
\li Qt for Python - Empty
\li Empty Application
\li Creates a \l{https://doc.qt.io/qtforpython/index.html}
{Qt for Python} application that contains only the main
code for a QApplication.
\row
\li Qt for Python - Window
\li Empty Window
\li Creates a Qt for Python application that contains an empty
window.
\row
\li Qt for Python - Window (UI file)
\li Window UI - Dynamic load
\li Creates a Qt for Python application that contains an empty
window with a widget-based UI.
\row
\li Qt for Python - Qt Quick Application
\li Qt Quick Application - Empty
\li Creates a Python project that contains an empty Qt Quick
Application.
\row

View File

@@ -38,7 +38,7 @@
"type": "ComboBox",
"data":
{
"items": ["<None>", "PySide2", "PySide6", "PyQt5"]
"items": ["<None>", "PySide6", "PySide2", "PyQt6", "PyQt5"]
}
},
{

View File

@@ -4,7 +4,7 @@
"id": "F.QtForPythonApplicationEmpty",
"category": "F.ApplicationPySide",
"trDescription": "Creates a Qt for Python application that contains only the main code for a QApplication.",
"trDisplayName": "Qt for Python - Empty",
"trDisplayName": "Empty Application",
"trDisplayCategory": "Application (Qt for Python)",
"icon": "icon.png",
"iconKind": "Themed",

View File

@@ -4,6 +4,10 @@ from %{PySideVersion}.QtWidgets import QApplication
if __name__ == "__main__":
app = QApplication([])
app = QApplication(sys.argv)
# ...
@if '%{PySideVersion}' === 'PySide6'
sys.exit(app.exec())
@else
sys.exit(app.exec_())
@endif

View File

@@ -16,12 +16,9 @@ class %{Class}(%{BaseCB}):
@else
class %{Class}:
@endif
def __init__(self):
@if '%{BaseCB}' === 'QWidget'
QWidget.__init__(self)
@endif
@if '%{BaseCB}' === 'QMainWindow'
QMainWindow.__init__(self)
def __init__(self, parent=None):
@if '%{BaseCB}' === 'QWidget' || '%{BaseCB}' === 'QMainWindow'
super().__init__(parent)
@endif
@if '%{BaseCB}' === ''
pass # call __init__(self) of the custom base class here
@@ -36,4 +33,8 @@ if __name__ == "__main__":
@else
window.show()
@endif
@if '%{PySideVersion}' === 'PySide6'
sys.exit(app.exec())
@else
sys.exit(app.exec_())
@endif

View File

@@ -1,7 +1,6 @@
# This Python file uses the following encoding: utf-8
import os
from pathlib import Path
import sys
from pathlib import Path
from %{PySideVersion}.QtGui import QGuiApplication
from %{PySideVersion}.QtQml import QQmlApplicationEngine
@@ -10,7 +9,16 @@ from %{PySideVersion}.QtQml import QQmlApplicationEngine
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(os.fspath(Path(__file__).resolve().parent / "%{QmlFileName}"))
qml_file = Path(__file__).resolve().parent / "%{QmlFileName}"
@if '%{PySideVersion}' === 'PySide6'
engine.load(qml_file)
@else
engine.load(str(qml_file))
@endif
if not engine.rootObjects():
sys.exit(-1)
@if '%{PySideVersion}' === 'PySide6'
sys.exit(app.exec())
@else
sys.exit(app.exec_())
@endif

View File

@@ -21,21 +21,29 @@ class %{Class}(%{BaseCB}):
@else
class %{Class}:
@endif
def __init__(self):
super(%{Class}, self).__init__()
def __init__(self, parent=None):
super().__init__(parent)
self.load_ui()
def load_ui(self):
loader = QUiLoader()
path = os.fspath(Path(__file__).resolve().parent / "form.ui")
path = Path(__file__).resolve().parent / "form.ui"
@if '%{PySideVersion}' === 'PySide6'
ui_file = QFile(path)
@else
ui_file = QFile(str(path))
@endif
ui_file.open(QFile.ReadOnly)
loader.load(ui_file, self)
ui_file.close()
if __name__ == "__main__":
app = QApplication([])
app = QApplication(sys.argv)
widget = %{Class}()
widget.show()
@if '%{PySideVersion}' === 'PySide6'
sys.exit(app.exec())
@else
sys.exit(app.exec_())
@endif

View File

@@ -4,7 +4,7 @@
"id": "F.QtForPythonApplicationWindow",
"category": "F.ApplicationPySide",
"trDescription": "Creates a Qt for Python application that contains an empty window.",
"trDisplayName": "Qt for Python - Window",
"trDisplayName": "Empty Window",
"trDisplayCategory": "Application (Qt for Python)",
"icon": "../icons/icon.png",
"iconKind": "Themed",

View File

@@ -4,7 +4,7 @@
"id": "F.QtQuickQtForPythonApplicationEmpty",
"category": "F.ApplicationPySide",
"trDescription": "Creates a Qt Quick application that contains an empty window.",
"trDisplayName": "Qt for Python - Qt Quick Application - Empty",
"trDisplayName": "Qt Quick Application - Empty",
"trDisplayCategory": "Application (Qt for Python)",
"icon": "../icons/icon.png",
"iconKind": "Themed",

View File

@@ -3,8 +3,8 @@
"supportedProjectTypes": [ "PythonProject" ],
"id": "F.QtForPythonApplicationWindowWidget",
"category": "F.ApplicationPySide",
"trDescription": "Creates a Qt for Python application that includes a Qt Designer-based widget (ui file)",
"trDisplayName": "Qt for Python - Window (UI file)",
"trDescription": "Creates a Qt for Python application that includes a Qt Designer-based widget (.ui file) - Load the forms dynamically/at runtime",
"trDisplayName": "Window UI - Dynamic load",
"trDisplayCategory": "Application (Qt for Python)",
"icon": "../icons/icon.png",
"iconKind": "Themed",