"""Line icons (Lucide, ISC licence) rendered in the current theme colour.""" import tempfile from functools import lru_cache from pathlib import Path from PySide6.QtCore import QByteArray, QRectF, Qt from PySide6.QtGui import QIcon, QPainter, QPixmap from PySide6.QtSvg import QSvgRenderer _PATHS = { "dashboard": '' '', "plug": '', "monitor": '', "server": '' '', "network": '' '' '', "globe": '', "list": '' '', "settings": '' '', "plus": '', "pencil": '', "trash": '', "wifi": '' '', "refresh": '' '', "printer": '' '', "play": '', "search": '', "check": '', "x": '', "chevron-down": '', "chevron-up": '', "chevron-right": '', "eye": '', "eye-off": '' '', "upload": '', "download": '', "copy": '', "folder": '', "more": '', "warning": '' '', "success": '', "error": '', "info": '', "terminal": '', "building": '' '' '', "database": '', "zap": '', "arrow-right": '', "arrow-left": '', "link": '' '', "stop": '', "shield": '', "dot": '', "radio-dot": '', } def _svg(name, color, stroke=2.0): body = _PATHS[name] return ( f'' f'{body.replace("currentColor", color)}' ) @lru_cache(maxsize=512) def icon(name, color="#475569", stroke=2.0): renderer = QSvgRenderer(QByteArray(_svg(name, color, stroke).encode("utf-8"))) result = QIcon() for size in (16, 20, 24, 32, 48, 64): pixmap = QPixmap(size, size) pixmap.fill(Qt.transparent) painter = QPainter(pixmap) painter.setRenderHint(QPainter.Antialiasing) renderer.render(painter, QRectF(0, 0, size, size)) painter.end() result.addPixmap(pixmap) return result def svg_file(name, color, stroke=2.0): """Write an icon to a temp file so that Qt style sheets can reference it.""" folder = Path(tempfile.gettempdir()) / "netbox-synchronizer-theme" folder.mkdir(parents=True, exist_ok=True) path = folder / f"{name}-{color.lstrip('#')}-{stroke}.svg" if not path.exists(): path.write_text(_svg(name, color, stroke), encoding="utf-8") return path.as_posix()