add encoding parameter to .as_std_string()
to handle PyUnicode Objects. Usually ASCII for object names and Utf-8 for file names and console output. issue #995
This commit is contained in:
parent
8ee81e0516
commit
faac8c36ba
|
@ -104,7 +104,7 @@ std::string PropertyPythonObject::toString() const
|
|||
args.setItem(0, dump);
|
||||
Py::Object res = method.apply(args);
|
||||
Py::String str(res);
|
||||
repr = str.as_std_string();
|
||||
repr = str.as_std_string("ascii");
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
Base::PyException e; // extract the Python error text
|
||||
|
|
|
@ -998,7 +998,7 @@ bool Application::activateWorkbench(const char* name)
|
|||
Py::Callable method(handler.getAttr(std::string("GetClassName")));
|
||||
Py::Tuple args;
|
||||
Py::String result(method.apply(args));
|
||||
type = result.as_std_string();
|
||||
type = result.as_std_string("ascii");
|
||||
if (Base::Type::fromName(type.c_str()).isDerivedFrom(Gui::PythonBaseWorkbench::getClassTypeId())) {
|
||||
Workbench* wb = WorkbenchManager::instance()->createWorkbench(name, type);
|
||||
handler.setAttr(std::string("__Workbench__"), Py::Object(wb->getPyObject(), true));
|
||||
|
@ -1012,7 +1012,7 @@ bool Application::activateWorkbench(const char* name)
|
|||
// can be defined after the call of Initialize()
|
||||
if (type.empty()) {
|
||||
Py::String result(method.apply(args));
|
||||
type = result.as_std_string();
|
||||
type = result.as_std_string("ascii");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1111,7 +1111,7 @@ QPixmap Application::workbenchIcon(const QString& wb) const
|
|||
if (handler.hasAttr(std::string("Icon"))) {
|
||||
Py::Object member = handler.getAttr(std::string("Icon"));
|
||||
Py::String data(member);
|
||||
std::string content = data.as_std_string();
|
||||
std::string content = data.as_std_string("utf-8");
|
||||
|
||||
// test if in XPM format
|
||||
QByteArray ary;
|
||||
|
@ -1178,7 +1178,7 @@ QString Application::workbenchToolTip(const QString& wb) const
|
|||
Py::Object member = handler.getAttr(std::string("ToolTip"));
|
||||
if (member.isString()) {
|
||||
Py::String tip(member);
|
||||
return QString::fromUtf8(tip.as_std_string().c_str());
|
||||
return QString::fromUtf8(tip.as_std_string("utf-8").c_str());
|
||||
}
|
||||
}
|
||||
catch (Py::Exception& e) {
|
||||
|
@ -1203,7 +1203,7 @@ QString Application::workbenchMenuText(const QString& wb) const
|
|||
Py::Object member = handler.getAttr(std::string("MenuText"));
|
||||
if (member.isString()) {
|
||||
Py::String tip(member);
|
||||
return QString::fromUtf8(tip.as_std_string().c_str());
|
||||
return QString::fromUtf8(tip.as_std_string("utf-8").c_str());
|
||||
}
|
||||
}
|
||||
catch (Py::Exception& e) {
|
||||
|
@ -1288,7 +1288,7 @@ void Application::setupContextMenu(const char* recipient, MenuItem* items) const
|
|||
e.clear();
|
||||
if (o.isString()) {
|
||||
Py::String s(o);
|
||||
std::clog << "Application::setupContextMenu: " << s.as_std_string() << std::endl;
|
||||
std::clog << "Application::setupContextMenu: " << s.as_std_string("utf-8") << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -613,7 +613,7 @@ PyObject* Application::sAddWorkbenchHandler(PyObject * /*self*/, PyObject *args,
|
|||
// Search for some methods and members without invoking them
|
||||
Py::Callable(object.getAttr(std::string("Initialize")));
|
||||
Py::Callable(object.getAttr(std::string("GetClassName")));
|
||||
item = name.as_std_string();
|
||||
item = name.as_std_string("ascii");
|
||||
|
||||
PyObject* wb = PyDict_GetItemString(Instance->_pcWorkbenchDictionary,item.c_str());
|
||||
if (wb) {
|
||||
|
|
|
@ -1711,11 +1711,11 @@ void View3DInventorPy::eventCallback(void * ud, SoEventCallback * n)
|
|||
Py::Object o = Py::type(e);
|
||||
if (o.isString()) {
|
||||
Py::String s(o);
|
||||
Base::Console().Warning("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
else {
|
||||
Py::String s(o.repr());
|
||||
Base::Console().Warning("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
// Prints message to console window if we are in interactive mode
|
||||
PyErr_Print();
|
||||
|
@ -1866,11 +1866,11 @@ void View3DInventorPy::eventCallbackPivy(void * ud, SoEventCallback * n)
|
|||
Py::Object o = Py::type(e);
|
||||
if (o.isString()) {
|
||||
Py::String s(o);
|
||||
Base::Console().Warning("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
else {
|
||||
Py::String s(o.repr());
|
||||
Base::Console().Warning("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
// Prints message to console window if we are in interactive mode
|
||||
PyErr_Print();
|
||||
|
@ -1899,11 +1899,11 @@ void View3DInventorPy::eventCallbackPivyEx(void * ud, SoEventCallback * n)
|
|||
Py::Object o = Py::type(e);
|
||||
if (o.isString()) {
|
||||
Py::String s(o);
|
||||
Base::Console().Warning("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
else {
|
||||
Py::String s(o.repr());
|
||||
Base::Console().Warning("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
// Prints message to console window if we are in interactive mode
|
||||
PyErr_Print();
|
||||
|
@ -2031,11 +2031,11 @@ void View3DInventorPy::draggerCallback(void * ud, SoDragger* n)
|
|||
Py::Object o = Py::type(e);
|
||||
if (o.isString()) {
|
||||
Py::String s(o);
|
||||
Base::Console().Warning("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
else {
|
||||
Py::String s(o.repr());
|
||||
Base::Console().Warning("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
// Prints message to console window if we are in interactive mode
|
||||
PyErr_Print();
|
||||
|
|
|
@ -247,10 +247,10 @@ QIcon ViewProviderPythonFeatureImp::getIcon() const
|
|||
Py::Callable method(vp.getAttr(std::string("getIcon")));
|
||||
Py::Tuple args;
|
||||
Py::String str(method.apply(args));
|
||||
std::string content = str.as_std_string();
|
||||
std::string content = str.as_std_string("utf-8");
|
||||
QPixmap icon;
|
||||
// Check if the passed string is a filename, otherwise treat as xpm data
|
||||
QFileInfo fi(QString::fromAscii(content.c_str()));
|
||||
QFileInfo fi(QString::fromUtf8(content.c_str()));
|
||||
if (fi.isFile() && fi.exists()) {
|
||||
icon.load(fi.absoluteFilePath());
|
||||
} else {
|
||||
|
@ -649,9 +649,9 @@ const char* ViewProviderPythonFeatureImp::getDefaultDisplayMode() const
|
|||
Py::Callable method(vp.getAttr(std::string("getDefaultDisplayMode")));
|
||||
Py::Tuple args;
|
||||
Py::String str(method.apply(args));
|
||||
if (str.isUnicode())
|
||||
str = str.encode("ascii"); // json converts strings into unicode
|
||||
mode = str.as_std_string();
|
||||
//if (str.isUnicode())
|
||||
// str = str.encode("ascii"); // json converts strings into unicode
|
||||
mode = str.as_std_string("ascii");
|
||||
return mode.c_str();
|
||||
}
|
||||
}
|
||||
|
@ -680,7 +680,7 @@ std::vector<std::string> ViewProviderPythonFeatureImp::getDisplayModes(void) con
|
|||
Py::Sequence list(method.apply(args));
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Py::String str(*it);
|
||||
modes.push_back(str.as_std_string());
|
||||
modes.push_back(str.as_std_string("ascii"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -690,7 +690,7 @@ std::vector<std::string> ViewProviderPythonFeatureImp::getDisplayModes(void) con
|
|||
Py::Sequence list(method.apply(args));
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Py::String str(*it);
|
||||
modes.push_back(str.as_std_string());
|
||||
modes.push_back(str.as_std_string("ascii"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -717,7 +717,7 @@ std::string ViewProviderPythonFeatureImp::setDisplayMode(const char* ModeName)
|
|||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::String(ModeName));
|
||||
Py::String str(method.apply(args));
|
||||
return str.as_std_string();
|
||||
return str.as_std_string("ascii");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ void CompleteGuiExport initCompleteGui()
|
|||
Py::Callable method(handler.getAttr(std::string("GetClassName")));
|
||||
Py::Tuple args;
|
||||
Py::String result(method.apply(args));
|
||||
type = result.as_std_string();
|
||||
type = result.as_std_string("ascii");
|
||||
if (type == "Gui::PythonWorkbench") {
|
||||
Gui::Workbench* wb = Gui::WorkbenchManager::instance()->createWorkbench("DraftWorkbench", type);
|
||||
handler.setAttr(std::string("__Workbench__"), Py::Object(wb->getPyObject(), true));
|
||||
|
@ -120,11 +120,11 @@ void CompleteGuiExport initCompleteGui()
|
|||
Py::Object o = Py::type(e);
|
||||
if (o.isString()) {
|
||||
Py::String s(o);
|
||||
Base::Console().Error("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Error("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
else {
|
||||
Py::String s(o.repr());
|
||||
Base::Console().Error("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Error("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
// Prints message to console window if we are in interactive mode
|
||||
PyErr_Print();
|
||||
|
|
|
@ -160,7 +160,7 @@ Py::String WaypointPy::getName(void) const
|
|||
|
||||
void WaypointPy::setName(Py::String arg)
|
||||
{
|
||||
getWaypointPtr()->Name = arg.as_std_string();
|
||||
getWaypointPtr()->Name = arg.as_std_string("ascii");
|
||||
}
|
||||
|
||||
Py::String WaypointPy::getType(void) const
|
||||
|
@ -181,7 +181,7 @@ Py::String WaypointPy::getType(void) const
|
|||
|
||||
void WaypointPy::setType(Py::String arg)
|
||||
{
|
||||
std::string typeStr(arg.as_std_string());
|
||||
std::string typeStr(arg.as_std_string("ascii"));
|
||||
if(typeStr=="PTP")
|
||||
getWaypointPtr()->Type = Waypoint::PTP;
|
||||
else if(typeStr=="LIN")
|
||||
|
|
|
@ -71,11 +71,11 @@ void StartGuiExport initStartGui()
|
|||
Py::Object o = Py::type(e);
|
||||
if (o.isString()) {
|
||||
Py::String s(o);
|
||||
Base::Console().Error("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Error("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
else {
|
||||
Py::String s(o.repr());
|
||||
Base::Console().Error("%s\n", s.as_std_string().c_str());
|
||||
Base::Console().Error("%s\n", s.as_std_string("utf-8").c_str());
|
||||
}
|
||||
// Prints message to console window if we are in interactive mode
|
||||
PyErr_Print();
|
||||
|
|
Loading…
Reference in New Issue
Block a user