Gui: handle exception in property item display
This commit is contained in:
@@ -347,49 +347,65 @@ QVariant PropertyItem::toString(const QVariant& prop) const
|
||||
if (prop != QVariant() || propertyItems.size()!=1)
|
||||
return prop;
|
||||
|
||||
Base::PyGILStateLocker lock;
|
||||
Py::Object pyobj(propertyItems[0]->getPyObject(), true);
|
||||
std::ostringstream ss;
|
||||
if (pyobj.isNone()) {
|
||||
ss << "<None>";
|
||||
}
|
||||
else if(pyobj.isSequence()) {
|
||||
ss << '[';
|
||||
Py::Sequence seq(pyobj);
|
||||
bool first = true;
|
||||
Py_ssize_t i=0;
|
||||
for (i=0; i<2 && i < seq.size(); ++i) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
ss << ", ";
|
||||
ss << Py::Object(seq[i]).as_string();
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Base::PyGILStateLocker lock;
|
||||
Py::Object pyobj(propertyItems[0]->getPyObject(), true);
|
||||
std::ostringstream ss;
|
||||
if (pyobj.isNone()) {
|
||||
ss << "<None>";
|
||||
}
|
||||
else if(pyobj.isSequence()) {
|
||||
ss << '[';
|
||||
Py::Sequence seq(pyobj);
|
||||
bool first = true;
|
||||
Py_ssize_t i=0;
|
||||
for (i=0; i<2 && i < seq.size(); ++i) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
ss << ", ";
|
||||
ss << Py::Object(seq[i]).as_string();
|
||||
}
|
||||
|
||||
if (i < seq.size())
|
||||
ss << "...";
|
||||
ss << ']';
|
||||
}
|
||||
else if (pyobj.isMapping()) {
|
||||
ss << '{';
|
||||
Py::Mapping map(pyobj);
|
||||
bool first = true;
|
||||
auto it = map.begin();
|
||||
for(int i=0; i<2 && it != map.end(); ++it, ++i) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
ss << ", ";
|
||||
const auto &v = *it;
|
||||
ss << Py::Object(v.first).as_string() << ':' << Py::Object(v.second).as_string();
|
||||
if (i < seq.size())
|
||||
ss << "...";
|
||||
ss << ']';
|
||||
}
|
||||
else if (pyobj.isMapping()) {
|
||||
ss << '{';
|
||||
Py::Mapping map(pyobj);
|
||||
bool first = true;
|
||||
auto it = map.begin();
|
||||
for(int i=0; i<2 && it != map.end(); ++it, ++i) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
ss << ", ";
|
||||
const auto &v = *it;
|
||||
ss << Py::Object(v.first).as_string() << ':' << Py::Object(v.second).as_string();
|
||||
}
|
||||
|
||||
if (it != map.end())
|
||||
ss << "...";
|
||||
ss << '}';
|
||||
}
|
||||
else {
|
||||
ss << pyobj.as_string();
|
||||
if (it != map.end())
|
||||
ss << "...";
|
||||
ss << '}';
|
||||
}
|
||||
else
|
||||
ss << pyobj.as_string();
|
||||
} catch (Py::Exception &) {
|
||||
Base::PyException e;
|
||||
ss.str("");
|
||||
ss << "ERR: " << e.what();
|
||||
} catch (Base::Exception &e) {
|
||||
ss.str("");
|
||||
ss << "ERR: " << e.what();
|
||||
} catch (std::exception &e) {
|
||||
ss.str("");
|
||||
ss << "ERR: " << e.what();
|
||||
} catch (...) {
|
||||
ss.str("");
|
||||
ss << "ERR!";
|
||||
}
|
||||
|
||||
return QVariant(QString::fromUtf8(ss.str().c_str()));
|
||||
|
||||
Reference in New Issue
Block a user