diff options
75 files changed, 2019 insertions, 874 deletions
diff --git a/build_scripts/main.py b/build_scripts/main.py index cf56850df..55cc6a882 100644 --- a/build_scripts/main.py +++ b/build_scripts/main.py @@ -74,10 +74,12 @@ def get_package_version(): final_version = "{}.{}.{}".format( d['major_version'], d['minor_version'], d['patch_version']) - pre_release_version_type = d['pre_release_version_type'] + release_version_type = d['release_version_type'] pre_release_version = d['pre_release_version'] - if pre_release_version and pre_release_version_type: - final_version += pre_release_version_type + pre_release_version + if pre_release_version and release_version_type: + final_version += release_version_type + pre_release_version + if release_version_type.startswith("comm"): + final_version += "." + release_version_type # Add the current timestamp to the version number, to suggest it # is a development snapshot build. diff --git a/coin_build_instructions.py b/coin_build_instructions.py index 5c3033b04..bfb10410c 100644 --- a/coin_build_instructions.py +++ b/coin_build_instructions.py @@ -95,9 +95,9 @@ def is_snapshot_build(): setup_script_dir, "sources", "pyside2", "pyside_version.py") d = get_python_dict(pyside_version_py) - pre_release_version_type = d['pre_release_version_type'] + release_version_type = d['release_version_type'] pre_release_version = d['pre_release_version'] - if pre_release_version or pre_release_version_type: + if pre_release_version and release_version_type: return True return False diff --git a/dist/changes-5.14.2.2 b/dist/changes-5.14.2.2 index 3f9506dde..63a7a9120 100644 --- a/dist/changes-5.14.2.2 +++ b/dist/changes-5.14.2.2 @@ -24,7 +24,15 @@ information about a particular change. - [PYSIDE-1272] signature: Add comparison for existing_doc type - [PYSIDE-1285] qareaseries: keep references of lower/upper series - [PYSIDE-1293] Windows: Fix encoding in custom message handler + - [PYSIDE-15] Support pickling of Qt Enum objects + - [PYSIDE-1223] Add QtUiTools.loadUiType + - [PYSIDE-1286] Implement __qualname__ and correct __module__ for classes + - [PYSIDE-1303] PySide2: Fix conversion of quintptr **************************************************************************** * Shiboken2 * **************************************************************************** + + - [PYSIDE-1286] shiboken: Prepare for introduction of __qualname__ + - [PYSIDE-1298] libshiboken: Support musl libc + - [PYSIDE-1299] shiboken: Fix cross builds diff --git a/dist/changes-5.15.0 b/dist/changes-5.15.0 new file mode 100644 index 000000000..77c8e7d27 --- /dev/null +++ b/dist/changes-5.15.0 @@ -0,0 +1,49 @@ +Qt for Python 5.15.0 is a minor release. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + +https://doc.qt.io/qtforpython/ + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + +https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + +**************************************************************************** +* PySide2 * +**************************************************************************** + + + - [PYSIDE-487] Add API of Qt 5.15 + - [PYSIDE-487] Add support for QSerialPort + - [PYSIDE-487] Add QtQuickControls2 + - [PYSIDE-841] example: add systray example + - [PYSIDE-841] doc: add more videos from Qt events + - [PYSIDE-841] doc: add tutorial for using qrc files + - [PYSIDE-904] libpyside: Remove deprecated API + - [PYSIDE-904] Add support for template type aliases + - [PYSIDE-957] Add a tool to dump meta objects of QObject-derived classes + - [PYSIDE-1280] Enable injecting raw code for setattro/getattro + - [PYSIDE-1309] Rename and update some snippets + +**************************************************************************** +* Shiboken2 * +**************************************************************************** + + - [PYSIDE-454] shiboken: Add a way of specifying system includes to be parsed + - [PYSIDE-454] shiboken: Handle smart pointers with const pointees + - [PYSIDE-904] libshiboken: Remove deprecated API + - [PYSIDE-957] shiboken: Fix refcounts of sbkenum + - [PYSIDE-990] shiboken: Handle inline namespaces + - [PYSIDE-1024] shiboken: Make it possible to specify smartpointer instantiations + - [PYSIDE-1074] shiboken: Fix classes in hidden namespaces + - [PYSIDE-1188] shiboken: Fix shared pointer return value in virtual function + - [PYSIDE-1265] shiboken: Introduce a separate logging category for documentation generation + - [PYSIDE-1265] shiboken: Change debug messages to use qCInfo and remove some messages + - [PYSIDE-1267] shiboken: Allow for parsing headers under system include paths + - [PYSIDE-1296] shiboken: Support non-type template parameters in functions + diff --git a/examples/declarative/textproperties/main.py b/examples/declarative/textproperties/main.py index 8da443edc..2f9b987d0 100644 --- a/examples/declarative/textproperties/main.py +++ b/examples/declarative/textproperties/main.py @@ -44,6 +44,7 @@ from os.path import abspath, dirname, join from PySide2.QtCore import QObject, Slot from PySide2.QtGui import QGuiApplication from PySide2.QtQml import QQmlApplicationEngine +from PySide2.QtQuickControls2 import QQuickStyle class Bridge(QObject): @@ -90,8 +91,8 @@ class Bridge(QObject): if __name__ == '__main__': - sys.argv += ['--style', 'material'] app = QGuiApplication(sys.argv) + QQuickStyle.setStyle("Material") engine = QQmlApplicationEngine() # Instance of the Python object diff --git a/sources/cmake_helpers/helpers.cmake b/sources/cmake_helpers/helpers.cmake index 75dcd9032..fed96b5cd 100644 --- a/sources/cmake_helpers/helpers.cmake +++ b/sources/cmake_helpers/helpers.cmake @@ -35,6 +35,7 @@ set(ALL_OPTIONAL_MODULES Location Qml Quick + QuickControls2 QuickWidgets RemoteObjects Scxml diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index 272f9a766..c27029f03 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -223,9 +223,9 @@ </primitive-type> <primitive-type name="quintptr" target-lang-api-name="PyLong"> <conversion-rule> - <native-to-target file="../glue/qtcore.cpp" snippet="return-pylong-unsigned"/> + <native-to-target file="../glue/qtcore.cpp" snippet="return-pylong-quintptr"/> <target-to-native> - <add-conversion type="PyLong" file="../glue/qtcore.cpp" snippet="conversion-pylong-unsigned"/> + <add-conversion type="PyLong" file="../glue/qtcore.cpp" snippet="conversion-pylong-quintptr"/> </target-to-native> </conversion-rule> </primitive-type> diff --git a/sources/pyside2/PySide2/QtQuickControls2/CMakeLists.txt b/sources/pyside2/PySide2/QtQuickControls2/CMakeLists.txt new file mode 100644 index 000000000..8321d8a3e --- /dev/null +++ b/sources/pyside2/PySide2/QtQuickControls2/CMakeLists.txt @@ -0,0 +1,41 @@ +project(QtQuickControls2) + +set(QtQuickControls2_SRC +${QtQuickControls2_GEN_DIR}/qquickstyle_wrapper.cpp +# module is always needed +${QtQuickControls2_GEN_DIR}/qtquickcontrols2_module_wrapper.cpp +) + + +set(QtQuickControls2_include_dirs ${QtQuickControls2_SOURCE_DIR} + ${QtQml_SOURCE_DIR} + ${Qt${QT_MAJOR_VERSION}Core_INCLUDE_DIRS} + ${Qt${QT_MAJOR_VERSION}Gui_INCLUDE_DIRS} + ${Qt${QT_MAJOR_VERSION}Network_INCLUDE_DIRS} + ${Qt${QT_MAJOR_VERSION}Qml_INCLUDE_DIRS} + ${Qt${QT_MAJOR_VERSION}Quick_INCLUDE_DIRS} + ${Qt${QT_MAJOR_VERSION}QuickControls2_INCLUDE_DIRS} + ${libpyside_SOURCE_DIR} + ${QtGui_GEN_DIR} + ${QtCore_GEN_DIR} + ${QtNetwork_GEN_DIR} + ${QtQml_GEN_DIR} + ${QtQuick_GEN_DIR} + ${QtQuickControls2_GEN_DIR}) + +set(QtQuickControls2_libraries pyside2 + ${Qt${QT_MAJOR_VERSION}Core_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}Gui_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}Network_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}Qml_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}Quick_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}QuickControls2_LIBRARIES}) + +set(QtQuickControls2_deps QtGui QtNetwork QtQml QtQuick) + +create_pyside_module(NAME QtQuickControls2 + INCLUDE_DIRS QtQuickControls2_include_dirs + LIBRARIES QtQuickControls2_libraries + DEPS QtQuickControls2_deps + TYPESYSTEM_PATH QtQuickControls2_SOURCE_DIR + SOURCES QtQuickControls2_SRC) diff --git a/sources/pyside2/PySide2/QtQuickControls2/typesystem_quickcontrols2.xml b/sources/pyside2/PySide2/QtQuickControls2/typesystem_quickcontrols2.xml new file mode 100644 index 000000000..51d42b46b --- /dev/null +++ b/sources/pyside2/PySide2/QtQuickControls2/typesystem_quickcontrols2.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +--> +<typesystem package="PySide2.QtQuickControls2"> + <load-typesystem name="QtQuick/typesystem_quick.xml" generate="no"/> + + <object-type name="QQuickStyle" since="5.7"/> + +</typesystem> diff --git a/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml b/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml index 7b27e8783..2ca12e788 100644 --- a/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml +++ b/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml @@ -139,4 +139,40 @@ </add-function> </object-type> + <!-- + After the removal of the 'pysideuic' Python module, many users were unable to generate and + load UI classes dynamically. + This function was created to provide an equivalent solution to the 'loadUiType' function from + Riverbank's PyQt. + --> + <add-function signature="loadUiType(const QString& @uifile@)" return-type="PyObject*"> + <inject-documentation format="target" mode="append"> + This function will allow users to generate and load a `.ui` file at runtime, and it returns + a `tuple` containing the reference to the Python class, and the base class. + + We don't recommend this approach since the workflow should be to generate a Python file + from the `.ui` file, and then import and load it to use it, but we do understand that + there are some corner cases when such functionality is required. + + The internal process relies on `uic` being in the PATH, which is the same requirement for + the new `pyside2-uic` to work (which is just a wrapper around `uic -g python`) + + A Simple use can be: + + .. code-block:: python + + from PySide2.QtUiTools import loadUiType + + generated_class, base_class = loadUiType("themewidget.ui") + # the values will be: + # (<class '__main__.Ui_ThemeWidgetForm'>, <class 'PySide2.QtWidgets.QWidget'>) + + + In that case, `generated_class` will be a reference to the Python class, + and `base_class` will be a reference to the base class. + </inject-documentation> + <inject-code file="../glue/qtuitools.cpp" snippet="loaduitype"/> + </add-function> + + </typesystem> diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index 83c8f8656..9b927cce4 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -1678,6 +1678,14 @@ Py_END_ALLOW_THREADS %out = %OUTTYPE(PyLong_AsUnsignedLong(%in)); // @snippet conversion-pylong-unsigned +// @snippet conversion-pylong-quintptr +#if defined(IS_PY3K) && QT_POINTER_SIZE == 8 +%out = %OUTTYPE(PyLong_AsUnsignedLongLong(%in)); +#else +%out = %OUTTYPE(PyLong_AsUnsignedLong(%in)); +#endif +// @snippet conversion-pylong-quintptr + // @snippet conversion-pyunicode #ifndef Py_LIMITED_API Py_UNICODE *unicode = PyUnicode_AS_UNICODE(%in); @@ -1878,6 +1886,14 @@ return PyLong_FromLong(%in); return PyLong_FromUnsignedLong(%in); // @snippet return-pylong-unsigned +// @snippet return-pylong-quintptr +#if defined(IS_PY3K) && QT_POINTER_SIZE == 8 +return PyLong_FromUnsignedLongLong(%in); +#else +return PyLong_FromUnsignedLong(%in); +#endif +// @snippet return-pylong-quintptr + // @snippet return-pyunicode QByteArray ba = %in.toUtf8(); return PyUnicode_FromStringAndSize(ba.constData(), ba.size()); diff --git a/sources/pyside2/PySide2/glue/qtuitools.cpp b/sources/pyside2/PySide2/glue/qtuitools.cpp index 00fc8e44a..668b512e4 100644 --- a/sources/pyside2/PySide2/glue/qtuitools.cpp +++ b/sources/pyside2/PySide2/glue/qtuitools.cpp @@ -109,3 +109,141 @@ registerCustomWidget(%PYARG_1); // Avoid calling the original function: %CPPSELF.%FUNCTION_NAME() %PYARG_0 = QUiLoaderLoadUiFromFileName(%CPPSELF, %1, %2); // @snippet quiloader-load-2 + +// @snippet loaduitype +/* +Arguments: + %PYARG_1 (uifile) +*/ +// 1. Generate the Python code from the UI file +#ifdef IS_PY3K +PyObject *strObj = PyUnicode_AsUTF8String(%PYARG_1); +char *arg1 = PyBytes_AsString(strObj); +QByteArray uiFileName(arg1); +Py_DECREF(strObj); +#else +QByteArray uiFileName(PyBytes_AsString(%PYARG_1)); +#endif + +QFile uiFile(uiFileName); + +if (!uiFile.exists()) { + qCritical().noquote() << "File" << uiFileName << "does not exists"; + Py_RETURN_NONE; +} + +if (uiFileName.isEmpty()) { + qCritical() << "Error converting the UI filename to QByteArray"; + Py_RETURN_NONE; +} + +QString uicBin("uic"); +QStringList uicArgs = {"-g", "python", QString::fromUtf8(uiFileName)}; + +QProcess uicProcess; +uicProcess.start(uicBin, uicArgs); +if (!uicProcess.waitForFinished()) { + qCritical() << "Cannot run 'uic': " << uicProcess.errorString() << " - " + << "Exit status " << uicProcess.exitStatus() + << " (" << uicProcess.exitCode() << ")\n" + << "Check if 'uic' is in PATH"; + Py_RETURN_NONE; +} +QByteArray uiFileContent = uicProcess.readAllStandardOutput(); +QByteArray errorOutput = uicProcess.readAllStandardError(); + +if (!errorOutput.isEmpty()) { + qCritical().noquote() << errorOutput; + Py_RETURN_NONE; +} + +// 2. Obtain the 'classname' and the Qt base class. +QByteArray className; +QByteArray baseClassName; + +// Problem +// The generated Python file doesn't have the Qt Base class information. + +// Solution +// Use the XML file +if (!uiFile.open(QIODevice::ReadOnly)) + Py_RETURN_NONE; + +// This will look for the first <widget> tag, e.g.: +// <widget class="QWidget" name="ThemeWidgetForm"> +// and then extract the information from "class", and "name", +// to get the baseClassName and className respectively +QXmlStreamReader reader(&uiFile); +while (!reader.atEnd() && baseClassName.isEmpty() && className.isEmpty()) { + auto token = reader.readNext(); + if (token == QXmlStreamReader::StartElement && reader.name() == "widget") { + baseClassName = reader.attributes().value(QLatin1String("class")).toUtf8(); + className = reader.attributes().value(QLatin1String("name")).toUtf8(); + } +} + +uiFile.close(); + +if (className.isEmpty() || baseClassName.isEmpty() || reader.hasError()) { + qCritical() << "An error occurred when parsing the UI file while looking for the class info " + << reader.errorString(); + Py_RETURN_NONE; +} + +QByteArray pyClassName("Ui_"+className); + +PyObject *module = PyImport_ImportModule("__main__"); +PyObject *loc = PyModule_GetDict(module); + +// 3. exec() the code so the class exists in the context: exec(uiFileContent) +// The context of PyRun_SimpleString is __main__. +// 'Py_file_input' is the equivalent to using exec(), since it will execute +// the code, without returning anything. +Shiboken::AutoDecRef codeUi(Py_CompileString(uiFileContent.constData(), "<stdin>", Py_file_input)); +if (codeUi.isNull()) { + qCritical() << "Error while compiling the generated Python file"; + Py_RETURN_NONE; +} +PyObject *uiObj = nullptr; +#ifdef IS_PY3K +uiObj = PyEval_EvalCode(codeUi, loc, loc); +#else +uiObj = PyEval_EvalCode(reinterpret_cast<PyCodeObject *>(codeUi.object()), loc, loc); +#endif + +if (uiObj == nullptr) { + qCritical() << "Error while running exec() on the generated code"; + Py_RETURN_NONE; +} + +// 4. eval() the name of the class on a variable to return +// 'Py_eval_input' is the equivalent to using eval(), since it will just +// evaluate an expression. +Shiboken::AutoDecRef codeClass(Py_CompileString(pyClassName.constData(),"<stdin>", Py_eval_input)); +if (codeClass.isNull()) { + qCritical() << "Error while compiling the Python class"; + Py_RETURN_NONE; +} + +Shiboken::AutoDecRef codeBaseClass(Py_CompileString(baseClassName.constData(), "<stdin>", Py_eval_input)); +if (codeBaseClass.isNull()) { + qCritical() << "Error while compiling the base class"; + Py_RETURN_NONE; +} + +#ifdef IS_PY3K +PyObject *classObj = PyEval_EvalCode(codeClass, loc, loc); +PyObject *baseClassObj = PyEval_EvalCode(codeBaseClass, loc, loc); +#else +PyObject *classObj = PyEval_EvalCode(reinterpret_cast<PyCodeObject *>(codeClass.object()), loc, loc); +PyObject *baseClassObj = PyEval_EvalCode(reinterpret_cast<PyCodeObject *>(codeBaseClass.object()), loc, loc); +#endif + +%PYARG_0 = PyTuple_New(2); +if (%PYARG_0 == nullptr) { + qCritical() << "Error while creating the return Tuple"; + Py_RETURN_NONE; +} +PyTuple_SET_ITEM(%PYARG_0, 0, classObj); +PyTuple_SET_ITEM(%PYARG_0, 1, baseClassObj); +// @snippet loaduitype diff --git a/sources/pyside2/PySide2/support/deprecated.py b/sources/pyside2/PySide2/support/deprecated.py index 8538826e4..57f33d9e2 100644 --- a/sources/pyside2/PySide2/support/deprecated.py +++ b/sources/pyside2/PySide2/support/deprecated.py @@ -64,7 +64,7 @@ class PySideDeprecationWarningRemovedInQt6(Warning): def constData(self): cls = self.__class__ - name = cls.__name__ + name = cls.__qualname__ warnings.warn(dedent(""" {name}.constData is unpythonic and will be removed in Qt For Python 6.0 . Please use {name}.data instead.""" diff --git a/sources/pyside2/PySide2/support/generate_pyi.py b/sources/pyside2/PySide2/support/generate_pyi.py index f92367c82..af9f4d4f5 100644 --- a/sources/pyside2/PySide2/support/generate_pyi.py +++ b/sources/pyside2/PySide2/support/generate_pyi.py @@ -1,7 +1,7 @@ # This Python file uses the following encoding: utf-8 ############################################################################# ## -## Copyright (C) 2019 The Qt Company Ltd. +## Copyright (C) 2020 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of Qt for Python. @@ -169,12 +169,6 @@ class Formatter(Writer): else: self.print("{spaces}class {class_str}: ...".format(**locals())) yield - if "<" in class_name: - # This is happening in QtQuick for some reason: - ## class QSharedPointer<QQuickItemGrabResult >: - # We simply skip over this class. - self.outfile.seek(here) - self.outfile.truncate() @contextmanager def function(self, func_name, signature, modifier=None): diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.py index 726ceb818..1cbd56241 100644 --- a/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.cpp +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.py @@ -65,10 +65,9 @@ def __init__(self, parent): previousItems = QListWidget(centralWidget) //! [0] - connect(clipboard, SIGNAL("dataChanged()"), self, SLOT("updateClipboard()")) + clipboard.dataChanged.connect(self.updateClipboard) //! [0] - connect(mimeTypeCombo, SIGNAL("activated(const QString &)"), - self, SLOT("updateData(const QString &))") + mimeTypeCombo.activated[str].connect(self.updateData) currentLayout = QVBoxLayout(currentItem) currentLayout.addWidget(mimeTypeLabel) diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.py index 1de4dbbe8..7e50f6701 100644 --- a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.py @@ -1,52 +1,52 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of Qt for Python. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the documentation of Qt for Python. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ //! [0] lineEdit = qt_find_obj_child(myWidget, "QLineEdit", "my line edit") @@ -96,8 +96,8 @@ layout.inherits("QLayoutItem") # returns false //! [5] -print "MyClass::setPrecision(): (%s) invalid precision %f" % \ - (qPrintable(objectName()), newPrecision) +print("MyClass.setPrecision(): ({}) invalid precision {}".format(qPrintable(objectName()), + newPrecision)) //! [5] @@ -112,7 +112,7 @@ class MainWindow(QMainWindow): if obj == textEdit: if event.type() == QEvent.KeyPress: keyEvent = event - print "Ate key press", keyEvent.key() + print("Ate key press", keyEvent.key()) return true else: return false @@ -138,14 +138,14 @@ class MyObject(QObject): def timerEvent(self, event): - print "Timer ID:", event.timerId() + print("Timer ID:", event.timerId()) //! [8] //! [9] -list = window().queryList("QAbstractButton") -for obj in list: +a_list = window().queryList("QAbstractButton") +for obj in a_list: obj.setEnabled(false) //! [9] @@ -156,7 +156,7 @@ button = parentWidget.findChild(QPushButton, "button1") //! [11] -list = parentWidget.findChild(QListWidget) +a_list = parentWidget.findChild(QListWidget) //! [11] @@ -179,7 +179,7 @@ monitoredObj.installEventFilter(filterObj) class KeyPressEater(QObject): def eventFilter(self, obj, event): if event.type() == QEvent.KeyPress: - print "Ate key press", event.key() + print("Ate key press", event.key()) return True else: # standard event processing @@ -234,15 +234,16 @@ if receivers(SIGNAL('valueChanged()')) > 0: //! [22] label = QLabel() scrollBar = QScrollBar() -QObject.connect(scrollBar, SIGNAL('valueChanged()'), - label, SLOT('setNum()')) +QObject.connect(scrollBar, SIGNAL('valueChanged(int)'), + label, SLOT('setNum(int)')); +# or scrollBar.valueChanged.connect(label.setNum) //! [22] //! [23] // WRONG -QObject.connect(scrollBar, SIGNAL('valueChanged()'), - label, SLOT('setNum()')); +QObject.connect(scrollBar, SIGNAL('valueChanged(int value)'), + label, SLOT('setNum(int value)')); //! [23] @@ -250,8 +251,7 @@ QObject.connect(scrollBar, SIGNAL('valueChanged()'), class MyWidget(QWidget): def __init__(self): myButton = QPushButton(self) - connect(myButton, SIGNAL('clicked()'), - self, SIGNAL('buttonClicked()')) + myButton.clicked.connect(self.buttonClicked) //! [24] @@ -323,7 +323,7 @@ Q_PROPERTY(type name [DESIGNABLE bool] [SCRIPTABLE bool] [STORED bool] - [USER bool]) + [USER bool]) //! [36] @@ -333,34 +333,40 @@ Q_PROPERTY(QString title READ title WRITE setTitle USER true) //! [38] -#this not apply for Python +#this does not apply to Python class MyClass(QObject): - Q_OBJECT - Q_ENUMS(Priority) + #Q_OBJECT, not needed + #Q_ENUMS(Priority), not supported -public: - MyClass(QObject *parent = 0); - ~MyClass(); + def __init__(self, parent=None): + pass - enum Priority { High, Low, VeryHigh, VeryLow }; - void setPriority(Priority priority); - Priority priority() const; + class Priority(Enum): + High = 1 + Low = 2 + VeryHigh = 3 + VeryLow 4 + + def setPriority(self, priority): + pass + + priority = Property(...) }; //! [38] //! [39] -#this not apply for Python +#this does not apply to Python Q_FLAGS(Options Alignment) //! [39] //! [40] -//: This name refers to a host name. +# This name refers to a host name. hostNameLabel.setText(self.tr("Name:")) -#: This text refers to a C++ code example. +# This text refers to a C++ code example. example = self.tr("Example") //! [40] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.py b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.py new file mode 100644 index 000000000..6cf5dd21c --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.py @@ -0,0 +1,74 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the documentation of Qt for Python. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + formWindow = QDesignerFormWindowInterface() + formWindow = QDesignerFormWindowInterface.findFormWindow(myWidget) +//! [0] + + +//! [1] + forms = [] # QList<QDesignerFormWindowInterface> + formWindow = QDesignerFormWindowInterface() + + manager = formEditor.formWindowManager() + + for i in range(manager.formWindowCount()): + formWindow = manager.formWindow(i) + forms.append(formWindow) +//! [1] + + +//! [2] + if formWindow.isManaged(myWidget): + formWindow.manageWidget(myWidget.childWidget) +//! [2] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp deleted file mode 100644 index 255231512..000000000 --- a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of Qt for Python. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//! [0] - QDesignerPropertyEditorInterface *propertyEditor = 0; - propertyEditor = formEditor->propertyEditor(); - - connect(propertyEditor, SIGNAL(propertyChanged(QString, QVariant)), - this, SLOT(checkProperty(QString, QVariant))); -//! [0] - - -//! [1] - void checkProperty(QString property, QVariant value) { - QDesignerPropertyEditorInterface *propertyEditor = 0; - propertyEditor = formEditor->propertyEditor(); - - QObject *object = propertyeditor->object(); - MyCustomWidget *widget = qobject_cast<MyCustomWidget>(object); - - if (widget && property == aProperty && value != expectedValue) - {...} - } -//! [1] - - diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.py b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.py new file mode 100644 index 000000000..1e2ac506f --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.py @@ -0,0 +1,71 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the documentation of Qt for Python. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [0] + propertyEdit = QDesignerPropertyEditorInterface() + propertyEditor = formEditor.propertyEditor() + + propertyEditor.propertyChanged.connect(self.checkProperty) +//! [0] + + +//! [1] + def checkProperty(self, property, value): + propertyEditor = QDesignerPropertyEditorInterface() + propertyEditor = formEditor.propertyEditor() + + object = propertyeditor.object() + widget = MyCustomWidget(object) + + if (widget and property == aProperty and value != expectedValue): + # ... +//! [1] + + diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.py index 047434f6d..7bdcb0c91 100644 --- a/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.cpp +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.py @@ -50,12 +50,10 @@ //! [0] -def find(self) - - if !self.findDialog: +def find(self): + if not self.findDialog: self.findDialog = FindDialog(self) - connect(findDialog, SIGNAL("findNext()"), self, SLOT("findNext()")) - + self.findDialog.findNext.connect(self.findNext) self.findDialog.show() self.findDialog.raise() @@ -72,58 +70,54 @@ def countWords(self): //! [1] //! [2] - mb = QMessageBox("Application Name", - "Hardware failure.\n\nDisk error detected\nDo you want to stop?", - QMessageBox.Question, - QMessageBox.Yes | QMessageBox.Default, - QMessageBox.No | QMessageBox.Escape, - QMessageBox.NoButton) - if mb.exec() == QMessageBox.No: - # try again + mb = QMessageBox("Application Name", + "Hardware failure.\n\nDisk error detected\nDo you want to stop?", + QMessageBox.Question, + QMessageBox.Yes | QMessageBox.Default, + QMessageBox.No | QMessageBox.Escape, + QMessageBox.NoButton) + if mb.exec() == QMessageBox.No: + # try again //! [2] //! [3] progress = QProgressDialog("Copying files...", "Abort Copy", 0, numFiles, self) progress.setWindowModality(Qt.WindowModal) - for i in rang(numFiles): + for i in range(numFiles): progress.setValue(i) if progress.wasCanceled(): break #... copy one file - + progress.setValue(numFiles) //! [3] //! [4] # Operation constructor -def __init__(self, parent): +def __init__(self, parent=None): QObject.__init__(self, parent) pd = QProgressDialog("Operation in progress.", "Cancel", 0, 100) - connect(pd, SIGNAL("canceled()"), self, SLOT("cancel()")) + pd.canceled.connect(self.cancel) t = QTimer(self) - connect(t, SIGNAL("timeout()"), self, SLOT("perform()")) + t.timeout.connect(self.perform) t.start(0) //! [4] //! [5] def perform(self): - pd.setValue(steps) #... perform one percent of the operation - steps++ + steps += 1 if steps > pd.maximum(): t.stop() //! [5] //! [6] def cancel(self): - t.stop() #... cleanup //! [6] - - diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h deleted file mode 100644 index 8607b6953..000000000 --- a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of Qt for Python. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef WINDOW_H -#define WINDOW_H - -#include <QString> -#include <QStringList> -#include <QWidget> - -class QComboBox; -class QFrame; -class QTextBrowser; - -class Window : public QWidget -{ - Q_OBJECT - -public: - Window(QWidget *parent = 0); - -protected: - void dragEnterEvent(QDragEnterEvent *event); - void dropEvent(QDropEvent *event); - -private: - QComboBox *mimeTypeCombo; - QFrame *dropFrame; - QTextBrowser *textBrowser; - QString oldText; - QStringList oldMimeTypes; -}; - -#endif diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.py b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.py new file mode 100644 index 000000000..66a6a7ba2 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.py @@ -0,0 +1,65 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of Qt for Python. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +from PySide2.QtWidgets import QWidget, QComboBox, QFrame, QTextBrowser + +class Window(QWidget): + + def __init__(self, parent=None): + self.mimeTypeCombo = QComboBox() + self.dropFrame = QFrame() + self.textBrowser = QTextBrowser() + self.oldText = "" + self.oldMimeTypes = [] + + def dragEnterEvent(self, event): + pass + def dropEvent(self, event): + pass diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.py b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.py new file mode 100644 index 000000000..184128406 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.py @@ -0,0 +1,87 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the documentation of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +from PySide2.QtWidgets import QApplication, QWidget, QStackedLayout, QComboBox + +class Widget(QWidget) + def __init__(self, parent=None): + QWidget.__init__(self, parent) +//! [0] + self.firstPageWidget = QWidget() + self.secondPageWidget = QWidget() + self.thirdPageWidget = QWidget() + + self.stackedLayout = QStackedLayout() + self.stackedLayout.addWidget(self.firstPageWidget) + self.stackedLayout.addWidget(self.secondPageWidget) + self.stackedLayout.addWidget(self.thirdPageWidget) + +//! [0] //! [1] + self.pageComboBox = QComboBox() + self.pageComboBox.addItem(tr("Page 1")) + self.pageComboBox.addItem(tr("Page 2")) + self.pageComboBox.addItem(tr("Page 3")) + self.pageComboBox.activated.connect(self.stackedLayout.setCurrentIndex) +//! [1] + +//! [2] + self.mainLayout = QVBoxLayout() +//! [2] + self.mainLayout.addWidget(self.pageComboBox) +//! [3] + self.mainLayout.addLayout(self.stackedLayout) + self.setLayout(self.mainLayout) +//! [3] + +if __name__ == "__main__": + app = QApplication(sys.argv) + widget = Widget() + widget.show() + sys.exit(app.exec_()) diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.py index 98a08be98..6f2c49d8e 100644 --- a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.cpp +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.py @@ -64,8 +64,7 @@ pageComboBox.addItem(tr("Page 1")) pageComboBox.addItem(tr("Page 2")) pageComboBox.addItem(tr("Page 3")) - connect(pageComboBox, SIGNAL("activated(int)"), - stackedWidget, SLOT("setCurrentIndex(int)")) + pageComboBox.activated[int].connect(stackedWidget.setCurrentIndex) //! [1] //! [2] layout = QVBoxLayout() diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.py index 734f603a9..16c12b7bc 100644 --- a/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.cpp +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.py @@ -49,11 +49,11 @@ ****************************************************************************/ //! [0] - QBuffer device; - device.setData(myQString.toUtf8()); - device.open(QIODevice::ReadOnly); + device = QBuffer() + device.setData(myQString.toUtf8()) + device.open(QIODevice.ReadOnly) - QXmlQuery query; - query.setQuery("doc($inputDocument)/query[theDocument]"); - query.bindVariable("inputDocument", &device); + query = QXmlQuery() + query.setQuery("doc($inputDocument)/query[theDocument]") + query.bindVariable("inputDocument", device) //! [0] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.py index 29ac9c87d..7c28cf5e6 100644 --- a/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.py @@ -77,7 +77,7 @@ def QSqlField_snippets(): //! [3] field = QSqlField("age", QVariant.Int) - field.setValue(QString("123")) # casts QString to int + field.setValue(str(123)) # casts str to int //! [3] //! [4] @@ -247,7 +247,7 @@ def QSqlTableModel_snippets(): //! [25] model = QSqlTableModel() model.setTable("employee") - QString name = model.record(4).value("name") + name = model.record(4).value("name") //! [25] def sql_intro_snippets(): @@ -351,7 +351,7 @@ def sql_intro_snippets(): employeeId = query.value(0) query.exec_("INSERT INTO project (id, name, ownerid) " "VALUES (201, 'Manhattan Project', " - + QString.number(employeeId) + ')') + + str(employeeId) + ')') QSqlDatabase.database().commit() //! [39] diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/template.py b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/template.py new file mode 100644 index 000000000..d38829fc7 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/template.py @@ -0,0 +1,66 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the documentation of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +//! [main.cpp body] +import sys +from PySide2.QtWidgets import QApplication + +# Include header files for application components. +# ... + +if __name__ == "__main__": + app = QApplication(sys.argv) + + # Set up and show widgets. + # ... + + sys.exit(app.exec_()) +} +//! [main.cpp body] diff --git a/sources/pyside2/doc/codesnippets/examples/dialogs/classwizard/classwizard.cpp b/sources/pyside2/doc/codesnippets/examples/dialogs/classwizard/classwizard.py index 897410ed7..08032cf2a 100644 --- a/sources/pyside2/doc/codesnippets/examples/dialogs/classwizard/classwizard.cpp +++ b/sources/pyside2/doc/codesnippets/examples/dialogs/classwizard/classwizard.py @@ -142,8 +142,7 @@ class ClassInfoPage(QWizardPage): defaultCtorRadioButton.setChecked(True) - self.connect(defaultCtorRadioButton, SIGNAL("toggled(bool)"), - copyCtorCheckBox, SLOT("setEnabled(bool)")) + defaultCtorRadioButton.toggled[bool].connect(copyCtorCheckBox.setEnabled) //! [11] //! [12] registerField("className*", classNameLineEdit) @@ -201,14 +200,10 @@ class CodeStylePage(QWizardPage): baseIncludeLineEdit = QLineEdit() baseIncludeLabel.setBuddy(baseIncludeLineEdit) - self.connect(protectCheckBox, SIGNAL("toggled(bool)"), - macroNameLabel, SLOT("setEnabled(bool)")) - self.connect(protectCheckBox, SIGNAL("toggled(bool)"), - macroNameLineEdit, SLOT("setEnabled(bool)")) - self.connect(includeBaseCheckBox, SIGNAL("toggled(bool)"), - baseIncludeLabel, SLOT("setEnabled(bool)")) - self.connect(includeBaseCheckBox, SIGNAL(toggled(bool)), - baseIncludeLineEdit, SLOT("setEnabled(bool)")) + protectCheckBox.toggled[bool].connect(macroNameLabel.setEnabled) + protectCheckBox.toggled[bool].connect(macroNameLineEdit.setEnabled) + includeBaseCheckBox.toggled[bool].connect(baseIncludeLabel.setEnabled) + includeBaseCheckBox.toggled[bool].connect(baseIncludeLineEdit.setEnabled) self.registerField("comment", commentCheckBox) self.registerField("protect", protectCheckBox) diff --git a/sources/pyside2/doc/codesnippets/examples/dialogs/extension/finddialog.cpp b/sources/pyside2/doc/codesnippets/examples/dialogs/extension/finddialog.py index a8496f4c8..1872e631b 100644 --- a/sources/pyside2/doc/codesnippets/examples/dialogs/extension/finddialog.cpp +++ b/sources/pyside2/doc/codesnippets/examples/dialogs/extension/finddialog.py @@ -85,7 +85,7 @@ def __init__(self, parent): //! [2] //! [3] - connect(moreButton, SIGNAL("toggled(bool)"), extension, SLOT("setVisible(bool)")) + moreButton.toggled[bool].connect(extension.setVisible) extensionLayout = QVBoxLayout() extensionLayout.setMargin(0) diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.h index f9d97e6ce..bdb7bcf22 100644 --- a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp +++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.h @@ -3,7 +3,7 @@ ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** -** This file is part of the documentation of Qt for Python. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage @@ -48,28 +48,65 @@ ** ****************************************************************************/ +from PySide2.QtWidgets import (QAction, QApplication, QMainWindow, QMenu, + QPlainTextEdit, QSessionManager) + + //! [0] - QDesignerFormWindowInterface *formWindow; - formWindow = QDesignerFormWindowInterface::findFormWindow(myWidget); -//! [0] +class MainWindow(QMainWindow): + def __init__(self, parent=None): + self.textEdit = QPlainTextEdit() + self.curFile = "" + # ... + + def loadFile(self, fileName): + pass + + def closeEvent(self, event): + pass + + def newFile(self): + pass + def open(self): + pass -//! [1] - QList<QDesignerFormWindowInterface *> forms; - QDesignerFormWindowInterface *formWindow; + def save(self): + pass - QDesignerFormWindowManagerInterface *manager = formEditor->formWindowManager(); + def saveAs(self): + pass - for (int i = 0; i < manager->formWindowCount(); i++) { - formWindow = manager->formWindow(i); - forms.append(formWindow); - } -//! [1] + def about(self): + pass + def documentWasModified(self): + pass + # Enable this only if QT_NO_SESSIONMANAGER is not defined + # def commitData(self): + # pass -//! [2] - if (formWindow->isManaged(myWidget)) - formWindow->manageWidget(myWidget->childWidget); -//! [2] + def createActions(self): + pass + def createStatusBar(self): + pass + def readSettings(self): + pass + + def writeSettings(self): + pass + + def maybeSave(self): + pass + + def saveFile(self, fileName): + pass + + def setCurrentFile(self, fileName): + pass + + def strippedName(self, fullFileName): + pass +//! [0] diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.py index b0331aa79..f976bb8e3 100644 --- a/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.cpp +++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.py @@ -49,28 +49,30 @@ ############################################################################ //! [0] -from PySide2.QtGui import * +from PySide2.QtCore import Qt, QFile, QFileInfo, QSettings, QTextStream +from PySide2.QtGui import QIcon +from PySide2.Widgets import (QAction, QApplication, QFileDialog, QMainWindow, + QPlainTextEdit, QFileDialog, QMessageBox, ) //! [0] //! [1] -def __init__(self): +def __init__(self, parent=None): QMainWindow.__init__(self) //! [1] //! [2] - textEdit = QPlainTextEdit() - setCentralWidget(textEdit) + self.textEdit = QPlainTextEdit() + self.setCentralWidget(textEdit) - createActions() - createMenus() - createToolBars() - createStatusBar() + self.createActions() + self.createMenus() + self.createToolBars() + self.createStatusBar() - readSettings() + self.readSettings() - connect(textEdit.document(), SIGNAL("contentsChanged()"), - self, SLOT("documentWasModified()")) + self.textEdit.document().contentsChanged.connect(self.documentWasModified) - setCurrentFile("") - setUnifiedTitleAndToolBarOnMac(True) + self.setCurrentFile("") + self.setUnifiedTitleAndToolBarOnMac(True) //! [2] @@ -97,7 +99,7 @@ def open(self): //! [7] //! [8] if maybeSave(): fileName = QFileDialog.getOpenFileName(self) - if !fileName.isEmpty(): + if not fileName.isEmpty(): loadFile(fileName) //! [8] @@ -142,70 +144,68 @@ def MainWindow.createActions(self): Act = QAction(QIcon(":/images/new.png"), tr("&New"), self) Act.setShortcuts(QKeySequence.New) Act.setStatusTip(tr("Create a new file")) - connect(Act, SIGNAL("triggered()"), self, SLOT("newFile()")) + Act.triggered.connect(newFile) //! [19] - openAct = QAction(QIcon(":/images/open.png"), tr("&Open..."), self) + openAct = QAction(QIcon(":/images/open.png"), tr("&Open..."), self) openAct.setShortcuts(QKeySequence.Open) openAct.setStatusTip(tr("Open an existing file")) - connect(openAct, SIGNAL("triggered()"), self, SLOT("open()")) + openAct.triggered.connect(open) //! [18] //! [19] - saveAct = QAction(QIcon(":/images/save.png"), tr("&Save"), self) + saveAct = QAction(QIcon(":/images/save.png"), tr("&Save"), self) saveAct.setShortcuts(QKeySequence.Save) saveAct.setStatusTip(tr("Save the document to disk")) - connect(saveAct, SIGNAL("triggered()"), self, SLOT("save()")) + saveAct.triggered.connect(save) - saveAsAct = QAction(tr("Save &As..."), self) + saveAsAct = QAction(tr("Save &As..."), self) saveAsAct.setShortcuts(QKeySequence.SaveAs) saveAsAct.setStatusTip(tr("Save the document under a name")) - connect(saveAsAct, SIGNAL("triggered()"), self, SLOT("saveAs()")) + saveAsAct.triggered.connect(saveAs) //! [20] - exitAct = QAction(tr("E&xit"), self) + exitAct = QAction(tr("E&xit"), self) exitAct.setShortcut(tr("Ctrl+Q")) //! [20] exitAct.setStatusTip(tr("Exit the application")) - connect(exitAct, SIGNAL("triggered()"), self, SLOT("close()")) + exitAct.triggered.connect(close) //! [21] - cutAct = QAction(QIcon(":/images/cut.png"), tr("Cu&t"), self) + cutAct = QAction(QIcon(":/images/cut.png"), tr("Cu&t"), self) //! [21] cutAct.setShortcuts(QKeySequence.Cut) cutAct.setStatusTip(tr("Cut the current selection's contents to the " "clipboard")) - connect(cutAct, SIGNAL("triggered()"), textEdit, SLOT("cut()")) + cutAct.triggered.connect(cut) - copyAct = QAction(QIcon(":/images/copy.png"), tr("&Copy"), self) + copyAct = QAction(QIcon(":/images/copy.png"), tr("&Copy"), self) copyAct.setShortcuts(QKeySequence.Copy) copyAct.setStatusTip(tr("Copy the current selection's contents to the " "clipboard")) - connect(copyAct, SIGNAL("triggered()"), textEdit, SLOT("copy()")) + copyAct.triggered.connect(copy) - pasteAct = QAction(QIcon(":/images/paste.png"), tr("&Paste"), self) + pasteAct = QAction(QIcon(":/images/paste.png"), tr("&Paste"), self) pasteAct.setShortcuts(QKeySequence.Paste) pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current " "selection")) - connect(pasteAct, SIGNAL("triggered()"), textEdit, SLOT("paste()")) + pasteAct.triggered.connect(textEdit.paste) - aboutAct = QAction(tr("&About"), self) + aboutAct = QAction(tr("&About"), self) aboutAct.setStatusTip(tr("Show the application's About box")) - connect(aboutAct, SIGNAL("triggered()"), self, SLOT("about()")) + aboutAct.triggered.connect(about) //! [22] aboutQtAct = QAction(tr("About &Qt"), self) aboutQtAct.setStatusTip(tr("Show the Qt library's About box")) - connect(aboutQtAct, SIGNAL("triggered()"), qApp, SLOT("aboutQt()")) + aboutQtAct.triggered.connect(qApp.aboutQt) //! [22] //! [23] cutAct.setEnabled(False) //! [23] //! [24] copyAct.setEnabled(False) - connect(textEdit, SIGNAL("copyAvailable(bool)"), - cutAct, SLOT("setEnabled(bool)")) - connect(textEdit, SIGNAL("copyAvailable(bool)"), - copyAct, SLOT("setEnabled(bool)")) + textEdit.copyAvailable[bool].connect(cutAct.setEnabled) + textEdit.copyAvailable[bool].connect(copyAct.setEnabled) } //! [24] @@ -298,10 +298,8 @@ def loadFile(self, fileName): //! [42] //! [43] file = QFile(fileName) if !file.open(QFile.ReadOnly | QFile.Text): - QMessageBox.warning(self, tr("Application"), - tr("Cannot read file %1:\n%2.") - .arg(fileName) - .arg(file.errorString())) + QMessageBox.warning(self, tr("Application"), tr("Cannot read file " + "{}:\n{}.".format(fileName, file.errorString()))) return in = QTextStream(file) @@ -309,8 +307,8 @@ def loadFile(self, fileName): textEdit.setPlainText(in.readAll()) QApplication.restoreOverrideCursor() - setCurrentFile(fileName) - statusBar().showMessage(tr("File loaded"), 2000) + self.setCurrentFile(fileName) + self.statusBar().showMessage(tr("File loaded"), 2000) //! [43] diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/dockwidgets/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/dockwidgets/mainwindow.py index e1a9f556e..55d551c24 100644 --- a/sources/pyside2/doc/codesnippets/examples/mainwindows/dockwidgets/mainwindow.cpp +++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/dockwidgets/mainwindow.py @@ -142,7 +142,7 @@ def save(self): .arg(fileName) .arg(file.errorString())) return - + out = QTextStream(file) QApplication.setOverrideCursor(Qt::WaitCursor) @@ -177,7 +177,7 @@ def insertCustomer(self, customer): for i in range(customerList.size()): cursor.insertBlock() cursor.insertText(customerList.at(i)) - + cursor.endEditBlock() else: oldcursor.endEditBlock() @@ -248,8 +248,6 @@ def createDockWindows(self): addDockWidget(Qt.RightDockWidgetArea, dock) viewMenu.addAction(dock.toggleViewAction()) - connect(customerList, SIGNAL("currentTextChanged(const QString &)"), - self, SLOT("insertCustomer(const QString &)")) - connect(paragraphsList, SIGNAL("currentTextChanged(const QString &)"), - self, SLOT("addParagraph(const QString &)")) + customerList.currentTextChanged[str].connect(self.insertCostumer) + paragraphsList.currentTextChanged[str].connect(self.addParagraph) //! [9] diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.py index 6ed5f5466..b0bbed810 100644 --- a/sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.cpp +++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.py @@ -196,63 +196,63 @@ def createActions(self): Act = new QAction(tr("&New"), self) Act.setShortcuts(QKeySequence.New) Act.setStatusTip(tr("Create a new file")) - connect(Act, SIGNAL("triggered()"), self, SLOT("newFile()")) + Act.triggered.connect(newFile) //! [4] openAct = QAction(tr("&Open..."), self) openAct.setShortcuts(QKeySequence.Open) openAct.setStatusTip(tr("Open an existing file")) - connect(openAct, SIGNAL("triggered()"), self, SLOT("open()")) + openAct.triggered.connect(open) //! [5] saveAct = QAction(tr("&Save"), self) saveAct.setShortcuts(QKeySequence.Save) saveAct.setStatusTip(tr("Save the document to disk")) - connect(saveAct, SIGNAL("triggered()"), self, SLOT("save()")) + saveAct.triggered.connect(save) printAct = QAction(tr("&Print..."), self) printAct.setShortcuts(QKeySequence.Print) printAct.setStatusTip(tr("Print the document")) - connect(printAct, SIGNAL("triggered()"), self, SLOT("print_()")) + printAct.triggered.connect(print_) exitAct = QAction(tr("E&xit"), self) exitAct.setShortcut(tr("Ctrl+Q")) exitAct.setStatusTip(tr("Exit the application")) - connect(exitAct, SIGNAL("triggered()"), self, SLOT("close()")) + exitAct.triggered.connect(close) undoAct = QAction(tr("&Undo"), self) undoAct.setShortcuts(QKeySequence.Undo) undoAct.setStatusTip(tr("Undo the last operation")) - connect(undoAct, SIGNAL("triggered()"), self, SLOT("undo()")) + undoAct.triggered.connect(undo) redoAct = QAction(tr("&Redo"), self) redoAct.setShortcuts(QKeySequence.Redo) redoAct.setStatusTip(tr("Redo the last operation")) - connect(redoAct, SIGNAL("triggered()"), self, SLOT("redo()")) + redoAct.triggered.connect(redo) cutAct = QAction(tr("Cu&t"), self) cutAct.setShortcuts(QKeySequence.Cut) cutAct.setStatusTip(tr("Cut the current selection's contents to the " "clipboard")) - connect(cutAct, SIGNAL("triggered()"), self, SLOT("cut()")) + cutAct.triggered.connect(cut) copyAct = QAction(tr("&Copy"), self) copyAct.setShortcut(tr("Ctrl+C")) copyAct.setStatusTip(tr("Copy the current selection's contents to the " "clipboard")) - connect(copyAct, SIGNAL("triggered()"), self, SLOT("copy()")) + copyAct.triggered.connect(copy) pasteAct = QAction(tr("&Paste"), self) pasteAct.setShortcuts(QKeySequence.Paste) pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current " "selection")) - connect(pasteAct, SIGNAL("triggered()"), self, SLOT("paste()")) + pasteAct.triggered.connect(paste) boldAct = QAction(tr("&Bold"), self) boldAct.setCheckable(True) boldAct.setShortcut(tr("Ctrl+B")) boldAct.setStatusTip(tr("Make the text bold")) - connect(boldAct, SIGNAL("triggered()"), self, SLOT("bold()")) + boldAct.triggered.connect(bold) QFont boldFont = boldAct.font() boldFont.setBold(True) @@ -262,7 +262,7 @@ def createActions(self): italicAct.setCheckable(True) italicAct.setShortcut(tr("Ctrl+I")) italicAct.setStatusTip(tr("Make the text italic")) - connect(italicAct, SIGNAL("triggered()"), self, SLOT("italic()")) + italicAct.triggered.connect(italic) QFont italicFont = italicAct.font() italicFont.setItalic(True) @@ -271,45 +271,44 @@ def createActions(self): setLineSpacingAct = QAction(tr("Set &Line Spacing..."), self) setLineSpacingAct.setStatusTip(tr("Change the gap between the lines of a " "paragraph")) - connect(setLineSpacingAct, SIGNAL("triggered()"), self, SLOT("setLineSpacing()")) + setLineSpacingAct.triggered.connect(setLineSpacing) setParagraphSpacingAct = QAction(tr("Set &Paragraph Spacing..."), self) setLineSpacingAct.setStatusTip(tr("Change the gap between paragraphs")) - connect(setParagraphSpacingAct, SIGNAL("triggered()"), - self, SLOT("setParagraphSpacing()")) + setParagraphSpacingAct.triggered.connect(setParagraphSpacing) aboutAct = QAction(tr("&About"), self) aboutAct.setStatusTip(tr("Show the application's About box")) - connect(aboutAct, SIGNAL("triggered()"), self, SLOT("about()")) + aboutAct.triggered.connect(about) aboutQtAct = QAction(tr("About &Qt"), self) aboutQtAct.setStatusTip(tr("Show the Qt library's About box")) - connect(aboutQtAct, SIGNAL("triggered()"), qApp, SLOT("aboutQt()")) - connect(aboutQtAct, SIGNAL("triggered()"), self, SLOT("aboutQt()")) + aboutQtAct.triggered.connect(qApp.aboutQt) + aboutQtAct.triggered.connect(aboutQt) leftAlignAct = QAction(tr("&Left Align"), self) leftAlignAct.setCheckable(True) leftAlignAct.setShortcut(tr("Ctrl+L")) leftAlignAct.setStatusTip(tr("Left align the selected text")) - connect(leftAlignAct, SIGNAL("triggered()"), self, SLOT("leftAlign()")) + leftAlignAct.triggered.connect(leftAlign) rightAlignAct = QAction(tr("&Right Align"), self) rightAlignAct.setCheckable(True) rightAlignAct.setShortcut(tr("Ctrl+R")) rightAlignAct.setStatusTip(tr("Right align the selected text")) - connect(rightAlignAct, SIGNAL("triggered()"), self, SLOT("rightAlign()")) + rightAlignAct.triggered.connect.(rightAlign) justifyAct = QAction(tr("&Justify"), self) justifyAct.setCheckable(True) justifyAct.setShortcut(tr("Ctrl+J")) justifyAct.setStatusTip(tr("Justify the selected text")) - connect(justifyAct, SIGNAL("triggered()"), self, SLOT("justify()")) + justifyAct.triggered.connect(justify) centerAct = QAction(tr("&Center"), self) centerAct.setCheckable(True) centerAct.setShortcut(tr("Ctrl+E")) centerAct.setStatusTip(tr("Center the selected text")) - connect(centerAct, SIGNAL("triggered()"), self, SLOT("center()")) + centerAct.triggered.connect(center) //! [6] //! [7] alignmentGroup = QActionGroup(self) diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.cpp deleted file mode 100644 index cfee5cdca..000000000 --- a/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.cpp +++ /dev/null @@ -1,381 +0,0 @@ -############################################################################ -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the examples of Qt for Python. -## -## $QT_BEGIN_LICENSE:BSD$ -## 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. -## -## BSD License Usage -## Alternatively, you may use this file under the terms of the BSD license -## as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################ - -from PySide2.QtGui import * - -def __init__(self): - - mdiArea = QMdiArea() - mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) - mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) - setCentralWidget(mdiArea) - connect(mdiArea, SIGNAL("subWindowActivated(QMdiSubWindow *)"), - self, SLOT("updateMenus()")) - windowMapper = QSignalMapper(self) - connect(windowMapper, SIGNAL("mapped(QWidget *)"), - self, SLOT("setActiveSubWindow(QWidget *)")) - - createActions() - createMenus() - createToolBars() - createStatusBar() - updateMenus() - - readSettings() - - setWindowTitle(tr("MDI")) - setUnifiedTitleAndToolBarOnMac(True) - - -def closeEvent(self, event): - mdiArea.closeAllSubWindows() - if self.activeMdiChild(): - event.ignore() - else: - self.writeSettings() - event.accept() - -def File(self): - child = self.createMdiChild() - child.File() - child.show() - - -def open(self): - fileName = QFileDialog.getOpenFileName(self) - if !fileName.isEmpty()): - existing = self.findMdiChild(fileName) - if existing: - mdiArea.setActiveSubWindow(existing) - return - - child = createMdiChild() - if child.loadFile(fileName)): - statusBar().showMessage(tr("File loaded"), 2000) - child.show() - else: - child.close() - -def save(self): - if self.activeMdiChild() && self.activeMdiChild().save(): - self.statusBar().showMessage(tr("File saved"), 2000) - -def saveAs(self): - if self.activeMdiChild() && self.activeMdiChild().saveAs(): - self.statusBar().showMessage(tr("File saved"), 2000) - -def cut(self): - if self.activeMdiChild(): - self.activeMdiChild().cut() - -def copy(self): - if self.activeMdiChild(): - activeMdiChild().copy() - -def paste(self): - if self.activeMdiChild(): - activeMdiChild().paste() - -def about(self): - QMessageBox.about(self, tr("About MDI"), - tr("The <b>MDI</b> example demonstrates how to write multiple " - "document interface applications using Qt.")") - -def updateMenus(self): - hasMdiChild = (activeMdiChild() != 0) - self.saveAct.setEnabled(hasMdiChild) - self.saveAsAct.setEnabled(hasMdiChild) - self.pasteAct.setEnabled(hasMdiChild) - self.closeAct.setEnabled(hasMdiChild) - self.closeAllAct.setEnabled(hasMdiChild) - self.tileAct.setEnabled(hasMdiChild) - self.cascadeAct.setEnabled(hasMdiChild) - self.nextAct.setEnabled(hasMdiChild) - self.previousAct.setEnabled(hasMdiChild) - self.separatorAct.setVisible(hasMdiChild) - - hasSelection = (self.activeMdiChild() && - self.activeMdiChild().textCursor().hasSelection()") - self.cutAct.setEnabled(hasSelection) - self.copyAct.setEnabled(hasSelection) - -def updateWindowMenu(self): - self.windowMenu.clear() - self.windowMenu.addAction(closeAct) - self.windowMenu.addAction(closeAllAct) - self.windowMenu.addSeparator() - self.windowMenu.addAction(tileAct) - self.windowMenu.addAction(cascadeAct) - self.windowMenu.addSeparator() - self.windowMenu.addAction(nextAct) - self.windowMenu.addAction(previousAct) - self.windowMenu.addAction(separatorAct) - - windows = mdiArea.subWindowList() - separatorAct.setVisible(!windows.isEmpty()") - - for i in range((int i = 0 i < windows.size(); ++i) - MdiChild *child = qobject_cast<MdiChild *>(windows.at(i).widget()") - - QString text - if (i < 9) - text = tr("&%1 %2").arg(i + 1) - .arg(child.userFriendlyCurrentFile()") - else - text = tr("%1 %2").arg(i + 1) - .arg(child.userFriendlyCurrentFile()") - - QAction *action = windowMenu.addAction(text) - action.setCheckable(True) - action .setChecked(child == activeMdiChild()") - connect(action, SIGNAL("triggered()"), windowMapper, SLOT("map()")) - windowMapper.setMapping(action, windows.at(i)") - - - -MdiChild *createMdiChild() - - MdiChild *child = MdiChild - mdiArea.addSubWindow(child) - - connect(child, SIGNAL("copyAvailable(bool)"), - cutAct, SLOT("setEnabled(bool)")) - connect(child, SIGNAL("copyAvailable(bool)"), - copyAct, SLOT("setEnabled(bool)")) - - return child - - -def createActions() - - Act = new QAction(QIcon(":/images/new.png"), tr("&New"), self) - Act.setShortcuts(QKeySequence.New) - Act.setStatusTip(tr("Create a new file")") - connect(Act, SIGNAL("triggered()"), self, SLOT("newFile()")) - - openAct = QAction(QIcon(":/images/open.png"), tr("&Open..."), self) - openAct.setShortcuts(QKeySequence.Open) - openAct.setStatusTip(tr("Open an existing file")") - connect(openAct, SIGNAL("triggered()"), self, SLOT("open()")) - - saveAct = QAction(QIcon(":/images/save.png"), tr("&Save"), self) - saveAct.setShortcuts(QKeySequence.Save) - saveAct.setStatusTip(tr("Save the document to disk")") - connect(saveAct, SIGNAL("triggered()"), self, SLOT("save()")) - - saveAsAct = QAction(tr("Save &As..."), self) - saveAsAct.setShortcuts(QKeySequence.SaveAs) - saveAsAct.setStatusTip(tr("Save the document under a name")") - connect(saveAsAct, SIGNAL("triggered()"), self, SLOT("saveAs()")) - -//! [0] - exitAct = QAction(tr("E&xit"), self) - exitAct.setShortcut(tr("Ctrl+Q")") - exitAct.setStatusTip(tr("Exit the application")") - connect(exitAct, SIGNAL("triggered()"), qApp, SLOT("closeAllWindows()")) -//! [0] - - cutAct = QAction(QIcon(":/images/cut.png"), tr("Cu&t"), self) - cutAct.setShortcuts(QKeySequence.Cut) - cutAct.setStatusTip(tr("Cut the current selection's contents to the " - "clipboard")") - connect(cutAct, SIGNAL("triggered()"), self, SLOT("cut()")) - - copyAct = QAction(QIcon(":/images/copy.png"), tr("&Copy"), self) - copyAct.setShortcuts(QKeySequence.Copy) - copyAct.setStatusTip(tr("Copy the current selection's contents to the " - "clipboard")") - connect(copyAct, SIGNAL("triggered()"), self, SLOT("copy()")) - - pasteAct = QAction(QIcon(":/images/paste.png"), tr("&Paste"), self) - pasteAct.setShortcuts(QKeySequence.Paste) - pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current " - "selection")") - connect(pasteAct, SIGNAL("triggered()"), self, SLOT("paste()")) - - closeAct = QAction(tr("Cl&ose"), self) - closeAct.setShortcut(tr("Ctrl+F4")") - closeAct.setStatusTip(tr("Close the active window")") - connect(closeAct, SIGNAL("triggered()"), - mdiArea, SLOT("closeActiveSubWindow()")) - - closeAllAct = QAction(tr("Close &All"), self) - closeAllAct.setStatusTip(tr("Close all the windows")") - connect(closeAllAct, SIGNAL("triggered()"), - mdiArea, SLOT("closeAllSubWindows()")) - - tileAct = QAction(tr("&Tile"), self) - tileAct.setStatusTip(tr("Tile the windows")") - connect(tileAct, SIGNAL("triggered()"), mdiArea, SLOT("tileSubWindows()")) - - cascadeAct = QAction(tr("&Cascade"), self) - cascadeAct.setStatusTip(tr("Cascade the windows")") - connect(cascadeAct, SIGNAL("triggered()"), mdiArea, SLOT("cascadeSubWindows()")) - - nextAct = QAction(tr("Ne&xt"), self) - nextAct.setShortcuts(QKeySequence.NextChild) - nextAct.setStatusTip(tr("Move the focus to the next window")") - connect(nextAct, SIGNAL("triggered()"), - mdiArea, SLOT("activateNextSubWindow()")) - - previousAct = QAction(tr("Pre&vious"), self) - previousAct.setShortcuts(QKeySequence.PreviousChild) - previousAct.setStatusTip(tr("Move the focus to the previous " - "window")") - connect(previousAct, SIGNAL("triggered()"), - mdiArea, SLOT("activatePreviousSubWindow()")) - - separatorAct = QAction(self) - separatorAct.setSeparator(True) - - aboutAct = QAction(tr("&About"), self) - aboutAct.setStatusTip(tr("Show the application's About box")") - connect(aboutAct, SIGNAL("triggered()"), self, SLOT("about()")) - - aboutQtAct = QAction(tr("About &Qt"), self) - aboutQtAct.setStatusTip(tr("Show the Qt library's About box")") - connect(aboutQtAct, SIGNAL("triggered()"), qApp, SLOT("aboutQt()")) - - -def createMenus() - - fileMenu = menuBar().addMenu(tr("&File")") - fileMenu.addAction(Act) - fileMenu.addAction(openAct) - fileMenu.addAction(saveAct) - fileMenu.addAction(saveAsAct) - fileMenu.addSeparator() - QAction *action = fileMenu.addAction(tr("Switch layout direction")") - connect(action, SIGNAL("triggered()"), self, SLOT("switchLayoutDirection()")) - fileMenu.addAction(exitAct) - - editMenu = menuBar().addMenu(tr("&Edit")") - editMenu.addAction(cutAct) - editMenu.addAction(copyAct) - editMenu.addAction(pasteAct) - - windowMenu = menuBar().addMenu(tr("&Window")") - updateWindowMenu() - connect(windowMenu, SIGNAL("aboutToShow()"), self, SLOT("updateWindowMenu()")) - - menuBar().addSeparator() - - helpMenu = menuBar().addMenu(tr("&Help")") - helpMenu.addAction(aboutAct) - helpMenu.addAction(aboutQtAct) - - -def createToolBars() - - fileToolBar = addToolBar(tr("File")") - fileToolBar.addAction(Act) - fileToolBar.addAction(openAct) - fileToolBar.addAction(saveAct) - - editToolBar = addToolBar(tr("Edit")") - editToolBar.addAction(cutAct) - editToolBar.addAction(copyAct) - editToolBar.addAction(pasteAct) - - -def createStatusBar() - - statusBar().showMessage(tr("Ready")") - - -def readSettings() - - QSettings settings("Trolltech", "MDI Example") - QPoint pos = settings.value("pos", QPoint(200, 200)").toPoint() - QSize size = settings.value("size", QSize(400, 400)").toSize() - move(pos) - resize(size) - - -def writeSettings() - - QSettings settings("Trolltech", "MDI Example") - settings.setValue("pos", pos()") - settings.setValue("size", size()") - - -MdiChild *activeMdiChild() - - if (QMdiSubWindow *activeSubWindow = mdiArea.activeSubWindow()") - return qobject_cast<MdiChild *>(activeSubWindow.widget()") - return 0 - - -QMdiSubWindow *findMdiChild(const QString &fileName) - - QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath() - - foreach (QMdiSubWindow *window, mdiArea.subWindowList()") - MdiChild *mdiChild = qobject_cast<MdiChild *>(window.widget()") - if (mdiChild.currentFile() == canonicalFilePath) - return window - - return 0 - - -def switchLayoutDirection() - - if (layoutDirection() == Qt.LeftToRight) - qApp.setLayoutDirection(Qt.RightToLeft) - else - qApp.setLayoutDirection(Qt.LeftToRight) - - -def setActiveSubWindow(QWidget *window) - - if (!window) - return - mdiArea.setActiveSubWindow(qobject_cast<QMdiSubWindow *>(window)") - diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.py b/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.py new file mode 100644 index 000000000..41f515847 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.py @@ -0,0 +1,360 @@ +############################################################################ +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the examples of Qt for Python. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################ + +from PySide2.QtGui import * + +class QMdiSubWindow(QMainWindow): + def __init__(self, parent=None): + QMainWindow.__init__(self, parent) + + mdiArea = QMdiArea() + mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) + mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) + setCentralWidget(mdiArea) + mdiArea.subWindowActivated[QMdiSubWindow].connect(updateMenus) + windowMapper = QSignalMapper(self) + windowMapper.mapped[QWidget].connect(setActiveSubWindow) + + self.createActions() + self.createMenus() + self.createToolBars() + self.createStatusBar() + self.updateMenus() + self.readSettings() + self.setWindowTitle(tr("MDI")) + self.setUnifiedTitleAndToolBarOnMac(True) + + + def closeEvent(self, event): + mdiArea.closeAllSubWindows() + if self.activeMdiChild(): + event.ignore() + else: + self.writeSettings() + event.accept() + + def File(self): + child = self.createMdiChild() + child.File() + child.show() + + + def open(self): + fileName = QFileDialog.getOpenFileName(self) + if not fileName.isEmpty(): + existing = self.findMdiChild(fileName) + if existing: + mdiArea.setActiveSubWindow(existing) + return + + child = createMdiChild() + if child.loadFile(fileName): + statusBar().showMessage(tr("File loaded"), 2000) + child.show() + else: + child.close() + + def save(self): + if self.activeMdiChild() and self.activeMdiChild().save(): + self.statusBar().showMessage(tr("File saved"), 2000) + + def saveAs(self): + if self.activeMdiChild() and self.activeMdiChild().saveAs(): + self.statusBar().showMessage(tr("File saved"), 2000) + + def cut(self): + if self.activeMdiChild(): + self.activeMdiChild().cut() + + def copy(self): + if self.activeMdiChild(): + activeMdiChild().copy() + + def paste(self): + if self.activeMdiChild(): + activeMdiChild().paste() + + def about(self): + QMessageBox.about(self, tr("About MDI"), + tr("The <b>MDI</b> example demonstrates how to write multiple " + "document interface applications using Qt.")) + + def updateMenus(self): + hasMdiChild = (activeMdiChild() != 0) + self.saveAct.setEnabled(hasMdiChild) + self.saveAsAct.setEnabled(hasMdiChild) + self.pasteAct.setEnabled(hasMdiChild) + self.closeAct.setEnabled(hasMdiChild) + self.closeAllAct.setEnabled(hasMdiChild) + self.tileAct.setEnabled(hasMdiChild) + self.cascadeAct.setEnabled(hasMdiChild) + self.nextAct.setEnabled(hasMdiChild) + self.previousAct.setEnabled(hasMdiChild) + self.separatorAct.setVisible(hasMdiChild) + + hasSelection = (self.activeMdiChild() and + self.activeMdiChild().textCursor().hasSelection()) + self.cutAct.setEnabled(hasSelection) + self.copyAct.setEnabled(hasSelection) + + def updateWindowMenu(self): + self.windowMenu.clear() + self.windowMenu.addAction(closeAct) + self.windowMenu.addAction(closeAllAct) + self.windowMenu.addSeparator() + self.windowMenu.addAction(tileAct) + self.windowMenu.addAction(cascadeAct) + self.windowMenu.addSeparator() + self.windowMenu.addAction(nextAct) + self.windowMenu.addAction(previousAct) + self.windowMenu.addAction(separatorAct) + + windows = mdiArea.subWindowList() + separatorAct.setVisible(not windows.isEmpty()) + + for i in range(0, windows.size()): + child = windows.at(i).widget() + + text = "" + if i < 9: + text = "{} {}".format(i + 1, child.userFriendlyCurrentFile()) + else: + text = "{} {}".format(i + 1, child.userFriendlyCurrentFile()) + + action = windowMenu.addAction(text) + action.setCheckable(True) + action.setChecked(child == activeMdiChild()) + action.triggered.connect(windowMapper.map) + windowMapper.setMapping(action, windows.at(i)) + + createMdiChild = MdiChild() + + child = MdiChild() + mdiArea.addSubWindow(child) + + child.copyAvailable[bool].connect(cutAct.setEnabled) + child.copyAvailable[bool].connect(copyAct.setEnabled) + + return child + + + def createActions(self): + + Act = QAction(QIcon(":/images/new.png"), tr("&New"), self) + Act.setShortcuts(QKeySequence.New) + Act.setStatusTip(tr("Create a new file")) + Act.triggered.connect(self.newFile) + + openAct = QAction(QIcon(":/images/open.png"), tr("&Open..."), self) + openAct.setShortcuts(QKeySequence.Open) + openAct.setStatusTip(tr("Open an existing file")) + openAct.triggered.connect(self.open) + + saveAct = QAction(QIcon(":/images/save.png"), tr("&Save"), self) + saveAct.setShortcuts(QKeySequence.Save) + saveAct.setStatusTip(tr("Save the document to disk")) + saveAct.triggered.connect(self.save) + + saveAsAct = QAction(tr("Save &As..."), self) + saveAsAct.setShortcuts(QKeySequence.SaveAs) + saveAsAct.setStatusTip(tr("Save the document under a name")) + saveAsAct.triggered.connect(self.saveAs) + +//! [0] + exitAct = QAction(tr("E&xit"), self) + exitAct.setShortcut(tr("Ctrl+Q")) + exitAct.setStatusTip(tr("Exit the application")) + exitAct.triggered.connect(qApp.closeAllWindows) +//! [0] + + cutAct = QAction(QIcon(":/images/cut.png"), tr("Cu&t"), self) + cutAct.setShortcuts(QKeySequence.Cut) + cutAct.setStatusTip(tr("Cut the current selection's contents to the " + "clipboard")) + cutAct.triggered.connect(self.cut) + + copyAct = QAction(QIcon(":/images/copy.png"), tr("&Copy"), self) + copyAct.setShortcuts(QKeySequence.Copy) + copyAct.setStatusTip(tr("Copy the current selection's contents to the " + "clipboard")) + copyAct.triggered.connect(self.copy) + + pasteAct = QAction(QIcon(":/images/paste.png"), tr("&Paste"), self) + pasteAct.setShortcuts(QKeySequence.Paste) + pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current " + "selection")) + pasteAct.triggered.connect(self.paste) + + closeAct = QAction(tr("Cl&ose"), self) + closeAct.setShortcut(tr("Ctrl+F4")) + closeAct.setStatusTip(tr("Close the active window")) + closeAct.triggered.connect(mdiArea.closeActiveSubWindow) + + closeAllAct = QAction(tr("Close &All"), self) + closeAllAct.setStatusTip(tr("Close all the windows")) + closeAllAct.triggered.connect(mdiArea.closeAllSubWindows) + + tileAct = QAction(tr("&Tile"), self) + tileAct.setStatusTip(tr("Tile the windows")) + tileAct.triggered.connect(mdiArea.tileSubWindows) + + cascadeAct = QAction(tr("&Cascade"), self) + cascadeAct.setStatusTip(tr("Cascade the windows")) + cascadeAct.triggered.connect(mdiArea.cascadeSubWindows) + + nextAct = QAction(tr("Ne&xt"), self) + nextAct.setShortcuts(QKeySequence.NextChild) + nextAct.setStatusTip(tr("Move the focus to the next window")) + nextAct.triggered.connect(mdiArea.activateNextSubWindow) + + previousAct = QAction(tr("Pre&vious"), self) + previousAct.setShortcuts(QKeySequence.PreviousChild) + previousAct.setStatusTip(tr("Move the focus to the previous " + "window")) + previousAct.triggered.connect(mdiArea.activatePreviousSubWindow) + + separatorAct = QAction(self) + separatorAct.setSeparator(True) + + aboutAct = QAction(tr("&About"), self) + aboutAct.setStatusTip(tr("Show the application's About box")) + aboutAct.triggered.connect(self.about) + + aboutQtAct = QAction(tr("About &Qt"), self) + aboutQtAct.setStatusTip(tr("Show the Qt library's About box")) + aboutQtAct.triggered.connect(qApp.aboutQt) + + + def createMenus(self): + + fileMenu = menuBar().addMenu(tr("&File")) + fileMenu.addAction(Act) + fileMenu.addAction(openAct) + fileMenu.addAction(saveAct) + fileMenu.addAction(saveAsAct) + fileMenu.addSeparator() + action = fileMenu.addAction(tr("Switch layout direction")) + action.triggered.connect(self.switchLayoutDirection) + fileMenu.addAction(exitAct) + + editMenu = menuBar().addMenu(tr("&Edit")) + editMenu.addAction(cutAct) + editMenu.addAction(copyAct) + editMenu.addAction(pasteAct) + + windowMenu = menuBar().addMenu(tr("&Window")) + updateWindowMenu() + windowMenu.aboutToShow.connect(self.updateWindowMenu) + + menuBar().addSeparator() + + helpMenu = menuBar().addMenu(tr("&Help")) + helpMenu.addAction(aboutAct) + helpMenu.addAction(aboutQtAct) + + + def createToolBars(self): + fileToolBar = addToolBar(tr("File")) + fileToolBar.addAction(Act) + fileToolBar.addAction(openAct) + fileToolBar.addAction(saveAct) + + editToolBar = addToolBar(tr("Edit")) + editToolBar.addAction(cutAct) + editToolBar.addAction(copyAct) + editToolBar.addAction(pasteAct) + + + def createStatusBar(self): + statusBar().showMessage(tr("Ready")) + + + def readSettings(self): + settings = QSettings("Trolltech", "MDI Example") + QPoint pos = settings.value("pos", QPoint(200, 200)").toPoint() + QSize size = settings.value("size", QSize(400, 400)").toSize() + move(pos) + resize(size) + + def writeSettings(self): + QSettings settings("Trolltech", "MDI Example") + settings.setValue("pos", pos()") + settings.setValue("size", size()") + + + activeMdiChild = MdiChild() + activeSubWindow = mdiArea.activeSubWindow() + if activeSubWindow: + return activeSubWindow.widget() + return 0 + + + def findMdiChild(self, fileName): + + canonicalFilePath = QFileInfo(fileName).canonicalFilePath() + + for window in mdiArea.subWindowList(): + mdiChild = window.widget() + if mdiChild.currentFile() == canonicalFilePath: + return window + return 0 + + + def switchLayoutDirection(self) + if layoutDirection() == Qt.LeftToRight: + qApp.setLayoutDirection(Qt.RightToLeft) + else: + qApp.setLayoutDirection(Qt.LeftToRight) + + + def setActiveSubWindow(self, window): + if not window: + return + mdiArea.setActiveSubWindow(window) diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.py index 6ed5f5466..6505f1f1a 100644 --- a/sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.cpp +++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.py @@ -196,63 +196,63 @@ def createActions(self): Act = new QAction(tr("&New"), self) Act.setShortcuts(QKeySequence.New) Act.setStatusTip(tr("Create a new file")) - connect(Act, SIGNAL("triggered()"), self, SLOT("newFile()")) + Act.triggered.connect(newFile) //! [4] openAct = QAction(tr("&Open..."), self) openAct.setShortcuts(QKeySequence.Open) openAct.setStatusTip(tr("Open an existing file")) - connect(openAct, SIGNAL("triggered()"), self, SLOT("open()")) + openAct.triggered.connect(open) //! [5] saveAct = QAction(tr("&Save"), self) saveAct.setShortcuts(QKeySequence.Save) saveAct.setStatusTip(tr("Save the document to disk")) - connect(saveAct, SIGNAL("triggered()"), self, SLOT("save()")) + saveAct.triggered.connect(save) printAct = QAction(tr("&Print..."), self) printAct.setShortcuts(QKeySequence.Print) printAct.setStatusTip(tr("Print the document")) - connect(printAct, SIGNAL("triggered()"), self, SLOT("print_()")) + printAct.triggered.connect(print_) exitAct = QAction(tr("E&xit"), self) exitAct.setShortcut(tr("Ctrl+Q")) exitAct.setStatusTip(tr("Exit the application")) - connect(exitAct, SIGNAL("triggered()"), self, SLOT("close()")) + exitAct.triggered.connect(close) undoAct = QAction(tr("&Undo"), self) undoAct.setShortcuts(QKeySequence.Undo) undoAct.setStatusTip(tr("Undo the last operation")) - connect(undoAct, SIGNAL("triggered()"), self, SLOT("undo()")) + undoAct.triggered.connect(undo) redoAct = QAction(tr("&Redo"), self) redoAct.setShortcuts(QKeySequence.Redo) redoAct.setStatusTip(tr("Redo the last operation")) - connect(redoAct, SIGNAL("triggered()"), self, SLOT("redo()")) + redoAct.triggered.connect(redo) cutAct = QAction(tr("Cu&t"), self) cutAct.setShortcuts(QKeySequence.Cut) cutAct.setStatusTip(tr("Cut the current selection's contents to the " "clipboard")) - connect(cutAct, SIGNAL("triggered()"), self, SLOT("cut()")) + cutAct.triggered.connect(cut) copyAct = QAction(tr("&Copy"), self) copyAct.setShortcut(tr("Ctrl+C")) copyAct.setStatusTip(tr("Copy the current selection's contents to the " "clipboard")) - connect(copyAct, SIGNAL("triggered()"), self, SLOT("copy()")) + copyAct.triggered.connect(copy) pasteAct = QAction(tr("&Paste"), self) pasteAct.setShortcuts(QKeySequence.Paste) pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current " "selection")) - connect(pasteAct, SIGNAL("triggered()"), self, SLOT("paste()")) + pasteAct.triggered.connect(paste) boldAct = QAction(tr("&Bold"), self) boldAct.setCheckable(True) boldAct.setShortcut(tr("Ctrl+B")) boldAct.setStatusTip(tr("Make the text bold")) - connect(boldAct, SIGNAL("triggered()"), self, SLOT("bold()")) + boldAct.triggered.connect(bold) QFont boldFont = boldAct.font() boldFont.setBold(True) @@ -262,7 +262,7 @@ def createActions(self): italicAct.setCheckable(True) italicAct.setShortcut(tr("Ctrl+I")) italicAct.setStatusTip(tr("Make the text italic")) - connect(italicAct, SIGNAL("triggered()"), self, SLOT("italic()")) + italicAct.triggered.connect(italic) QFont italicFont = italicAct.font() italicFont.setItalic(True) @@ -271,45 +271,44 @@ def createActions(self): setLineSpacingAct = QAction(tr("Set &Line Spacing..."), self) setLineSpacingAct.setStatusTip(tr("Change the gap between the lines of a " "paragraph")) - connect(setLineSpacingAct, SIGNAL("triggered()"), self, SLOT("setLineSpacing()")) + setLineSpacingAct.triggered.connect(setLineSpacing) setParagraphSpacingAct = QAction(tr("Set &Paragraph Spacing..."), self) setLineSpacingAct.setStatusTip(tr("Change the gap between paragraphs")) - connect(setParagraphSpacingAct, SIGNAL("triggered()"), - self, SLOT("setParagraphSpacing()")) + setParagraphSpacingAct.triggered.connect(setParagraphSpacing) aboutAct = QAction(tr("&About"), self) aboutAct.setStatusTip(tr("Show the application's About box")) - connect(aboutAct, SIGNAL("triggered()"), self, SLOT("about()")) + aboutAct.triggered.connect(about) aboutQtAct = QAction(tr("About &Qt"), self) aboutQtAct.setStatusTip(tr("Show the Qt library's About box")) - connect(aboutQtAct, SIGNAL("triggered()"), qApp, SLOT("aboutQt()")) - connect(aboutQtAct, SIGNAL("triggered()"), self, SLOT("aboutQt()")) + aboutQtAct.triggered.connect(qApp.aboutQt) + aboutQtAct.triggered.connect(aboutQt) leftAlignAct = QAction(tr("&Left Align"), self) leftAlignAct.setCheckable(True) leftAlignAct.setShortcut(tr("Ctrl+L")) leftAlignAct.setStatusTip(tr("Left align the selected text")) - connect(leftAlignAct, SIGNAL("triggered()"), self, SLOT("leftAlign()")) + leftAlignAct.triggered.connect(leftAlign) rightAlignAct = QAction(tr("&Right Align"), self) rightAlignAct.setCheckable(True) rightAlignAct.setShortcut(tr("Ctrl+R")) rightAlignAct.setStatusTip(tr("Right align the selected text")) - connect(rightAlignAct, SIGNAL("triggered()"), self, SLOT("rightAlign()")) + rightAlignAct.triggered.connect(rightAlign) justifyAct = QAction(tr("&Justify"), self) justifyAct.setCheckable(True) justifyAct.setShortcut(tr("Ctrl+J")) justifyAct.setStatusTip(tr("Justify the selected text")) - connect(justifyAct, SIGNAL("triggered()"), self, SLOT("justify()")) + justifyAct.triggered.connect(justify) centerAct = QAction(tr("&Center"), self) centerAct.setCheckable(True) centerAct.setShortcut(tr("Ctrl+E")) centerAct.setStatusTip(tr("Center the selected text")) - connect(centerAct, SIGNAL("triggered()"), self, SLOT("center()")) + centerAct.triggered.connect(center) //! [6] //! [7] alignmentGroup = QActionGroup(self) diff --git a/sources/pyside2/doc/codesnippets/examples/widgets/spinboxes/window.cpp b/sources/pyside2/doc/codesnippets/examples/widgets/spinboxes/window.py index 7eace108a..40fe28bf1 100644 --- a/sources/pyside2/doc/codesnippets/examples/widgets/spinboxes/window.cpp +++ b/sources/pyside2/doc/codesnippets/examples/widgets/spinboxes/window.py @@ -147,8 +147,7 @@ def createDateTimeEdits(self): formatComboBox.addItem("hh:mm ap") //! [9] //! [10] - connect(formatComboBox, SIGNAL("activated(const QString &)"), - self, SLOT("setFormatString(const QString &)")) + formatComboBox.activated[str].connect(setFormatString) //! [10] setFormatString(formatComboBox.currentText()) @@ -174,12 +173,12 @@ def setFormatString(self, formatString): meetingEdit.setDateRange(QDate(2004, 11, 1), QDate(2005, 11, 30)) meetingLabel.setText(tr("Meeting date (between %0 and %1):") .arg(meetingEdit.minimumDate().toString(Qt.ISODate)) - .arg(meetingEdit.maximumDate().toString(Qt.ISODate))) + .arg(meetingEdit.maximumDate().toString(Qt.ISODate))) else: meetingEdit.setTimeRange(QTime(0, 7, 20, 0), QTime(21, 0, 0, 0)) meetingLabel.setText(tr("Meeting time (between %0 and %1):") .arg(meetingEdit.minimumTime().toString(Qt.ISODate)) - .arg(meetingEdit.maximumTime().toString(Qt.ISODate))) + .arg(meetingEdit.maximumTime().toString(Qt.ISODate))) //! [13] //! [14] @@ -222,9 +221,8 @@ def createDoubleSpinBoxes(): priceSpinBox.setPrefix("$") priceSpinBox.setValue(99.99) - connect(precisionSpinBox, SIGNAL("valueChanged(int)"), + precisionSpinBox.valueChanged[int].connect(changePrecision) //! [17] - self, SLOT("changePrecision(int))") //! [18] spinBoxLayout = QVBoxLayout() diff --git a/sources/pyside2/doc/inheritance_diagram.py b/sources/pyside2/doc/inheritance_diagram.py index 054cb7be9..875e17b50 100644 --- a/sources/pyside2/doc/inheritance_diagram.py +++ b/sources/pyside2/doc/inheritance_diagram.py @@ -176,7 +176,7 @@ class InheritanceGraph(object): if module == '__builtin__': fullname = cls.__name__ else: - fullname = '%s.%s' % (module, cls.__name__) + fullname = '%s.%s' % (module, cls.__qualname__) if parts == 0: return fullname name_parts = fullname.split('.') diff --git a/sources/pyside2/doc/tutorials/basictutorial/icons.png b/sources/pyside2/doc/tutorials/basictutorial/icons.png Binary files differnew file mode 100644 index 000000000..0bcfd7d77 --- /dev/null +++ b/sources/pyside2/doc/tutorials/basictutorial/icons.png diff --git a/sources/pyside2/doc/tutorials/basictutorial/icons/forward.png b/sources/pyside2/doc/tutorials/basictutorial/icons/forward.png Binary files differnew file mode 100644 index 000000000..c7a532dfe --- /dev/null +++ b/sources/pyside2/doc/tutorials/basictutorial/icons/forward.png diff --git a/sources/pyside2/doc/tutorials/basictutorial/icons/pause.png b/sources/pyside2/doc/tutorials/basictutorial/icons/pause.png Binary files differnew file mode 100644 index 000000000..d0beadb43 --- /dev/null +++ b/sources/pyside2/doc/tutorials/basictutorial/icons/pause.png diff --git a/sources/pyside2/doc/tutorials/basictutorial/icons/play.png b/sources/pyside2/doc/tutorials/basictutorial/icons/play.png Binary files differnew file mode 100644 index 000000000..345685337 --- /dev/null +++ b/sources/pyside2/doc/tutorials/basictutorial/icons/play.png diff --git a/sources/pyside2/doc/tutorials/basictutorial/icons/previous.png b/sources/pyside2/doc/tutorials/basictutorial/icons/previous.png Binary files differnew file mode 100644 index 000000000..979f18565 --- /dev/null +++ b/sources/pyside2/doc/tutorials/basictutorial/icons/previous.png diff --git a/sources/pyside2/doc/tutorials/basictutorial/icons/stop.png b/sources/pyside2/doc/tutorials/basictutorial/icons/stop.png Binary files differnew file mode 100644 index 000000000..1e88ded3a --- /dev/null +++ b/sources/pyside2/doc/tutorials/basictutorial/icons/stop.png diff --git a/sources/pyside2/doc/tutorials/basictutorial/player-new.png b/sources/pyside2/doc/tutorials/basictutorial/player-new.png Binary files differnew file mode 100644 index 000000000..e1f660e5f --- /dev/null +++ b/sources/pyside2/doc/tutorials/basictutorial/player-new.png diff --git a/sources/pyside2/doc/tutorials/basictutorial/player.png b/sources/pyside2/doc/tutorials/basictutorial/player.png Binary files differnew file mode 100644 index 000000000..3060a990d --- /dev/null +++ b/sources/pyside2/doc/tutorials/basictutorial/player.png diff --git a/sources/pyside2/doc/tutorials/basictutorial/qrcfiles.rst b/sources/pyside2/doc/tutorials/basictutorial/qrcfiles.rst new file mode 100644 index 000000000..2f986875c --- /dev/null +++ b/sources/pyside2/doc/tutorials/basictutorial/qrcfiles.rst @@ -0,0 +1,169 @@ +Using `.qrc` Files (`pyside2-rcc`) +********************************** + +The `Qt Resource System`_ is a mechanism for storing binary files +in an application. + +The most common uses are for custom images, icons, fonts, among others. + +In this tutorial you will learn how to load custom images as button icons. + +For inspiration, we will try to adapt the multimedia player example +from Qt. + +As you can see on the following image, the `QPushButton` that are used +for the media actions (play, pause, stop, and so on) are using the +default icons meant for such actions. + +.. image:: player.png + :alt: Multimedia Player Qt Example + +You could make the application more attractive by designing the icons, +but in case you don't want to design them, `download the following set`_ +and use them. + +.. image:: icons.png + :alt: New Multimedia icons + +You can find more information about the `rcc` command, and `.qrc` file +format, and the resource system in general in the `Qt Resource System`_ +site. + +.. _`download the following set`: icons/ + + +The `.qrc` file +================ + +Before running any command, add information about the resources to a `.qrc` +file. +In the following example, notice how the resources are listed in `icons.qrc` + +:: + + </ui> + <!DOCTYPE RCC><RCC version="1.0"> + <qresource> + <file>icons/play.png</file> + <file>icons/pause.png</file> + <file>icons/stop.png</file> + <file>icons/previous.png</file> + <file>icons/forward.png</file> + </qresource> + </RCC> + + +Generating a Python file +========================= + +Now that the `icons.qrc` file is ready, use the `pyside2-rcc` tool to generate +a Python class containing the binary information about the resources + +To do this, we need to run:: + + pyside2-rcc icons.rc -o rc_icons.py + +The `-o` option lets you specify the output filename, +which is `rc_icons.py` in this case. + +To use the generated file, add the following import at the top of your main Python file:: + + import rc_icons + + +Changes in the code +=================== + +As you are modifying an existing example, you need to modify the following +lines: + +.. code-block:: python + + from PySide2.QtGui import QIcon, QKeySequence + playIcon = self.style().standardIcon(QStyle.SP_MediaPlay) + previousIcon = self.style().standardIcon(QStyle.SP_MediaSkipBackward) + pauseIcon = self.style().standardIcon(QStyle.SP_MediaPause) + nextIcon = self.style().standardIcon(QStyle.SP_MediaSkipForward) + stopIcon = self.style().standardIcon(QStyle.SP_MediaStop) + +and replace them with the following: + +.. code-block:: python + + from PySide2.QtGui import QIcon, QKeySequence, QPixmap + playIcon = QIcon(QPixmap(":/icons/play.png")) + previousIcon = QIcon(QPixmap(":/icons/previous.png")) + pauseIcon = QIcon(QPixmap(":/icons/pause.png")) + nextIcon = QIcon(QPixmap(":/icons/forward.png")) + stopIcon = QIcon(QPixmap(":/icons/stop.png")) + +This ensures that the new icons are used instead of the default ones provided +by the application theme. +Notice that the lines are not consecutive, but are in different parts +of the file. + +After all your imports, add the following + +.. code-block:: python + + import rc_icons + +Now, the constructor of your class should look like this: + +.. code-block:: python + + def __init__(self): + super(MainWindow, self).__init__() + + self.playlist = QMediaPlaylist() + self.player = QMediaPlayer() + + toolBar = QToolBar() + self.addToolBar(toolBar) + + fileMenu = self.menuBar().addMenu("&File") + openAction = QAction(QIcon.fromTheme("document-open"), + "&Open...", self, shortcut=QKeySequence.Open, + triggered=self.open) + fileMenu.addAction(openAction) + exitAction = QAction(QIcon.fromTheme("application-exit"), "E&xit", + self, shortcut="Ctrl+Q", triggered=self.close) + fileMenu.addAction(exitAction) + + playMenu = self.menuBar().addMenu("&Play") + playIcon = QIcon(QPixmap(":/icons/play.png")) + self.playAction = toolBar.addAction(playIcon, "Play") + self.playAction.triggered.connect(self.player.play) + playMenu.addAction(self.playAction) + + previousIcon = QIcon(QPixmap(":/icons/previous.png")) + self.previousAction = toolBar.addAction(previousIcon, "Previous") + self.previousAction.triggered.connect(self.previousClicked) + playMenu.addAction(self.previousAction) + + pauseIcon = QIcon(QPixmap(":/icons/pause.png")) + self.pauseAction = toolBar.addAction(pauseIcon, "Pause") + self.pauseAction.triggered.connect(self.player.pause) + playMenu.addAction(self.pauseAction) + + nextIcon = QIcon(QPixmap(":/icons/forward.png")) + self.nextAction = toolBar.addAction(nextIcon, "Next") + self.nextAction.triggered.connect(self.playlist.next) + playMenu.addAction(self.nextAction) + + stopIcon = QIcon(QPixmap(":/icons/stop.png")) + self.stopAction = toolBar.addAction(stopIcon, "Stop") + self.stopAction.triggered.connect(self.player.stop) + playMenu.addAction(self.stopAction) + + # many lines were omitted + +Executing the example +===================== + +Run the application by calling `python main.py` to checkout the new icon-set: + +.. image:: player-new.png + :alt: New Multimedia Player Qt Example + +.. _`Qt Resource System`: https://doc.qt.io/qt-5/resources.html diff --git a/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst b/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst index 2c0178e2e..2a0d65e46 100644 --- a/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst +++ b/sources/pyside2/doc/tutorials/basictutorial/uifiles.rst @@ -1,5 +1,5 @@ -Using UI Files -*************** +Using `.ui` Files (`QUiLoader` and `pyside2-uic`) +************************************************* This page describes the use of Qt Creator to create graphical interfaces for your Qt for Python project. diff --git a/sources/pyside2/doc/tutorials/index.rst b/sources/pyside2/doc/tutorials/index.rst index 73e6b6b26..598b42ca1 100644 --- a/sources/pyside2/doc/tutorials/index.rst +++ b/sources/pyside2/doc/tutorials/index.rst @@ -18,6 +18,7 @@ Basic tutorials basictutorial/clickablebutton.rst basictutorial/dialog.rst basictutorial/uifiles.rst + basictutorial/qrcfiles.rst Real use-cases applications --------------------------- diff --git a/sources/pyside2/libpyside/pysideweakref.cpp b/sources/pyside2/libpyside/pysideweakref.cpp index 84b390e96..cd90634bd 100644 --- a/sources/pyside2/libpyside/pysideweakref.cpp +++ b/sources/pyside2/libpyside/pysideweakref.cpp @@ -98,11 +98,6 @@ PyObject *create(PyObject *obj, PySideWeakRefFunction func, void *userData) PySideCallableObject *callable = PyObject_New(PySideCallableObject, type); if (!callable || PyErr_Occurred()) return 0; - if (!PepRuntime_38_flag) { - // PYSIDE-939: Handling references correctly. - // Workaround for Python issue 35810; no longer necessary in Python 3.8 - Py_INCREF(type); - } PyObject *weak = PyWeakref_NewRef(obj, reinterpret_cast<PyObject *>(callable)); if (!weak || PyErr_Occurred()) diff --git a/sources/pyside2/pyside_version.py b/sources/pyside2/pyside_version.py index c022fc803..f5ef03613 100644 --- a/sources/pyside2/pyside_version.py +++ b/sources/pyside2/pyside_version.py @@ -44,7 +44,7 @@ patch_version = "0" # For example: "a", "b", "rc" # (which means "alpha", "beta", "release candidate"). # An empty string means the generated package will be an official release. -pre_release_version_type = "a" +release_version_type = "a" # For example: "1", "2" (which means "beta1", "beta2", if type is "b"). pre_release_version = "1" @@ -52,4 +52,4 @@ pre_release_version = "1" if __name__ == '__main__': # Used by CMake. print('{0};{1};{2};{3};{4}'.format(major_version, minor_version, patch_version, - pre_release_version_type, pre_release_version)) + release_version_type, pre_release_version)) diff --git a/sources/pyside2/tests/QtCore/qenum_test.py b/sources/pyside2/tests/QtCore/qenum_test.py index dd91d1581..1edb8981a 100644 --- a/sources/pyside2/tests/QtCore/qenum_test.py +++ b/sources/pyside2/tests/QtCore/qenum_test.py @@ -30,15 +30,18 @@ '''Test cases for QEnum and QFlags''' +import gc import os import sys +import pickle 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 * +from PySide2.QtCore import Qt, QIODevice + class TestEnum(unittest.TestCase): @@ -73,6 +76,23 @@ class TestEnum(unittest.TestCase): with self.assertRaises(TypeError): a = k*2.0 + @unittest.skipUnless(getattr(sys, "getobjects", None), "requires debug build") + def testEnumNew_NoLeak(self): + gc.collect() + total = sys.gettotalrefcount() + for idx in range(1000): + ret = Qt.Key(42) + gc.collect() + delta = sys.gettotalrefcount() - total + print("delta total refcount =", delta) + if abs(delta) >= 10: + all = sys.getobjects(0) + all.sort(key=lambda x: sys.getrefcount(x), reverse=True) + for ob in all[:10]: + print(sys.getrefcount(ob), ob) + self.assertTrue(abs(delta) < 10) + + class TestQFlags(unittest.TestCase): def testToItn(self): om = QIODevice.NotOpen @@ -94,5 +114,33 @@ class TestQFlags(unittest.TestCase): except: pass + +# PYSIDE-15: Pickling of enums +class TestEnumPickling(unittest.TestCase): + def testPickleEnum(self): + + # Pickling of enums with different depth works. + ret = pickle.loads(pickle.dumps(QIODevice.Append)) + self.assertEqual(ret, QIODevice.Append) + + ret = pickle.loads(pickle.dumps(Qt.Key.Key_Asterisk)) + self.assertEqual(ret, Qt.Key.Key_Asterisk) + self.assertEqual(ret, Qt.Key(42)) + + # We can also pickle the whole enum class (built in): + ret = pickle.loads(pickle.dumps(QIODevice)) + + # This works also with nested classes for Python 3, after we + # introduced the correct __qualname__ attribute. + + # Note: For Python 2, we would need quite strange patches. + func = lambda: pickle.loads(pickle.dumps(Qt.Key)) + if sys.version_info[0] < 3: + with self.assertRaises(pickle.PicklingError): + func() + else: + func() + + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtQuickControls2/CMakeLists.txt b/sources/pyside2/tests/QtQuickControls2/CMakeLists.txt new file mode 100644 index 000000000..2f7cb08b9 --- /dev/null +++ b/sources/pyside2/tests/QtQuickControls2/CMakeLists.txt @@ -0,0 +1 @@ +# Please add some tests, here diff --git a/sources/pyside2/tests/QtSerialPort/serial.py b/sources/pyside2/tests/QtSerialPort/serial.py index c30d9eb03..7c0839d8e 100644 --- a/sources/pyside2/tests/QtSerialPort/serial.py +++ b/sources/pyside2/tests/QtSerialPort/serial.py @@ -39,20 +39,57 @@ from init_paths import init_test_paths init_test_paths(False) from PySide2.QtSerialPort import QSerialPort, QSerialPortInfo +from PySide2.QtCore import QIODevice +class QSerialPortTest(unittest.TestCase): + def testDefaultConstructedPort(self): + serialPort = QSerialPort() -def callPortInfoMemberFunctions(portinfo): - portinfo.description() - portinfo.hasProductIdentifier() - portinfo.hasVendorIdentifier() - portinfo.isNull() + self.assertEqual(serialPort.error(), QSerialPort.NoError) + self.assertTrue(not serialPort.errorString() == "") + + # properties + defaultBaudRate = QSerialPort.Baud9600 + self.assertEqual(serialPort.baudRate(), defaultBaudRate) + self.assertEqual(serialPort.baudRate(QSerialPort.Input), defaultBaudRate) + self.assertEqual(serialPort.baudRate(QSerialPort.Output), defaultBaudRate) + self.assertEqual(serialPort.dataBits(), QSerialPort.Data8) + self.assertEqual(serialPort.parity(), QSerialPort.NoParity) + self.assertEqual(serialPort.stopBits(), QSerialPort.OneStop) + self.assertEqual(serialPort.flowControl(), QSerialPort.NoFlowControl) + + self.assertEqual(serialPort.pinoutSignals(), QSerialPort.NoSignal) + self.assertEqual(serialPort.isRequestToSend(), False) + self.assertEqual(serialPort.isDataTerminalReady(), False) + + # QIODevice + self.assertEqual(serialPort.openMode(), QIODevice.NotOpen) + self.assertTrue(not serialPort.isOpen()) + self.assertTrue(not serialPort.isReadable()) + self.assertTrue(not serialPort.isWritable()) + self.assertTrue(serialPort.isSequential()) + self.assertEqual(serialPort.canReadLine(), False) + self.assertEqual(serialPort.pos(), 0) + self.assertEqual(serialPort.size(), 0) + self.assertTrue(serialPort.atEnd()) + self.assertEqual(serialPort.bytesAvailable(), 0) + self.assertEqual(serialPort.bytesToWrite(), 0) + + def testOpenExisting(self): + allportinfos = QSerialPortInfo.availablePorts() + for portinfo in allportinfos: + serialPort = QSerialPort(portinfo) + self.assertEqual(serialPort.portName(), portinfo.portName()) class QSerialPortInfoTest(unittest.TestCase): def test_available_ports(self): allportinfos = QSerialPortInfo.availablePorts() for portinfo in allportinfos: - callPortInfoMemberFunctions(portinfo) + portinfo.description() + portinfo.hasProductIdentifier() + portinfo.hasVendorIdentifier() + portinfo.isNull() if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtUiTools/loadUiType_test.py b/sources/pyside2/tests/QtUiTools/loadUiType_test.py new file mode 100644 index 000000000..9a3756376 --- /dev/null +++ b/sources/pyside2/tests/QtUiTools/loadUiType_test.py @@ -0,0 +1,75 @@ +############################################################################# +## +## 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 helper.usesqapplication import UsesQApplication + +from PySide2.QtWidgets import QWidget, QFrame, QPushButton +from PySide2.QtUiTools import loadUiType + +class loadUiTypeTester(UsesQApplication): + def testFunction(self): + filePath = os.path.join(os.path.dirname(__file__), "minimal.ui") + loaded = loadUiType(filePath) + self.assertNotEqual(loaded, None) + + # (<class '__main__.Ui_Form'>, <class 'PySide2.QtWidgets.QFrame'>) + generated, base = loaded + + # Generated class contains retranslateUi method + self.assertTrue("retranslateUi" in dir(generated)) + + # Base class instance will be QFrame for this example + self.assertTrue(isinstance(base(), QFrame)) + + anotherFileName = os.path.join(os.path.dirname(__file__), "test.ui") + another = loadUiType(anotherFileName) + self.assertNotEqual(another, None) + + generated, base = another + # Base class instance will be QWidget for this example + self.assertTrue(isinstance(base(), QWidget)) + + w = base() + ui = generated() + ui.setupUi(w) + + self.assertTrue(isinstance(ui.child_object, QFrame)) + self.assertTrue(isinstance(ui.grandson_object, QPushButton)) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/QtWidgets/qwidget_test.py b/sources/pyside2/tests/QtWidgets/qwidget_test.py index 74e97d7be..5e94a8248 100644 --- a/sources/pyside2/tests/QtWidgets/qwidget_test.py +++ b/sources/pyside2/tests/QtWidgets/qwidget_test.py @@ -61,7 +61,9 @@ class QWidgetTest(UsesQApplication): if sys.version_info[0] < 3: def testCallType_Issue_816(self): thing = type(QWidget).__new__(type(QWidget), "", (), {}) - self.assertEqual(repr(thing), "<class '__main__.'>") + # PYSIDE-1286: This works now like in Python 3 + #self.assertEqual(repr(thing), "<class '__main__.'>") + self.assertEqual(repr(thing), "<class '__main__.ObjectType'>") class QWidgetVisible(UsesQApplication): diff --git a/sources/pyside2/tests/registry/existence_test.py b/sources/pyside2/tests/registry/existence_test.py index 4bfd63cc3..b8a42058d 100644 --- a/sources/pyside2/tests/registry/existence_test.py +++ b/sources/pyside2/tests/registry/existence_test.py @@ -1,6 +1,6 @@ ############################################################################# ## -## Copyright (C) 2019 The Qt Company Ltd. +## Copyright (C) 2020 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of Qt for Python. @@ -67,6 +67,7 @@ List entry """ import os +import re import sys from textwrap import dedent import unittest @@ -144,8 +145,19 @@ class TestSignaturesExists(unittest.TestCase): name = key.rsplit(".", 1)[-1] if name in ("next", "__next__"): # ignore problematic cases continue + if "<" in key: + # Skip over remaining crap in "<...>" + continue + if key.startswith("sample.SampleNamespace"): + # We cannot work with sample namespaces after the change to __qualname__. + continue + if (key.startswith("smart.SharedPtr") or + re.match(r"PySide2\..*?\.QSharedPointer_", key)): + # These mangled names are not supported. + # We should fix them. + continue if key not in found_sigs: - warn("missing key: '{}'".format(key), stacklevel=3) + warn("missing key: '{} value={}'".format(key, value), stacklevel=3) else: found_val = found_sigs[key] if type(value) is list and ( diff --git a/sources/shiboken2/ApiExtractor/CMakeLists.txt b/sources/shiboken2/ApiExtractor/CMakeLists.txt index de6bf019f..f8e504583 100644 --- a/sources/shiboken2/ApiExtractor/CMakeLists.txt +++ b/sources/shiboken2/ApiExtractor/CMakeLists.txt @@ -84,7 +84,7 @@ endif() target_compile_definitions(apiextractor PRIVATE CMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}") -set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE) +set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE) if (BUILD_TESTS) find_package(Qt${QT_MAJOR_VERSION}Test 5.12 REQUIRED) diff --git a/sources/shiboken2/generator/CMakeLists.txt b/sources/shiboken2/generator/CMakeLists.txt index e311d400e..1a3f4e5c4 100644 --- a/sources/shiboken2/generator/CMakeLists.txt +++ b/sources/shiboken2/generator/CMakeLists.txt @@ -30,7 +30,7 @@ configure_file(shibokenconfig.h.in "${CMAKE_CURRENT_BINARY_DIR}/shibokenconfig.h install(TARGETS shiboken2 EXPORT Shiboken2Targets - DESTINATION bin) + DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") set(shiboken_generator_package_name "shiboken2_generator") diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 52892663e..4c637e701 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -4646,8 +4646,6 @@ void CppGenerator::writeSignatureInfo(QTextStream &s, const AbstractMetaFunction strArg += QLatin1Char('='); QString e = arg->defaultValueExpression(); e.replace(QLatin1String("::"), QLatin1String(".")); - // the tests insert stuff like Str("<unknown>"): - e.replace(QLatin1Char('"'), QLatin1String("\\\"")); strArg += e; } args << arg->name() + QLatin1Char(':') + strArg; @@ -4976,6 +4974,20 @@ QString CppGenerator::getInitFunctionName(const GeneratorContext &context) const : getFilteredCppSignatureString(context.preciseType()->cppSignature()); } +void CppGenerator::writeSignatureStrings(QTextStream &s, + QTextStream &signatureStream, + const QString &arrayName, + const char *comment) const +{ + s << "// The signatures string for the " << comment << ".\n"; + s << "// Multiple signatures have their index \"n:\" in front.\n"; + s << "static const char *" << arrayName << "_SignatureStrings[] = {\n"; + QString line; + while (signatureStream.readLineInto(&line)) + s << INDENT << "R\"CPP(" << line << ")CPP\",\n"; + s << INDENT << NULL_PTR << "}; // Sentinel\n\n"; +} + void CppGenerator::writeClassRegister(QTextStream &s, const AbstractMetaClass *metaClass, const GeneratorContext &classContext, @@ -4990,13 +5002,7 @@ void CppGenerator::writeClassRegister(QTextStream &s, QString initFunctionName = getInitFunctionName(classContext); // PYSIDE-510: Create a signatures string for the introspection feature. - s << "// The signatures string for the functions.\n"; - s << "// Multiple signatures have their index \"n:\" in front.\n"; - s << "static const char *" << initFunctionName << "_SignatureStrings[] = {\n"; - QString line; - while (signatureStream.readLineInto(&line)) - s << INDENT << '"' << line << "\",\n"; - s << INDENT << NULL_PTR << "}; // Sentinel\n\n"; + writeSignatureStrings(s, signatureStream, initFunctionName, "functions"); s << "void init_" << initFunctionName; s << "(PyObject *" << enclosingObjectVariable << ")\n{\n"; @@ -5802,13 +5808,7 @@ bool CppGenerator::finishGeneration() s << "#endif\n\n"; // PYSIDE-510: Create a signatures string for the introspection feature. - s << "// The signatures string for the global functions.\n"; - s << "// Multiple signatures have their index \"n:\" in front.\n"; - s << "static const char *" << moduleName() << "_SignatureStrings[] = {\n"; - QString line; - while (signatureStream.readLineInto(&line)) - s << INDENT << '"' << line << "\",\n"; - s << INDENT << NULL_PTR << "}; // Sentinel\n\n"; + writeSignatureStrings(s, signatureStream, moduleName(), "global functions"); s << "SBK_MODULE_INIT_FUNCTION_BEGIN(" << moduleName() << ")\n"; diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.h b/sources/shiboken2/generator/shiboken2/cppgenerator.h index 7308f7d18..4e995d56f 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.h +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.h @@ -249,6 +249,9 @@ private: QString getInitFunctionName(const GeneratorContext &context) const; QString getSimpleClassInitFunctionName(const AbstractMetaClass *metaClass) const; + void writeSignatureStrings(QTextStream &s, QTextStream &signatureStream, + const QString &arrayName, + const char *comment) const; void writeClassRegister(QTextStream &s, const AbstractMetaClass *metaClass, const GeneratorContext &classContext, diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index 5543427fc..443d25cdf 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -104,6 +104,23 @@ static PyGetSetDef SbkObjectType_Type_getsetlist[] = { {nullptr} // Sentinel }; +#if PY_VERSION_HEX < 0x03000000 + +static PyObject *SbkObjectType_repr(PyObject *type) +{ + Shiboken::AutoDecRef mod(PyObject_GetAttr(type, Shiboken::PyMagicName::module())); + if (mod.isNull()) + return nullptr; + Shiboken::AutoDecRef name(PyObject_GetAttr(type, Shiboken::PyMagicName::qualname())); + if (name.isNull()) + return nullptr; + return PyString_FromFormat("<class '%s.%s'>", + PyString_AS_STRING(mod.object()), + PyString_AS_STRING(name.object())); +} + +#endif // PY_VERSION_HEX < 0x03000000 + static PyType_Slot SbkObjectType_Type_slots[] = { {Py_tp_dealloc, reinterpret_cast<void *>(SbkObjectTypeDealloc)}, {Py_tp_setattro, reinterpret_cast<void *>(PyObject_GenericSetAttr)}, @@ -112,6 +129,9 @@ static PyType_Slot SbkObjectType_Type_slots[] = { {Py_tp_new, reinterpret_cast<void *>(SbkObjectTypeTpNew)}, {Py_tp_free, reinterpret_cast<void *>(PyObject_GC_Del)}, {Py_tp_getset, reinterpret_cast<void *>(SbkObjectType_Type_getsetlist)}, +#if PY_VERSION_HEX < 0x03000000 + {Py_tp_repr, reinterpret_cast<void *>(SbkObjectType_repr)}, +#endif {0, nullptr} }; static PyType_Spec SbkObjectType_Type_spec = { @@ -633,11 +653,42 @@ PyObject *SbkType_FromSpec(PyType_Spec *spec) PyObject *SbkType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) { + // PYSIDE-1286: Generate correct __module__ and __qualname__ + // The name field can now be extended by an "n:" prefix which is + // the number of modules in the name. The default is 1. + // + // Example: + // "2:mainmod.submod.mainclass.subclass" + // results in + // __module__ : "mainmod.submod" + // __qualname__ : "mainclass.subclass" + // __name__ : "subclass" + PyType_Spec new_spec = *spec; const char *colon = strchr(spec->name, ':'); assert(colon); - new_spec.name = colon + 1; - return PyType_FromSpecWithBases(&new_spec, bases); + int package_level = atoi(spec->name); + const char *mod = new_spec.name = colon + 1; + + PyObject *type = PyType_FromSpecWithBases(&new_spec, bases); + if (type == nullptr) + return nullptr; + + const char *qual = mod; + for (int idx = package_level; idx > 0; --idx) { + const char *dot = strchr(qual, '.'); + if (!dot) + break; + qual = dot + 1; + } + int mlen = qual - mod - 1; + Shiboken::AutoDecRef module(Shiboken::String::fromCString(mod, mlen)); + Shiboken::AutoDecRef qualname(Shiboken::String::fromCString(qual)); + if (PyObject_SetAttr(type, Shiboken::PyMagicName::module(), module) < 0) + return nullptr; + if (PyObject_SetAttr(type, Shiboken::PyMagicName::qualname(), qualname) < 0) + return nullptr; + return type; } } //extern "C" diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp index c04848eb3..f07cac613 100644 --- a/sources/shiboken2/libshiboken/pep384impl.cpp +++ b/sources/shiboken2/libshiboken/pep384impl.cpp @@ -638,6 +638,38 @@ PepType_GetNameStr(PyTypeObject *type) /***************************************************************************** * + * Newly introduced convenience functions + * + */ +#if PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API) + +PyObject * +PyImport_GetModule(PyObject *name) +{ + PyObject *m; + PyObject *modules = PyImport_GetModuleDict(); + if (modules == NULL) { + PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules"); + return NULL; + } + Py_INCREF(modules); + if (PyDict_CheckExact(modules)) { + m = PyDict_GetItemWithError(modules, name); /* borrowed */ + Py_XINCREF(m); + } + else { + m = PyObject_GetItem(modules, name); + if (m == NULL && PyErr_ExceptionMatches(PyExc_KeyError)) { + PyErr_Clear(); + } + } + Py_DECREF(modules); + return m; +} + +#endif // PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API) +/***************************************************************************** + * * Extra support for name mangling * */ diff --git a/sources/shiboken2/libshiboken/pep384impl.h b/sources/shiboken2/libshiboken/pep384impl.h index e735095e8..541b0e775 100644 --- a/sources/shiboken2/libshiboken/pep384impl.h +++ b/sources/shiboken2/libshiboken/pep384impl.h @@ -523,6 +523,16 @@ extern LIBSHIBOKEN_API PyTypeObject *PepMethodDescr_TypePtr; /***************************************************************************** * + * Newly introduced convenience functions + * + * This is not defined if Py_LIMITED_API is defined. + */ +#if PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API) +LIBSHIBOKEN_API PyObject *PyImport_GetModule(PyObject *name); +#endif // PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API) + +/***************************************************************************** + * * Runtime support for Python 3.8 incompatibilities * */ diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp index f49623440..36f2f48f9 100644 --- a/sources/shiboken2/libshiboken/sbkenum.cpp +++ b/sources/shiboken2/libshiboken/sbkenum.cpp @@ -107,16 +107,18 @@ static PyObject *SbkEnum_tp_new(PyTypeObject *type, PyObject *args, PyObject *) if (!self) return nullptr; self->ob_value = itemValue; - PyObject *item = Shiboken::Enum::getEnumItemFromValue(type, itemValue); - if (item) { - self->ob_name = SbkEnumObject_name(item, nullptr); - Py_XDECREF(item); - } else { - self->ob_name = nullptr; - } + Shiboken::AutoDecRef item(Shiboken::Enum::getEnumItemFromValue(type, itemValue)); + self->ob_name = item.object() ? SbkEnumObject_name(item, nullptr) : nullptr; return reinterpret_cast<PyObject *>(self); } +void enum_object_dealloc(PyObject *ob) +{ + auto self = reinterpret_cast<SbkEnumObject *>(ob); + Py_XDECREF(self->ob_name); + Sbk_object_dealloc(ob); +} + static PyObject *enum_op(enum_func f, PyObject *a, PyObject *b) { PyObject *valA = a; PyObject *valB = b; @@ -260,6 +262,23 @@ static PyGetSetDef SbkEnumGetSetList[] = { {nullptr, nullptr, nullptr, nullptr, nullptr} // Sentinel }; +#if PY_VERSION_HEX < 0x03000000 + +static PyObject *SbkEnumType_repr(PyObject *type) +{ + Shiboken::AutoDecRef mod(PyObject_GetAttr(type, Shiboken::PyMagicName::module())); + if (mod.isNull()) + return nullptr; + Shiboken::AutoDecRef name(PyObject_GetAttr(type, Shiboken::PyMagicName::qualname())); + if (name.isNull()) + return nullptr; + return PyString_FromFormat("<class '%s.%s'>", + PyString_AS_STRING(mod.object()), + PyString_AS_STRING(name.object())); +} + +#endif // PY_VERSION_HEX < 0x03000000 + static void SbkEnumTypeDealloc(PyObject *pyObj); static PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds); @@ -287,6 +306,9 @@ static PyType_Slot SbkEnumType_Type_slots[] = { {Py_tp_alloc, (void *)PyType_GenericAlloc}, {Py_tp_new, (void *)SbkEnumTypeTpNew}, {Py_tp_free, (void *)PyObject_GC_Del}, +#if PY_VERSION_HEX < 0x03000000 + {Py_tp_repr, (void *)SbkEnumType_repr}, +#endif {0, nullptr} }; static PyType_Spec SbkEnumType_Type_spec = { @@ -341,6 +363,107 @@ PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwd } // extern "C" +/////////////////////////////////////////////////////////////// +// +// PYSIDE-15: Pickling Support for Qt Enum objects +// This works very well and fixes the issue. +// +extern "C" { + +static void init_enum(); // forward + +static PyObject *enum_unpickler = nullptr; + +// Pickling: reduce the Qt Enum object +static PyObject *enum___reduce__(PyObject *obj) +{ + init_enum(); + return Py_BuildValue("O(Ni)", + enum_unpickler, + Py_BuildValue("s", Py_TYPE(obj)->tp_name), + PyInt_AS_LONG(obj)); +} + +} // extern "C" + +namespace Shiboken { namespace Enum { + +// Unpickling: rebuild the Qt Enum object +PyObject *unpickleEnum(PyObject *enum_class_name, PyObject *value) +{ + Shiboken::AutoDecRef parts(PyObject_CallMethod(enum_class_name, + const_cast<char *>("split"), const_cast<char *>("s"), ".")); + if (parts.isNull()) + return nullptr; + PyObject *top_name = PyList_GetItem(parts, 0); // borrowed ref + if (top_name == nullptr) + return nullptr; + PyObject *module = PyImport_GetModule(top_name); + if (module == nullptr) { + PyErr_Format(PyExc_ImportError, "could not import module %.200s", + Shiboken::String::toCString(top_name)); + return nullptr; + } + Shiboken::AutoDecRef cur_thing(module); + int len = PyList_Size(parts); + for (int idx = 1; idx < len; ++idx) { + PyObject *name = PyList_GetItem(parts, idx); // borrowed ref + PyObject *thing = PyObject_GetAttr(cur_thing, name); + if (thing == nullptr) { + PyErr_Format(PyExc_ImportError, "could not import Qt Enum type %.200s", + Shiboken::String::toCString(enum_class_name)); + return nullptr; + } + cur_thing.reset(thing); + } + PyObject *klass = cur_thing; + return PyObject_CallFunctionObjArgs(klass, value, nullptr); +} + +} // namespace Enum +} // namespace Shiboken + +extern "C" { + +// Initialization +static bool _init_enum() +{ + static PyObject *shiboken_name = Py_BuildValue("s", "shiboken2"); + if (shiboken_name == nullptr) + return false; + Shiboken::AutoDecRef shibo(PyImport_GetModule(shiboken_name)); + if (shibo.isNull()) + return false; + Shiboken::AutoDecRef sub(PyObject_GetAttr(shibo, shiboken_name)); + PyObject *mod = sub.object(); + if (mod == nullptr) { + // We are in the build dir and already in shiboken. + PyErr_Clear(); + mod = shibo.object(); + } + enum_unpickler = PyObject_GetAttrString(mod, "_unpickle_enum"); + if (enum_unpickler == nullptr) + return false; + return true; +} + +static void init_enum() +{ + if (!(enum_unpickler || _init_enum())) + Py_FatalError("could not load enum pickling helper function"); +} + +static PyMethodDef SbkEnumObject_Methods[] = { + {const_cast<char *>("__reduce__"), reinterpret_cast<PyCFunction>(enum___reduce__), + METH_NOARGS, nullptr}, + {nullptr, nullptr, 0, nullptr} // Sentinel +}; + +} // extern "C" + +// +/////////////////////////////////////////////////////////////// + namespace Shiboken { class DeclaredEnumTypes @@ -376,7 +499,7 @@ PyObject *getEnumItemFromValue(PyTypeObject *enumType, long itemValue) while (PyDict_Next(values, &pos, &key, &value)) { auto *obj = reinterpret_cast<SbkEnumObject *>(value); if (obj->ob_value == itemValue) { - Py_INCREF(obj); + Py_INCREF(value); return value; } } @@ -501,6 +624,7 @@ static PyType_Slot SbkNewType_slots[] = { {Py_tp_repr, (void *)SbkEnumObject_repr}, {Py_tp_str, (void *)SbkEnumObject_repr}, {Py_tp_getset, (void *)SbkEnumGetSetList}, + {Py_tp_methods, (void *)SbkEnumObject_Methods}, {Py_tp_new, (void *)SbkEnum_tp_new}, {Py_nb_add, (void *)enum_add}, {Py_nb_subtract, (void *)enum_subtract}, @@ -522,7 +646,7 @@ static PyType_Slot SbkNewType_slots[] = { {Py_nb_index, (void *)enum_int}, {Py_tp_richcompare, (void *)enum_richcompare}, {Py_tp_hash, (void *)enum_hash}, - {Py_tp_dealloc, (void *)Sbk_object_dealloc}, + {Py_tp_dealloc, (void *)enum_object_dealloc}, {0, nullptr} }; static PyType_Spec SbkNewType_spec = { @@ -613,7 +737,6 @@ newTypeWithName(const char *name, newspec->slots = newslots; auto *type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(newspec)); Py_TYPE(type) = SbkEnumType_TypeF(); - Py_INCREF(Py_TYPE(type)); auto *enumType = reinterpret_cast<SbkEnumType *>(type); PepType_SETP(enumType)->cppName = cppName; diff --git a/sources/shiboken2/libshiboken/sbkenum.h b/sources/shiboken2/libshiboken/sbkenum.h index 759d72636..c294c17d9 100644 --- a/sources/shiboken2/libshiboken/sbkenum.h +++ b/sources/shiboken2/libshiboken/sbkenum.h @@ -114,6 +114,8 @@ namespace Enum LIBSHIBOKEN_API void setTypeConverter(PyTypeObject *enumType, SbkConverter *converter); /// Returns the converter assigned to the enum \p type. LIBSHIBOKEN_API SbkConverter *getTypeConverter(PyTypeObject *enumType); + + LIBSHIBOKEN_API PyObject *unpickleEnum(PyObject *, PyObject *); } } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index 5430ab064..ba1fc119e 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -39,6 +39,7 @@ #include "basewrapper.h" #include "autodecref.h" +#include "sbkstring.h" #include "sbkstaticstrings.h" #include "sbkstaticstrings_p.h" @@ -185,7 +186,6 @@ _get_class_of_sm(PyObject *ob_sm) static PyObject * _get_class_of_descr(PyObject *ob) { - Shiboken::AutoDecRef func_name(PyObject_GetAttr(ob, Shiboken::PyMagicName::name())); return PyObject_GetAttr(ob, Shiboken::PyMagicName::objclass()); } @@ -318,6 +318,20 @@ pyside_tp_get___signature__(PyObject *obtype_mod, PyObject *modifier) static PyObject * GetSignature_Cached(PyObject *props, PyObject *func_kind, PyObject *modifier); +// Helper for __qualname__ which might not always exist in Python 2 (type). +static PyObject * +_get_qualname(PyObject *ob) +{ + // We support __qualname__ for types, only. + assert(PyType_Check(ob)); + PyObject *name = PyObject_GetAttr(ob, Shiboken::PyMagicName::qualname()); + if (name == nullptr) { + PyErr_Clear(); + name = PyObject_GetAttr(ob, Shiboken::PyMagicName::name()); + } + return name; +} + static PyObject * GetTypeKey(PyObject *ob) { @@ -334,19 +348,20 @@ GetTypeKey(PyObject *ob) * * This is the PyCFunction behavior, as opposed to Python functions. */ - Shiboken::AutoDecRef class_name(PyObject_GetAttr(ob, Shiboken::PyMagicName::name())); + // PYSIDE-1286: We use correct __module__ and __qualname__, now. Shiboken::AutoDecRef module_name(PyObject_GetAttr(ob, Shiboken::PyMagicName::module())); - - if (module_name.isNull()) + if (module_name.isNull()) { + // We have no module_name because this is a module ;-) PyErr_Clear(); - - // Note: if we have a module, then __module__ is null, and we get - // the module name through __name__ . - if (class_name.isNull()) + module_name.reset(PyObject_GetAttr(ob, Shiboken::PyMagicName::name())); + return Py_BuildValue("O", module_name.object()); + } + Shiboken::AutoDecRef class_name(_get_qualname(ob)); + if (class_name.isNull()) { + Py_FatalError("Signature: missing class name in GetTypeKey"); return nullptr; - if (module_name.object()) - return Py_BuildValue("(OO)", module_name.object(), class_name.object()); - return Py_BuildValue("O", class_name.object()); + } + return Py_BuildValue("(OO)", module_name.object(), class_name.object()); } static PyObject *empty_dict = nullptr; @@ -402,7 +417,6 @@ GetSignature_Wrapper(PyObject *ob, PyObject *modifier) Shiboken::AutoDecRef func_name(PyObject_GetAttr(ob, Shiboken::PyMagicName::name())); Shiboken::AutoDecRef objclass(PyObject_GetAttr(ob, Shiboken::PyMagicName::objclass())); Shiboken::AutoDecRef class_key(GetTypeKey(objclass)); - if (func_name.isNull() || objclass.isNull() || class_key.isNull()) return nullptr; PyObject *dict = TypeKey_to_PropsDict(class_key, objclass); @@ -851,12 +865,15 @@ get_signature(PyObject * /* self */, PyObject *args) //////////////////////////////////////////////////////////////////////////// // a stack trace for linux-like platforms #include <stdio.h> -#include <execinfo.h> +#if defined(__GLIBC__) +# include <execinfo.h> +#endif #include <signal.h> #include <stdlib.h> #include <unistd.h> void handler(int sig) { +#if defined(__GLIBC__) void *array[30]; size_t size; @@ -864,8 +881,11 @@ void handler(int sig) { size = backtrace(array, 30); // print out all the frames to stderr +#endif fprintf(stderr, "Error: signal %d:\n", sig); +#if defined(__GLIBC__) backtrace_symbols_fd(array, size, STDERR_FILENO); +#endif exit(1); } diff --git a/sources/shiboken2/shiboken_version.py b/sources/shiboken2/shiboken_version.py index c022fc803..f5ef03613 100644 --- a/sources/shiboken2/shiboken_version.py +++ b/sources/shiboken2/shiboken_version.py @@ -44,7 +44,7 @@ patch_version = "0" # For example: "a", "b", "rc" # (which means "alpha", "beta", "release candidate"). # An empty string means the generated package will be an official release. -pre_release_version_type = "a" +release_version_type = "a" # For example: "1", "2" (which means "beta1", "beta2", if type is "b"). pre_release_version = "1" @@ -52,4 +52,4 @@ pre_release_version = "1" if __name__ == '__main__': # Used by CMake. print('{0};{1};{2};{3};{4}'.format(major_version, minor_version, patch_version, - pre_release_version_type, pre_release_version)) + release_version_type, pre_release_version)) diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/backport_inspect.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/backport_inspect.py index 1f6d70b31..0f9598c64 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/backport_inspect.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/backport_inspect.py @@ -109,8 +109,13 @@ CO_NOFREE = 0x0040 ############################################################################### + +# PYSIDE-1286: We now use the added __qualname__ for classes. +def _get_class_name(cls): + return getattr(cls, "__qualname__", cls.__name__) + # This function was changed: 'builtins' and 'qualname' don't exist. -# We use '__builtin__' and '__name__' instead. +# We use '__builtin__' and '__(qual)?name__' instead. def formatannotation(annotation, base_module=None): if getattr(annotation, '__module__', None) == 'typing': # The replace must not be done on Python 2.7 because it @@ -118,8 +123,8 @@ def formatannotation(annotation, base_module=None): return repr(annotation) ##.replace('typing.', '') if isinstance(annotation, type): if annotation.__module__ in ('__builtin__', base_module): - return annotation.__name__ - return annotation.__module__+'.'+annotation.__name__ + return _get_class_name(annotation) + return annotation.__module__ + '.' + _get_class_name(annotation) return repr(annotation) @@ -393,7 +398,7 @@ class Parameter(object): return formatted def __repr__(self): - return '<{} "{}">'.format(self.__class__.__name__, self) + return '<{} "{}">'.format(_get_class_name(self.__class__), self) def __hash__(self): return hash((self.name, self.kind, self.annotation, self.default)) @@ -536,7 +541,7 @@ class BoundArguments(object): args = [] for arg, value in self.arguments.items(): args.append('{}={!r}'.format(arg, value)) - return '<{} ({})>'.format(self.__class__.__name__, ', '.join(args)) + return '<{} ({})>'.format(_get_class_name(self.__class__), ', '.join(args)) class Signature(object): @@ -842,7 +847,7 @@ class Signature(object): self._return_annotation = state['_return_annotation'] def __repr__(self): - return '<{} {}>'.format(self.__class__.__name__, self) + return '<{} {}>'.format(_get_class_name(self.__class__), self) def __str__(self): result = [] diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py index 0403358bb..4dbed077d 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py @@ -1,6 +1,6 @@ ############################################################################# ## -## Copyright (C) 2019 The Qt Company Ltd. +## Copyright (C) 2020 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of Qt for Python. diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py index 0417f132a..7af43bea0 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py @@ -70,7 +70,7 @@ def finish_import(module): if func: func(module) except Exception as e: - name = e.__class__.__name__ + name = e.__class__.__qualname__ print(72 * "*") print("Error in deprecated.py, ignored:") print(" {name}: {e}".format(**locals())) diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py index f11f3cf3d..fa4d5e77c 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py @@ -1,6 +1,6 @@ ############################################################################# ## -## Copyright (C) 2018 The Qt Company Ltd. +## Copyright (C) 2020 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of Qt for Python. @@ -100,17 +100,19 @@ class ExactEnumerator(object): return ret def klass(self, class_name, klass): + ret = self.result_type() + if "<" in class_name: + # This is happening in QtQuick for some reason: + ## class QSharedPointer<QQuickItemGrabResult >: + # We simply skip over this class. + return ret bases_list = [] for base in klass.__bases__: name = base.__name__ - if name in ("object", "type"): - pass - else: - modname = base.__module__ - name = modname + "." + base.__name__ + if name not in ("object", "type"): + name = base.__module__ + "." + name bases_list.append(name) class_str = "{}({})".format(class_name, ", ".join(bases_list)) - ret = self.result_type() # class_members = inspect.getmembers(klass) # gives us also the inherited things. class_members = sorted(list(klass.__dict__.items())) diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py index 8d970956b..2053c3e9d 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -165,6 +165,11 @@ def try_to_guess(thing, valtype): return ret return None +def get_name(thing): + if isinstance(thing, type): + return getattr(thing, "__qualname__", thing.__name__) + else: + return thing.__name__ def _resolve_value(thing, valtype, line): if thing in ("0", "None") and valtype: @@ -172,7 +177,7 @@ def _resolve_value(thing, valtype, line): return None map = type_map[valtype] # typing.Any: '_SpecialForm' object has no attribute '__name__' - name = map.__name__ if hasattr(map, "__name__") else str(map) + name = get_name(map) if hasattr(map, "__name__") else str(map) thing = "zero({})".format(name) if thing in type_map: return type_map[thing] @@ -212,7 +217,8 @@ def to_string(thing): return thing if hasattr(thing, "__name__"): dot = "." in str(thing) - return thing.__module__ + "." + thing.__name__ if dot else thing.__name__ + name = get_name(thing) + return thing.__module__ + "." + name if dot else name # Note: This captures things from the typing module: return str(thing) diff --git a/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml b/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml index bdb0c9338..3eba557fb 100644 --- a/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml +++ b/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml @@ -103,6 +103,12 @@ </inject-code> </add-function> + <add-function signature="_unpickle_enum(PyObject*, PyObject*)" return-type="PyObject*"> + <inject-code> + %PYARG_0 = Shiboken::Enum::unpickleEnum(%1, %2); + </inject-code> + </add-function> + <extra-includes> <include file-name="sbkversion.h" location="local"/> <include file-name="voidptr.h" location="local"/> diff --git a/sources/shiboken2/tests/shiboken_test_helper.py b/sources/shiboken2/tests/shiboken_test_helper.py index 2564c91d4..793baf4ad 100644 --- a/sources/shiboken2/tests/shiboken_test_helper.py +++ b/sources/shiboken2/tests/shiboken_test_helper.py @@ -31,8 +31,10 @@ def objectFullname(t): + # '__qualname__' for Python 2 does exist for PySide types, only. + name = getattr(t, "__qualname__", t.__name__) module = t.__module__ if module is None or module == str.__class__.__module__: - return t.__name__ + return name else: - return module + '.' + t.__name__ + return module + '.' + name |