| 1549 | } |
| 1550 | |
| 1551 | PyObject* 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 | |
| 1588 | PyObject* ApplicationPy::sGetIcon(PyObject* /*self*/, PyObject* args) |
| 1589 | { |
nothing calls this directly
no test coverage detected