diff options
Diffstat (limited to 'sources/pyside2')
-rw-r--r-- | sources/pyside2/PySide2/QtCore/typesystem_core_common.xml | 1 | ||||
-rw-r--r-- | sources/pyside2/PySide2/QtQuick/typesystem_quick.xml | 2 | ||||
-rw-r--r-- | sources/pyside2/PySide2/glue/qtcore.cpp | 2 | ||||
-rw-r--r-- | sources/pyside2/doc/pyside-examples/examples.qdoc | 7 | ||||
-rw-r--r-- | sources/pyside2/doc/tutorials/basictutorial/uifiles.rst | 11 | ||||
-rw-r--r-- | sources/pyside2/libpyside/dynamicqmetaobject.cpp | 3 | ||||
-rw-r--r-- | sources/pyside2/libpyside/signalmanager.cpp | 12 | ||||
-rw-r--r-- | sources/pyside2/libpyside/signalmanager.h | 1 | ||||
-rw-r--r-- | sources/pyside2/tests/pysidetest/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sources/pyside2/tests/pysidetest/properties_test.py | 132 |
10 files changed, 164 insertions, 8 deletions
diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index f64a8fd73..b418d2689 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -2885,6 +2885,7 @@ <object-type name="Connection"> <include file-name="qobjectdefs.h" location="global"/> </object-type> + <modify-function signature="^invokeMethod\(" allow-thread="yes"/> </object-type> <value-type name="QMetaProperty" > <!-- This isn't part of Qt public API --> diff --git a/sources/pyside2/PySide2/QtQuick/typesystem_quick.xml b/sources/pyside2/PySide2/QtQuick/typesystem_quick.xml index 12c1ac33d..223eff773 100644 --- a/sources/pyside2/PySide2/QtQuick/typesystem_quick.xml +++ b/sources/pyside2/PySide2/QtQuick/typesystem_quick.xml @@ -64,7 +64,7 @@ <object-type name="QQuickImageResponse" since="5.6"/> <object-type name="QQuickTransform"/> - <object-type name="QQuickItem" delete-in-main-thread="true" no-override-caching="true"> + <object-type name="QQuickItem" delete-in-main-thread="true"> <value-type name="UpdatePaintNodeData"/> <enum-type name="Flag" flags="Flags"/> <enum-type name="ItemChange"/> diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index 60ddf675c..169b89cae 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -1685,7 +1685,7 @@ Py_UNICODE *unicode = PyUnicode_AS_UNICODE(%in); // cast as Py_UNICODE can be a different type %out = QString::fromUcs4((const uint *)unicode); # else -%out = QString::fromUtf16((const ushort *)unicode, PyUnicode_GET_SIZE(%in)); +%out = QString::fromUtf16((const ushort *)unicode, PepUnicode_GetLength(%in)); # endif #else wchar_t *temp = PyUnicode_AsWideCharString(%in, NULL); diff --git a/sources/pyside2/doc/pyside-examples/examples.qdoc b/sources/pyside2/doc/pyside-examples/examples.qdoc index d82b33cf7..748c4f8fd 100644 --- a/sources/pyside2/doc/pyside-examples/examples.qdoc +++ b/sources/pyside2/doc/pyside-examples/examples.qdoc @@ -28,5 +28,10 @@ /*! \group all-pyside-examples \title All Qt for Python Examples - \brief A list of all the examples that are available with the Qt for Python package. + \brief A varied selection of examples can be found in the 'examples' directory of the + pyside-setup repository. This can be accessed after installing + PySide2 via pip, checking the 'site-packages/PySide2/examples' directory. + + This page aims to document the most important use cases of the module + and it will be extended with each release. */ diff --git a/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst b/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst index a45bfc18c..2c0178e2e 100644 --- a/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst +++ b/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst @@ -163,12 +163,17 @@ The complete code of this example looks like this: if __name__ == "__main__": app = QApplication(sys.argv) - ui_file = QFile("mainwindow.ui") - ui_file.open(QFile.ReadOnly) - + ui_file_name = "mainwindow.ui" + ui_file = QFile(ui_file_name) + if not ui_file.open(QIODevice.ReadOnly): + print("Cannot open {}: {}".format(ui_file_name, ui_file.errorString())) + sys.exit(-1) loader = QUiLoader() window = loader.load(ui_file) ui_file.close() + if not window: + print(loader.errorString()) + sys.exit(-1) window.show() sys.exit(app.exec_()) diff --git a/sources/pyside2/libpyside/dynamicqmetaobject.cpp b/sources/pyside2/libpyside/dynamicqmetaobject.cpp index 51e6598b3..dae9e2059 100644 --- a/sources/pyside2/libpyside/dynamicqmetaobject.cpp +++ b/sources/pyside2/libpyside/dynamicqmetaobject.cpp @@ -140,7 +140,8 @@ MetaObjectBuilder::MetaObjectBuilder(PyTypeObject *type, const QMetaObject *meta MetaObjectBuilder::~MetaObjectBuilder() { - qDeleteAll(m_d->m_cachedMetaObjects); + for (auto *metaObject : m_d->m_cachedMetaObjects) + free(const_cast<QMetaObject*>(metaObject)); delete m_d->m_builder; delete m_d; } diff --git a/sources/pyside2/libpyside/signalmanager.cpp b/sources/pyside2/libpyside/signalmanager.cpp index 01b347a3d..8e8cc9f02 100644 --- a/sources/pyside2/libpyside/signalmanager.cpp +++ b/sources/pyside2/libpyside/signalmanager.cpp @@ -114,18 +114,24 @@ namespace PySide { PyObjectWrapper::PyObjectWrapper() :m_me(Py_None) { + // PYSIDE-813: When PYSIDE-164 was solved by adding some thread allowance, + // this code was no longer protected. It was hard to find this connection. + // See the website https://bugreports.qt.io/browse/PYSIDE-813 for details. + Shiboken::GilState gil; Py_XINCREF(m_me); } PyObjectWrapper::PyObjectWrapper(PyObject *me) : m_me(me) { + Shiboken::GilState gil; Py_XINCREF(m_me); } PyObjectWrapper::PyObjectWrapper(const PyObjectWrapper &other) : m_me(other.m_me) { + Shiboken::GilState gil; Py_XINCREF(m_me); } @@ -142,6 +148,7 @@ PyObjectWrapper::~PyObjectWrapper() void PyObjectWrapper::reset(PyObject *o) { + Shiboken::GilState gil; Py_XINCREF(o); Py_XDECREF(m_me); m_me = o; @@ -559,7 +566,10 @@ static MetaObjectBuilder *metaBuilderFromDict(PyObject *dict) if (!dict || !PyDict_Contains(dict, metaObjectAttr)) return nullptr; - PyObject *pyBuilder = PyDict_GetItem(dict, metaObjectAttr); + // PYSIDE-813: The above assumption is not true in debug mode: + // PyDict_GetItem would touch PyThreadState_GET and the global error state. + // PyDict_GetItemWithError instead can work without GIL. + PyObject *pyBuilder = PyDict_GetItemWithError(dict, metaObjectAttr); #ifdef IS_PY3K return reinterpret_cast<MetaObjectBuilder *>(PyCapsule_GetPointer(pyBuilder, nullptr)); #else diff --git a/sources/pyside2/libpyside/signalmanager.h b/sources/pyside2/libpyside/signalmanager.h index 229ddb91d..fe077bd1a 100644 --- a/sources/pyside2/libpyside/signalmanager.h +++ b/sources/pyside2/libpyside/signalmanager.h @@ -43,6 +43,7 @@ #include "pysidemacros.h" #include <sbkpython.h> +#include <shibokenmacros.h> #include <QtCore/QMetaMethod> diff --git a/sources/pyside2/tests/pysidetest/CMakeLists.txt b/sources/pyside2/tests/pysidetest/CMakeLists.txt index 3ba2ad29d..46a8023c3 100644 --- a/sources/pyside2/tests/pysidetest/CMakeLists.txt +++ b/sources/pyside2/tests/pysidetest/CMakeLists.txt @@ -143,6 +143,7 @@ PYSIDE_TEST(mixin_signal_slots_test.py) PYSIDE_TEST(modelview_test.py) PYSIDE_TEST(new_inherited_functions_test.py) PYSIDE_TEST(notify_id.py) +PYSIDE_TEST(properties_test.py) PYSIDE_TEST(qapp_like_a_macro_test.py) PYSIDE_TEST(qvariant_test.py) PYSIDE_TEST(repr_test.py) diff --git a/sources/pyside2/tests/pysidetest/properties_test.py b/sources/pyside2/tests/pysidetest/properties_test.py new file mode 100644 index 000000000..cedfac8d1 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/properties_test.py @@ -0,0 +1,132 @@ +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import os +import sys +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide2.QtCore import QObject, QStringListModel, Signal, Property, Slot + +"""Tests PySide2.QtCore.Property()""" + + +class TestObject(QObject): + + valueChanged = Signal() + + def __init__(self, parent=None): + super(TestObject, self).__init__(parent) + self._value = -1 + self.valueChanged.connect(self._changed) + self.getter_called = 0 + self.setter_called = 0 + self.changed_emitted = 0 + + @Slot(int) + def _changed(self): + self.changed_emitted += 1 + + def getValue(self): + self.getter_called += 1 + return self._value + + def setValue(self, value): + self.setter_called += 1 + if (self._value != value): + self._value = value + self.valueChanged.emit() + + value = Property(int, fget=getValue, fset=setValue, + notify=valueChanged) + + +class TestDerivedObject(QStringListModel): + + valueChanged = Signal() + + def __init__(self, parent=None): + super(TestDerivedObject, self).__init__(parent) + self._value = -1 + self.valueChanged.connect(self._changed) + self.getter_called = 0 + self.setter_called = 0 + self.changed_emitted = 0 + + @Slot(int) + def _changed(self): + self.changed_emitted += 1 + + def getValue(self): + self.getter_called += 1 + return self._value + + def setValue(self, value): + self.setter_called += 1 + if (self._value != value): + self._value = value + self.valueChanged.emit() + + value = Property(int, fget=getValue, fset=setValue, + notify=valueChanged) + + +class PropertyTest(unittest.TestCase): + + def test1Object(self): + """Basic property test.""" + testObject = TestObject() + v = testObject.value + self.assertEqual(v, -1) + self.assertEqual(testObject.getter_called, 1) + testObject.value = 42 + v = testObject.value + self.assertEqual(v, 42) + self.assertEqual(testObject.changed_emitted, 1) + self.assertEqual(testObject.setter_called, 1) + self.assertEqual(testObject.getter_called, 2) + + def test2DerivedObject(self): + """PYSIDE-1255: Run the same test for a class inheriting QObject.""" + testObject = TestDerivedObject() + v = testObject.value + self.assertEqual(v, -1) + self.assertEqual(testObject.getter_called, 1) + testObject.value = 42 + v = testObject.value + self.assertEqual(v, 42) + self.assertEqual(testObject.changed_emitted, 1) + self.assertEqual(testObject.setter_called, 1) + self.assertEqual(testObject.getter_called, 2) + + +if __name__ == '__main__': + unittest.main() |