aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-07-03 10:46:33 +0200
committerChristian Tismer <tismer@stackless.com>2021-07-06 18:06:25 +0200
commit10abd17ffb8826e4aa5861f89642c46c47b641a8 (patch)
tree25c6c150c1cbbc5cd793b6e6148fcefc2b18a83f
parent57500ee1a277dd36fc650baa1af989a648dec9a7 (diff)
pathlib: support all cases which are found in the examples
Wherever possible/useful, os.fspath was removed and the according pathlike modification inserted. This is still not the awaited end of the conversion, but a good step forward. Task-number: PYSIDE-1499 Pick-to: 6.1 Change-Id: I0a22ddeec06ada05dc4a97ed104d06f5f1bbf472 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--examples/charts/qmlpolarchart/qmlpolarchart.py2
-rw-r--r--sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml22
-rw-r--r--sources/pyside6/PySide6/QtQml/typesystem_qml.xml10
-rw-r--r--sources/pyside6/PySide6/QtUiTools/typesystem_uitools.xml2
-rw-r--r--sources/pyside6/PySide6/glue/qtuitools.cpp3
-rw-r--r--sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py2
-rw-r--r--sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py2
-rw-r--r--sources/pyside6/doc/tutorials/qmlintegration/main.py2
-rw-r--r--sources/pyside6/tests/QtUiTools/bug_1060.py2
-rw-r--r--sources/pyside6/tests/QtUiTools/bug_797.py2
-rw-r--r--sources/pyside6/tests/QtUiTools/bug_909.py2
-rw-r--r--sources/pyside6/tests/QtUiTools/bug_913.py2
-rw-r--r--sources/pyside6/tests/QtUiTools/bug_958.py2
-rw-r--r--sources/pyside6/tests/QtUiTools/bug_965.py2
-rw-r--r--sources/pyside6/tests/QtWidgets/qimage_test.py2
15 files changed, 35 insertions, 24 deletions
diff --git a/examples/charts/qmlpolarchart/qmlpolarchart.py b/examples/charts/qmlpolarchart/qmlpolarchart.py
index f205f8db1..02902b56d 100644
--- a/examples/charts/qmlpolarchart/qmlpolarchart.py
+++ b/examples/charts/qmlpolarchart/qmlpolarchart.py
@@ -58,7 +58,7 @@ if __name__ == '__main__':
viewer.engine().quit.connect(viewer.close)
viewer.setTitle = "QML Polar Chart"
- viewer.setSource(QUrl.fromLocalFile(os.fspath(src_dir / 'main.qml')))
+ viewer.setSource(QUrl.fromLocalFile(src_dir / 'main.qml'))
viewer.setResizeMode(QQuickView.SizeRootObjectToView)
viewer.show()
diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
index 34f22f2ca..6e9332068 100644
--- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
+++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
@@ -533,14 +533,6 @@
</value-type>
<value-type name="QPixmap" >
- <!--<conversion-rule>-->
- <!--<target-to-native replace="no">-->
- <!--<add-conversion type="QVariant" check="%CHECKTYPE[QVariant](%in)">-->
- <!--QVariant in = %CONVERTTOCPP[QVariant](%in);-->
- <!--%out = in.value&lt;%OUTTYPE&gt;();-->
- <!--</add-conversion>-->
- <!--</target-to-native>-->
- <!--</conversion-rule>-->
<add-function signature="QPixmap(const QImage&amp;)">
<modify-argument index="1">
<rename to="image"/>
@@ -555,7 +547,10 @@
<insert-template name="load_xpm"/>
</inject-code>
</modify-function>
-
+ <modify-function signature="QPixmap(const QString &amp;, const char *, QFlags&lt;Qt::ImageConversionFlag&gt;)">
+ <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>
<!-- ### Operator ! doesn't make sense in Python. -->
<modify-function signature="operator!()const" remove="all"/>
@@ -680,6 +675,7 @@
</extra-includes>
</function> -->
<primitive-type name="QImageCleanupFunction"/>
+
<value-type name="QImage">
<enum-type name="Format"/>
<enum-type name="InvertMode"/>
@@ -693,7 +689,6 @@
<modify-function signature="load(QIODevice*,const char*)" allow-thread="yes"/>
<modify-function signature="save(const QString&amp;,const char*,int)const" allow-thread="yes"/>
<modify-function signature="save(QIODevice*,const char*,int)const" allow-thread="yes"/>
-
<modify-function signature="QImage(uchar*,int,int,qsizetype,QImage::Format,QImageCleanupFunction,void*)">
<modify-argument index="1">
<replace-type modified-type="PyBuffer"/>
@@ -715,6 +710,11 @@
</inject-code>
</modify-function>
+ <modify-function signature="QImage(const QString&amp;, const char *)">
+ <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>
+
<add-function signature="QImage(QString&amp;,int,int,int,QImage::Format)">
<inject-code>
<insert-template name="qimage_buffer_constructor">
@@ -773,13 +773,13 @@
-->
<modify-function signature="bits()const" remove="all"/>
<modify-function signature="scanLine(int)const" remove="all"/>
-
<modify-function signature="invertPixels(QImage::InvertMode)">
<modify-argument index="1">
<rename to="mode"/>
</modify-argument>
</modify-function>
</value-type>
+
<value-type name="QCursor" >
<extra-includes>
<include file-name="QPixmap" location="global"/>
diff --git a/sources/pyside6/PySide6/QtQml/typesystem_qml.xml b/sources/pyside6/PySide6/QtQml/typesystem_qml.xml
index df88fd466..779ffc332 100644
--- a/sources/pyside6/PySide6/QtQml/typesystem_qml.xml
+++ b/sources/pyside6/PySide6/QtQml/typesystem_qml.xml
@@ -167,13 +167,23 @@
<object-type name="QQmlDebuggingEnabler">
<enum-type name="StartMode"/>
</object-type>
+
<object-type name="QQmlEngine">
<modify-function signature="addImageProvider(const QString&amp;,QQmlImageProviderBase*)">
<modify-argument index="2">
<define-ownership owner="c++"/>
</modify-argument>
</modify-function>
+ <modify-function signature="addImportPath(const QString &amp;)">
+ <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>
+ <modify-function signature="addPluginPath(const QString &amp;)">
+ <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>
</object-type>
+
<object-type name="QQmlExpression">
<modify-function signature="evaluate(bool*)" allow-thread="yes">
<modify-argument index="1">
diff --git a/sources/pyside6/PySide6/QtUiTools/typesystem_uitools.xml b/sources/pyside6/PySide6/QtUiTools/typesystem_uitools.xml
index faefee12b..a8bf52112 100644
--- a/sources/pyside6/PySide6/QtUiTools/typesystem_uitools.xml
+++ b/sources/pyside6/PySide6/QtUiTools/typesystem_uitools.xml
@@ -130,7 +130,7 @@
</modify-function>
<!-- Syntax sugar -->
- <add-function signature="load(QString,QWidget*)" return-type="QWidget*">
+ <add-function signature="load(PyPathLike,QWidget*)" return-type="QWidget*">
<modify-argument index="2">
<replace-default-expression with="0"/>
<rename to="parentWidget"/>
diff --git a/sources/pyside6/PySide6/glue/qtuitools.cpp b/sources/pyside6/PySide6/glue/qtuitools.cpp
index ea45aeeb5..08cb89c46 100644
--- a/sources/pyside6/PySide6/glue/qtuitools.cpp
+++ b/sources/pyside6/PySide6/glue/qtuitools.cpp
@@ -108,7 +108,8 @@ registerCustomWidget(%PYARG_1);
// @snippet quiloader-load-2
// Avoid calling the original function: %CPPSELF.%FUNCTION_NAME()
-%PYARG_0 = QUiLoaderLoadUiFromFileName(%CPPSELF, %1, %2);
+auto str = PySide::pyPathToQString(%1);
+%PYARG_0 = QUiLoaderLoadUiFromFileName(%CPPSELF, str, %2);
// @snippet quiloader-load-2
// @snippet loaduitype
diff --git a/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py b/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py
index bebb40f50..31acc901b 100644
--- a/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py
+++ b/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py
@@ -55,7 +55,7 @@ class BookDelegate(QSqlRelationalDelegate):
def __init__(self, parent=None):
QSqlRelationalDelegate.__init__(self, parent)
star_png = Path(__file__).parent / "images" / "star.png"
- self.star = QPixmap(os.fspath(star_png))
+ self.star = QPixmap(star_png)
def paint(self, painter, option, index):
""" Paint the items in the table.
diff --git a/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py b/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py
index 4b5009b32..3ca6a6953 100644
--- a/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py
+++ b/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py
@@ -55,7 +55,7 @@ class BookDelegate(QSqlRelationalDelegate):
def __init__(self, star_png, parent=None):
QSqlRelationalDelegate.__init__(self, parent)
star_png = Path(__file__).parent / "images" / "star.png"
- self.star = QPixmap(os.fspath(star_png))
+ self.star = QPixmap(star_png)
def paint(self, painter, option, index):
""" Paint the items in the table.
diff --git a/sources/pyside6/doc/tutorials/qmlintegration/main.py b/sources/pyside6/doc/tutorials/qmlintegration/main.py
index 16fbee999..5fc40ad36 100644
--- a/sources/pyside6/doc/tutorials/qmlintegration/main.py
+++ b/sources/pyside6/doc/tutorials/qmlintegration/main.py
@@ -106,7 +106,7 @@ if __name__ == '__main__':
# Get the path of the current directory, and then add the name
# of the QML file, to load it.
qmlFile = Path(__file__).parent / 'view.qml'
- engine.load(os.fspath(qmlFile.resolve()))
+ engine.load(qmlFile.resolve())
if not engine.rootObjects():
sys.exit(-1)
diff --git a/sources/pyside6/tests/QtUiTools/bug_1060.py b/sources/pyside6/tests/QtUiTools/bug_1060.py
index db201f40a..106f7e515 100644
--- a/sources/pyside6/tests/QtUiTools/bug_1060.py
+++ b/sources/pyside6/tests/QtUiTools/bug_1060.py
@@ -53,5 +53,5 @@ if __name__ == "__main__":
file = Path(__file__).resolve().parent / 'bug_1060.ui'
assert(file.is_file())
- ui = MyQUiLoader().load(os.fspath(file))
+ ui = MyQUiLoader().load(file)
ui.show()
diff --git a/sources/pyside6/tests/QtUiTools/bug_797.py b/sources/pyside6/tests/QtUiTools/bug_797.py
index ac9ec2dcc..1185302e2 100644
--- a/sources/pyside6/tests/QtUiTools/bug_797.py
+++ b/sources/pyside6/tests/QtUiTools/bug_797.py
@@ -44,7 +44,7 @@ app = QApplication([])
loader = QUiLoader()
file = Path(__file__).resolve().parent / 'bug_552.ui'
assert(file.is_file())
-file = QFile(os.fspath(file))
+file = QFile(file)
w = QWidget()
# An exception can't be thrown
mainWindow = loader.load(file, w)
diff --git a/sources/pyside6/tests/QtUiTools/bug_909.py b/sources/pyside6/tests/QtUiTools/bug_909.py
index 96e1d1fa8..99c80aa09 100644
--- a/sources/pyside6/tests/QtUiTools/bug_909.py
+++ b/sources/pyside6/tests/QtUiTools/bug_909.py
@@ -46,7 +46,7 @@ class TestDestruction(UsesQApplication):
def testBug909(self):
file = Path(__file__).resolve().parent / 'bug_909.ui'
self.assertTrue(file.is_file())
- fileName = QFile(os.fspath(file))
+ fileName = QFile(file)
loader = QUiLoader()
main_win = loader.load(fileName)
self.assertEqual(sys.getrefcount(main_win), 2)
diff --git a/sources/pyside6/tests/QtUiTools/bug_913.py b/sources/pyside6/tests/QtUiTools/bug_913.py
index 9128969d8..f2ec3415f 100644
--- a/sources/pyside6/tests/QtUiTools/bug_913.py
+++ b/sources/pyside6/tests/QtUiTools/bug_913.py
@@ -50,7 +50,7 @@ class TestBug913 (unittest.TestCase):
loader = QUiLoader()
file = Path(__file__).resolve().parent / 'bug_913.ui'
self.assertTrue(file.is_file())
- widget = loader.load(os.fspath(file))
+ widget = loader.load(file)
widget.tabWidget.currentIndex() # direct child is available as member
widget.le_first.setText('foo') # child of QTabWidget must also be available!
diff --git a/sources/pyside6/tests/QtUiTools/bug_958.py b/sources/pyside6/tests/QtUiTools/bug_958.py
index d56424b7b..ddb6fc9ef 100644
--- a/sources/pyside6/tests/QtUiTools/bug_958.py
+++ b/sources/pyside6/tests/QtUiTools/bug_958.py
@@ -49,7 +49,7 @@ class Gui_Qt(QMainWindow):
# this used to cause a segfault because the old inject code used to destroy the parent layout
file = Path(__file__).resolve().parent / 'bug_958.ui'
assert(file.is_file())
- self._cw = lLoader.load(os.fspath(file), self)
+ self._cw = lLoader.load(file, self)
self.setCentralWidget(self._cw)
diff --git a/sources/pyside6/tests/QtUiTools/bug_965.py b/sources/pyside6/tests/QtUiTools/bug_965.py
index 92da3312a..be6984c4e 100644
--- a/sources/pyside6/tests/QtUiTools/bug_965.py
+++ b/sources/pyside6/tests/QtUiTools/bug_965.py
@@ -53,7 +53,7 @@ class BugTest(UsesQApplication):
loader = MyQUiLoader()
file = Path(__file__).resolve().parent / 'bug_965.ui'
self.assertTrue(file.is_file())
- self.assertRaises(RuntimeError, loader.load, os.fspath(file))
+ self.assertRaises(RuntimeError, loader.load, file)
if __name__ == '__main__':
diff --git a/sources/pyside6/tests/QtWidgets/qimage_test.py b/sources/pyside6/tests/QtWidgets/qimage_test.py
index 216126df9..6d15d8c3e 100644
--- a/sources/pyside6/tests/QtWidgets/qimage_test.py
+++ b/sources/pyside6/tests/QtWidgets/qimage_test.py
@@ -282,7 +282,7 @@ class QImageTest(UsesQApplication):
'''Test if the QImage signatures receiving string buffers exist.'''
file = Path(__file__).resolve().parent / 'sample.png'
self.assertTrue(file.is_file())
- img0 = QImage(os.fspath(file))
+ img0 = QImage(file)
# btw let's test the bits() method
img1 = QImage(img0.bits(), img0.width(), img0.height(), img0.format())