aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-10-19 10:44:34 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-11-04 12:21:18 +0000
commitbd84acfadb5f00de686a771fce54f9353f046605 (patch)
tree99f4d6c252cd3048f6992df1d3d5ad07eb385d6d /examples
parent5a7ef37f48fb998a9922101f501df1606cb7e42d (diff)
Port OpenGL examples
Adapt to Qt 5 and fix license. Add detailed text with instructions to the messagebox warning about missing PyOpenGL. Task-number: PYSIDE-314 Change-Id: I560901a675669e1116fb5c7a4a33c33739930fc8 Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/opengl/2dpainting.py64
-rwxr-xr-xexamples/opengl/grabber.py117
-rwxr-xr-xexamples/opengl/hellogl.py79
-rwxr-xr-xexamples/opengl/overpainting.py72
-rwxr-xr-xexamples/opengl/samplebuffers.py67
-rwxr-xr-xexamples/opengl/textures/textures.py89
6 files changed, 339 insertions, 149 deletions
diff --git a/examples/opengl/2dpainting.py b/examples/opengl/2dpainting.py
index 27d3474..6073024 100755
--- a/examples/opengl/2dpainting.py
+++ b/examples/opengl/2dpainting.py
@@ -2,41 +2,63 @@
############################################################################
##
-## Copyright (C) 2006-2006 Trolltech ASA. All rights reserved.
+## Copyright (C) 2013 Riverbank Computing Limited.
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
##
-## This file is part of the example classes of the Qt Toolkit.
+## This file is part of the PySide examples of the Qt Toolkit.
##
-## This file may be used under the terms of the GNU General Public
-## License version 2.0 as published by the Free Software Foundation
-## and appearing in the file LICENSE.GPL included in the packaging of
-## this file. Please review the following information to ensure GNU
-## General Public Licensing requirements will be met:
-## http://www.trolltech.com/products/qt/opensource.html
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
##
-## If you are unsure which license is appropriate for your use, please
-## review the following information:
-## http://www.trolltech.com/products/qt/licensing.html or contact the
-## sales department at sales@trolltech.com.
+## "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 file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+##
+## 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$
##
############################################################################
+"""PySide2 port of the opengl/legacy/2dpainting example from Qt v5.x"""
+
import sys
import math
-from PySide.QtCore import *
-from PySide.QtGui import *
-from PySide.QtOpenGL import *
+from PySide2.QtCore import *
+from PySide2.QtGui import *
+from PySide2.QtWidgets import *
+from PySide2.QtOpenGL import *
try:
from OpenGL import GL
except ImportError:
app = QApplication(sys.argv)
- QMessageBox.critical(None, "OpenGL 2dpainting",
- "PyOpenGL must be installed to run this example.",
- QMessageBox.Ok | QMessageBox.Default,
- QMessageBox.NoButton)
+ messageBox = QMessageBox(QMessageBox.Critical, "OpenGL 2dpainting",
+ "PyOpenGL must be installed to run this example.",
+ QMessageBox.Close)
+ messageBox.setDetailedText("Run:\npip install PyOpenGL PyOpenGL_accelerate")
+ messageBox.exec_()
sys.exit(1)
diff --git a/examples/opengl/grabber.py b/examples/opengl/grabber.py
index d8382ff..2c7dcbb 100755
--- a/examples/opengl/grabber.py
+++ b/examples/opengl/grabber.py
@@ -1,39 +1,62 @@
#!/usr/bin/env python
-#############################################################################
+############################################################################
##
-## Copyright (C) 2004-2005 Trolltech AS. All rights reserved.
+## Copyright (C) 2013 Riverbank Computing Limited.
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
##
-## This file is part of the example classes of the Qt Toolkit.
+## This file is part of the PySide examples of the Qt Toolkit.
##
-## This file may be used under the terms of the GNU General Public
-## License version 2.0 as published by the Free Software Foundation
-## and appearing in the file LICENSE.GPL included in the packaging of
-## this file. Please review the following information to ensure GNU
-## General Public Licensing requirements will be met:
-## http://www.trolltech.com/products/qt/opensource.html
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
##
-## If you are unsure which license is appropriate for your use, please
-## review the following information:
-## http://www.trolltech.com/products/qt/licensing.html or contact the
-## sales department at sales@trolltech.com.
+## "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 file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
##
-#############################################################################
+## 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$
+##
+############################################################################
+
+"""PySide2 port of the opengl/legacy/grabber example from Qt v5.x"""
import sys
import math
-from PySide2 import QtCore, QtGui, QtOpenGL
+from PySide2 import QtCore, QtGui, QtWidgets, QtOpenGL
try:
from OpenGL.GL import *
except ImportError:
- app = QtGui.QApplication(sys.argv)
- QtGui.QMessageBox.critical(None, "OpenGL grabber",
- "PyOpenGL must be installed to run this example.")
+ app = QtWidgets.QApplication(sys.argv)
+ messageBox = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical, "OpenGL grabber",
+ "PyOpenGL must be installed to run this example.",
+ QtWidgets.QMessageBox.Close)
+ messageBox.setDetailedText("Run:\npip install PyOpenGL PyOpenGL_accelerate")
+ messageBox.exec_()
sys.exit(1)
@@ -57,7 +80,7 @@ class GLWidget(QtOpenGL.QGLWidget):
timer.timeout.connect(self.advanceGears)
timer.start(20)
- def __del__(self):
+ def freeResources(self):
self.makeCurrent()
glDeleteLists(self.gear1, 1)
glDeleteLists(self.gear2, 1)
@@ -128,7 +151,7 @@ class GLWidget(QtOpenGL.QGLWidget):
if side < 0:
return
- glViewport((width - side) / 2, (height - side) / 2, side, side)
+ glViewport(int((width - side) / 2), int((height - side) / 2), side, side)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
@@ -263,29 +286,29 @@ class GLWidget(QtOpenGL.QGLWidget):
angle -= 360 * 16
-class MainWindow(QtGui.QMainWindow):
+class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
- centralWidget = QtGui.QWidget()
+ centralWidget = QtWidgets.QWidget()
self.setCentralWidget(centralWidget)
self.glWidget = GLWidget()
- self.pixmapLabel = QtGui.QLabel()
+ self.pixmapLabel = QtWidgets.QLabel()
- self.glWidgetArea = QtGui.QScrollArea()
+ self.glWidgetArea = QtWidgets.QScrollArea()
self.glWidgetArea.setWidget(self.glWidget)
self.glWidgetArea.setWidgetResizable(True)
self.glWidgetArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.glWidgetArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
- self.glWidgetArea.setSizePolicy(QtGui.QSizePolicy.Ignored,
- QtGui.QSizePolicy.Ignored)
+ self.glWidgetArea.setSizePolicy(QtWidgets.QSizePolicy.Ignored,
+ QtWidgets.QSizePolicy.Ignored)
self.glWidgetArea.setMinimumSize(50, 50)
- self.pixmapLabelArea = QtGui.QScrollArea()
+ self.pixmapLabelArea = QtWidgets.QScrollArea()
self.pixmapLabelArea.setWidget(self.pixmapLabel)
- self.pixmapLabelArea.setSizePolicy(QtGui.QSizePolicy.Ignored,
- QtGui.QSizePolicy.Ignored)
+ self.pixmapLabelArea.setSizePolicy(QtWidgets.QSizePolicy.Ignored,
+ QtWidgets.QSizePolicy.Ignored)
self.pixmapLabelArea.setMinimumSize(50, 50)
xSlider = self.createSlider(self.glWidget.xRotationChanged,
@@ -298,7 +321,7 @@ class MainWindow(QtGui.QMainWindow):
self.createActions()
self.createMenus()
- centralLayout = QtGui.QGridLayout()
+ centralLayout = QtWidgets.QGridLayout()
centralLayout.addWidget(self.glWidgetArea, 0, 0)
centralLayout.addWidget(self.pixmapLabelArea, 0, 1)
centralLayout.addWidget(xSlider, 1, 0, 1, 2)
@@ -328,27 +351,27 @@ class MainWindow(QtGui.QMainWindow):
self.setPixmap(QtGui.QPixmap())
def about(self):
- QtGui.QMessageBox.about(self, "About Grabber",
+ QtWidgets.QMessageBox.about(self, "About Grabber",
"The <b>Grabber</b> example demonstrates two approaches for "
"rendering OpenGL into a Qt pixmap.")
def createActions(self):
- self.renderIntoPixmapAct = QtGui.QAction("&Render into Pixmap...",
+ self.renderIntoPixmapAct = QtWidgets.QAction("&Render into Pixmap...",
self, shortcut="Ctrl+R", triggered=self.renderIntoPixmap)
- self.grabFrameBufferAct = QtGui.QAction("&Grab Frame Buffer", self,
+ self.grabFrameBufferAct = QtWidgets.QAction("&Grab Frame Buffer", self,
shortcut="Ctrl+G", triggered=self.grabFrameBuffer)
- self.clearPixmapAct = QtGui.QAction("&Clear Pixmap", self,
+ self.clearPixmapAct = QtWidgets.QAction("&Clear Pixmap", self,
shortcut="Ctrl+L", triggered=self.clearPixmap)
- self.exitAct = QtGui.QAction("E&xit", self, shortcut="Ctrl+Q",
+ self.exitAct = QtWidgets.QAction("E&xit", self, shortcut="Ctrl+Q",
triggered=self.close)
- self.aboutAct = QtGui.QAction("&About", self, triggered=self.about)
+ self.aboutAct = QtWidgets.QAction("&About", self, triggered=self.about)
- self.aboutQtAct = QtGui.QAction("About &Qt", self,
- triggered=QtGui.qApp.aboutQt)
+ self.aboutQtAct = QtWidgets.QAction("About &Qt", self,
+ triggered=QtWidgets.qApp.aboutQt)
def createMenus(self):
self.fileMenu = self.menuBar().addMenu("&File")
@@ -363,12 +386,12 @@ class MainWindow(QtGui.QMainWindow):
self.helpMenu.addAction(self.aboutQtAct)
def createSlider(self, changedSignal, setterSlot):
- slider = QtGui.QSlider(QtCore.Qt.Horizontal)
+ slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
slider.setRange(0, 360 * 16)
slider.setSingleStep(16)
slider.setPageStep(15 * 16)
slider.setTickInterval(15 * 16)
- slider.setTickPosition(QtGui.QSlider.TicksRight)
+ slider.setTickPosition(QtWidgets.QSlider.TicksRight)
slider.valueChanged.connect(setterSlot)
changedSignal.connect(slider.setValue)
@@ -385,8 +408,8 @@ class MainWindow(QtGui.QMainWindow):
self.pixmapLabel.resize(size)
def getSize(self):
- text, ok = QtGui.QInputDialog.getText(self, "Grabber",
- "Enter pixmap size:", QtGui.QLineEdit.Normal,
+ text, ok = QtWidgets.QInputDialog.getText(self, "Grabber",
+ "Enter pixmap size:", QtWidgets.QLineEdit.Normal,
"%d x %d" % (self.glWidget.width(), self.glWidget.height()))
if not ok:
@@ -405,7 +428,9 @@ class MainWindow(QtGui.QMainWindow):
if __name__ == '__main__':
- app = QtGui.QApplication(sys.argv)
+ app = QtWidgets.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
- sys.exit(app.exec_())
+ res = app.exec_()
+ mainWin.glWidget.freeResources()
+ sys.exit(res)
diff --git a/examples/opengl/hellogl.py b/examples/opengl/hellogl.py
index 7d93d30..e3fa40b 100755
--- a/examples/opengl/hellogl.py
+++ b/examples/opengl/hellogl.py
@@ -1,25 +1,67 @@
#!/usr/bin/env python
-"""PySide port of the opengl/hellogl example from Qt v4.x"""
+############################################################################
+##
+## Copyright (C) 2013 Riverbank Computing Limited.
+## 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$
+##
+############################################################################
+
+"""PySide2 port of the opengl/legacy/hellogl example from Qt v5.x"""
import sys
import math
-from PySide2 import QtCore, QtGui, QtOpenGL
+from PySide2 import QtCore, QtGui, QtWidgets, QtOpenGL
try:
from OpenGL import GL
except ImportError:
- app = QtGui.QApplication(sys.argv)
- QtGui.QMessageBox.critical(None, "OpenGL hellogl",
- "PyOpenGL must be installed to run this example.",
- QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default,
- QtGui.QMessageBox.NoButton)
+ app = QtWidgets.QApplication(sys.argv)
+ messageBox = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical, "OpenGL hellogl",
+ "PyOpenGL must be installed to run this example.",
+ QtWidgets.QMessageBox.Close)
+ messageBox.setDetailedText("Run:\npip install PyOpenGL PyOpenGL_accelerate")
+ messageBox.exec_()
sys.exit(1)
-class Window(QtGui.QWidget):
+class Window(QtWidgets.QWidget):
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
self.glWidget = GLWidget()
@@ -30,7 +72,7 @@ class Window(QtGui.QWidget):
self.zSlider = self.createSlider(QtCore.SIGNAL("zRotationChanged(int)"),
self.glWidget.setZRotation)
- mainLayout = QtGui.QHBoxLayout()
+ mainLayout = QtWidgets.QHBoxLayout()
mainLayout.addWidget(self.glWidget)
mainLayout.addWidget(self.xSlider)
mainLayout.addWidget(self.ySlider)
@@ -44,13 +86,13 @@ class Window(QtGui.QWidget):
self.setWindowTitle(self.tr("Hello GL"))
def createSlider(self, changedSignal, setterSlot):
- slider = QtGui.QSlider(QtCore.Qt.Vertical)
+ slider = QtWidgets.QSlider(QtCore.Qt.Vertical)
slider.setRange(0, 360 * 16)
slider.setSingleStep(16)
slider.setPageStep(15 * 16)
slider.setTickInterval(15 * 16)
- slider.setTickPosition(QtGui.QSlider.TicksRight)
+ slider.setTickPosition(QtWidgets.QSlider.TicksRight)
self.glWidget.connect(slider, QtCore.SIGNAL("valueChanged(int)"), setterSlot)
self.connect(self.glWidget, changedSignal, slider, QtCore.SLOT("setValue(int)"))
@@ -62,6 +104,10 @@ class GLWidget(QtOpenGL.QGLWidget):
def __init__(self, parent=None):
QtOpenGL.QGLWidget.__init__(self, parent)
+ xRotationChanged = QtCore.Signal(int)
+ yRotationChanged = QtCore.Signal(int)
+ zRotationChanged = QtCore.Signal(int)
+
self.object = 0
self.xRot = 0
self.yRot = 0
@@ -229,9 +275,14 @@ class GLWidget(QtOpenGL.QGLWidget):
angle -= 360 * 16
return angle
+ def freeResources(self):
+ self.makeCurrent()
+ GL.glDeleteLists(self.object, 1)
if __name__ == '__main__':
- app = QtGui.QApplication(sys.argv)
+ app = QtWidgets.QApplication(sys.argv)
window = Window()
window.show()
- sys.exit(app.exec_())
+ res = app.exec_()
+ window.glWidget.freeResources()
+ sys.exit(res)
diff --git a/examples/opengl/overpainting.py b/examples/opengl/overpainting.py
index 2947325..9285eaa 100755
--- a/examples/opengl/overpainting.py
+++ b/examples/opengl/overpainting.py
@@ -2,41 +2,63 @@
############################################################################
##
-## Copyright (C) 2006-2006 Trolltech ASA. All rights reserved.
+## Copyright (C) 2013 Riverbank Computing Limited.
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
##
-## This file is part of the example classes of the Qt Toolkit.
+## This file is part of the PySide examples of the Qt Toolkit.
##
-## This file may be used under the terms of the GNU General Public
-## License version 2.0 as published by the Free Software Foundation
-## and appearing in the file LICENSE.GPL included in the packaging of
-## this file. Please review the following information to ensure GNU
-## General Public Licensing requirements will be met:
-## http://www.trolltech.com/products/qt/opensource.html
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
##
-## If you are unsure which license is appropriate for your use, please
-## review the following information:
-## http://www.trolltech.com/products/qt/licensing.html or contact the
-## sales department at sales@trolltech.com.
+## "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 file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+##
+## 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$
##
############################################################################
+"""PySide2 port of the opengl/legacy/overpainting example from Qt v5.x"""
+
import sys
import math, random
-from PySide.QtCore import *
-from PySide.QtGui import *
-from PySide.QtOpenGL import *
+from PySide2.QtCore import *
+from PySide2.QtGui import *
+from PySide2.QtWidgets import *
+from PySide2.QtOpenGL import *
try:
from OpenGL.GL import *
except ImportError:
app = QApplication(sys.argv)
- QMessageBox.critical(None, "OpenGL overpainting",
- "PyOpenGL must be installed to run this example.",
- QMessageBox.Ok | QMessageBox.Default,
- QMessageBox.NoButton)
+ messageBox = QMessageBox(QMessageBox.Critical, "OpenGL overpainting",
+ "PyOpenGL must be installed to run this example.",
+ QMessageBox.Close)
+ messageBox.setDetailedText("Run:\npip install PyOpenGL PyOpenGL_accelerate")
+ messageBox.exec_()
sys.exit(1)
@@ -128,7 +150,7 @@ class GLWidget(QGLWidget):
self.setMinimumSize(200, 200)
self.setWindowTitle(self.tr("Overpainting a Scene"))
- def __del__(self):
+ def freeResources(self):
self.makeCurrent()
glDeleteLists(self.object, 1)
@@ -216,7 +238,7 @@ class GLWidget(QGLWidget):
def resizeGL(self, width, height):
side = min(width, height)
- glViewport((width - side) / 2, (height - side) / 2, side, side)
+ glViewport(int((width - side) / 2), int((height - side) / 2), side, side)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
@@ -359,4 +381,6 @@ if __name__ == '__main__':
app = QApplication(sys.argv)
window = GLWidget()
window.show()
- sys.exit(app.exec_())
+ res = app.exec_()
+ window.freeResources()
+ sys.exit(res)
diff --git a/examples/opengl/samplebuffers.py b/examples/opengl/samplebuffers.py
index f738b7d..eabcdd3 100755
--- a/examples/opengl/samplebuffers.py
+++ b/examples/opengl/samplebuffers.py
@@ -1,19 +1,61 @@
#!/usr/bin/env python
-"""PySide port of the opengl/samplebuffers example from Qt v4.x"""
+############################################################################
+##
+## Copyright (C) 2013 Riverbank Computing Limited.
+## 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$
+##
+############################################################################
+
+"""PySide2 port of the opengl/legacy/samplebuffers example from Qt v5.x"""
import sys
import math
-from PySide2 import QtCore, QtGui, QtOpenGL
+from PySide2 import QtCore, QtGui, QtWidgets, QtOpenGL
try:
from OpenGL import GL
except ImportError:
- app = QtGui.QApplication(sys.argv)
- QtGui.QMessageBox.critical(None, "OpenGL samplebuffers",
- "PyOpenGL must be installed to run this example.",
- QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default,
- QtGui.QMessageBox.NoButton)
+ app = QtWidgets.QApplication(sys.argv)
+ messageBox = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical, "OpenGL samplebuffers",
+ "PyOpenGL must be installed to run this example.",
+ QtWidgets.QMessageBox.Close)
+ messageBox.setDetailedText("Run:\npip install PyOpenGL PyOpenGL_accelerate")
+ messageBox.exec_()
sys.exit(1)
@@ -125,9 +167,13 @@ class GLWidget(QtOpenGL.QGLWidget):
GL.glEnd()
+ def freeResources(self):
+ self.makeCurrent()
+ GL.glDeleteLists(self.list_, 1)
+
if __name__ == '__main__':
- app = QtGui.QApplication(sys.argv)
+ app = QtWidgets.QApplication(sys.argv)
if not QtOpenGL.QGLFormat.hasOpenGL():
QMessageBox.information(0, "OpenGL pbuffers",
@@ -142,5 +188,6 @@ if __name__ == '__main__':
widget = GLWidget()
widget.resize(640, 480)
widget.show()
-
- sys.exit(app.exec_())
+ res = app.exec_()
+ widget.freeResources()
+ sys.exit(res)
diff --git a/examples/opengl/textures/textures.py b/examples/opengl/textures/textures.py
index ea63ac5..3c91a60 100755
--- a/examples/opengl/textures/textures.py
+++ b/examples/opengl/textures/textures.py
@@ -1,39 +1,60 @@
#!/usr/bin/env python
-"""***************************************************************************
-**
-** Copyright (C) 2005-2005 Trolltech AS. All rights reserved.
-**
-** This file is part of the example classes of the Qt Toolkit.
-**
-** This file may be used under the terms of the GNU General Public
-** License version 2.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of
-** this file. Please review the following information to ensure GNU
-** General Public Licensing requirements will be met:
-** http://www.trolltech.com/products/qt/opensource.html
-**
-** If you are unsure which license is appropriate for your use, please
-** review the following information:
-** http://www.trolltech.com/products/qt/licensing.html or contact the
-** sales department at sales@trolltech.com.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-***************************************************************************"""
+############################################################################
+##
+## Copyright (C) 2013 Riverbank Computing Limited.
+## 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$
+##
+############################################################################
+
+"""PySide2 port of the opengl/textures example from Qt v5.x"""
import sys
-from PySide2 import QtCore, QtGui, QtOpenGL
+from PySide2 import QtCore, QtGui, QtWidgets, QtOpenGL
try:
from OpenGL.GL import *
except ImportError:
- app = QtGui.QApplication(sys.argv)
- QtGui.QMessageBox.critical(None, "OpenGL textures",
- "PyOpenGL must be installed to run this example.",
- QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default,
- QtGui.QMessageBox.NoButton)
+ app = QtWidgets.QApplication(sys.argv)
+ messageBox = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical, "OpenGL textures",
+ "PyOpenGL must be installed to run this example.",
+ QtWidgets.QMessageBox.Close)
+ messageBox.setDetailedText("Run:\npip install PyOpenGL PyOpenGL_accelerate")
+ messageBox.exec_()
sys.exit(1)
import textures_rc
@@ -110,7 +131,7 @@ class GLWidget(QtOpenGL.QGLWidget):
def resizeGL(self, width, height):
side = min(width, height)
- glViewport((width - side) / 2, (height - side) / 2, side, side)
+ glViewport(int((width - side) / 2), int((height - side) / 2), side, side)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
@@ -156,14 +177,14 @@ class GLWidget(QtOpenGL.QGLWidget):
return dlist
-class Window(QtGui.QWidget):
+class Window(QtWidgets.QWidget):
NumRows = 2
NumColumns = 3
def __init__(self, parent=None):
- QtGui.QWidget.__init__(self, parent)
+ QtWidgets.QWidget.__init__(self, parent)
- mainLayout = QtGui.QGridLayout()
+ mainLayout = QtWidgets.QGridLayout()
self.glWidgets = []
for i in range(Window.NumRows):
@@ -184,7 +205,7 @@ class Window(QtGui.QWidget):
mainLayout.addWidget(self.glWidgets[i][j], i, j)
self.glWidgets[i][j].clicked.connect(self.setCurrentGlWidget)
- QtGui.qApp.lastWindowClosed.connect(self.glWidgets[i][j].freeGLResources)
+ QtWidgets.qApp.lastWindowClosed.connect(self.glWidgets[i][j].freeGLResources)
self.setLayout(mainLayout)
@@ -205,7 +226,7 @@ class Window(QtGui.QWidget):
if __name__ == "__main__":
- app = QtGui.QApplication(sys.argv)
+ app = QtWidgets.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())