diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index f5c83a98a5..ddac0a85db 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -441,27 +441,48 @@ void PropertyEnumeration::setPyObject(PyObject *value) throw Base::ValueError(out.str()); } } - else if (PyList_Check(value)) { - Py_ssize_t nSize = PyList_Size(value); + else if (PyUnicode_Check(value)) { + PyObject* unicode = PyUnicode_AsUTF8String(value); + std::string str = PyString_AsString(unicode); + Py_DECREF(unicode); + if (_enum.contains(str.c_str())) { + aboutToSetValue(); + _enum.setValue(str); + hasSetValue(); + } + else { + std::stringstream out; + out << "'" << str << "' is not part of the enumeration"; + throw Base::ValueError(out.str()); + } + } + else if (PySequence_Check(value)) { + Py_ssize_t nSize = PySequence_Size(value); std::vector values; values.resize(nSize); for (Py_ssize_t i = 0; i < nSize; ++i) { - PyObject *item = PyList_GetItem(value, i); + PyObject *item = PySequence_GetItem(value, i); - if ( !PyString_Check(item) ) { - std::string error = std::string("type in list must be str, not "); + if (PyString_Check(item)) { + values[i] = PyString_AsString(item); + } + else if (PyUnicode_Check(item)) { + PyObject* unicode = PyUnicode_AsUTF8String(item); + values[i] = PyString_AsString(unicode); + Py_DECREF(unicode); + } + else { + std::string error = std::string("type in list must be str or unicode, not "); throw Base::TypeError(error + item->ob_type->tp_name); } - - values[i] = PyString_AsString(item); } _enum.setEnums(values); setValue((long)0); } else { - std::string error = std::string("type must be int or str, not "); + std::string error = std::string("type must be int, str or unicode not "); throw Base::TypeError(error + value->ob_type->tp_name); } } diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index f3c75aac8e..106947677b 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -1977,8 +1977,9 @@ void PropertyEnumItem::setValue(const QVariant& value) return; QStringList items = value.toStringList(); if (!items.isEmpty()) { - QString val = items.front(); - QString data = QString::fromLatin1("\"%1\"").arg(val); + QByteArray val = items.front().toUtf8(); + std::string str = Base::Tools::escapedUnicodeFromUtf8(val); + QString data = QString::fromLatin1("u\"%1\"").arg(QString::fromStdString(str)); setPropertyValue(data); } } @@ -2007,12 +2008,12 @@ void PropertyEnumItem::setEditorData(QWidget *editor, const QVariant& data) cons const std::vector& value = prop->getEnumVector(); if (it == items.begin()) { for (std::vector::const_iterator jt = value.begin(); jt != value.end(); ++jt) - commonModes << QLatin1String(jt->c_str()); + commonModes << QString::fromUtf8(jt->c_str()); } else { for (std::vector::const_iterator jt = value.begin(); jt != value.end(); ++jt) { - if (commonModes.contains(QLatin1String(jt->c_str()))) - modes << QLatin1String(jt->c_str()); + if (commonModes.contains(QString::fromUtf8(jt->c_str()))) + modes << QString::fromUtf8(jt->c_str()); } commonModes = modes;