Commit 9fd8ce17 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

add pythonappend call to dtkObjectManager::value to return real type to python instead of QVariant

parent ef9bc310
......@@ -117,6 +117,7 @@ if(DTK_BUILD_WRAPPERS)
if(SWIG_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dtkCore.i ${CMAKE_BINARY_DIR}/dtkCore.i COPYONLY)
set(${PROJECT_NAME}_WRAP_DEPENDS ${${PROJECT_NAME}_WRAP_DEPENDS} ${CMAKE_BINARY_DIR}/dtkCore.i)
if (DTK_WRAPPING_PYTHON AND PYTHONLIBS_FOUND)
dtk_wrap(${PROJECT_NAME} ${PROJECT_NAME}_SOURCES_WRAP dtkcore python ${PROJECT_SOURCE_DIR}/dtkCore.i "${${PROJECT_NAME}_WRAP_DEPENDS}" ".")
......
......@@ -37,6 +37,18 @@
#undef DTKCORE_EXPORT
#define DTKCORE_EXPORT
%pythonappend dtkObjectManager::value(const QString &key) const %{
# print "convert variant to embedded object type"
method_name = "to" + val.typeName().strip("*")
try:
method = getattr(val, method_name)
return method()
except:
print "can't convert to real type, return a QVariant"
return val
%}
// /////////////////////////////////////////////////////////////////
// Wrapper input
// /////////////////////////////////////////////////////////////////
......
......@@ -8,6 +8,7 @@ public:
QString toString() const;
QStringList toStringList() const;
bool toBool() const;
const char *typeName() const;
};
%extend QVariant {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment