+ Avoid to unnecessarily throw Py::Exception

This commit is contained in:
wmayer
2014-02-22 11:35:51 +01:00
parent f8cd87a696
commit 11ebf1deb7
3 changed files with 75 additions and 33 deletions

View File

@@ -1091,45 +1091,47 @@ QPixmap Application::workbenchIcon(const QString& wb) const
// get its Icon member if possible
try {
Py::Object handler(pcWorkbench);
Py::Object member = handler.getAttr(std::string("Icon"));
Py::String data(member);
std::string content = data.as_std_string();
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();
// test if in XPM format
QByteArray ary;
int strlen = (int)content.size();
ary.resize(strlen);
for (int j=0; j<strlen; j++)
ary[j]=content[j];
if (ary.indexOf("/* XPM */") > 0) {
// Make sure to remove crap around the XPM data
QList<QByteArray> lines = ary.split('\n');
QByteArray buffer;
buffer.reserve(ary.size()+lines.size());
for (QList<QByteArray>::iterator it = lines.begin(); it != lines.end(); ++it) {
QByteArray trim = it->trimmed();
if (!trim.isEmpty()) {
buffer.append(trim);
buffer.append('\n');
// test if in XPM format
QByteArray ary;
int strlen = (int)content.size();
ary.resize(strlen);
for (int j=0; j<strlen; j++)
ary[j]=content[j];
if (ary.indexOf("/* XPM */") > 0) {
// Make sure to remove crap around the XPM data
QList<QByteArray> lines = ary.split('\n');
QByteArray buffer;
buffer.reserve(ary.size()+lines.size());
for (QList<QByteArray>::iterator it = lines.begin(); it != lines.end(); ++it) {
QByteArray trim = it->trimmed();
if (!trim.isEmpty()) {
buffer.append(trim);
buffer.append('\n');
}
}
icon.loadFromData(buffer, "XPM");
}
else {
// is it a file name...
QString file = QString::fromUtf8(content.c_str());
icon.load(file);
if (icon.isNull()) {
// ... or the name of another icon?
icon = BitmapFactory().pixmap(file.toUtf8());
}
}
icon.loadFromData(buffer, "XPM");
}
else {
// is it a file name...
QString file = QString::fromUtf8(content.c_str());
icon.load(file);
if (icon.isNull()) {
// ... or the name of another icon?
icon = BitmapFactory().pixmap(file.toUtf8());
if (!icon.isNull()) {
BitmapFactory().addPixmapToCache(iconName.c_str(), icon);
}
}
if (!icon.isNull()) {
BitmapFactory().addPixmapToCache(iconName.c_str(), icon);
return icon;
}
return icon;
}
catch (Py::Exception& e) {
e.clear();