diff --git a/src/Gui/PythonWrapper.cpp b/src/Gui/PythonWrapper.cpp index f737ff45a2..3fcbf2d121 100644 --- a/src/Gui/PythonWrapper.cpp +++ b/src/Gui/PythonWrapper.cpp @@ -108,6 +108,7 @@ PyTypeObject** SbkPySide_QtGuiTypes=nullptr; PyTypeObject** SbkPySide2_QtCoreTypes=nullptr; PyTypeObject** SbkPySide2_QtGuiTypes=nullptr; PyTypeObject** SbkPySide2_QtWidgetsTypes=nullptr; +PyTypeObject** SbkPySide2_QtPrintSupportTypes=nullptr; # endif // HAVE_PYSIDE2 #endif // HAVE_SHIBOKEN2 @@ -585,6 +586,34 @@ QDir* PythonWrapper::toQDir(PyObject* pyobj) return nullptr; } +Py::Object PythonWrapper::fromQPrinter(QPrinter* printer) +{ + if (!printer) + return Py::None(); +#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) + // Access shiboken/PySide via C++ + // + PyTypeObject * type = getPyTypeObjectForTypeName(); + if (!type) { + type = Shiboken::Conversions::getPythonTypeObject("QPrinter"); + } + if (type) { + auto sbk_type = reinterpret_cast(type); + PyObject* pyobj = Shiboken::Object::newObject(sbk_type, printer, false, false, "QPrinter"); + return Py::asObject(pyobj); + } + + throw Py::RuntimeError("Failed to wrap object"); +#else + // Access shiboken2/PySide2 via Python + // + return qt_wrapInstance(printer, "QPrinter", "shiboken2", "PySide2.QtCore", "wrapInstance"); +#endif +#ifdef HAVE_PYQT // Unwrapping using sip/PyQt + return qt_wrapInstance(printer, "QPrinter", "sip", "PyQt5.QtCore", "wrapinstance"); +#endif +} + Py::Object PythonWrapper::fromQObject(QObject* object, const char* className) { if (!object) @@ -730,6 +759,20 @@ bool PythonWrapper::loadWidgetsModule() return true; } +bool PythonWrapper::loadPrintSupportModule() +{ +#if defined (HAVE_SHIBOKEN2) && defined(HAVE_PYSIDE2) + // QtPrintSupport + if (!SbkPySide2_QtPrintSupportTypes) { + Shiboken::AutoDecRef requiredModule(Shiboken::Module::import("PySide2.QtPrintSupport")); + if (requiredModule.isNull()) + return false; + SbkPySide2_QtPrintSupportTypes = Shiboken::Module::getTypes(requiredModule); + } +#endif + return true; +} + bool PythonWrapper::loadUiToolsModule() { #if defined (HAVE_SHIBOKEN2) && defined(HAVE_PYSIDE2) diff --git a/src/Gui/PythonWrapper.h b/src/Gui/PythonWrapper.h index 10de58290d..961590dfb6 100644 --- a/src/Gui/PythonWrapper.h +++ b/src/Gui/PythonWrapper.h @@ -34,6 +34,7 @@ class QIcon; class QGraphicsObject; class QGraphicsItem; class QObject; +class QPrinter; class QWidget; QT_END_NAMESPACE @@ -46,6 +47,7 @@ public: bool loadCoreModule(); bool loadGuiModule(); bool loadWidgetsModule(); + bool loadPrintSupportModule(); bool loadUiToolsModule(); bool toCString(const Py::Object&, std::string&); @@ -53,6 +55,8 @@ public: QGraphicsItem* toQGraphicsItem(PyObject* ptr); QGraphicsObject* toQGraphicsObject(PyObject* pyPtr); + Py::Object fromQPrinter(QPrinter*); + Py::Object fromQObject(QObject*, const char* className=nullptr); Py::Object fromQWidget(QWidget*, const char* className=nullptr); const char* getWrapperName(QObject*) const;