py3: App: files D-Z ported to python3

issue 0000995
diff to py3-branch will remain in the following files in src/App:
- ExtensionContainer.cpp
- FeaturePythonPyImp.h +.inl
most likely these files depend on Tools and Base
This commit is contained in:
looooo
2017-05-11 09:55:40 +02:00
committed by wmayer
parent f9bfd77555
commit ca3e58e2f3
10 changed files with 389 additions and 20 deletions

View File

@@ -75,19 +75,29 @@ Base::Quantity PropertyQuantity::createQuantityFromPy(PyObject *value)
{
Base::Quantity quant;
if (PyString_Check(value))
quant = Quantity::parse(QString::fromLatin1(PyString_AsString(value)));
else if (PyUnicode_Check(value)){
if (PyUnicode_Check(value)){
#if PY_MAJOR_VERSION >= 3
quant = Quantity::parse(QString::fromUtf8(PyUnicode_AsUTF8(value)));
}
#else
PyObject* unicode = PyUnicode_AsUTF8String(value);
std::string Str;
Str = PyString_AsString(unicode);
quant = Quantity::parse(QString::fromUtf8(Str.c_str()));
Py_DECREF(unicode);
}
else if (PyString_Check(value))
quant = Quantity::parse(QString::fromLatin1(PyString_AsString(value)));
#endif
else if (PyFloat_Check(value))
quant = Quantity(PyFloat_AsDouble(value),_Unit);
#if PY_MAJOR_VERSION < 3
else if (PyInt_Check(value))
quant = Quantity((double)PyInt_AsLong(value),_Unit);
#else
else if (PyLong_Check(value))
quant = Quantity((double)PyLong_AsLong(value),_Unit);
#endif
else if (PyObject_TypeCheck(value, &(QuantityPy::Type))) {
Base::QuantityPy *pcObject = static_cast<Base::QuantityPy*>(value);
quant = *(pcObject->getQuantityPtr());