From 29c8e82daefc43c4ed3353e8755d1f8baef7366b Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 24 Sep 2015 13:10:54 +0200 Subject: [PATCH] + fixes unicode support in expression engine --- src/App/DocumentObjectPyImp.cpp | 14 ++++++++++++++ src/Gui/ExpressionBinding.cpp | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index 03550c39b6..7c74b48da2 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -172,6 +172,20 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args) getDocumentObjectPtr()->setExpression(p, shared_expr, comment); } + else if (PyUnicode_Check(expr)) { + PyObject* unicode = PyUnicode_AsEncodedString(expr, "utf-8", 0); + if (unicode) { + std::string exprStr = PyString_AsString(unicode); + Py_DECREF(unicode); + boost::shared_ptr shared_expr(ExpressionParser::parse(getDocumentObjectPtr(), exprStr.c_str())); + + getDocumentObjectPtr()->setExpression(p, shared_expr, comment); + } + else { + // utf-8 encoding failed + return 0; + } + } else throw Py::TypeError("String or None expected."); Py_Return; diff --git a/src/Gui/ExpressionBinding.cpp b/src/Gui/ExpressionBinding.cpp index 4795edb9ea..7c7d54f32b 100644 --- a/src/Gui/ExpressionBinding.cpp +++ b/src/Gui/ExpressionBinding.cpp @@ -112,7 +112,7 @@ bool ExpressionBinding::apply(const std::string & propName) if (!docObj) throw Base::Exception("Document object not found."); - Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument('%s').%s.setExpression('%s', '%s')", + Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument('%s').%s.setExpression('%s', u'%s')", docObj->getDocument()->getName(), docObj->getNameInDocument(), path.toEscapedString().c_str(),