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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,6 @@
# This Python file uses the following encoding: utf-8 # This Python file uses the following encoding: utf-8
import os
from pathlib import Path
import sys import sys
from pathlib import Path
from %{PySideVersion}.QtGui import QGuiApplication from %{PySideVersion}.QtGui import QGuiApplication
from %{PySideVersion}.QtQml import QQmlApplicationEngine from %{PySideVersion}.QtQml import QQmlApplicationEngine
@@ -10,7 +9,16 @@ from %{PySideVersion}.QtQml import QQmlApplicationEngine
if __name__ == "__main__": if __name__ == "__main__":
app = QGuiApplication(sys.argv) app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine() 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(): if not engine.rootObjects():
sys.exit(-1) sys.exit(-1)
@if '%{PySideVersion}' === 'PySide6'
sys.exit(app.exec())
@else
sys.exit(app.exec_()) sys.exit(app.exec_())
@endif

View File

@@ -21,21 +21,29 @@ class %{Class}(%{BaseCB}):
@else @else
class %{Class}: class %{Class}:
@endif @endif
def __init__(self): def __init__(self, parent=None):
super(%{Class}, self).__init__() super().__init__(parent)
self.load_ui() self.load_ui()
def load_ui(self): def load_ui(self):
loader = QUiLoader() 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) ui_file = QFile(path)
@else
ui_file = QFile(str(path))
@endif
ui_file.open(QFile.ReadOnly) ui_file.open(QFile.ReadOnly)
loader.load(ui_file, self) loader.load(ui_file, self)
ui_file.close() ui_file.close()
if __name__ == "__main__": if __name__ == "__main__":
app = QApplication([]) app = QApplication(sys.argv)
widget = %{Class}() widget = %{Class}()
widget.show() widget.show()
@if '%{PySideVersion}' === 'PySide6'
sys.exit(app.exec())
@else
sys.exit(app.exec_()) sys.exit(app.exec_())
@endif

View File

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

View File

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

View File

@@ -3,8 +3,8 @@
"supportedProjectTypes": [ "PythonProject" ], "supportedProjectTypes": [ "PythonProject" ],
"id": "F.QtForPythonApplicationWindowWidget", "id": "F.QtForPythonApplicationWindowWidget",
"category": "F.ApplicationPySide", "category": "F.ApplicationPySide",
"trDescription": "Creates a Qt for Python application that includes a Qt Designer-based widget (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": "Qt for Python - Window (UI file)", "trDisplayName": "Window UI - Dynamic load",
"trDisplayCategory": "Application (Qt for Python)", "trDisplayCategory": "Application (Qt for Python)",
"icon": "../icons/icon.png", "icon": "../icons/icon.png",
"iconKind": "Themed", "iconKind": "Themed",