diff options
author | Friedemann Kleint <[email protected]> | 2017-10-13 16:35:40 +0200 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2017-10-13 16:35:52 +0200 |
commit | bd0c77f81fcc66e2cd57d78123bd1ea5ece3cb28 (patch) | |
tree | 757aebd9db2e1198f3c1d5bacbddfb25a45c8a3c | |
parent | 29bf933c9244883b570a9d53e900415fdcf7d437 (diff) | |
parent | b43152d1708b51f7d5c62c7a249c776354f745f5 (diff) |
Change-Id: I7f2e832b6642d84028a2a2fb39c6ac896136b7c3
-rw-r--r-- | examples.pyqtc | 103 | ||||
-rw-r--r-- | examples/charts/memoryusage.py | 2 | ||||
-rw-r--r-- | examples/datavisualization/bars3d.py | 115 | ||||
-rw-r--r-- | examples/declarative/extending/chapter1-basics/basics.py | 5 | ||||
-rw-r--r-- | examples/declarative/extending/chapter2-methods/methods.py | 5 | ||||
-rw-r--r-- | examples/declarative/extending/chapter3-bindings/bindings.py | 5 | ||||
-rw-r--r-- | examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py | 5 | ||||
-rw-r--r-- | examples/declarative/extending/chapter5-listproperties/listproperties.py | 5 | ||||
-rwxr-xr-x | examples/declarative/scrolling.py | 7 | ||||
-rwxr-xr-x | examples/declarative/signals/pytoqml1/main.py | 6 | ||||
-rwxr-xr-x | examples/declarative/signals/qmltopy1/main.py | 6 | ||||
-rwxr-xr-x | examples/declarative/signals/qmltopy2/main.py | 6 | ||||
-rwxr-xr-x | examples/declarative/signals/qmltopy3/main.py | 6 | ||||
-rwxr-xr-x | examples/declarative/signals/qmltopy4/main.py | 6 | ||||
-rw-r--r-- | examples/declarative/usingmodel.py | 8 | ||||
-rw-r--r-- | examples/multimedia/player.py | 10 | ||||
-rw-r--r-- | examples/webenginewidgets/simplebrowser.py | 102 |
17 files changed, 382 insertions, 20 deletions
diff --git a/examples.pyqtc b/examples.pyqtc new file mode 100644 index 0000000..9d49ba1 --- /dev/null +++ b/examples.pyqtc @@ -0,0 +1,103 @@ +examples/charts/memoryusage.py +examples/corelib/threads/mandelbrot.py +examples/corelib/tools/codecs/codecs.py +examples/corelib/tools/regexp.py +examples/corelib/tools/settingseditor/settingseditor.py +examples/declarative/extending/chapter1-basics/basics.py +examples/declarative/extending/chapter2-methods/methods.py +examples/declarative/extending/chapter3-bindings/bindings.py +examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py +examples/declarative/extending/chapter5-listproperties/listproperties.py +examples/declarative/scrolling.py +examples/declarative/signals/pytoqml1/main.py +examples/declarative/signals/qmltopy1/main.py +examples/declarative/signals/qmltopy2/main.py +examples/declarative/signals/qmltopy3/main.py +examples/declarative/signals/qmltopy4/main.py +examples/declarative/usingmodel.py +examples/macextras/macpasteboardmime.py +examples/multimedia/audiooutput.py +examples/multimedia/camera.py +examples/multimedia/player.py +examples/network/blockingfortuneclient.py +examples/network/fortuneclient.py +examples/network/fortuneserver.py +examples/network/threadedfortuneserver.py +examples/opengl/2dpainting.py +examples/opengl/grabber.py +examples/opengl/hellogl.py +examples/opengl/overpainting.py +examples/opengl/samplebuffers.py +examples/opengl/textures/textures.py +examples/script/helloscript.py +examples/texttospeech/texttospeech.py +examples/tutorial/t1.py +examples/tutorial/t10.py +examples/tutorial/t11.py +examples/tutorial/t12.py +examples/tutorial/t13.py +examples/tutorial/t14.py +examples/tutorial/t2.py +examples/tutorial/t3.py +examples/tutorial/t4.py +examples/tutorial/t5.py +examples/tutorial/t6.py +examples/tutorial/t7.py +examples/tutorial/t8.py +examples/tutorial/t9.py +examples/webenginewidgets/simplebrowser.py +examples/widgets/animation/animatedtiles/animatedtiles.py +examples/widgets/animation/appchooser/appchooser.py +examples/widgets/animation/easing/easing.py +examples/widgets/animation/states/states.py +examples/widgets/dialogs/classwizard/classwizard.py +examples/widgets/dialogs/extension.py +examples/widgets/dialogs/findfiles.py +examples/widgets/dialogs/standarddialogs.py +examples/widgets/dialogs/trivialwizard.py +examples/widgets/draganddrop/draggabletext/draggabletext.py +examples/widgets/effects/lighting.py +examples/widgets/graphicsview/anchorlayout.py +examples/widgets/graphicsview/collidingmice/collidingmice.py +examples/widgets/graphicsview/diagramscene/diagramscene.py +examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py +examples/widgets/graphicsview/elasticnodes.py +examples/widgets/itemviews/addressbook/adddialogwidget.py +examples/widgets/itemviews/addressbook/addressbook.py +examples/widgets/itemviews/addressbook/addresswidget.py +examples/widgets/itemviews/addressbook/newaddresstab.py +examples/widgets/itemviews/addressbook/tablemodel.py +examples/widgets/itemviews/basicsortfiltermodel.py +examples/widgets/itemviews/fetchmore.py +examples/widgets/itemviews/stardelegate/stardelegate.py +examples/widgets/itemviews/stardelegate/stareditor.py +examples/widgets/itemviews/stardelegate/starrating.py +examples/widgets/layouts/basiclayouts.py +examples/widgets/layouts/dynamiclayouts.py +examples/widgets/layouts/flowlayout.py +examples/widgets/mainwindows/application/application.py +examples/widgets/mainwindows/dockwidgets/dockwidgets.py +examples/widgets/mainwindows/mdi/mdi.py +examples/widgets/painting/basicdrawing/basicdrawing.py +examples/widgets/painting/concentriccircles.py +examples/widgets/richtext/orderform.py +examples/widgets/richtext/syntaxhighlighter.py +examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.py +examples/widgets/richtext/textobject/textobject.py +examples/widgets/state-machine/eventtrans.py +examples/widgets/state-machine/factstates.py +examples/widgets/state-machine/pingpong.py +examples/widgets/state-machine/rogue.py +examples/widgets/state-machine/trafficlight.py +examples/widgets/state-machine/twowaybutton.py +examples/widgets/tutorials/addressbook/part1.py +examples/widgets/tutorials/addressbook/part2.py +examples/widgets/tutorials/addressbook/part3.py +examples/widgets/tutorials/addressbook/part4.py +examples/widgets/tutorials/addressbook/part5.py +examples/widgets/tutorials/addressbook/part6.py +examples/widgets/tutorials/addressbook/part7.py +examples/widgets/widgets/hellogl_openglwidget_legacy.py +examples/widgets/widgets/tetrix.py +examples/xml/dombookmarks/dombookmarks.py +examples/xmlpatterns/schema/schema.py diff --git a/examples/charts/memoryusage.py b/examples/charts/memoryusage.py index 5842e4c..c0e0a38 100644 --- a/examples/charts/memoryusage.py +++ b/examples/charts/memoryusage.py @@ -66,7 +66,7 @@ def getMemoryUsage(): command = line[0:23].strip() if command.endswith('.exe'): command = command[0:len(command) - 4] - memoryUsage = float(line[64:74].strip().replace(',', '')) + memoryUsage = float(line[64:74].strip().replace(',', '').replace('.', '')) legend = '' if memoryUsage > 10240: legend = '{} {}M'.format(command, round(memoryUsage / 1024)) diff --git a/examples/datavisualization/bars3d.py b/examples/datavisualization/bars3d.py new file mode 100644 index 0000000..c07314c --- /dev/null +++ b/examples/datavisualization/bars3d.py @@ -0,0 +1,115 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2017 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 QtDataVisualization example""" + +import os +import sys +from PySide2.QtCore import QRect, QSize, QProcess, Qt +from PySide2.QtGui import QGuiApplication, QScreen, QWindow +from PySide2.QtWidgets import QApplication, QSizePolicy, QMainWindow, QWidget +from PySide2.QtDataVisualization import QtDataVisualization + +def dataToBarDataRow(data): + return list(QtDataVisualization.QBarDataItem(d) for d in data) + +def dataToBarDataArray(data): + return list(dataToBarDataRow(row) for row in data) + +class MainWindow(QMainWindow): + + def __init__(self): + super(MainWindow, self).__init__() + + self.setWindowTitle('Qt DataVisualization 3D Bars') + + self.bars = QtDataVisualization.Q3DBars() + + self.columnAxis = QtDataVisualization.QCategory3DAxis() + self.columnAxis.setTitle('Columns') + self.columnAxis.setTitleVisible(True) + self.columnAxis.setLabels(['Column1', 'Column2']) + self.columnAxis.setLabelAutoRotation(30); + + self.rowAxis = QtDataVisualization.QCategory3DAxis() + self.rowAxis.setTitle('Rows') + self.rowAxis.setTitleVisible(True) + self.rowAxis.setLabels(['Row1', 'Row2']) + self.rowAxis.setLabelAutoRotation(30); + + self.valueAxis = QtDataVisualization.QValue3DAxis() + self.valueAxis.setTitle('Values') + self.valueAxis.setTitleVisible(True) + self.valueAxis.setRange(0, 5); + + self.bars.setRowAxis(self.rowAxis) + self.bars.setColumnAxis(self.columnAxis) + self.bars.setValueAxis(self.valueAxis) + + self.series = QtDataVisualization.QBar3DSeries() + self.arrayData = [[1, 2], [3, 4]] + self.series.dataProxy().addRows(dataToBarDataArray(self.arrayData)) + + self.bars.setPrimarySeries(self.series) + + self.container = QWidget.createWindowContainer(self.bars) + + if not self.bars.hasContext(): + print("Couldn't initialize the OpenGL context.") + sys.exit(-1) + + camera = self.bars.scene().activeCamera() + camera.setYRotation(22.5) + + geometry = QGuiApplication.primaryScreen().geometry() + size = geometry.height() * 3 / 4 + self.container.setMinimumSize(size, size) + + self.container.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding); + self.container.setFocusPolicy(Qt.StrongFocus); + self.setCentralWidget(self.container) + +if __name__ == '__main__': + app = QApplication(sys.argv) + mainWin = MainWindow() + mainWin.show() + sys.exit(app.exec_()) diff --git a/examples/declarative/extending/chapter1-basics/basics.py b/examples/declarative/extending/chapter1-basics/basics.py index 64d7ad0..2ed02fd 100644 --- a/examples/declarative/extending/chapter1-basics/basics.py +++ b/examples/declarative/extending/chapter1-basics/basics.py @@ -88,7 +88,10 @@ if __name__ == '__main__': view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) - view.setSource(QUrl.fromLocalFile('app.qml')) + qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances diff --git a/examples/declarative/extending/chapter2-methods/methods.py b/examples/declarative/extending/chapter2-methods/methods.py index 847d5e5..f9bd6d3 100644 --- a/examples/declarative/extending/chapter2-methods/methods.py +++ b/examples/declarative/extending/chapter2-methods/methods.py @@ -93,7 +93,10 @@ if __name__ == '__main__': view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) - view.setSource(QUrl.fromLocalFile('app.qml')) + qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances diff --git a/examples/declarative/extending/chapter3-bindings/bindings.py b/examples/declarative/extending/chapter3-bindings/bindings.py index 47e02a6..e87d3f4 100644 --- a/examples/declarative/extending/chapter3-bindings/bindings.py +++ b/examples/declarative/extending/chapter3-bindings/bindings.py @@ -98,7 +98,10 @@ if __name__ == '__main__': view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) - view.setSource(QUrl.fromLocalFile('app.qml')) + qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances diff --git a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py index 4b936fa..fd94991 100644 --- a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py +++ b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py @@ -103,7 +103,10 @@ if __name__ == '__main__': view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) - view.setSource(QUrl.fromLocalFile('app.qml')) + qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances diff --git a/examples/declarative/extending/chapter5-listproperties/listproperties.py b/examples/declarative/extending/chapter5-listproperties/listproperties.py index a6b270b..718691f 100644 --- a/examples/declarative/extending/chapter5-listproperties/listproperties.py +++ b/examples/declarative/extending/chapter5-listproperties/listproperties.py @@ -116,7 +116,10 @@ if __name__ == '__main__': view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) - view.setSource(QUrl.fromLocalFile('app.qml')) + qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances diff --git a/examples/declarative/scrolling.py b/examples/declarative/scrolling.py index a614c70..ff704c4 100755 --- a/examples/declarative/scrolling.py +++ b/examples/declarative/scrolling.py @@ -42,6 +42,7 @@ from __future__ import print_function +import os import sys from PySide2.QtCore import QUrl from PySide2.QtGui import QGuiApplication @@ -60,8 +61,10 @@ if __name__ == '__main__': ctxt = view.rootContext() ctxt.setContextProperty("myModel", dataList) - url = QUrl('view.qml') - view.setSource(url) + qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) view.show() app.exec_() diff --git a/examples/declarative/signals/pytoqml1/main.py b/examples/declarative/signals/pytoqml1/main.py index 0ca1ffe..92f94fe 100755 --- a/examples/declarative/signals/pytoqml1/main.py +++ b/examples/declarative/signals/pytoqml1/main.py @@ -42,6 +42,7 @@ from __future__ import print_function +import os import sys from PySide2.QtCore import QTimer, QUrl from PySide2.QtGui import QGuiApplication @@ -55,7 +56,10 @@ if __name__ == '__main__': timer.start(2000) view = QQuickView() - view.setSource(QUrl('view.qml')) + qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) root = view.rootObject() timer.timeout.connect(root.updateRotater) diff --git a/examples/declarative/signals/qmltopy1/main.py b/examples/declarative/signals/qmltopy1/main.py index 1ce0507..683169e 100755 --- a/examples/declarative/signals/qmltopy1/main.py +++ b/examples/declarative/signals/qmltopy1/main.py @@ -42,6 +42,7 @@ from __future__ import print_function +import os import sys from PySide2.QtCore import QObject, QUrl, Slot from PySide2.QtGui import QGuiApplication @@ -76,7 +77,10 @@ if __name__ == '__main__': context = view.rootContext() context.setContextProperty("con", con) - view.setSource(QUrl('view.qml')) + qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances diff --git a/examples/declarative/signals/qmltopy2/main.py b/examples/declarative/signals/qmltopy2/main.py index 2526ede..bb84f27 100755 --- a/examples/declarative/signals/qmltopy2/main.py +++ b/examples/declarative/signals/qmltopy2/main.py @@ -42,6 +42,7 @@ from __future__ import print_function +import os import sys from PySide2.QtCore import QObject, QUrl, Slot from PySide2.QtGui import QGuiApplication @@ -68,7 +69,10 @@ if __name__ == '__main__': context = view.rootContext() context.setContextProperty("rotatevalue", rotatevalue) - view.setSource(QUrl('view.qml')) + qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances diff --git a/examples/declarative/signals/qmltopy3/main.py b/examples/declarative/signals/qmltopy3/main.py index f2ddd49..c78c77a 100755 --- a/examples/declarative/signals/qmltopy3/main.py +++ b/examples/declarative/signals/qmltopy3/main.py @@ -42,6 +42,7 @@ from __future__ import print_function +import os import sys from PySide2.QtCore import QObject, QUrl from PySide2.QtGui import QGuiApplication @@ -54,7 +55,10 @@ def sayThis(s): if __name__ == '__main__': app = QGuiApplication(sys.argv) view = QQuickView() - view.setSource(QUrl('view.qml')) + qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) root = view.rootObject() root.textRotationChanged.connect(sayThis) diff --git a/examples/declarative/signals/qmltopy4/main.py b/examples/declarative/signals/qmltopy4/main.py index fb6fc3e..9eb9d41 100755 --- a/examples/declarative/signals/qmltopy4/main.py +++ b/examples/declarative/signals/qmltopy4/main.py @@ -42,6 +42,7 @@ from __future__ import print_function +import os import sys from PySide2.QtCore import QObject, QUrl from PySide2.QtGui import QGuiApplication @@ -54,7 +55,10 @@ def sayThis(s): if __name__ == '__main__': app = QGuiApplication(sys.argv) view = QQuickView() - view.setSource(QUrl('view.qml')) + qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) root = view.rootObject() button = root.findChild(QObject, "buttonMouseArea") diff --git a/examples/declarative/usingmodel.py b/examples/declarative/usingmodel.py index cbb334e..7d73990 100644 --- a/examples/declarative/usingmodel.py +++ b/examples/declarative/usingmodel.py @@ -42,8 +42,9 @@ from __future__ import print_function +import os import sys -from PySide2.QtCore import QAbstractListModel, Qt +from PySide2.QtCore import QAbstractListModel, Qt, QUrl from PySide2.QtGui import QGuiApplication import PySide2.QtQml from PySide2.QtQuick import QQuickView @@ -89,7 +90,10 @@ if __name__ == '__main__': myModel.populate() view.rootContext().setContextProperty("myModel", myModel) - view.setSource('view.qml') + qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) view.show() app.exec_() diff --git a/examples/multimedia/player.py b/examples/multimedia/player.py index a519332..76445cd 100644 --- a/examples/multimedia/player.py +++ b/examples/multimedia/player.py @@ -73,7 +73,7 @@ class MainWindow(QMainWindow): playMenu = self.menuBar().addMenu("&Play") playIcon = self.style().standardIcon(QStyle.SP_MediaPlay) self.playAction = toolBar.addAction(playIcon, "Play") - self.playAction.triggered.connect(self.player, SLOT("play()")) + self.playAction.triggered.connect(self.player.play) playMenu.addAction(self.playAction) previousIcon = self.style().standardIcon(QStyle.SP_MediaSkipBackward) @@ -83,17 +83,17 @@ class MainWindow(QMainWindow): pauseIcon = self.style().standardIcon(QStyle.SP_MediaPause) self.pauseAction = toolBar.addAction(pauseIcon, "Pause") - self.pauseAction.triggered.connect(self.player, SLOT("pause()")) + self.pauseAction.triggered.connect(self.player.pause) playMenu.addAction(self.pauseAction) nextIcon = self.style().standardIcon(QStyle.SP_MediaSkipForward) self.nextAction = toolBar.addAction(nextIcon, "Next") - self.nextAction.triggered.connect(self.playlist, SLOT("next()")) + self.nextAction.triggered.connect(self.playlist.next) playMenu.addAction(self.nextAction) stopIcon = self.style().standardIcon(QStyle.SP_MediaStop) self.stopAction = toolBar.addAction(stopIcon, "Stop") - self.stopAction.triggered.connect(self.player, SLOT("stop()")) + self.stopAction.triggered.connect(self.player.stop) playMenu.addAction(self.stopAction) self.volumeSlider = QSlider() @@ -105,7 +105,7 @@ class MainWindow(QMainWindow): self.volumeSlider.setTickInterval(10) self.volumeSlider.setTickPosition(QSlider.TicksBelow) self.volumeSlider.setToolTip("Volume") - self.volumeSlider.valueChanged.connect(self.player, SLOT("setVolume(int)")) + self.volumeSlider.valueChanged.connect(self.player.setVolume) toolBar.addWidget(self.volumeSlider) aboutMenu = self.menuBar().addMenu("&About") diff --git a/examples/webenginewidgets/simplebrowser.py b/examples/webenginewidgets/simplebrowser.py new file mode 100644 index 0000000..b895acb --- /dev/null +++ b/examples/webenginewidgets/simplebrowser.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python + +############################################################################# +## +## Copyright (C) 2017 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 WebEngineWidgets Example""" + +import sys +from PySide2.QtCore import QUrl +from PySide2.QtGui import QIcon +from PySide2.QtWidgets import (QApplication, QDesktopWidget, QLineEdit, + QMainWindow, QPushButton, QToolBar) +from PySide2.QtWebEngineWidgets import QWebEnginePage, QWebEngineView + +class MainWindow(QMainWindow): + + def __init__(self): + super(MainWindow, self).__init__() + + self.setWindowTitle('PySide2 WebEngineWidgets Example') + + self.toolBar = QToolBar() + self.addToolBar(self.toolBar) + self.backButton = QPushButton() + self.backButton.setIcon(QIcon(':/qt-project.org/styles/commonstyle/images/left-32.png')) + self.backButton.clicked.connect(self.back) + self.toolBar.addWidget(self.backButton) + self.forwardButton = QPushButton() + self.forwardButton.setIcon(QIcon(':/qt-project.org/styles/commonstyle/images/right-32.png')) + self.forwardButton.clicked.connect(self.forward) + self.toolBar.addWidget(self.forwardButton) + + self.addressLineEdit = QLineEdit() + self.addressLineEdit.returnPressed.connect(self.load) + self.toolBar.addWidget(self.addressLineEdit) + + self.webEngineView = QWebEngineView() + self.setCentralWidget(self.webEngineView) + initialUrl = 'http://qt.io/' + self.addressLineEdit.setText(initialUrl) + self.webEngineView.load(QUrl(initialUrl)) + self.webEngineView.page().titleChanged.connect(self.setWindowTitle) + self.webEngineView.page().urlChanged.connect(self.urlChanged) + + def load(self): + url = QUrl.fromUserInput(self.addressLineEdit.text()) + if url.isValid(): + self.webEngineView.load(url) + + def back(self): + self.webEngineView.page().triggerAction(QWebEnginePage.Back) + + def forward(self): + self.webEngineView.page().triggerAction(QWebEnginePage.Forward) + + def urlChanged(self, url): + self.addressLineEdit.setText(url.toString()) + +if __name__ == '__main__': + app = QApplication(sys.argv) + mainWin = MainWindow() + availableGeometry = app.desktop().availableGeometry(mainWin) + mainWin.resize(availableGeometry.width() * 2 / 3, availableGeometry.height() * 2 / 3) + mainWin.show() + sys.exit(app.exec_()) |