aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/PySide2/glue/qtgui.cpp
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2019-08-10 18:09:17 +0200
committerChristian Tismer <tismer@stackless.com>2019-10-30 16:34:41 +0100
commit46d44749d01b7bd195e8838e681b227aef4b5f06 (patch)
treef7735a3548770ba1c93e0f4ed8dcdea6383da6d6 /sources/pyside2/PySide2/glue/qtgui.cpp
parentd04df47c5aafe519123b311ce3705b6eae511dc4 (diff)
Improve the NumPy Support by iterables
Working example, by overriding cppgenerator: >>> from PySide2 import * >>> QtCore.QUrl.fromStringList(("asd", "def")) [PySide2.QtCore.QUrl('asd'), PySide2.QtCore.QUrl('def')] >>> def func(lis): ... for thing in lis: ... yield thing ... >>> QtCore.QUrl.fromStringList(func(["asd", "def"])) [PySide2.QtCore.QUrl('asd'), PySide2.QtCore.QUrl('def')] Also working, by overriding shibokengenerator >>> QtGui.QMatrix4x4(func(range(16))) And all other QMatrix sizes as well: >>> QtGui.QMatrix2x2(func(range(4))) >>> QtGui.QMatrix2x3(func(range(6))) The PySequence cases seem to be quite completely covered. Supporting lists and QVector is not yet clear and needs more research. Note.. QtOpenGLFunctions is not tested at all and nothing works on macOS, segfault. Ignored for now! A simple numpy test shows how versatile this solution is. We now need to improve signatures and error messages to optimize the experience. Task-number: PYSIDE-795 Change-Id: I195cd46cf47c2eb83276fe48fce8e6070cf30fda Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2/PySide2/glue/qtgui.cpp')
-rw-r--r--sources/pyside2/PySide2/glue/qtgui.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/sources/pyside2/PySide2/glue/qtgui.cpp b/sources/pyside2/PySide2/glue/qtgui.cpp
index 5be8cc287..d2480e99e 100644
--- a/sources/pyside2/PySide2/glue/qtgui.cpp
+++ b/sources/pyside2/PySide2/glue/qtgui.cpp
@@ -455,10 +455,12 @@ QPoint p(%CPPSELF.%FUNCTION_NAME(%1));
// @snippet qmatrix-map-point
// @snippet qmatrix4x4
-if (PySequence_Size(%PYARG_1) == 16) {
+// PYSIDE-795: All PySequences can be made iterable with PySequence_Fast.
+Shiboken::AutoDecRef seq(PySequence_Fast(%PYARG_1, "Can't turn into sequence"));
+if (PySequence_Size(seq) == 16) {
float values[16];
for (int i=0; i < 16; ++i) {
- PyObject *pv = PySequence_Fast_GET_ITEM(%PYARG_1, i);
+ PyObject *pv = PySequence_Fast_GET_ITEM(seq.object(), i);
values[i] = PyFloat_AsDouble(pv);
}