aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-02-12 19:13:43 +0100
committerChristian Tismer <tismer@stackless.com>2021-06-12 19:15:33 +0200
commit5276f9bf787eadd5a336f5f6eb6bcf19865de198 (patch)
tree0fa765d7acd45623fc83892026fd98fba6ff9da4 /sources/pyside6/libpyside
parentf8205c58207fd6c35ce743fc931392bac49ccc2f (diff)
build support for pathlib.Path, baseline
[ChangeLog][PySide6] pathlib.Path gets additionally accepted for all function arguments which have a std::filesystem::path type. This is a first part that implements those modifications which have a std::filesystem::path entry. In a later patch, all the possible other Path insertions will be made. Task-number: PYSIDE-1499 Change-Id: I2dec04dbdb2aaff6ca56c39b28f60281262fe078 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/libpyside')
-rw-r--r--sources/pyside6/libpyside/pyside.cpp17
-rw-r--r--sources/pyside6/libpyside/pyside.h5
2 files changed, 21 insertions, 1 deletions
diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp
index a78e4e9eb..16d77ab57 100644
--- a/sources/pyside6/libpyside/pyside.cpp
+++ b/sources/pyside6/libpyside/pyside.cpp
@@ -478,7 +478,8 @@ void setQuickRegisterItemFunction(QuickRegisterItemFunction function)
#endif // PYSIDE_QML_SUPPORT
// Inspired by Shiboken::String::toCString;
-QString pyStringToQString(PyObject *str) {
+QString pyStringToQString(PyObject *str)
+{
if (str == Py_None)
return QString();
@@ -495,6 +496,20 @@ QString pyStringToQString(PyObject *str) {
return QString();
}
+// PySide-1499: Provide an efficient, correct PathLike interface
+QString pyPathToQString(PyObject *path)
+{
+ // str or bytes pass through
+ if (PyUnicode_Check(path) || PyBytes_Check(path))
+ return pyStringToQString(path);
+
+ // Let PyOS_FSPath do its work and then fix the result for Windows.
+ Shiboken::AutoDecRef strPath(PyOS_FSPath(path));
+ if (strPath.isNull())
+ return QString();
+ return QDir::fromNativeSeparators(pyStringToQString(strPath));
+}
+
static const unsigned char qt_resource_name[] = {
// qt
0x0,0x2,
diff --git a/sources/pyside6/libpyside/pyside.h b/sources/pyside6/libpyside/pyside.h
index 3c4ae92b2..9bb0ab12e 100644
--- a/sources/pyside6/libpyside/pyside.h
+++ b/sources/pyside6/libpyside/pyside.h
@@ -157,6 +157,11 @@ PYSIDE_API void setQuickRegisterItemFunction(QuickRegisterItemFunction function)
PYSIDE_API QString pyStringToQString(PyObject *str);
/**
+ * Provide an efficient, correct PathLike interface.
+ */
+PYSIDE_API QString pyPathToQString(PyObject *path);
+
+/**
* Registers a dynamic "qt.conf" file with the Qt resource system.
*
* This is used in a standalone build, to inform QLibraryInfo of the Qt prefix (where Qt libraries