aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-09-15 15:28:29 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-09-15 15:09:48 +0000
commitdb336fa57497f837cfe9d58eb2d7763b33bef2e7 (patch)
tree26c7268d9d4bef941d0d63f764c143591ad2e6a1
parentaae2c80a7325f8cae47ac2fb371a5eed4b90097f (diff)
Quick examples: Standardize loading code
Expand local file by directory of script and load via QUrl. Exit on error. Change-Id: Ia5fd36cbe9b8940e265968e91a5e5ec2b216276b Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--examples/declarative/extending/chapter1-basics/basics.py5
-rw-r--r--examples/declarative/extending/chapter2-methods/methods.py5
-rw-r--r--examples/declarative/extending/chapter3-bindings/bindings.py5
-rw-r--r--examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py5
-rw-r--r--examples/declarative/extending/chapter5-listproperties/listproperties.py5
-rwxr-xr-xexamples/declarative/scrolling.py7
-rwxr-xr-xexamples/declarative/signals/pytoqml1/main.py6
-rwxr-xr-xexamples/declarative/signals/qmltopy1/main.py6
-rwxr-xr-xexamples/declarative/signals/qmltopy2/main.py6
-rwxr-xr-xexamples/declarative/signals/qmltopy3/main.py6
-rwxr-xr-xexamples/declarative/signals/qmltopy4/main.py6
-rw-r--r--examples/declarative/usingmodel.py8
12 files changed, 56 insertions, 14 deletions
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_()