From 427c7147d23fa21c6e8bd08407b1badc48b49c3c Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 22 May 2017 16:44:51 +0200 Subject: move everying into sources/pyside2 (5.9 edition) in preparation for a subtree merge. this should not be necessary to do in a separate commit, but git is a tad stupid about following history correctly without it. --- sources/pyside2/PySide2/QtUiTools/CMakeLists.txt | 46 +++++++ sources/pyside2/PySide2/QtUiTools/glue/plugins.h | 64 +++++++++ .../PySide2/QtUiTools/glue/uitools_loadui.cpp | 91 +++++++++++++ .../PySide2/QtUiTools/typesystem_uitools.xml | 150 +++++++++++++++++++++ 4 files changed, 351 insertions(+) create mode 100644 sources/pyside2/PySide2/QtUiTools/CMakeLists.txt create mode 100644 sources/pyside2/PySide2/QtUiTools/glue/plugins.h create mode 100644 sources/pyside2/PySide2/QtUiTools/glue/uitools_loadui.cpp create mode 100644 sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml (limited to 'sources/pyside2/PySide2/QtUiTools') diff --git a/sources/pyside2/PySide2/QtUiTools/CMakeLists.txt b/sources/pyside2/PySide2/QtUiTools/CMakeLists.txt new file mode 100644 index 000000000..b7ae6974d --- /dev/null +++ b/sources/pyside2/PySide2/QtUiTools/CMakeLists.txt @@ -0,0 +1,46 @@ +project(QtUiTools) + +set(QtUiTools_SRC +${QtUiTools_GEN_DIR}/quiloader_wrapper.cpp +# module is always needed +${QtUiTools_GEN_DIR}/qtuitools_module_wrapper.cpp +) + +make_path(QtUiTools_typesystem_path + ${QtCore_SOURCE_DIR} ${QtGui_SOURCE_DIR} ${QtWidgets_SOURCE_DIR} ${QtXml_SOURCE_DIR} + ${QtCore_BINARY_DIR} ${QtGui_BINARY_DIR} ${QtWidgets_BINARY_DIR} ${QtXml_BINARY_DIR} + ${QtUiTools_SOURCE_DIR}) + +set(QtUiTools_include_dirs ${QtUiTools_SOURCE_DIR} + ${QtUiTools_BINARY_DIR} + ${Qt5Core_INCLUDE_DIRS} + ${Qt5Gui_INCLUDE_DIRS} + ${Qt5Widgets_INCLUDE_DIRS} + ${Qt5Xml_INCLUDE_DIRS} + ${Qt5Designer_INCLUDE_DIRS} + ${Qt5UiTools_INCLUDE_DIRS} + ${SHIBOKEN_PYTHON_INCLUDE_DIR} + ${SHIBOKEN_INCLUDE_DIR} + ${libpyside_SOURCE_DIR} + ${plugins_SOURCE_DIR} + ${QtCore_GEN_DIR} + ${QtXml_GEN_DIR} + ${QtGui_GEN_DIR} + ${QtWidgets_GEN_DIR} + ) +set(QtUiTools_libraries pyside2 + uiplugin + ${SHIBOKEN_PYTHON_LIBRARIES} + ${Qt5UiTools_LIBRARIES} + ${Qt5Core_LIBRARIES} + ${Qt5Gui_LIBRARIES} + ${Qt5Widgets_LIBRARIES} + ) +set(QtUiTools_deps QtWidgets QtXml) +create_pyside_module(QtUiTools + QtUiTools_include_dirs + QtUiTools_libraries + QtUiTools_deps + QtUiTools_typesystem_path + QtUiTools_SRC + "") diff --git a/sources/pyside2/PySide2/QtUiTools/glue/plugins.h b/sources/pyside2/PySide2/QtUiTools/glue/plugins.h new file mode 100644 index 000000000..d550c3fc6 --- /dev/null +++ b/sources/pyside2/PySide2/QtUiTools/glue/plugins.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of PySide2. +** +** $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$ +** +****************************************************************************/ + +#ifndef _PLUGIN_H_ +#define _PLUGIN_H_ + +#include +#include "customwidgets.h" + +inline void registerCustomWidget(PyObject* obj) +{ + static PyCustomWidgets* plugin = 0; + + if (plugin == 0) { + foreach(QObject* o, QPluginLoader::staticInstances()) { + plugin = qobject_cast(o); + if (plugin) + break; + } + } + + if (!plugin) + qDebug() << "Failed to load uiloader plugin."; + else + plugin->registerWidgetType(obj); +} + +#endif diff --git a/sources/pyside2/PySide2/QtUiTools/glue/uitools_loadui.cpp b/sources/pyside2/PySide2/QtUiTools/glue/uitools_loadui.cpp new file mode 100644 index 000000000..9a5d23046 --- /dev/null +++ b/sources/pyside2/PySide2/QtUiTools/glue/uitools_loadui.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of PySide2. +** +** $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$ +** +****************************************************************************/ + +/* + * Based on code provided by: + * Antonio Valentino + * Frédéric + */ + +#include +#include +#include +#include + +static void createChildrenNameAttributes(PyObject* root, QObject* object) +{ + foreach (QObject* child, object->children()) { + const QByteArray name = child->objectName().toLocal8Bit(); + + if (!name.isEmpty() && !name.startsWith("_") && !name.startsWith("qt_")) { + bool hasAttr = PyObject_HasAttrString(root, name.constData()); + if (!hasAttr) { + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QObject*](child)); + PyObject_SetAttrString(root, name.constData(), pyChild); + } + createChildrenNameAttributes(root, child); + } + createChildrenNameAttributes(root, child); + } +} + +static PyObject* QUiLoadedLoadUiFromDevice(QUiLoader* self, QIODevice* dev, QWidget* parent) +{ + QWidget* wdg = self->load(dev, parent); + + if (wdg) { + PyObject* pyWdg = %CONVERTTOPYTHON[QWidget*](wdg); + createChildrenNameAttributes(pyWdg, wdg); + if (parent) { + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget*](parent)); + Shiboken::Object::setParent(pyParent, pyWdg); + } + return pyWdg; + } + + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "Unable to open/read ui device"); + return 0; +} + +static PyObject* QUiLoaderLoadUiFromFileName(QUiLoader* self, const QString& uiFile, QWidget* parent) +{ + QFile fd(uiFile); + return QUiLoadedLoadUiFromDevice(self, &fd, parent); +} diff --git a/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml b/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml new file mode 100644 index 000000000..a74af0076 --- /dev/null +++ b/sources/pyside2/PySide2/QtUiTools/typesystem_uitools.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + Q_IMPORT_PLUGIN(PyCustomWidgets); + + + + + + + Registers a Python created custom widget to QUiLoader, so it can be recognized when + loading a `.ui` file. The custom widget type is passed via the ``customWidgetType`` argument. + This is needed when you want to override a virtual method of some widget in the interface, + since duck punching will not work with widgets created by QUiLoader based on the contents + of the `.ui` file. + + (Remember that `duck punching virtual methods is an invitation for your own demise! + <http://www.pyside.org/docs/shiboken/wordsofadvice.html#duck-punching-and-virtual-methods>`_) + + Let's see an obvious example. If you want to create a new widget it's probable you'll end up + overriding :class:`~PySide2.QtGui.QWidget`'s :meth:`~PySide2.QtGui.QWidget.paintEvent` method. + + .. code-block:: python + + class Circle(QWidget): + def paintEvent(self, event): + painter = QPainter(self) + painter.setPen(self.pen) + painter.setBrush(QBrush(self.color)) + painter.drawEllipse(event.rect().center(), 20, 20) + + # ... + + loader = QUiLoader() + loader.registerCustomWidget(Circle) + circle = loader.load('circle.ui') + circle.show() + + # ... + + + registerCustomWidget(%PYARG_1); + %CPPSELF.addPluginPath(""); // force reload widgets + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + // Avoid calling the original function: %CPPSELF.%FUNCTION_NAME() + %PYARG_0 = QUiLoadedLoadUiFromDevice(%CPPSELF, %1, %2); + + + + + + + + + + + + + + // Avoid calling the original function: %CPPSELF.%FUNCTION_NAME() + %PYARG_0 = QUiLoaderLoadUiFromFileName(%CPPSELF, %1, %2); + + + + + -- cgit v1.2.3