"""Monochrome play/pause icons for the dashboard toolbar (avoids Windows emoji glyphs).""" from __future__ import annotations from typing import Literal from PyQt5.QtCore import QPointF, QRectF, Qt from PyQt5.QtGui import QColor, QIcon, QPainter, QPixmap, QPolygonF TransportKind = Literal["play", "pause"] _DEFAULT_ICON_PX = 18 def transport_icon(kind: TransportKind, color: str, *, size: int = _DEFAULT_ICON_PX) -> QIcon: """Build a flat play triangle or pause bars in ``color`` (#rrggbb).""" pixmap = QPixmap(size, size) pixmap.fill(Qt.transparent) painter = QPainter(pixmap) painter.setRenderHint(QPainter.Antialiasing, True) painter.setBrush(QColor(color)) painter.setPen(Qt.NoPen) if kind == "play": w = size * 0.52 h = size * 0.60 x0 = (size - w) * 0.58 y0 = (size - h) / 2.0 painter.drawPolygon( QPolygonF( [ QPointF(x0, y0), QPointF(x0, y0 + h), QPointF(x0 + w, y0 + h / 2.0), ] ) ) else: bar_w = size * 0.17 bar_h = size * 0.60 gap = size * 0.14 y0 = (size - bar_h) / 2.0 x0 = (size - (2.0 * bar_w + gap)) / 2.0 radius = max(1.0, size * 0.06) painter.drawRoundedRect(QRectF(x0, y0, bar_w, bar_h), radius, radius) painter.drawRoundedRect(QRectF(x0 + bar_w + gap, y0, bar_w, bar_h), radius, radius) painter.end() return QIcon(pixmap)