diff options
author | Christian Tismer <[email protected]> | 2021-07-01 15:05:38 +0200 |
---|---|---|
committer | Christian Tismer <[email protected]> | 2021-07-02 08:09:58 +0200 |
commit | e2a3fa037b8133d857b34ddcecf1afe156095a4f (patch) | |
tree | 4752e8f7d4f3c13873a838f2143be988c2574e4a /sources | |
parent | ddf15e3cd1a6faeb1f98a9e2452e736cf629eec2 (diff) |
pathlib: extend QUrl.fromFilePath to support os.PathLike
[ChangeLog][PySide6] The function QUrl.fromFilePath supports now
the os.PathLike structure in addition to string arguments.
The new interface was applied, everywhere.
Change-Id: I2d888383c54b7f964e448d210264c7e902759f43
Pick-to: 6.1
Reviewed-by: Friedemann Kleint <[email protected]>
Diffstat (limited to 'sources')
23 files changed, 29 insertions, 23 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml index 20daf0b92..2a05cb0fb 100644 --- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml +++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml @@ -1799,6 +1799,7 @@ </extra-includes> </object-type> <value-type name="QUrlQuery" since="5.0"/> + <value-type name="QUrl" hash-function="PySide::hash"> <!-- Qt5: lots of changes --> <enum-type name="ComponentFormattingOption" flags="ComponentFormattingOptions,FormattingOptions"/> @@ -1826,7 +1827,12 @@ </insert-template> </inject-code> </add-function> + <modify-function signature="fromLocalFile(const QString &)"> + <modify-argument index="1"><replace-type modified-type="PyPathLike"/></modify-argument> + <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qfile-path-1"/> + </modify-function> </value-type> + <value-type name="QRegularExpression"> <enum-type name="WildcardConversionOption" flags="WildcardConversionOptions" since="6.0"/> <enum-type name="MatchOption" flags="MatchOptions"/> diff --git a/sources/pyside6/doc/tutorials/qmlapp/main.py b/sources/pyside6/doc/tutorials/qmlapp/main.py index c85b12ad7..a34dc9296 100644 --- a/sources/pyside6/doc/tutorials/qmlapp/main.py +++ b/sources/pyside6/doc/tutorials/qmlapp/main.py @@ -76,7 +76,7 @@ if __name__ == '__main__': #Load the QML file qml_file = Path(__file__).parent / "view.qml" - view.setSource(QUrl.fromLocalFile(os.fspath(qml_file.resolve()))) + view.setSource(QUrl.fromLocalFile(qml_file.resolve())) #Show the window if view.status() == QQuickView.Error: diff --git a/sources/pyside6/tests/QtQml/bug_451.py b/sources/pyside6/tests/QtQml/bug_451.py index bfa2eb83e..3c7a95c7f 100644 --- a/sources/pyside6/tests/QtQml/bug_451.py +++ b/sources/pyside6/tests/QtQml/bug_451.py @@ -89,7 +89,7 @@ class TestBug(unittest.TestCase): context.setContextProperty("python", obj) file = Path(__file__).resolve().parent / 'bug_451.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) root = view.rootObject() self.assertTrue(root, quickview_errorstring(view)) root.simpleFunction() diff --git a/sources/pyside6/tests/QtQml/bug_456.py b/sources/pyside6/tests/QtQml/bug_456.py index 270e56ee8..ef0f56442 100644 --- a/sources/pyside6/tests/QtQml/bug_456.py +++ b/sources/pyside6/tests/QtQml/bug_456.py @@ -71,7 +71,7 @@ class TestConnectionWithInvalidSignature(TimedQApplication): context.setContextProperty("rotatevalue", rotatevalue) file = Path(__file__).resolve().parent / 'bug_456.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) root = view.rootObject() self.assertTrue(root, quickview_errorstring(view)) button = root.findChild(QObject, "buttonMouseArea") diff --git a/sources/pyside6/tests/QtQml/bug_557.py b/sources/pyside6/tests/QtQml/bug_557.py index 172a15777..17f9582e6 100644 --- a/sources/pyside6/tests/QtQml/bug_557.py +++ b/sources/pyside6/tests/QtQml/bug_557.py @@ -49,5 +49,5 @@ component = QQmlComponent(engine) # This should segfault if the QDeclarativeComponent has not QQmlEngine file = Path(__file__).resolve().parent / 'foo.qml' assert(not file.is_file()) -component.loadUrl(QUrl.fromLocalFile(os.fspath(file))) +component.loadUrl(QUrl.fromLocalFile(file)) diff --git a/sources/pyside6/tests/QtQml/bug_726.py b/sources/pyside6/tests/QtQml/bug_726.py index f4dd93145..8eeb5bb39 100644 --- a/sources/pyside6/tests/QtQml/bug_726.py +++ b/sources/pyside6/tests/QtQml/bug_726.py @@ -71,7 +71,7 @@ class TestConnectionWithInvalidSignature(TimedQApplication): context.setContextProperty("proxy", proxy) file = Path(__file__).resolve().parent / 'bug_726.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) root = view.rootObject() self.assertTrue(root, quickview_errorstring(view)) button = root.findChild(QObject, "buttonMouseArea") diff --git a/sources/pyside6/tests/QtQml/bug_814.py b/sources/pyside6/tests/QtQml/bug_814.py index 9b5ac7af0..05cd440f1 100644 --- a/sources/pyside6/tests/QtQml/bug_814.py +++ b/sources/pyside6/tests/QtQml/bug_814.py @@ -76,7 +76,7 @@ class TestBug814(TimedQApplication): view.rootContext().setContextProperty("pythonModel", model) file = Path(__file__).resolve().parent / 'bug_814.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) root = view.rootObject() self.assertTrue(root, quickview_errorstring(view)) view.show() diff --git a/sources/pyside6/tests/QtQml/bug_825.py b/sources/pyside6/tests/QtQml/bug_825.py index 55d2e2514..936cbd82b 100644 --- a/sources/pyside6/tests/QtQml/bug_825.py +++ b/sources/pyside6/tests/QtQml/bug_825.py @@ -88,7 +88,7 @@ class TestBug825 (unittest.TestCase): view = QQuickView() file = Path(__file__).resolve().parent / 'bug_825.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() QTimer.singleShot(250, view.close) diff --git a/sources/pyside6/tests/QtQml/bug_847.py b/sources/pyside6/tests/QtQml/bug_847.py index 256320b1e..f578392b0 100644 --- a/sources/pyside6/tests/QtQml/bug_847.py +++ b/sources/pyside6/tests/QtQml/bug_847.py @@ -75,7 +75,7 @@ class TestQML(UsesQApplication): view.called.connect(self.done) file = Path(__file__).resolve().parent / 'bug_847.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) while view.status() == QQuickView.Loading: self.app.processEvents() self.assertEqual(view.status(), QQuickView.Ready) diff --git a/sources/pyside6/tests/QtQml/bug_926.py b/sources/pyside6/tests/QtQml/bug_926.py index 9dad2e92c..bbb000b01 100644 --- a/sources/pyside6/tests/QtQml/bug_926.py +++ b/sources/pyside6/tests/QtQml/bug_926.py @@ -70,7 +70,7 @@ class TestBug926 (unittest.TestCase): view = QQuickView() file = Path(__file__).resolve().parent / 'bug_926.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() diff --git a/sources/pyside6/tests/QtQml/bug_951.py b/sources/pyside6/tests/QtQml/bug_951.py index 3a121a0e6..75fc0b6eb 100644 --- a/sources/pyside6/tests/QtQml/bug_951.py +++ b/sources/pyside6/tests/QtQml/bug_951.py @@ -65,7 +65,7 @@ class TestRegisterQMLType(TimedQApplication): view = QQuickView() file = Path(__file__).resolve().parent / 'bug_951.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) self.assertTrue(view.rootObject(), quickview_errorstring(view)) self.app.exec() diff --git a/sources/pyside6/tests/QtQml/bug_995.py b/sources/pyside6/tests/QtQml/bug_995.py index 7db0c2e77..52a7b1d9d 100644 --- a/sources/pyside6/tests/QtQml/bug_995.py +++ b/sources/pyside6/tests/QtQml/bug_995.py @@ -45,7 +45,7 @@ from PySide6.QtQuick import QQuickView app = QGuiApplication([]) file = Path(__file__).resolve().parent / 'bug_995.qml' assert(file.is_file()) -view = QQuickView(QUrl.fromLocalFile(os.fspath(file))) +view = QQuickView(QUrl.fromLocalFile(file)) view.show() view.resize(200, 200) contentItem = view.contentItem() diff --git a/sources/pyside6/tests/QtQml/bug_997.py b/sources/pyside6/tests/QtQml/bug_997.py index 44c2a7ade..4ffb1d298 100644 --- a/sources/pyside6/tests/QtQml/bug_997.py +++ b/sources/pyside6/tests/QtQml/bug_997.py @@ -54,7 +54,7 @@ class TestBug(UsesQApplication): ctxt.setContextProperty('owner', ownerData) file = Path(__file__).resolve().parent / 'bug_997.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() QTimer.singleShot(1000, self.app.quit) diff --git a/sources/pyside6/tests/QtQml/connect_python_qml.py b/sources/pyside6/tests/QtQml/connect_python_qml.py index 77a4947c2..86273763d 100644 --- a/sources/pyside6/tests/QtQml/connect_python_qml.py +++ b/sources/pyside6/tests/QtQml/connect_python_qml.py @@ -63,7 +63,7 @@ class TestConnectionWithInvalidSignature(TimedQApplication): view = QQuickView() file = Path(__file__).resolve().parent / 'connect_python_qml.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) root = view.rootObject() self.assertTrue(root, quickview_errorstring(view)) button = root.findChild(QObject, "buttonMouseArea") diff --git a/sources/pyside6/tests/QtQml/javascript_exceptions.py b/sources/pyside6/tests/QtQml/javascript_exceptions.py index 7bb3aa43f..fe2518487 100644 --- a/sources/pyside6/tests/QtQml/javascript_exceptions.py +++ b/sources/pyside6/tests/QtQml/javascript_exceptions.py @@ -103,7 +103,7 @@ class JavaScriptExceptionsTest(UsesQApplication): view = QQuickView() file = Path(__file__).resolve().parent / 'javascript_exceptions.qml' self.assertTrue(file.is_file()) - qml_url = QUrl.fromLocalFile(os.fspath(file)) + qml_url = QUrl.fromLocalFile(file) view.setSource(qml_url) self.assertTrue(view.rootObject(), quickview_errorstring(view)) diff --git a/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py b/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py index 8a0fccf45..5c2bd86aa 100644 --- a/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py +++ b/sources/pyside6/tests/QtQml/qqmlincubator_incubateWhile.py @@ -80,7 +80,7 @@ class TestBug(unittest.TestCase): view.setResizeMode(QQuickView.SizeRootObjectToView) file = Path(__file__).resolve().parent / 'qqmlincubator_incubateWhile.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() diff --git a/sources/pyside6/tests/QtQml/qqmlnetwork_test.py b/sources/pyside6/tests/QtQml/qqmlnetwork_test.py index 8ab4dca0e..517888c79 100644 --- a/sources/pyside6/tests/QtQml/qqmlnetwork_test.py +++ b/sources/pyside6/tests/QtQml/qqmlnetwork_test.py @@ -68,7 +68,7 @@ class TestQQmlNetworkFactory(TimedQApplication): file = Path(__file__).resolve().parent / 'hw.qml' self.assertTrue(file.is_file()) - url = QUrl.fromLocalFile(os.fspath(file)) + url = QUrl.fromLocalFile(file) view.setSource(url) self.assertTrue(view.rootObject(), quickview_errorstring(view)) diff --git a/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py b/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py index df88f6d99..17b01620b 100644 --- a/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py +++ b/sources/pyside6/tests/QtQml/qquickitem_grabToImage.py @@ -50,7 +50,7 @@ class TestGrabToSharedPointerImage(TimedQApplication): view = QQuickView() file = Path(__file__).resolve().parent / 'qquickitem_grabToImage.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() diff --git a/sources/pyside6/tests/QtQml/qquickview_test.py b/sources/pyside6/tests/QtQml/qquickview_test.py index 9cf9bbabb..b783c2dd0 100644 --- a/sources/pyside6/tests/QtQml/qquickview_test.py +++ b/sources/pyside6/tests/QtQml/qquickview_test.py @@ -72,7 +72,7 @@ class TestQQuickView(TimedQApplication): file = Path(__file__).resolve().parent / 'view.qml' self.assertTrue(file.is_file()) - url = QUrl.fromLocalFile(os.fspath(file)) + url = QUrl.fromLocalFile(file) view.setSource(url) self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() @@ -93,7 +93,7 @@ class TestQQuickView(TimedQApplication): file = Path(__file__).resolve().parent / 'viewmodel.qml' self.assertTrue(file.is_file()) - url = QUrl.fromLocalFile(os.fspath(file)) + url = QUrl.fromLocalFile(file) view.setSource(url) self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() diff --git a/sources/pyside6/tests/QtQml/registersingletontype.py b/sources/pyside6/tests/QtQml/registersingletontype.py index 65fb96c01..30844ff8c 100644 --- a/sources/pyside6/tests/QtQml/registersingletontype.py +++ b/sources/pyside6/tests/QtQml/registersingletontype.py @@ -83,7 +83,7 @@ class TestQmlSupport(unittest.TestCase): view = QQuickView() file = Path(__file__).resolve().parent / 'registersingletontype.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) self.assertTrue(view.rootObject(), quickview_errorstring(view)) view.show() QTimer.singleShot(250, view.close) diff --git a/sources/pyside6/tests/QtQml/registertype.py b/sources/pyside6/tests/QtQml/registertype.py index 2bd91f2db..2bfb38d9a 100644 --- a/sources/pyside6/tests/QtQml/registertype.py +++ b/sources/pyside6/tests/QtQml/registertype.py @@ -123,7 +123,7 @@ class TestQmlSupport(unittest.TestCase): view = QQuickView() file = Path(__file__).resolve().parent / 'registertype.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) root_object = view.rootObject() self.assertTrue(root_object, quickview_errorstring(view)) self.assertTrue(qjsEngine(root_object)) diff --git a/sources/pyside6/tests/QtQml/registeruncreatabletype.py b/sources/pyside6/tests/QtQml/registeruncreatabletype.py index 6d399b8ae..c9c9b3bae 100644 --- a/sources/pyside6/tests/QtQml/registeruncreatabletype.py +++ b/sources/pyside6/tests/QtQml/registeruncreatabletype.py @@ -69,7 +69,7 @@ class TestQmlSupport(unittest.TestCase): engine = QQmlEngine() file = Path(__file__).resolve().parent / 'registeruncreatable.qml' self.assertTrue(file.is_file()) - component = QQmlComponent(engine, QUrl.fromLocalFile(os.fspath(file))) + component = QQmlComponent(engine, QUrl.fromLocalFile(file)) # Check that the uncreatable item produces the correct error self.assertEqual(component.status(), QQmlComponent.Error) diff --git a/sources/pyside6/tests/QtQml/signal_arguments.py b/sources/pyside6/tests/QtQml/signal_arguments.py index 2848a4a6a..b44372743 100644 --- a/sources/pyside6/tests/QtQml/signal_arguments.py +++ b/sources/pyside6/tests/QtQml/signal_arguments.py @@ -68,7 +68,7 @@ class TestConnectionWithQml(TimedQApplication): context.setContextProperty("o", obj) file = Path(__file__).resolve().parent / 'signal_arguments.qml' self.assertTrue(file.is_file()) - view.setSource(QUrl.fromLocalFile(os.fspath(file))) + view.setSource(QUrl.fromLocalFile(file)) root = view.rootObject() self.assertTrue(root, quickview_errorstring(view)) button = root.findChild(QObject, "button") |