Skip to content

Commit

Permalink
wrapper for QVariant <> Base::Quantity <> PyObjectWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 15, 2017
1 parent d8afbe5 commit 2f66ff6
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions src/Gui/WidgetFactory.cpp
Expand Up @@ -24,8 +24,12 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <limits>
# include <QTextStream>
#endif
#if QT_VERSION >= 0x050200
# include <QMetaType>
#endif

// Uncomment this block to remove PySide support and switch back to PyQt
// #undef HAVE_SHIBOKEN
Expand Down Expand Up @@ -80,6 +84,7 @@ PyTypeObject** SbkPySide_QtGuiTypes=NULL;
# include <pyside2_qtcore_python.h>
# include <pyside2_qtgui_python.h>
# include <pyside2_qtwidgets_python.h>
# include <signalmanager.h>

This comment has been minimized.

Copy link
@fastflo

fastflo Feb 15, 2020

i just did the build from source on by debian buster with py3.8 and qt5. build failed here because compiler could not find signalmanager.h.
found it with the pyside2 include files at /usr/include/PySide2/signalmanager.h and changed this line to include PySide2/signalmanager.h which let the build continue...

This comment has been minimized.

Copy link
@wwmayer

wwmayer Feb 15, 2020

Author Contributor

There are not many projects out there using PySide2 but the few I found all include signalmanager.h and not PySide2/signalmanger.h -- also because this makes it more independent whether PySide or PySide2 is used.

Actually the list of include directories must handle this and the variable for this is PYSIDE_INCLUDE_DIR. On my system I found the file /usr/lib/x86_64-linux-gnu/cmake/PySide2-5.11.2/PySide2Config.cpython-36m-x86_64-linux-gnu.cmake and this sets SET(PYSIDE_INCLUDE_DIR "/usr/include/PySide2") -- as expected.

This comment has been minimized.

Copy link
@fastflo

fastflo Feb 16, 2020

i was trying to build the tag 0.19_pre
the CMakeCache.txt of my build dir only mentions pyside here:

//Path to a program.
PYSIDE2RCCBINARY:FILEPATH=/usr/bin/pyside2-rcc

//Path to a program.
PYSIDE2UICBINARY:FILEPATH=/usr/bin/pyside2-uic
#...
//The directory containing a CMake configuration file for PySide2.
PySide2_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/PySide2-5.13.2

i called cmake with

cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3.8 ..

cmake's stdout mentiones pyside only here:

-- PySide2:             5.13.2 [/usr/lib/include/PySide2]
-- PySide2Tools:        [/usr/bin/pyside2-uic] [/usr/bin/pyside2-rcc]

but on stderr cmake complains:

=================================================
Now run 'cmake --build /home/flo/FreeCAD/build' to build FreeCAD
=================================================

CMake Error in src/Gui/CMakeLists.txt:
  Imported target "PySide2::pyside2" includes non-existent path

    "/usr/lib/include/PySide2"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.



CMake Error in src/Gui/CMakeLists.txt:
  Imported target "PySide2::pyside2" includes non-existent path

    "/usr/lib/include/PySide2"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.

so i guess there is something wrong with the cmake files(the ones from debian/pyside or yours) as they refer to /usr/lib/include/PySide2 instead of /usr/include/PySide2.

the debian buster package libpyside2-dev (version 5.13.2-2.2+b1) includes the file /usr/lib/x86_64-linux-gnu/cmake/PySide2-5.13.2/PySide2Targets.cmake which includes

# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
#...
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/PySide2"

which looks correct to me -- it should resolve to /usr/include/PySide2.

not sure what is going wrong here. but i hate cmake so i leave it with that...

PyTypeObject** SbkPySide2_QtCoreTypes=NULL;
PyTypeObject** SbkPySide2_QtGuiTypes=NULL;
PyTypeObject** SbkPySide2_QtWidgetsTypes=NULL;
Expand Down Expand Up @@ -148,11 +153,52 @@ PythonToCppFunc toCppPointerCheckFuncQuantity(PyObject* obj)
return 0;
}

void BaseQuantity_PythonToCpp_QVariant(PyObject* pyIn, void* cppOut)
{
Base::Quantity* q = static_cast<Base::QuantityPy*>(pyIn)->getQuantityPtr();
*((QVariant*)cppOut) = QVariant::fromValue<Base::Quantity>(*q);
}

PythonToCppFunc isBaseQuantity_PythonToCpp_QVariantConvertible(PyObject* obj)
{
if (PyObject_TypeCheck(obj, &(Base::QuantityPy::Type)))
return BaseQuantity_PythonToCpp_QVariant;
return 0;
}

#if QT_VERSION >= 0x050200
Base::Quantity convertWrapperToQuantity(const PySide::PyObjectWrapper &w)
{
PyObject* pyIn = static_cast<PyObject*>(w);
if (PyObject_TypeCheck(pyIn, &(Base::QuantityPy::Type))) {
return *static_cast<Base::QuantityPy*>(pyIn)->getQuantityPtr();
}

return Base::Quantity(std::numeric_limits<double>::quiet_NaN());
}
#endif

void registerTypes()
{
SbkConverter* convert = Shiboken::Conversions::createConverter(&Base::QuantityPy::Type, toPythonFuncQuantity);
Shiboken::Conversions::setPythonToCppPointerFunctions(convert, toCppPointerConvFuncQuantity, toCppPointerCheckFuncQuantity);
SbkConverter* convert = Shiboken::Conversions::createConverter(&Base::QuantityPy::Type,
toPythonFuncQuantity);
Shiboken::Conversions::setPythonToCppPointerFunctions(convert,
toCppPointerConvFuncQuantity,
toCppPointerCheckFuncQuantity);
Shiboken::Conversions::registerConverterName(convert, "Base::Quantity");

SbkConverter* qvariant_conv = Shiboken::Conversions::getConverter("QVariant");
if (qvariant_conv) {
// The type QVariant already has a converter from PyBaseObject_Type which will
// come before our own converter.
Shiboken::Conversions::addPythonToCppValueConversion(qvariant_conv,
BaseQuantity_PythonToCpp_QVariant,
isBaseQuantity_PythonToCpp_QVariantConvertible);
}

#if QT_VERSION >= 0x050200
QMetaType::registerConverter<PySide::PyObjectWrapper, Base::Quantity>(&convertWrapperToQuantity);
#endif
}
#endif

Expand Down

0 comments on commit 2f66ff6

Please sign in to comment.