forked from qt-creator/qt-creator
python: add wizard project based on uic
This includes a new template that allow users to create a UI based project, but without a dynamic loading. To get the initial empty window, the user needs to use a 'uic' tool to generate Python code from a UI file first. This tool is different for PySide2, PySide6, PyQt5 and PySide6. Change-Id: Ic12fe23696bf3b18eaf240ffac03e9bd92a5455b Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
committed by
Cristian Maureira-Fredes
parent
958531adbf
commit
ba22a5bdf9
@@ -130,6 +130,12 @@
|
||||
\li Empty Window
|
||||
\li Creates a Qt for Python application that contains an empty
|
||||
window.
|
||||
\row
|
||||
\li Window UI
|
||||
\li Creates a Qt for Python application that contains an empty
|
||||
window with a widget-based UI. Preferred approach that requires
|
||||
you to generate a Python file from the .ui file, to import
|
||||
it directly into your application.
|
||||
\row
|
||||
\li Window UI - Dynamic load
|
||||
\li Creates a Qt for Python application that contains an empty
|
||||
|
@@ -0,0 +1,39 @@
|
||||
# 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
|
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"files": ["%{SrcFileName}", "form.ui"]
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
{
|
||||
"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}",
|
||||
|
||||
"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": { "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