from __future__ import annotations
from PySide6.QtCore import QByteArray, QSize, Qt
from PySide6.QtGui import QColor, QIcon, QPainter, QPixmap
from PySide6.QtSvg import QSvgRenderer
LUCIDE_PATHS = {
"archive-restore": '',
"brush": '',
"chevron-right": '',
"eraser": '',
"eye": '',
"file-plus": '',
"file-code": '',
"folder-open": '',
"grid-2x2": '',
"layers": '',
"list-plus": '',
"paintbrush": '',
"plus": '',
"redo-2": '',
"rotate-cw": '',
"save": '',
"save-all": '',
"trash-2": '',
"undo-2": '',
}
def lucide_icon(name: str, color: str = "#e5e7eb", size: int = 22) -> QIcon:
path = LUCIDE_PATHS.get(name)
if path is None:
path = LUCIDE_PATHS["plus"]
svg = (
''
).format(color=color, path=path)
renderer = QSvgRenderer(QByteArray(svg.encode("utf-8")))
pixmap = QPixmap(QSize(size, size))
pixmap.fill(Qt.transparent)
painter = QPainter(pixmap)
renderer.render(painter)
painter.end()
return QIcon(pixmap)
def recolor_icon(name: str, color: QColor | str) -> QIcon:
return lucide_icon(name, QColor(color).name() if isinstance(color, QColor) else color)