diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-03-23 13:22:37 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-03-23 16:52:02 +0100 |
commit | ea35d748ec16822a4b845e8e839ecd04f59ac763 (patch) | |
tree | b8ec29de751d26f03b39035327a51dd52c529b19 /examples | |
parent | 83e70cc9914a814658bfe495c6092b70e166a905 (diff) |
Use pathlib in examples
Task-number: PYSIDE-1112
Change-Id: Ib99dbfb2c3889495d062b50dc9dbea04f1f78c79
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'examples')
14 files changed, 45 insertions, 30 deletions
diff --git a/examples/charts/qmlpolarchart/qmlpolarchart.py b/examples/charts/qmlpolarchart/qmlpolarchart.py index 006a801f1..ca24fdc7a 100644 --- a/examples/charts/qmlpolarchart/qmlpolarchart.py +++ b/examples/charts/qmlpolarchart/qmlpolarchart.py @@ -40,8 +40,10 @@ """PySide6 port of the QML Polar Chart Example from Qt v5.x""" -import sys import os +from pathlib import Path +import sys + from PySide6.QtQuick import QQuickView from PySide6.QtCore import Qt, QUrl from PySide6.QtWidgets import QApplication, QMainWindow @@ -51,12 +53,12 @@ if __name__ == '__main__': app = QApplication(sys.argv) viewer = QQuickView() - viewer.engine().addImportPath(os.path.dirname(__file__)) + src_dir = Path(__file__).resolve().parent + viewer.engine().addImportPath(os.fspath(src_dir)) viewer.engine().quit.connect(viewer.close) viewer.setTitle = "QML Polar Chart" - qmlFile = os.path.join(os.path.dirname(__file__), 'main.qml') - viewer.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + viewer.setSource(QUrl.fromLocalFile(os.fspath(src_dir / 'main.qml'))) viewer.setResizeMode(QQuickView.SizeRootObjectToView) viewer.show() diff --git a/examples/declarative/extending/chapter1-basics/basics.py b/examples/declarative/extending/chapter1-basics/basics.py index 5e2614fc7..9cbead9cc 100644 --- a/examples/declarative/extending/chapter1-basics/basics.py +++ b/examples/declarative/extending/chapter1-basics/basics.py @@ -42,6 +42,7 @@ """PySide6 port of the qml/tutorials/extending-qml/chapter1-basics example from Qt v5.x""" import os +from pathlib import Path import sys from PySide6.QtCore import Property, Signal, Qt, QUrl @@ -88,8 +89,8 @@ if __name__ == '__main__': view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) - qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'app.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) view.show() diff --git a/examples/declarative/extending/chapter2-methods/methods.py b/examples/declarative/extending/chapter2-methods/methods.py index 8b9c94c62..a37376ca8 100644 --- a/examples/declarative/extending/chapter2-methods/methods.py +++ b/examples/declarative/extending/chapter2-methods/methods.py @@ -42,6 +42,7 @@ """PySide6 port of the qml/tutorials/extending-qml/chapter2-methods example from Qt v5.x""" import os +from pathlib import Path import sys from PySide6.QtCore import Property, Signal, Slot, Qt, QUrl @@ -94,8 +95,8 @@ if __name__ == '__main__': view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) - qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'app.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) view.show() diff --git a/examples/declarative/extending/chapter3-bindings/bindings.py b/examples/declarative/extending/chapter3-bindings/bindings.py index 474745652..d19df7f24 100644 --- a/examples/declarative/extending/chapter3-bindings/bindings.py +++ b/examples/declarative/extending/chapter3-bindings/bindings.py @@ -42,6 +42,7 @@ """PySide6 port of the qml/tutorials/extending-qml/chapter3-bindings example from Qt v5.x""" import os +from pathlib import Path import sys from PySide6.QtCore import Property, Signal, Slot, QUrl, Qt @@ -98,8 +99,8 @@ if __name__ == '__main__': view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) - qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'app.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) view.show() diff --git a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py index 6a4be313e..1bf9387f5 100644 --- a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py +++ b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py @@ -42,6 +42,7 @@ """PySide6 port of the qml/tutorials/extending-qml/chapter4-customPropertyTypes example from Qt v5.x""" import os +from pathlib import Path import sys from PySide6.QtCore import Property, QUrl @@ -100,8 +101,8 @@ if __name__ == '__main__': view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) - qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'app.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) view.show() diff --git a/examples/declarative/extending/chapter5-listproperties/listproperties.py b/examples/declarative/extending/chapter5-listproperties/listproperties.py index 37603ea12..646a14458 100644 --- a/examples/declarative/extending/chapter5-listproperties/listproperties.py +++ b/examples/declarative/extending/chapter5-listproperties/listproperties.py @@ -42,6 +42,7 @@ """PySide6 port of the qml/tutorials/extending-qml/chapter5-listproperties example from Qt v5.x""" import os +from pathlib import Path import sys from PySide6.QtCore import Property, QUrl @@ -114,8 +115,8 @@ if __name__ == '__main__': view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) - qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'app.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) view.show() diff --git a/examples/declarative/scrolling/scrolling.py b/examples/declarative/scrolling/scrolling.py index 63f79a45b..be909e2d6 100644 --- a/examples/declarative/scrolling/scrolling.py +++ b/examples/declarative/scrolling/scrolling.py @@ -40,6 +40,7 @@ ############################################################################# import os +from pathlib import Path import sys from PySide6.QtCore import QUrl from PySide6.QtGui import QGuiApplication @@ -57,8 +58,8 @@ if __name__ == '__main__': ctxt = view.rootContext() ctxt.setContextProperty("myModel", dataList) - qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parents[1] / 'usingmodel' / 'view.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) view.show() diff --git a/examples/declarative/signals/pytoqml1/main.py b/examples/declarative/signals/pytoqml1/main.py index c210d7182..fa31c50bb 100644 --- a/examples/declarative/signals/pytoqml1/main.py +++ b/examples/declarative/signals/pytoqml1/main.py @@ -40,6 +40,7 @@ ############################################################################# import os +from pathlib import Path import sys from PySide6.QtCore import QTimer, QUrl from PySide6.QtGui import QGuiApplication @@ -52,8 +53,8 @@ if __name__ == '__main__': timer.start(2000) view = QQuickView() - qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'view.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) root = view.rootObject() diff --git a/examples/declarative/signals/pytoqml2/main.py b/examples/declarative/signals/pytoqml2/main.py index 7d86d1b3d..657161263 100644 --- a/examples/declarative/signals/pytoqml2/main.py +++ b/examples/declarative/signals/pytoqml2/main.py @@ -40,6 +40,7 @@ ############################################################################# import os +from pathlib import Path import sys from PySide6.QtCore import QObject, QTimer, QUrl, Signal, Slot from PySide6.QtGui import QGuiApplication @@ -69,8 +70,8 @@ if __name__ == '__main__': context = view.rootContext() context.setContextProperty("rotatevalue", rotatevalue) - qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'view.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) diff --git a/examples/declarative/signals/qmltopy1/main.py b/examples/declarative/signals/qmltopy1/main.py index 2875cc6cc..69f9e2f80 100644 --- a/examples/declarative/signals/qmltopy1/main.py +++ b/examples/declarative/signals/qmltopy1/main.py @@ -40,6 +40,7 @@ ############################################################################# import os +from pathlib import Path import sys from PySide6.QtCore import QObject, QUrl, Slot from PySide6.QtGui import QGuiApplication @@ -73,8 +74,8 @@ if __name__ == '__main__': context = view.rootContext() context.setContextProperty("con", con) - qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'view.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) view.show() diff --git a/examples/declarative/signals/qmltopy2/main.py b/examples/declarative/signals/qmltopy2/main.py index c0c6a25ef..219206be6 100644 --- a/examples/declarative/signals/qmltopy2/main.py +++ b/examples/declarative/signals/qmltopy2/main.py @@ -40,6 +40,7 @@ ############################################################################# import os +from pathlib import Path import sys from PySide6.QtCore import QObject, QUrl, Slot from PySide6.QtGui import QGuiApplication @@ -65,8 +66,8 @@ if __name__ == '__main__': context = view.rootContext() context.setContextProperty("rotatevalue", rotatevalue) - qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'view.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) view.show() diff --git a/examples/declarative/signals/qmltopy3/main.py b/examples/declarative/signals/qmltopy3/main.py index ada78cc30..d28121c8f 100644 --- a/examples/declarative/signals/qmltopy3/main.py +++ b/examples/declarative/signals/qmltopy3/main.py @@ -40,6 +40,7 @@ ############################################################################# import os +from pathlib import Path import sys from PySide6.QtCore import QUrl from PySide6.QtGui import QGuiApplication @@ -51,8 +52,8 @@ def sayThis(s): if __name__ == '__main__': app = QGuiApplication(sys.argv) view = QQuickView() - qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'view.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) diff --git a/examples/declarative/signals/qmltopy4/main.py b/examples/declarative/signals/qmltopy4/main.py index 865d157f7..2cc6920d3 100644 --- a/examples/declarative/signals/qmltopy4/main.py +++ b/examples/declarative/signals/qmltopy4/main.py @@ -40,6 +40,7 @@ ############################################################################# import os +from pathlib import Path import sys from PySide6.QtCore import QObject, QUrl from PySide6.QtGui import QGuiApplication @@ -51,8 +52,8 @@ def sayThis(s): if __name__ == '__main__': app = QGuiApplication(sys.argv) view = QQuickView() - qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'view.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) diff --git a/examples/declarative/usingmodel/usingmodel.py b/examples/declarative/usingmodel/usingmodel.py index a32945a25..7c54cc49e 100644 --- a/examples/declarative/usingmodel/usingmodel.py +++ b/examples/declarative/usingmodel/usingmodel.py @@ -40,6 +40,7 @@ ############################################################################# import os +from pathlib import Path import sys from PySide6.QtCore import QAbstractListModel, Qt, QUrl, QByteArray from PySide6.QtGui import QGuiApplication @@ -86,8 +87,8 @@ if __name__ == '__main__': myModel.populate() view.rootContext().setContextProperty("myModel", myModel) - qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') - view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + qml_file = os.fspath(Path(__file__).resolve().parent / 'view.qml') + view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) view.show() |