MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / sAddIcon

Method sAddIcon

src/Gui/ApplicationPy.cpp:1551–1586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1549}
1550
1551PyObject* ApplicationPy::sAddIcon(PyObject* /*self*/, PyObject* args)
1552{
1553 const char* iconName = nullptr;
1554 Py_buffer content;
1555 const char* format = "XPM";
1556 if (!PyArg_ParseTuple(args, "ss*|s", &iconName, &content, &format)) {
1557 return nullptr;
1558 }
1559
1560 QPixmap icon;
1561 if (BitmapFactory().findPixmapInCache(iconName, icon)) {
1562 PyErr_SetString(PyExc_AssertionError, "Icon with this name already registered");
1563 PyBuffer_Release(&content);
1564 return nullptr;
1565 }
1566
1567 const char* contentStr = static_cast<const char*>(content.buf);
1568 QByteArray ary(contentStr, static_cast<int>(content.len));
1569 icon.loadFromData(ary, format);
1570
1571 if (icon.isNull()) {
1572 QString file = QString::fromUtf8(contentStr, static_cast<int>(content.len));
1573 icon.load(file);
1574 }
1575
1576 PyBuffer_Release(&content);
1577
1578 if (icon.isNull()) {
1579 PyErr_SetString(Base::PyExc_FC_GeneralError, "Invalid icon added to application");
1580 return nullptr;
1581 }
1582
1583 BitmapFactory().addPixmapToCache(iconName, icon);
1584
1585 Py_Return;
1586}
1587
1588PyObject* ApplicationPy::sGetIcon(PyObject* /*self*/, PyObject* args)
1589{

Callers

nothing calls this directly

Calls 4

findPixmapInCacheMethod · 0.80
addPixmapToCacheMethod · 0.80
isNullMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected