Add Qt for Python templates

Qt for Python
* Add files with basic statements to execute a QApplication using ".ui" files
* Add files with basic statements to execute a QtQuick application

Task-number: QTCREATORBUG-21824
Change-Id: I6e69d82f2a6ba9c67ede96b36ecf4421f30f169f
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Mariana Meireles
2019-09-26 08:58:26 +02:00
parent 732b0660bf
commit 5767a097e7
12 changed files with 306 additions and 7 deletions

View File

@@ -1,14 +1,13 @@
{ {
"version": 1, "version": 1,
"supportedProjectTypes": [ "PythonProject" ], "supportedProjectTypes": [ "PythonProject" ],
"id": "U.QtForPythonApplicationEmpty", "id": "F.QtForPythonApplicationEmpty",
"category": "F.Application", "category": "F.Application",
"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": "Qt for Python - Empty",
"trDisplayCategory": "Application", "trDisplayCategory": "Application",
"icon": "icon.png", "icon": "icon.png",
"enabled": "%{JS: value('Plugins').indexOf('Python') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('Python') >= 0}",
"featuresRequired": [ "QtSupport.Wizards.FeatureQt.5.6" ],
"options": "options":
[ [
@@ -44,6 +43,11 @@
"source": "../main_empty.py", "source": "../main_empty.py",
"target": "%{SrcFileName}", "target": "%{SrcFileName}",
"openInEditor": true "openInEditor": true
},
{
"source": "../../git.ignore",
"target": ".gitignore",
"condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}"
} }
] ]
} }

View File

@@ -0,0 +1,16 @@
# This Python file uses the following encoding: utf-8
import sys
import os
from PySide2.QtGui import QGuiApplication
from PySide2.QtQml import QQmlApplicationEngine
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())

View File

@@ -0,0 +1,40 @@
# This Python file uses the following encoding: utf-8
import sys
import os
@if '%{BaseCB}' === 'QWidget'
from PySide2.QtWidgets import QApplication, QWidget
@endif
@if '%{BaseCB}' === 'QMainWindow'
from PySide2.QtWidgets import QApplication, QMainWindow
@endif
@if '%{BaseCB}' === 'QDialog'
from PySide2.QtWidgets import QApplication, QDialog
@endif
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader
@if '%{BaseCB}'
class %{Class}(%{BaseCB}):
@else
class %{Class}:
@endif
def __init__(self):
super(%{Class}, self).__init__()
self.load_ui()
def load_ui(self):
loader = QUiLoader()
path = os.path.join(os.path.dirname(__file__), "form.ui")
ui_file = QFile(path)
ui_file.open(QFile.ReadOnly)
loader.load(ui_file, self)
ui_file.close()
if __name__ == "__main__":
app = QApplication([])
widget = %{Class}()
widget.show()
sys.exit(app.exec_())

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>%{Class}</class>
<widget class="%{BaseCB}" name="%{Class}">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>%{Class}</string>
</property>
@if '%{BaseCB}' === 'QMainWindow'
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar"/>
<widget class="QStatusBar" name="statusbar"/>
@endif
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -1,14 +1,13 @@
{ {
"version": 1, "version": 1,
"supportedProjectTypes": [ "PythonProject" ], "supportedProjectTypes": [ "PythonProject" ],
"id": "U.QtForPythonApplicationWindow", "id": "F.QtForPythonApplicationWindow",
"category": "F.Application", "category": "F.Application",
"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": "Qt for Python - Window",
"trDisplayCategory": "Application", "trDisplayCategory": "Application",
"icon": "icon.png", "icon": "../icons/icon.png",
"enabled": "%{JS: value('Plugins').indexOf('Python') >= 0}", "enabled": "%{JS: value('Plugins').indexOf('Python') >= 0}",
"featuresRequired": [ "QtSupport.Wizards.FeatureQt.5.6" ],
"options": "options":
[ [
@@ -43,8 +42,8 @@
"type": "ComboBox", "type": "ComboBox",
"data": "data":
{ {
"items": [ { "trKey": "<Custom>", "value": "" }, "items": [ "QWidget", "QMainWindow",
"QWidget", "QMainWindow"] { "trKey": "<Custom>", "value": "" } ]
} }
}, },
{ {
@@ -84,6 +83,11 @@
"source": "../main_mainwindow.py", "source": "../main_mainwindow.py",
"target": "%{MainPyFileName}", "target": "%{MainPyFileName}",
"openInEditor": true "openInEditor": true
},
{
"source": "../../git.ignore",
"target": ".gitignore",
"condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}"
} }
] ]
} }

View File

@@ -0,0 +1,3 @@
{
"files": ["%{SrcFileName}", "%{QmlFileName}"]
}

View File

@@ -0,0 +1,9 @@
import QtQuick %{QtQuickVersion}
import QtQuick.Window %{QtQuickWindowVersion}
Window {
title: qsTr("Hello World")
width: 640
height: 480
visible: true
}

View File

@@ -0,0 +1,98 @@
{
"version": 1,
"supportedProjectTypes": [ "PythonProject" ],
"id": "F.QtQuickQtForPythonApplicationEmpty",
"category": "F.Application",
"trDescription": "Creates a Qt Quick application that contains an empty window.",
"trDisplayName": "Qt for Python - Qt Quick Application - Empty",
"trDisplayCategory": "Application",
"icon": "../icons/icon.png",
"enabled": "%{JS: value('Plugins').indexOf('Python') >= 0}",
"options":
[
{ "key": "SrcFileName", "value": "main.py" },
{ "key": "QmlFileName", "value": "main.qml" },
{ "key": "PyProjectFile", "value": "main.pyproject" },
{ "key": "QtQuickVersion", "value": "%{JS: value('QtVersion').QtQuickVersion}" },
{ "key": "QtQuickWindowVersion", "value": "%{JS: value('QtVersion').QtQuickWindowVersion}" }
],
"pages":
[
{
"trDisplayName": "Project Location",
"trShortTitle": "Location",
"typeId": "Project"
},
{
"trDisplayName": "Define Project Details",
"trShortTitle": "Details",
"typeId": "Fields",
"data":
[
{
"name": "QtVersion",
"trDisplayName": "PySide version:",
"type": "ComboBox",
"data":
{
"index": 1,
"items":
[
{
"trKey": "PySide 5.13",
"value":
{
"QtQuickVersion": "2.13",
"QtQuickWindowVersion": "2.13"
}
},
{
"trKey": "PySide 5.12",
"value":
{
"QtQuickVersion": "2.12",
"QtQuickWindowVersion": "2.12"
}
}
]
}
}
]
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators":
[
{
"typeId": "File",
"data":
[
{
"source": "../main_qtquick.py",
"target": "main.py"
},
{
"source": "main.pyproject",
"target": "main.pyproject",
"openAsProject": true
},
{
"source": "main.qml.tpl",
"target": "main.qml",
"openInEditor": true
},
{
"source": "../../git.ignore",
"target": ".gitignore",
"condition": "%{JS: !value('IsSubproject') && value('VersionControl') === 'G.Git'}"
}
]
}
]
}

View File

@@ -0,0 +1,3 @@
{
"files": ["%{SrcFileName}", "form.ui"]
}

View File

@@ -0,0 +1,98 @@
{
"version": 1,
"supportedProjectTypes": [ "PythonProject" ],
"id": "F.QtForPythonApplicationWindowWidget",
"category": "F.Application",
"trDescription": "Creates a Qt for Python application that includes a Qt Designer-based widget (ui file)",
"trDisplayName": "Qt for Python - Window (UI file)",
"trDisplayCategory": "Application",
"icon": "../icons/icon.png",
"enabled": "%{JS: value('Plugins').indexOf('Python') >= 0}",
"options":
[
{ "key": "SrcFileName", "value": "main.py" },
{ "key": "PyProjectFile", "value": "main.pyproject" }
],
"pages":
[
{
"trDisplayName": "Project Location",
"trShortTitle": "Location",
"typeId": "Project",
"name": "ProjectPath"
},
{
"trDisplayName": "Define Class",
"trShortTitle": "Details",
"typeId": "Fields",
"data" :
[
{
"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]*|)" }
},
{
"name": "BaseCB",
"trDisplayName": "Base class:",
"type": "ComboBox",
"data":
{
"items": [ "QWidget", "QDialog", "QMainWindow" ]
}
},
{
"name": "SrcFileName",
"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: Cpp.classToFileName(value('Class'), 'pyproject')}" }
}
]
},
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
],
"generators":
[
{
"typeId": "File",
"data":
[
{
"source": "main.pyproject",
"target": "%{PyProjectFile}",
"openAsProject": true
},
{
"source": "../main_widget.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'}"
}
]
}
]
}