forked from qt-creator/qt-creator
Python: Remove wizard for dynamically loaded ui projects
The dialog and main window variant of this wizard was broken since ever. Generally two widget ui templates are generally confusing for the user, so remove the broken wizard that promotes the not recommended way of using ui files. Also we support the automatic conversion from ui to py files nowadays via the PySide6 project tool. Fixes: QTCREATORBUG-25807 Change-Id: I3ec6000a6c3fb076e3a54c70f3cccdd12df28701 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
# 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
|
||||||
|
|
||||||
@if '%{BaseCB}' === 'QWidget'
|
@if '%{BaseCB}' === 'QWidget'
|
||||||
@@ -12,9 +10,12 @@ from %{PySideVersion}.QtWidgets import QApplication, QMainWindow
|
|||||||
@if '%{BaseCB}' === 'QDialog'
|
@if '%{BaseCB}' === 'QDialog'
|
||||||
from %{PySideVersion}.QtWidgets import QApplication, QDialog
|
from %{PySideVersion}.QtWidgets import QApplication, QDialog
|
||||||
@endif
|
@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}'
|
@if '%{BaseCB}'
|
||||||
class %{Class}(%{BaseCB}):
|
class %{Class}(%{BaseCB}):
|
||||||
@@ -23,19 +24,8 @@ class %{Class}:
|
|||||||
@endif
|
@endif
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.load_ui()
|
self.ui = Ui_%{Class}()
|
||||||
|
self.ui.setupUi(self)
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@@ -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
|
|
@@ -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) - Load the forms dynamically/at runtime",
|
"trDescription": "Creates a Qt for Python application that includes a Qt Designer-based widget (ui file) - Requires .ui to Python conversion",
|
||||||
"trDisplayName": "Window UI - Dynamic load",
|
"trDisplayName": "Window UI",
|
||||||
"trDisplayCategory": "Application (Qt for Python)",
|
"trDisplayCategory": "Application (Qt for Python)",
|
||||||
"icon": "../icons/icon.png",
|
"icon": "../icons/icon.png",
|
||||||
"iconKind": "Themed",
|
"iconKind": "Themed",
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"files": ["%{SrcFileName}", "form.ui"]
|
|
||||||
}
|
|
@@ -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'}"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
Reference in New Issue
Block a user