forked from qt-creator/qt-creator
Wizards: Improve python class wizard
Some minor fixes, simplifications and improvements. In detail: * create valid Python code * allow creating a Python class also without a Qt package * hint about the need for a Qt package depending on the base class * remove QDeclarativeItem as base class as this is not present in recent Qt packages Change-Id: I7198f315b3a9eec9a04f52d7438d05ccce40c3f7 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -1,38 +1,24 @@
|
|||||||
# This Python file uses the following encoding: utf-8
|
# This Python file uses the following encoding: utf-8
|
||||||
@if '%{Module}' === 'PySide2'
|
@if '%{Module}' !== '<None>'
|
||||||
@if '%{ImportQtCore}'
|
@if '%{ImportQtCore}' !== ''
|
||||||
from PySide2 import QtCore
|
from %{Module} import QtCore
|
||||||
@endif
|
@endif
|
||||||
@if '%{ImportQtWidgets}'
|
@if '%{ImportQtWidgets}' !== ''
|
||||||
from PySide2 import QtWidgets
|
from %{Module} import QtWidgets
|
||||||
@endif
|
@endif
|
||||||
@if '%{ImportQtQuick}'
|
@if '%{ImportQtQuick}' !== ''
|
||||||
from PySide2 import QtQuick
|
from %{Module} import QtQuick
|
||||||
@endif
|
|
||||||
@else
|
|
||||||
@if '%{ImportQtCore}'
|
|
||||||
from PyQt5 import QtCore
|
|
||||||
@endif
|
|
||||||
@if '%{ImportQtWidgets}'
|
|
||||||
from PyQt5 import QtWidgets
|
|
||||||
@endif
|
|
||||||
@if '%{ImportQtQuick}'
|
|
||||||
from PyQt5 import QtQuick
|
|
||||||
@endif
|
@endif
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|
||||||
@if '%{Base}'
|
@if '%{Base}'
|
||||||
class %{Class}(%{Base}):
|
class %{Class}(%{FullBase}):
|
||||||
@else
|
@else
|
||||||
class %{Class}:
|
class %{Class}:
|
||||||
@endif
|
@endif
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@if '%{Base}' === 'QWidget'
|
@if %{JS: [ "QObject", "QWidget", "QMainWindow", "QQuickItem" ].indexOf("%Base")} >= 0
|
||||||
QtWidgets.QWidget.__init__(self)
|
%{FullBase}.__init__(self)
|
||||||
@elif '%{Base}' === 'QMainWindow'
|
|
||||||
QtWidgets.QMainWindow.__init__(self)
|
|
||||||
@elif '%{Base}' === 'QQuickItem'
|
|
||||||
QtQuick.QQuickItem.__init__(self)
|
|
||||||
@endif
|
@endif
|
||||||
pass
|
pass
|
||||||
|
@@ -12,7 +12,8 @@
|
|||||||
"options":
|
"options":
|
||||||
[
|
[
|
||||||
{ "key": "Base", "value":"%{JS: value('BaseCB') === '' ? value('BaseEdit') : value('BaseCB')}" },
|
{ "key": "Base", "value":"%{JS: value('BaseCB') === '' ? value('BaseEdit') : value('BaseCB')}" },
|
||||||
{ "key": "Imports", "value": "%{ImportQtCore}%{ImportQtWidgets}%{ImportQtDeclarative}"}
|
{ "key": "Package", "value": "%{JS: [ 'QWidget', 'QMainWindow' ].indexOf(value('Base')) >= 0 ? 'QtWidgets' : (value('Base') === 'QQuickItem' ? 'QtQuick' : (value('Base') === 'QObject' ? 'QtCore' : ''))}" },
|
||||||
|
{ "key": "FullBase", "value": "%{JS: value('Package') === '' ? value('Base') : value('Package') + '.' + value('Base')}" }
|
||||||
],
|
],
|
||||||
|
|
||||||
"pages":
|
"pages":
|
||||||
@@ -32,11 +33,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Module",
|
"name": "Module",
|
||||||
"trDisplayName": "Python module:",
|
"trDisplayName": "Qt for Python module:",
|
||||||
"type": "ComboBox",
|
"type": "ComboBox",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"items": ["PySide2", "PyQt5"]
|
"items": ["<None>", "PySide2", "PyQt5"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -46,8 +47,10 @@
|
|||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"items": [ { "trKey": "<Custom>", "value": "" },
|
"items": [ { "trKey": "<Custom>", "value": "" },
|
||||||
"QObject", "QWidget", "QMainWindow", "QDeclarativeItem", "QQuickItem" ]
|
"QObject", "QWidget", "QMainWindow", "QQuickItem" ]
|
||||||
}
|
},
|
||||||
|
"isComplete": "%{JS: (value('Module') === '<None>' && value('BaseCB') === '') || value('Module') !== '<None>'}",
|
||||||
|
"trIncompleteMessage": "You can choose Qt classes only if you select a Qt for Python module."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "BaseEdit",
|
"name": "BaseEdit",
|
||||||
@@ -67,33 +70,36 @@
|
|||||||
"name": "ImportQtCore",
|
"name": "ImportQtCore",
|
||||||
"trDisplayName": "Import QtCore",
|
"trDisplayName": "Import QtCore",
|
||||||
"type": "CheckBox",
|
"type": "CheckBox",
|
||||||
|
"enabled": "%{JS: value('Module') !== '<None>'}",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"checkedValue": "QtCore",
|
"checkedValue": "QtCore",
|
||||||
"uncheckedValue": "",
|
"uncheckedValue": "",
|
||||||
"checked": "%{JS: value('Base') !== ''}"
|
"checked": "%{JS: value('BaseCB') !== ''}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ImportQWidget",
|
"name": "ImportQtWidgets",
|
||||||
"trDisplayName": "Import QtWidgets",
|
"trDisplayName": "Import QtWidgets",
|
||||||
"type": "CheckBox",
|
"type": "CheckBox",
|
||||||
|
"enabled": "%{JS: value('Module') !== '<None>'}",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"checkedValue": "QtWidgets",
|
"checkedValue": "QtWidgets",
|
||||||
"uncheckedValue": "",
|
"uncheckedValue": "",
|
||||||
"checked": "%{JS: value('Base') === 'QWidget'}"
|
"checked": "%{JS: [ 'QWidget', 'QMainWindow' ].indexOf(value('BaseCB')) >= 0}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ImportQtQuick",
|
"name": "ImportQtQuick",
|
||||||
"trDisplayName": "Import QtQuick",
|
"trDisplayName": "Import QtQuick",
|
||||||
"type": "CheckBox",
|
"type": "CheckBox",
|
||||||
|
"enabled": "%{JS: value('Module') !== '<None>'}",
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"checkedValue": "QtQuick",
|
"checkedValue": "QtQuick",
|
||||||
"uncheckedValue": "",
|
"uncheckedValue": "",
|
||||||
"checked": "%{JS: value('Base') === 'QQuickItem'}"
|
"checked": "%{JS: value('BaseCB') === 'QQuickItem'}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user