diff --git a/src/Gui/PythonWrapper.cpp b/src/Gui/PythonWrapper.cpp index 3a1a2ef622..29d9ef9551 100644 --- a/src/Gui/PythonWrapper.cpp +++ b/src/Gui/PythonWrapper.cpp @@ -612,9 +612,9 @@ QImage *PythonWrapper::toQImage(PyObject *pyobj) Py::Object PythonWrapper::fromQIcon(const QIcon* icon) { #if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) - const char* typeName = typeid(*const_cast(icon)).name(); auto type = getPyTypeObjectForTypeName(); if (type) { + const char* typeName = typeid(*const_cast(icon)).name(); PyObject* pyobj = Shiboken::Object::newObject(type, const_cast(icon), true, false, typeName); return Py::asObject(pyobj); } @@ -636,14 +636,18 @@ QIcon *PythonWrapper::toQIcon(PyObject *pyobj) Py::Object PythonWrapper::fromQDir(const QDir& dir) { #if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) - const char* typeName = typeid(dir).name(); auto type = getPyTypeObjectForTypeName(); if (type) { + const char* typeName = typeid(dir).name(); PyObject* pyobj = Shiboken::Object::newObject(type, const_cast(&dir), false, false, typeName); return Py::asObject(pyobj); } #else - Q_UNUSED(dir) + // Access shiboken/PySide via Python + Py::Object obj = qt_wrapInstance(&dir, "QDir", "QtGui"); + if (!obj.isNull()) { + return obj; + } #endif throw Py::RuntimeError("Failed to wrap directory"); } @@ -713,32 +717,23 @@ Py::Object PythonWrapper::fromQObject(QObject* object, const char* className) if (!object) { return Py::None(); } -#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) - // Access shiboken/PySide via C++ - auto type = getPyTypeObjectForTypeName(); - if (type) { - std::string typeName; - if (className) { - typeName = className; - } - else { - typeName = object->metaObject()->className(); - } - - PyObject* pyobj = Shiboken::Object::newObject(type, object, false, false, typeName.c_str()); - WrapperManager::instance().addQObject(object, pyobj); - return Py::asObject(pyobj); - } -#else - // Access shiboken/PySide via Python - std::string typeName; + const char* typeName; if (className) { typeName = className; } else { typeName = object->metaObject()->className(); } - +#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) + // Access shiboken/PySide via C++ + auto type = getPyTypeObjectForTypeName(); + if (type) { + PyObject* pyobj = Shiboken::Object::newObject(type, object, false, false, typeName); + WrapperManager::instance().addQObject(object, pyobj); + return Py::asObject(pyobj); + } +#else + // Access shiboken/PySide via Python Py::Object obj = qt_wrapInstance(object, typeName, "QtCore"); if (!obj.isNull()) { return obj; @@ -749,32 +744,23 @@ Py::Object PythonWrapper::fromQObject(QObject* object, const char* className) Py::Object PythonWrapper::fromQWidget(QWidget* widget, const char* className) { -#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) - // Access shiboken/PySide via C++ - auto type = getPyTypeObjectForTypeName(); - if (type) { - std::string typeName; - if (className) { - typeName = className; - } - else { - typeName = widget->metaObject()->className(); - } - - PyObject* pyobj = Shiboken::Object::newObject(type, widget, false, false, typeName.c_str()); - WrapperManager::instance().addQObject(widget, pyobj); - return Py::asObject(pyobj); - } -#else - // Access shiboken/PySide via Python - std::string typeName; + const char* typeName; if (className) { typeName = className; } else { typeName = widget->metaObject()->className(); } - +#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) + // Access shiboken/PySide via C++ + auto type = getPyTypeObjectForTypeName(); + if (type) { + PyObject* pyobj = Shiboken::Object::newObject(type, widget, false, false, typeName); + WrapperManager::instance().addQObject(widget, pyobj); + return Py::asObject(pyobj); + } +#else + // Access shiboken/PySide via Python Py::Object obj = qt_wrapInstance(widget, typeName, "QtWidgets"); if (!obj.isNull()) { return obj;