"""Inline SVG icons + Qt pixmap rasteriser.
Icons are stored as SVG strings so the pyz stays a single file (no
external assets). Rendering uses ``QSvgRenderer`` from whichever Qt
binding loaded — PySide6 or PyQt6.
Color baked into the SVG (Qt's QSvgRenderer ignores stylesheet
``currentColor`` inheritance). To recolour, edit the SVG string here
or call :func:`recolor` to substitute the placeholder ``#FFFFFF``.
Card glyphs from the Material Icons set (Apache-2.0). Badge glyphs
hand-rolled from pure SVG primitives so we don't pull a glyph font.
"""
from __future__ import annotations
from typing import Any
# ---------------------------------------------------------------------------
# Card glyphs (24x24, single-color, drawn over card bg)
# ---------------------------------------------------------------------------
# Material Icons "cloud" path data — outline of a stylised cumulus.
CLOUD_SVG = """"""
# Material Icons "storage" — three stacked server racks. Reads as
# "local storage" without the visual ambiguity of a floppy disk.
STORAGE_SVG = """"""
# ---------------------------------------------------------------------------
# Header badges (32x32, full disc + glyph)
# ---------------------------------------------------------------------------
# Light-gray disc with a dark exclamation. Used in the conflict dialog.
WARNING_BADGE_SVG = """"""
# Prism-green disc with a dark plus. Used in the login dialog.
PLUS_BADGE_SVG = """"""
# Prism-green disc with a circular arrow. Used in the progress window.
SYNC_BADGE_SVG = """"""
# ---------------------------------------------------------------------------
# Rasterise
# ---------------------------------------------------------------------------
def svg_pixmap(svg: str, size: int) -> Any:
"""Render an SVG string to a ``QPixmap`` of ``size`` × ``size`` px.
Caller is responsible for keeping the returned pixmap alive (e.g.
by attaching it to a QLabel). Raises ``ImportError`` if no Qt
binding is available.
"""
QtCore, QtGui, QtSvg = _import_qt_for_svg()
pm = QtGui.QPixmap(size, size)
pm.fill(QtCore.Qt.GlobalColor.transparent)
renderer = QtSvg.QSvgRenderer(QtCore.QByteArray(svg.encode("utf-8")))
painter = QtGui.QPainter(pm)
try:
renderer.render(painter)
finally:
painter.end()
return pm
def _import_qt_for_svg() -> tuple[Any, Any, Any]:
try:
from PySide6 import QtCore, QtGui, QtSvg # type: ignore
return QtCore, QtGui, QtSvg
except ImportError:
from PyQt6 import QtCore, QtGui, QtSvg # type: ignore
return QtCore, QtGui, QtSvg