From 4ca11515b6c5376269cb91a4975e8c5b71a2cdb4 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 28 Sep 2016 16:48:53 +0200 Subject: Port QtQuick examples to PySide2 Change-Id: If2d650d2ef47c7e5259d5059dc2b5176c63cc91d Reviewed-by: Friedemann Kleint --- .../declarative/extending/chapter1-basics/app.qml | 26 +++-- .../extending/chapter1-basics/basics.py | 114 +++++++++++-------- .../declarative/extending/chapter2-methods/app.qml | 26 +++-- .../extending/chapter2-methods/methods.py | 113 ++++++++++-------- .../extending/chapter3-bindings/app.qml | 24 ++-- .../extending/chapter3-bindings/bindings.py | 113 ++++++++++-------- .../extending/chapter4-customPropertyTypes/app.qml | 18 +-- .../customPropertyTypes.py | 119 ++++++++++--------- .../extending/chapter5-listproperties/app.qml | 18 +-- .../chapter5-listproperties/listproperties.py | 119 ++++++++++--------- examples/declarative/scrolling.py | 109 ++++++++++-------- examples/declarative/signals/pytoqml1/main.py | 101 +++++++++-------- examples/declarative/signals/pytoqml1/view.qml | 19 ++-- examples/declarative/signals/qmltopy1/main.py | 126 ++++++++++----------- examples/declarative/signals/qmltopy1/view.qml | 20 ++-- examples/declarative/signals/qmltopy2/main.py | 110 +++++++++--------- examples/declarative/signals/qmltopy2/view.qml | 20 ++-- examples/declarative/signals/qmltopy3/README | 2 +- examples/declarative/signals/qmltopy3/main.py | 110 +++++++++--------- examples/declarative/signals/qmltopy3/view.qml | 24 ++-- examples/declarative/signals/qmltopy4/main.py | 103 +++++++++-------- examples/declarative/signals/qmltopy4/view.qml | 20 ++-- examples/declarative/usingmodel.py | 103 +++++++++-------- examples/declarative/view.qml | 30 +++-- examples/utils/utils.py | 49 ++++++++ 25 files changed, 917 insertions(+), 719 deletions(-) create mode 100644 examples/utils/utils.py diff --git a/examples/declarative/extending/chapter1-basics/app.qml b/examples/declarative/extending/chapter1-basics/app.qml index 4d67fc6..60ecd7b 100644 --- a/examples/declarative/extending/chapter1-basics/app.qml +++ b/examples/declarative/extending/chapter1-basics/app.qml @@ -1,11 +1,11 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the QtDeclarative module of the Qt Toolkit. +** This file is part of the PySide examples of the Qt Toolkit. ** +** $QT_BEGIN_LICENSE:BSD$ ** 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 @@ -17,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,10 +34,12 @@ ** (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] import Charts 1.0 -import Qt 4.7 +import QtQuick 2.0 Item { width: 300; height: 200 @@ -51,7 +53,11 @@ Item { } Text { - anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 } + anchors { + bottom: parent.bottom; + horizontalCenter: parent.horizontalCenter; + bottomMargin: 20 + } text: aPieChart.name } } diff --git a/examples/declarative/extending/chapter1-basics/basics.py b/examples/declarative/extending/chapter1-basics/basics.py index 04419c8..64d7ad0 100644 --- a/examples/declarative/extending/chapter1-basics/basics.py +++ b/examples/declarative/extending/chapter1-basics/basics.py @@ -1,53 +1,64 @@ #!/usr/bin/python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# 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 Nokia Corporation and its Subsidiary(-ies) 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." - -import sys -from PySide.QtCore import * -from PySide.QtGui import * -from PySide.QtDeclarative import * - -class PieChart (QDeclarativeItem): +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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 __future__ import print_function + +"""PySide2 port of the qml/tutorials/extending-qml/chapter1-basics example from Qt v5.x""" + +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'utils')) +from utils import text_type + +from PySide2.QtCore import Property, Signal, QUrl +from PySide2.QtGui import QGuiApplication, QPen, QPainter, QColor +from PySide2.QtQml import qmlRegisterType +from PySide2.QtQuick import QQuickPaintedItem, QQuickView + +class PieChart (QQuickPaintedItem): def __init__(self, parent = None): - QDeclarativeItem.__init__(self, parent) - # need to disable this flag to draw inside a QDeclarativeItem - self.setFlag(QGraphicsItem.ItemHasNoContents, False) + QQuickPaintedItem.__init__(self, parent) self._name = u'' - def paint(self, painter, options, widget): + def paint(self, painter): pen = QPen(self.color, 2) painter.setPen(pen); painter.setRenderHints(QPainter.Antialiasing, True); @@ -65,15 +76,22 @@ class PieChart (QDeclarativeItem): def setName(self, value): self._name = value + nameChanged = Signal() + color = Property(QColor, getColor, setColor) - name = Property(unicode, getName, setName) + name = Property(text_type, getName, setName, notify=nameChanged) if __name__ == '__main__': - app = QApplication(sys.argv) + app = QGuiApplication(sys.argv) qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart'); - view = QDeclarativeView() + view = QQuickView() + view.setResizeMode(QQuickView.SizeRootObjectToView) view.setSource(QUrl.fromLocalFile('app.qml')) view.show() - sys.exit(app.exec_()) + res = app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view + sys.exit(res) diff --git a/examples/declarative/extending/chapter2-methods/app.qml b/examples/declarative/extending/chapter2-methods/app.qml index 7f21320..863b597 100644 --- a/examples/declarative/extending/chapter2-methods/app.qml +++ b/examples/declarative/extending/chapter2-methods/app.qml @@ -1,11 +1,11 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the QtDeclarative module of the Qt Toolkit. +** This file is part of the PySide examples of the Qt Toolkit. ** +** $QT_BEGIN_LICENSE:BSD$ ** 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 @@ -17,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,10 +34,12 @@ ** (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] import Charts 1.0 -import Qt 4.7 +import QtQuick 2.0 Item { width: 300; height: 200 @@ -57,7 +59,11 @@ Item { } Text { - anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 } + anchors { + bottom: parent.bottom; + horizontalCenter: parent.horizontalCenter; + bottomMargin: 20 + } text: "Click anywhere to clear the chart" } } diff --git a/examples/declarative/extending/chapter2-methods/methods.py b/examples/declarative/extending/chapter2-methods/methods.py index dcbf6cc..847d5e5 100644 --- a/examples/declarative/extending/chapter2-methods/methods.py +++ b/examples/declarative/extending/chapter2-methods/methods.py @@ -1,53 +1,64 @@ #!/usr/bin/python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# 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 Nokia Corporation and its Subsidiary(-ies) 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." - -import sys -from PySide.QtCore import * -from PySide.QtGui import * -from PySide.QtDeclarative import * - -class PieChart (QDeclarativeItem): +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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 __future__ import print_function + +"""PySide2 port of the qml/tutorials/extending-qml/chapter2-methods example from Qt v5.x""" + +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'utils')) +from utils import text_type + +from PySide2.QtCore import Property, Signal, Slot, QUrl, Qt +from PySide2.QtGui import QGuiApplication, QPen, QPainter, QColor +from PySide2.QtQml import qmlRegisterType +from PySide2.QtQuick import QQuickPaintedItem, QQuickView + +class PieChart (QQuickPaintedItem): def __init__(self, parent = None): - QDeclarativeItem.__init__(self, parent) - # need to disable this flag to draw inside a QDeclarativeItem - self.setFlag(QGraphicsItem.ItemHasNoContents, False) + QQuickPaintedItem.__init__(self, parent) self._name = u'' - def paint(self, painter, options, widget): + def paint(self, painter): pen = QPen(self.color, 2) painter.setPen(pen); painter.setRenderHints(QPainter.Antialiasing, True); @@ -66,8 +77,7 @@ class PieChart (QDeclarativeItem): self._name = value color = Property(QColor, getColor, setColor) - name = Property(unicode, getName, setName) - + name = Property(text_type, getName, setName) chartCleared = Signal() @Slot() # This should be something like @Invokable @@ -77,11 +87,16 @@ class PieChart (QDeclarativeItem): self.chartCleared.emit() if __name__ == '__main__': - app = QApplication(sys.argv) + app = QGuiApplication(sys.argv) qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart'); - view = QDeclarativeView() + view = QQuickView() + view.setResizeMode(QQuickView.SizeRootObjectToView) view.setSource(QUrl.fromLocalFile('app.qml')) view.show() - sys.exit(app.exec_()) + res = app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view + sys.exit(res) diff --git a/examples/declarative/extending/chapter3-bindings/app.qml b/examples/declarative/extending/chapter3-bindings/app.qml index 2ff6ae1..01b9216 100644 --- a/examples/declarative/extending/chapter3-bindings/app.qml +++ b/examples/declarative/extending/chapter3-bindings/app.qml @@ -1,10 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the QtDeclarative module of the Qt Toolkit. +** This file is part of the PySide examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: @@ -18,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,12 +33,13 @@ ** 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] import Charts 1.0 -import Qt 4.7 +import QtQuick 2.0 Item { width: 300; height: 200 @@ -67,7 +67,11 @@ Item { } Text { - anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 } + anchors { + bottom: parent.bottom; + horizontalCenter: parent.horizontalCenter; + bottomMargin: 20 + } text: "Click anywhere to change the chart color" } } diff --git a/examples/declarative/extending/chapter3-bindings/bindings.py b/examples/declarative/extending/chapter3-bindings/bindings.py index 39d3dde..47e02a6 100644 --- a/examples/declarative/extending/chapter3-bindings/bindings.py +++ b/examples/declarative/extending/chapter3-bindings/bindings.py @@ -1,54 +1,65 @@ #!/usr/bin/python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# 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 Nokia Corporation and its Subsidiary(-ies) 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." - -import sys -from PySide.QtCore import * -from PySide.QtGui import * -from PySide.QtDeclarative import * - -class PieChart (QDeclarativeItem): +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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 __future__ import print_function + +"""PySide2 port of the qml/tutorials/extending-qml/chapter3-bindings example from Qt v5.x""" + +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'utils')) +from utils import text_type + +from PySide2.QtCore import Property, Signal, Slot, QUrl, Qt +from PySide2.QtGui import QGuiApplication, QPen, QPainter, QColor +from PySide2.QtQml import qmlRegisterType +from PySide2.QtQuick import QQuickPaintedItem, QQuickView + +class PieChart (QQuickPaintedItem): def __init__(self, parent = None): - QDeclarativeItem.__init__(self, parent) - # need to disable this flag to draw inside a QDeclarativeItem - self.setFlag(QGraphicsItem.ItemHasNoContents, False) + QQuickPaintedItem.__init__(self, parent) self._name = u'' self._color = QColor() - def paint(self, painter, options, widget): + def paint(self, painter): pen = QPen(self._color, 2) painter.setPen(pen); painter.setRenderHints(QPainter.Antialiasing, True); @@ -71,8 +82,7 @@ class PieChart (QDeclarativeItem): colorChanged = Signal() color = Property(QColor, getColor, setColor, notify=colorChanged) - name = Property(unicode, getName, setName) - + name = Property(text_type, getName, setName) chartCleared = Signal() @Slot() # This should be something like @Invokable @@ -82,11 +92,16 @@ class PieChart (QDeclarativeItem): self.chartCleared.emit() if __name__ == '__main__': - app = QApplication(sys.argv) + app = QGuiApplication(sys.argv) qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart'); - view = QDeclarativeView() + view = QQuickView() + view.setResizeMode(QQuickView.SizeRootObjectToView) view.setSource(QUrl.fromLocalFile('app.qml')) view.show() - sys.exit(app.exec_()) + res = app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view + sys.exit(res) diff --git a/examples/declarative/extending/chapter4-customPropertyTypes/app.qml b/examples/declarative/extending/chapter4-customPropertyTypes/app.qml index fcd3806..7e495d6 100644 --- a/examples/declarative/extending/chapter4-customPropertyTypes/app.qml +++ b/examples/declarative/extending/chapter4-customPropertyTypes/app.qml @@ -1,10 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the QtDeclarative module of the Qt Toolkit. +** This file is part of the PySide examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: @@ -18,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,12 +33,13 @@ ** 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] import Charts 1.0 -import Qt 4.7 +import QtQuick 2.0 Item { width: 300; height: 200 diff --git a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py index d09ad90..4b936fa 100644 --- a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py +++ b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py @@ -1,50 +1,61 @@ #!/usr/bin/python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# 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 Nokia Corporation and its Subsidiary(-ies) 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." - -import sys -from PySide.QtCore import * -from PySide.QtGui import * -from PySide.QtDeclarative import * - -class PieSlice (QDeclarativeItem): - +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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 __future__ import print_function + +"""PySide2 port of the qml/tutorials/extending-qml/chapter4-customPropertyTypes example from Qt v5.x""" + +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'utils')) +from utils import text_type + +from PySide2.QtCore import Property, QUrl +from PySide2.QtGui import QGuiApplication, QPen, QPainter, QColor +from PySide2.QtQml import qmlRegisterType +from PySide2.QtQuick import QQuickPaintedItem, QQuickView + +class PieSlice (QQuickPaintedItem): def __init__(self, parent = None): - QDeclarativeItem.__init__(self, parent) - # need to disable this flag to draw inside a QDeclarativeItem - self.setFlag(QGraphicsItem.ItemHasNoContents, False) + QQuickPaintedItem.__init__(self, parent) self._color = QColor() def getColor(self): @@ -55,16 +66,15 @@ class PieSlice (QDeclarativeItem): color = Property(QColor, getColor, setColor) - def paint(self, painter, options, widget): + def paint(self, painter): pen = QPen(self._color, 2) painter.setPen(pen); painter.setRenderHints(QPainter.Antialiasing, True); painter.drawPie(self.boundingRect(), 90 * 16, 290 * 16); -class PieChart (QDeclarativeItem): - +class PieChart (QQuickPaintedItem): def __init__(self, parent = None): - QDeclarativeItem.__init__(self, parent) + QQuickPaintedItem.__init__(self, parent) self._name = u'' self._pieSlice = None @@ -74,7 +84,7 @@ class PieChart (QDeclarativeItem): def setName(self, value): self._name = value - name = Property(unicode, getName, setName) + name = Property(text_type, getName, setName) def getPieSlice(self): return self._pieSlice @@ -86,12 +96,17 @@ class PieChart (QDeclarativeItem): pieSlice = Property(PieSlice, getPieSlice, setPieSlice) if __name__ == '__main__': - app = QApplication(sys.argv) + app = QGuiApplication(sys.argv) qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart'); qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice"); - view = QDeclarativeView() + view = QQuickView() + view.setResizeMode(QQuickView.SizeRootObjectToView) view.setSource(QUrl.fromLocalFile('app.qml')) view.show() - sys.exit(app.exec_()) + res = app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view + sys.exit(res) diff --git a/examples/declarative/extending/chapter5-listproperties/app.qml b/examples/declarative/extending/chapter5-listproperties/app.qml index 1b6d924..230c295 100644 --- a/examples/declarative/extending/chapter5-listproperties/app.qml +++ b/examples/declarative/extending/chapter5-listproperties/app.qml @@ -1,10 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the examples of the Qt Toolkit. +** This file is part of the PySide examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: @@ -18,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,12 +33,13 @@ ** 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] import Charts 1.0 -import QtQuick 1.0 +import QtQuick 2.0 Item { width: 300; height: 200 diff --git a/examples/declarative/extending/chapter5-listproperties/listproperties.py b/examples/declarative/extending/chapter5-listproperties/listproperties.py index eadc319..a6b270b 100644 --- a/examples/declarative/extending/chapter5-listproperties/listproperties.py +++ b/examples/declarative/extending/chapter5-listproperties/listproperties.py @@ -1,50 +1,61 @@ #!/usr/bin/python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# 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 Nokia Corporation and its Subsidiary(-ies) 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." - -import sys -from PySide.QtCore import * -from PySide.QtGui import * -from PySide.QtDeclarative import * - -class PieSlice (QDeclarativeItem): - +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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 __future__ import print_function + +"""PySide2 port of the qml/tutorials/extending-qml/chapter5-listproperties example from Qt v5.x""" + +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'utils')) +from utils import text_type + +from PySide2.QtCore import Property, QUrl +from PySide2.QtGui import QGuiApplication, QPen, QPainter, QColor +from PySide2.QtQml import qmlRegisterType, ListProperty +from PySide2.QtQuick import QQuickPaintedItem, QQuickView + +class PieSlice (QQuickPaintedItem): def __init__(self, parent = None): - QDeclarativeItem.__init__(self, parent) - # need to disable this flag to draw inside a QDeclarativeItem - self.setFlag(QGraphicsItem.ItemHasNoContents, False) + QQuickPaintedItem.__init__(self, parent) self._color = QColor() self._fromAngle = 0 self._angleSpan = 0 @@ -71,16 +82,15 @@ class PieSlice (QDeclarativeItem): fromAngle = Property(int, getFromAngle, setFromAngle) angleSpan = Property(int, getAngleSpan, setAngleSpan) - def paint(self, painter, options, widget): + def paint(self, painter): pen = QPen(self._color, 2) painter.setPen(pen); painter.setRenderHints(QPainter.Antialiasing, True); painter.drawPie(self.boundingRect(), self._fromAngle * 16, self._angleSpan * 16); -class PieChart (QDeclarativeItem): - +class PieChart (QQuickPaintedItem): def __init__(self, parent = None): - QDeclarativeItem.__init__(self, parent) + QQuickPaintedItem.__init__(self, parent) self._name = u'' self._slices = [] @@ -90,7 +100,7 @@ class PieChart (QDeclarativeItem): def setName(self, value): self._name = value - name = Property(unicode, getName, setName) + name = Property(text_type, getName, setName) def appendSlice(self, _slice): _slice.setParentItem(self) @@ -99,12 +109,17 @@ class PieChart (QDeclarativeItem): slices = ListProperty(PieSlice, appendSlice) if __name__ == '__main__': - app = QApplication(sys.argv) + app = QGuiApplication(sys.argv) qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart'); qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice"); - view = QDeclarativeView() + view = QQuickView() + view.setResizeMode(QQuickView.SizeRootObjectToView) view.setSource(QUrl.fromLocalFile('app.qml')) view.show() - sys.exit(app.exec_()) + res = app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view + sys.exit(res) diff --git a/examples/declarative/scrolling.py b/examples/declarative/scrolling.py index e6106db..a614c70 100755 --- a/examples/declarative/scrolling.py +++ b/examples/declarative/scrolling.py @@ -1,57 +1,70 @@ #!/usr/bin/env python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# 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 Nokia Corporation and its Subsidiary(-ies) 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." - -from PySide.QtCore import QUrl -from PySide.QtGui import QPushButton, QApplication -from PySide.QtDeclarative import QDeclarativeView +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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$ +## +############################################################################# -# This example uses a QML file to show a scrolling list containing -# all the items listed into dataList. +from __future__ import print_function + +import sys +from PySide2.QtCore import QUrl +from PySide2.QtGui import QGuiApplication +import PySide2.QtQml +from PySide2.QtQuick import QQuickView -dataList = ["Item 1", "Item 2", "Item 3", "Item 4"] +# This example uses a QML file to show a scrolling list containing +# all the items listed in dataList. -app = QApplication([]) -view = QDeclarativeView() +if __name__ == '__main__': + dataList = ["Item 1", "Item 2", "Item 3", "Item 4"] -ctxt = view.rootContext() -ctxt.setContextProperty("myModel", dataList) + app = QGuiApplication(sys.argv) + view = QQuickView() -url = QUrl('view.qml') + ctxt = view.rootContext() + ctxt.setContextProperty("myModel", dataList) -view.setSource(url) -view.show() + url = QUrl('view.qml') + view.setSource(url) + view.show() -app.exec_() + app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view diff --git a/examples/declarative/signals/pytoqml1/main.py b/examples/declarative/signals/pytoqml1/main.py index e857344..0ca1ffe 100755 --- a/examples/declarative/signals/pytoqml1/main.py +++ b/examples/declarative/signals/pytoqml1/main.py @@ -1,58 +1,69 @@ #!/usr/bin/python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# $QT_BEGIN_LICENSE:BSD$ -# 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 Nokia Corporation and its Subsidiary(-ies) 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 import QtCore, QtGui, QtDeclarative +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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$ +## +############################################################################# -if __name__ == '__main__': - import sys +from __future__ import print_function + +import sys +from PySide2.QtCore import QTimer, QUrl +from PySide2.QtGui import QGuiApplication +import PySide2.QtQml +from PySide2.QtQuick import QQuickView - app = QtGui.QApplication(sys.argv) +if __name__ == '__main__': + app = QGuiApplication(sys.argv) - timer = QtCore.QTimer() + timer = QTimer() timer.start(2000) - view = QtDeclarative.QDeclarativeView() - view.setSource(QtCore.QUrl('view.qml')) + view = QQuickView() + view.setSource(QUrl('view.qml')) root = view.rootObject() timer.timeout.connect(root.updateRotater) view.show() - - sys.exit(app.exec_()) + res = app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view + sys.exit(res) diff --git a/examples/declarative/signals/pytoqml1/view.qml b/examples/declarative/signals/pytoqml1/view.qml index ae0830e..21ba8aa 100644 --- a/examples/declarative/signals/pytoqml1/view.qml +++ b/examples/declarative/signals/pytoqml1/view.qml @@ -1,10 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: PySide Team (pyside@openbossa.org) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the examples of PySide: Python for Qt. +** This file is part of the PySide examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: @@ -18,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,11 +33,12 @@ ** 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$ ** ****************************************************************************/ -import Qt 4.7 +import QtQuick 2.0 Rectangle { id: page @@ -47,7 +47,6 @@ Rectangle { rotater.angle = rotater.angle + 45 } - width: 500; height: 200 color: "lightgray" diff --git a/examples/declarative/signals/qmltopy1/main.py b/examples/declarative/signals/qmltopy1/main.py index 76e7995..1ce0507 100755 --- a/examples/declarative/signals/qmltopy1/main.py +++ b/examples/declarative/signals/qmltopy1/main.py @@ -1,86 +1,86 @@ #!/usr/bin/python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# $QT_BEGIN_LICENSE:BSD$ -# 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 Nokia Corporation and its Subsidiary(-ies) 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 import QtCore, QtGui, QtDeclarative - -class Console(QtCore.QObject): +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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 __future__ import print_function + +import sys +from PySide2.QtCore import QObject, QUrl, Slot +from PySide2.QtGui import QGuiApplication +import PySide2.QtQml +from PySide2.QtQuick import QQuickView + +class Console(QObject): """Output stuff on the console.""" - @QtCore.Slot(str) - @QtCore.Slot('double') + @Slot(str) + @Slot('double') def output(self, s): - """ - An overloaded output function. - - At the moment, QML is unable to handle overloaded slots correctly - and is very finicky about the order in which the slots are declared. - See http://bugreports.qt.nokia.com/browse/QTBUG-11604 for details. - As a temporary solution, use separate functions with one slot per - function. - """ print(s) - @QtCore.Slot(str) + @Slot(str) def outputStr(self, s): print(s) - @QtCore.Slot('double') + @Slot('double') def outputFloat(self, x): print(x) if __name__ == '__main__': - import sys + app = QGuiApplication(sys.argv) + view = QQuickView() - app = QtGui.QApplication(sys.argv) - - view = QtDeclarative.QDeclarativeView() - - # instantiate the Python object + # Instantiate the Python object. con = Console() - # expose the object to QML + # Expose the object to QML. context = view.rootContext() context.setContextProperty("con", con) - view.setSource(QtCore.QUrl('view.qml')) + view.setSource(QUrl('view.qml')) view.show() - - sys.exit(app.exec_()) + res = app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view + sys.exit(res) diff --git a/examples/declarative/signals/qmltopy1/view.qml b/examples/declarative/signals/qmltopy1/view.qml index 6ea907d..0115d43 100644 --- a/examples/declarative/signals/qmltopy1/view.qml +++ b/examples/declarative/signals/qmltopy1/view.qml @@ -1,10 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: PySide Team (pyside@openbossa.org) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the examples of PySide: Python for Qt. +** This file is part of the PySide examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: @@ -18,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,12 +33,13 @@ ** 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$ ** ****************************************************************************/ -import Qt 4.7 +import QtQuick 2.0 Rectangle { id: page @@ -79,7 +79,7 @@ Rectangle { text: "Press me!" anchors.horizontalCenter: button.horizontalCenter anchors.verticalCenter: button.verticalCenter - font.pointSize: 16; + font.pointSize: 16 } } } diff --git a/examples/declarative/signals/qmltopy2/main.py b/examples/declarative/signals/qmltopy2/main.py index deaab94..2526ede 100755 --- a/examples/declarative/signals/qmltopy2/main.py +++ b/examples/declarative/signals/qmltopy2/main.py @@ -1,72 +1,78 @@ #!/usr/bin/python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# $QT_BEGIN_LICENSE:BSD$ -# 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 Nokia Corporation and its Subsidiary(-ies) 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: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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 import QtCore, QtGui, QtDeclarative +from __future__ import print_function -class RotateValue(QtCore.QObject): +import sys +from PySide2.QtCore import QObject, QUrl, Slot +from PySide2.QtGui import QGuiApplication +import PySide2.QtQml +from PySide2.QtQuick import QQuickView + +class RotateValue(QObject): def __init__(self): super(RotateValue,self).__init__() self.r = 0 - # if a slot returns a value the return value type must be explicitly - # defined in the decorator - @QtCore.Slot(result=int) + # If a slot returns a value, the return value type must be explicitly + # defined in the decorator. + @Slot(result=int) def val(self): self.r = self.r + 10 return self.r if __name__ == '__main__': - import sys - - app = QtGui.QApplication(sys.argv) - - view = QtDeclarative.QDeclarativeView() + app = QGuiApplication(sys.argv) + view = QQuickView() rotatevalue = RotateValue() - - timer = QtCore.QTimer() - timer.start(2000) - context = view.rootContext() context.setContextProperty("rotatevalue", rotatevalue) - view.setSource(QtCore.QUrl('view.qml')) + view.setSource(QUrl('view.qml')) view.show() - - sys.exit(app.exec_()) + res = app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view + sys.exit(res) diff --git a/examples/declarative/signals/qmltopy2/view.qml b/examples/declarative/signals/qmltopy2/view.qml index fca90ec..2a905a6 100644 --- a/examples/declarative/signals/qmltopy2/view.qml +++ b/examples/declarative/signals/qmltopy2/view.qml @@ -1,10 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: PySide Team (pyside@openbossa.org) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the examples of PySide: Python for Qt. +** This file is part of the PySide examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: @@ -18,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,11 +33,12 @@ ** 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$ ** ****************************************************************************/ -import Qt 4.7 +import QtQuick 2.0 Rectangle { id: page @@ -74,7 +74,7 @@ Rectangle { text: "Press me!" anchors.horizontalCenter: button.horizontalCenter anchors.verticalCenter: button.verticalCenter - font.pointSize: 16; + font.pointSize: 16 } } } diff --git a/examples/declarative/signals/qmltopy3/README b/examples/declarative/signals/qmltopy3/README index bb0d887..fba04e9 100644 --- a/examples/declarative/signals/qmltopy3/README +++ b/examples/declarative/signals/qmltopy3/README @@ -1,4 +1,4 @@ -This example illustrates connecting signals to from QML to Python in +This example illustrates connecting signals from QML to Python in Python using a top-level QML signal. When the button is held depressed, the button turns upside down. The diff --git a/examples/declarative/signals/qmltopy3/main.py b/examples/declarative/signals/qmltopy3/main.py index ee4500f..f2ddd49 100755 --- a/examples/declarative/signals/qmltopy3/main.py +++ b/examples/declarative/signals/qmltopy3/main.py @@ -1,72 +1,68 @@ #!/usr/bin/python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# $QT_BEGIN_LICENSE:BSD$ -# 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 Nokia Corporation and its Subsidiary(-ies) 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: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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 import QtCore, QtGui, QtDeclarative +from __future__ import print_function -class Console(QtCore.QObject): - - @QtCore.Slot('double') - def output(self,s): - print(s) +import sys +from PySide2.QtCore import QObject, QUrl +from PySide2.QtGui import QGuiApplication +import PySide2.QtQml +from PySide2.QtQuick import QQuickView def sayThis(s): print(s) if __name__ == '__main__': - import sys - - app = QtGui.QApplication(sys.argv) - - view = QtDeclarative.QDeclarativeView() + app = QGuiApplication(sys.argv) + view = QQuickView() + view.setSource(QUrl('view.qml')) - #con = Console() - - view.setSource(QtCore.QUrl('view.qml')) - root = view.rootObject() - - button = root.findChild(QtCore.QObject,"buttonMouseArea") - root.textRotationChanged.connect(sayThis) - root.buttonClicked.connect(lambda: sayThis("clicked button (QML top-level signal)")) view.show() - - sys.exit(app.exec_()) - + res = app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view + sys.exit(res) diff --git a/examples/declarative/signals/qmltopy3/view.qml b/examples/declarative/signals/qmltopy3/view.qml index c1e1d8c..72984a1 100644 --- a/examples/declarative/signals/qmltopy3/view.qml +++ b/examples/declarative/signals/qmltopy3/view.qml @@ -1,10 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: PySide Team (pyside@openbossa.org) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the examples of PySide: Python for Qt. +** This file is part of the PySide examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: @@ -18,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,11 +33,12 @@ ** 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$ ** ****************************************************************************/ -import Qt 4.7 +import QtQuick 2.0 Rectangle { id: page @@ -58,7 +58,7 @@ Rectangle { onRotationChanged: textRotationChanged(rotation) states: State { - name: "down"; when: buttonMouseArea.pressed == true + name: "down"; when: buttonMouseArea.pressed === true PropertyChanges { target: helloText; rotation: 180; @@ -89,7 +89,7 @@ Rectangle { objectName: "buttonMouseArea" anchors.fill: parent onClicked: { - buttonClicked(); + buttonClicked() } } Text { @@ -97,7 +97,7 @@ Rectangle { text: "Press me!" anchors.horizontalCenter: button.horizontalCenter anchors.verticalCenter: button.verticalCenter - font.pointSize: 16; + font.pointSize: 16 } } } diff --git a/examples/declarative/signals/qmltopy4/main.py b/examples/declarative/signals/qmltopy4/main.py index 7c0cf42..fb6fc3e 100755 --- a/examples/declarative/signals/qmltopy4/main.py +++ b/examples/declarative/signals/qmltopy4/main.py @@ -1,61 +1,68 @@ #!/usr/bin/python -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# $QT_BEGIN_LICENSE:BSD$ -# 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 Nokia Corporation and its Subsidiary(-ies) 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: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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 import QtCore, QtGui, QtDeclarative +from __future__ import print_function + +import sys +from PySide2.QtCore import QObject, QUrl +from PySide2.QtGui import QGuiApplication +import PySide2.QtQml +from PySide2.QtQuick import QQuickView def sayThis(s): print(s) if __name__ == '__main__': - import sys - - app = QtGui.QApplication(sys.argv) + app = QGuiApplication(sys.argv) + view = QQuickView() + view.setSource(QUrl('view.qml')) - view = QtDeclarative.QDeclarativeView() - - view.setSource(QtCore.QUrl('view.qml')) - root = view.rootObject() - - button = root.findChild(QtCore.QObject,"buttonMouseArea") + button = root.findChild(QObject, "buttonMouseArea") button.clicked.connect(lambda: sayThis("clicked button (signal directly connected)")) view.show() - - sys.exit(app.exec_()) - + res = app.exec_() + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view + sys.exit(res) diff --git a/examples/declarative/signals/qmltopy4/view.qml b/examples/declarative/signals/qmltopy4/view.qml index c7dbaf2..212df77 100644 --- a/examples/declarative/signals/qmltopy4/view.qml +++ b/examples/declarative/signals/qmltopy4/view.qml @@ -1,10 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: PySide Team (pyside@openbossa.org) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the examples of PySide: Python for Qt. +** This file is part of the PySide examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: @@ -18,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,11 +33,12 @@ ** 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$ ** ****************************************************************************/ -import Qt 4.7 +import QtQuick 2.0 Rectangle { id: page @@ -62,7 +62,7 @@ Rectangle { text: "Press me!" anchors.horizontalCenter: button.horizontalCenter anchors.verticalCenter: button.verticalCenter - font.pointSize: 16; + font.pointSize: 16 } } } diff --git a/examples/declarative/usingmodel.py b/examples/declarative/usingmodel.py index 88cef27..cbb334e 100644 --- a/examples/declarative/usingmodel.py +++ b/examples/declarative/usingmodel.py @@ -1,56 +1,67 @@ #!/usr/bin/env python -# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -# All rights reserved. -# Contact: PySide Team (pyside@openbossa.org) -# -# This file is part of the examples of PySide: Python for Qt. -# -# 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 Nokia Corporation and its Subsidiary(-ies) 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." +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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 __future__ import print_function import sys -from PySide.QtCore import * -from PySide.QtGui import * -from PySide.QtDeclarative import * +from PySide2.QtCore import QAbstractListModel, Qt +from PySide2.QtGui import QGuiApplication +import PySide2.QtQml +from PySide2.QtQuick import QQuickView class PersonModel (QAbstractListModel): - MyRole = Qt.UserRole + 1 def __init__(self, parent = None): QAbstractListModel.__init__(self, parent) - self.setRoleNames({ - PersonModel.MyRole : 'modelData', - Qt.DisplayRole : 'display' # Qt asserts if you don't define a display role - }) self._data = [] + def roleNames(self): + roles = { + PersonModel.MyRole : 'modelData', + Qt.DisplayRole : 'display' + } + return roles + def rowCount(self, index): return len(self._data) @@ -70,8 +81,9 @@ class PersonModel (QAbstractListModel): self._data.append({'name':'PySide', 'myrole':'role2'}) if __name__ == '__main__': - app = QApplication(sys.argv) - view = QDeclarativeView() + app = QGuiApplication(sys.argv) + view = QQuickView() + view.setResizeMode(QQuickView.SizeRootObjectToView) myModel = PersonModel() myModel.populate() @@ -81,5 +93,6 @@ if __name__ == '__main__': view.show() app.exec_() - - + # Deleting the view before it goes out of scope is required to make sure all child QML instances + # are destroyed in the correct order. + del view diff --git a/examples/declarative/view.qml b/examples/declarative/view.qml index ec5597d..caf2dc1 100644 --- a/examples/declarative/view.qml +++ b/examples/declarative/view.qml @@ -1,10 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** -** This file is part of the QtDeclarative module of the Qt Toolkit. +** This file is part of the PySide examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: @@ -18,10 +17,10 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. +** * 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 @@ -34,11 +33,12 @@ ** 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$ ** ****************************************************************************/ -import Qt 4.7 +import QtQuick 2.0 ListView { width: 100 @@ -49,7 +49,17 @@ ListView { Rectangle { height: 25 width: 100 - Text { text: modelData } + Text { + function displayText() { + var result = "" + if (typeof display !== "undefined") + result = display + ": " + result += modelData + return result + } + + text: displayText() + } } } } diff --git a/examples/utils/utils.py b/examples/utils/utils.py new file mode 100644 index 0000000..ddba61b --- /dev/null +++ b/examples/utils/utils.py @@ -0,0 +1,49 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the PySide examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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$ +## +############################################################################# + +import sys +isPY3 = sys.version_info[0] == 3 + +if isPY3: + text_type = str +else: + text_type = unicode -- cgit v1.2.3