diff options
Diffstat (limited to 'share/qtcreator/templates/wizards/projects/qtforpythonapplication')
5 files changed, 9 insertions, 175 deletions
diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget.py b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget.py index 02b7ab7911..bd7d4fa807 100644 --- a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget.py +++ b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget.py @@ -1,6 +1,4 @@ # This Python file uses the following encoding: utf-8 -import os -from pathlib import Path import sys @if '%{BaseCB}' === 'QWidget' @@ -12,9 +10,12 @@ from %{PySideVersion}.QtWidgets import QApplication, QMainWindow @if '%{BaseCB}' === 'QDialog' from %{PySideVersion}.QtWidgets import QApplication, QDialog @endif -from %{PySideVersion}.QtCore import QFile -from %{PySideVersion}.QtUiTools import QUiLoader +# Important: +# You need to run the following command to generate the ui_form.py file +# pyside6-uic form.ui -o ui_form.py, or +# pyside2-uic form.ui -o ui_form.py +from ui_form import Ui_%{Class} @if '%{BaseCB}' class %{Class}(%{BaseCB}): @@ -23,19 +24,8 @@ class %{Class}: @endif def __init__(self, parent=None): super().__init__(parent) - self.load_ui() - - def load_ui(self): - loader = QUiLoader() - 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() + self.ui = Ui_%{Class}() + self.ui.setupUi(self) if __name__ == "__main__": diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget_gen.py b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget_gen.py deleted file mode 100644 index bd7d4fa807..0000000000 --- a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/main_widget_gen.py +++ /dev/null @@ -1,39 +0,0 @@ -# This Python file uses the following encoding: utf-8 -import sys - -@if '%{BaseCB}' === 'QWidget' -from %{PySideVersion}.QtWidgets import QApplication, QWidget -@endif -@if '%{BaseCB}' === 'QMainWindow' -from %{PySideVersion}.QtWidgets import QApplication, QMainWindow -@endif -@if '%{BaseCB}' === 'QDialog' -from %{PySideVersion}.QtWidgets import QApplication, QDialog -@endif - -# Important: -# You need to run the following command to generate the ui_form.py file -# pyside6-uic form.ui -o ui_form.py, or -# pyside2-uic form.ui -o ui_form.py -from ui_form import Ui_%{Class} - -@if '%{BaseCB}' -class %{Class}(%{BaseCB}): -@else -class %{Class}: -@endif - def __init__(self, parent=None): - super().__init__(parent) - self.ui = Ui_%{Class}() - self.ui.setupUi(self) - - -if __name__ == "__main__": - app = QApplication(sys.argv) - widget = %{Class}() - widget.show() -@if '%{PySideVersion}' === 'PySide6' - sys.exit(app.exec()) -@else - sys.exit(app.exec_()) -@endif diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget/wizard.json b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget/wizard.json index 1a8e1bd72c..951be73475 100644 --- a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget/wizard.json +++ b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget/wizard.json @@ -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) - Load the forms dynamically/at runtime", - "trDisplayName": "Window UI - Dynamic load", + "trDescription": "Creates a Qt for Python application that includes a Qt Designer-based widget (ui file) - Requires .ui to Python conversion", + "trDisplayName": "Window UI", "trDisplayCategory": "Application (Qt for Python)", "icon": "../icons/icon.png", "iconKind": "Themed", diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/main.pyproject b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/main.pyproject deleted file mode 100644 index 64c2987a8f..0000000000 --- a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/main.pyproject +++ /dev/null @@ -1,3 +0,0 @@ -{ - "files": ["%{SrcFileName}", "form.ui"] -} diff --git a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/wizard.json b/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/wizard.json deleted file mode 100644 index 3bfe3af638..0000000000 --- a/share/qtcreator/templates/wizards/projects/qtforpythonapplication/widget_gen/wizard.json +++ /dev/null @@ -1,114 +0,0 @@ -{ - "version": 1, - "supportedProjectTypes": [ "PythonProject" ], - "id": "F.QtForPythonApplicationWindowWidgetGen", - "category": "F.ApplicationPySide", - "trDescription": "Creates a Qt for Python application that includes a Qt Designer-based widget (ui file) - Requires .ui to Python conversion", - "trDisplayName": "Window UI", - "trDisplayCategory": "Application (Qt for Python)", - "icon": "../icons/icon.png", - "iconKind": "Themed", - "enabled": "%{JS: value('Plugins').indexOf('Python') >= 0 && (!value('Platform').length || ['Desktop', 'DockerDeviceType', 'GenericLinuxOsType'].includes(value('Platform')))}", - - "options": - [ - { "key": "SrcFileName", "value": "%{MainFileName}" }, - { "key": "PyProjectFile", "value": "%{ProjectFileName}" } - ], - - "pages": - [ - { - "trDisplayName": "Project Location", - "trShortTitle": "Location", - "typeId": "Project", - "name": "ProjectPath" - }, - { - "trDisplayName": "Define Class", - "trShortTitle": "Details", - "typeId": "Fields", - "data" : - [ - { - "name": "PySideVersion", - "trDisplayName": "PySide version:", - "type": "ComboBox", - "data": - { - "index": 1, - "items": [ "PySide2", "PySide6" ] - } - }, - { - "name": "Class", - "trDisplayName": "Class name:", - "mandatory": true, - "type": "LineEdit", - "data": - { - "validator": "(?:(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*|)", - "trText": "%{JS: value('BaseCB') ? value('BaseCB').slice(1) : 'MyClass'}" - } - - }, - { - "name": "BaseCB", - "trDisplayName": "Base class:", - "type": "ComboBox", - "data": - { - "items": [ "QWidget", "QDialog", "QMainWindow" ] - } - }, - { - "name": "MainFileName", - "type": "LineEdit", - "trDisplayName": "Source file:", - "mandatory": true, - "data": { "trText": "%{JS: Cpp.classToFileName(value('Class'), Util.preferredSuffix('text/x-python'))}" } - }, - { - "name": "ProjectFileName", - "type": "LineEdit", - "trDisplayName": "Project file:", - "mandatory": true, - "data": { "trText": "%{JS: Util.fileName('%{ProjectName}', 'pyproject')}" } - } - ] - }, - { - "trDisplayName": "Project Management", - "trShortTitle": "Summary", - "typeId": "Summary" - } - ], - "generators": - [ - { - "typeId": "File", - "data": - [ - { - "source": "main.pyproject", - "target": "%{PyProjectFile}", - "openAsProject": true - }, - { - "source": "../main_widget_gen.py", - "target": "%{SrcFileName}", - "openInEditor": true - }, - { - "source": "../main_widget.ui", - "target": "form.ui" - }, - { - "source": "../../git.ignore", - "target": ".gitignore", - "condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}" - } - ] - } - ] -} |