aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/PySide2
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2019-08-13 11:15:52 +0200
committerChristian Tismer <tismer@stackless.com>2019-08-21 03:30:23 +0200
commit01b43dc3d93e632c3c42fb8e1105f200b9cee2ae (patch)
treef4431f927b267835f940a761ee1bcfb76ac4a580 /sources/pyside2/PySide2
parent86f56c1ea0846540b082c67d0dc3e942fd311208 (diff)
Add QtCore.Slot.__signature__ and much more manually
The signature of QtCore.Slot and other classes could not automatically be generated because the function is not generated by cppgenerator.cpp . We add it manually in the C++ code into the generation process. The case of QtCore.Slot had diverse follow-up issues to be solved: - Classes which did not inherit from Shiboken were not generated. This is a long-standing omission and creates very many new simple types. - The arity of Slot has default arguments after the varargs parameter "*types". This needed an extended Python parser analysis that fixes the arguments given to the inspect module, accordingly. - The signature generation was completely new implemented and relies no longer on the restricted syntax of a Python (2) function but generates signatures directly as Parameter instances. Implemented classes with hand-made signatures: QtCore.ClassInfo QtCore.MetaFunction, QtCore.MetaSignal QtCore.Property QtCore.Signal QtCore.SignalInstance QtCore.Slot QtQml.ListProperty QtQml.VolatileBool As a side effect, many more subtypes were published. Enums are done, which concludes this work. Fixes: PYSIDE-945 Fixes: PYSIDE-1052 Change-Id: Ic09f02ece3a90325519e42e4e39719beb0c27ae9 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside2/PySide2')
-rw-r--r--sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp15
-rw-r--r--sources/pyside2/PySide2/support/generate_pyi.py13
2 files changed, 23 insertions, 5 deletions
diff --git a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp
index db297db7c..6427e5198 100644
--- a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp
+++ b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp
@@ -41,6 +41,7 @@
// shiboken
#include <shiboken.h>
+#include <signature.h>
// pyside
#include <pyside.h>
@@ -469,12 +470,22 @@ PyTypeObject *QtQml_VolatileBoolTypeF(void)
return type;
}
+static const char *PropertyList_SignatureStrings[] = {
+ "PySide2.QtQml.ListProperty(type:type,append:typing.Callable,"
+ "at:typing.Callable=None,clear:typing.Callable=None,count:typing.Callable=None)",
+ nullptr}; // Sentinel
+
+static const char *VolatileBool_SignatureStrings[] = {
+ "PySide2.QtQml.VolatileBool.get()->bool",
+ "PySide2.QtQml.VolatileBool.set(a:object)",
+ nullptr}; // Sentinel
+
void PySide::initQmlSupport(PyObject *module)
{
ElementFactory<PYSIDE_MAX_QML_TYPES - 1>::init();
// Export QmlListProperty type
- if (PyType_Ready(PropertyListTypeF()) < 0) {
+ if (SbkSpecial_Type_Ready(module, PropertyListTypeF(), PropertyList_SignatureStrings) < 0) {
PyErr_Print();
qWarning() << "Error initializing PropertyList type.";
return;
@@ -484,7 +495,7 @@ void PySide::initQmlSupport(PyObject *module)
PyModule_AddObject(module, PepType_GetNameStr(PropertyListTypeF()),
reinterpret_cast<PyObject *>(PropertyListTypeF()));
- if (PyType_Ready(QtQml_VolatileBoolTypeF()) < 0) {
+ if (SbkSpecial_Type_Ready(module, QtQml_VolatileBoolTypeF(), VolatileBool_SignatureStrings) < 0) {
PyErr_Print();
qWarning() << "Error initializing VolatileBool type.";
return;
diff --git a/sources/pyside2/PySide2/support/generate_pyi.py b/sources/pyside2/PySide2/support/generate_pyi.py
index c732227f4..8aa69c983 100644
--- a/sources/pyside2/PySide2/support/generate_pyi.py
+++ b/sources/pyside2/PySide2/support/generate_pyi.py
@@ -141,7 +141,7 @@ class Formatter(Writer):
self.outfile.seek(here)
self.outfile.truncate()
# Note: we cannot use class_str when we have no body.
- self.print("{spaces}class {class_name}: ...".format(**locals()))
+ self.print("{spaces}class {class_str}: ...".format(**locals()))
if "<" in class_name:
# This is happening in QtQuick for some reason:
## class QSharedPointer<QQuickItemGrabResult >:
@@ -168,6 +168,13 @@ class Formatter(Writer):
self.print('{spaces}@staticmethod'.format(**locals()))
self.print('{spaces}def {func_name}{signature}: ...'.format(**locals()))
+ @contextmanager
+ def enum(self, class_name, enum_name, value):
+ spaces = self.spaces
+ hexval = hex(value)
+ self.print("{spaces}{enum_name:20}: {class_name} = ... # {hexval}".format(**locals()))
+ yield
+
def get_license_text():
with io.open(sourcepath) as f:
@@ -247,10 +254,10 @@ def generate_all_pyi(outpath, options):
os.environ["PYTHONPATH"] = pypath
# now we can import
- global PySide2, inspect, HintingEnumerator
+ global PySide2, inspect, HintingEnumerator, EnumType
import PySide2
from PySide2.support.signature import inspect
- from PySide2.support.signature.lib.enum_sig import HintingEnumerator
+ from PySide2.support.signature.lib.enum_sig import HintingEnumerator, EnumType
# propagate USE_PEP563 to the mapping module.
# Perhaps this can be automated?