Files
lintunes/lintunes/gui/icons.py
T
trav b7f8761bd1 Import existing LinTunes project
Snapshot of the existing codebase before working through the TASKS.md
backlog. Real library data (data/) and the iTunes import fixture
(itunes-test-library/) are gitignored.
2026-06-26 21:12:01 -04:00

79 lines
2.4 KiB
Python

"""Hand-painted transport glyphs (prev/play/pause/next/shuffle) in any color,
so buttons can flash the theme highlight while pressed."""
from PyQt6.QtCore import Qt, QPointF, QRectF
from PyQt6.QtGui import QIcon, QPixmap, QPainter, QPen, QColor, QPolygonF
_cache: dict[tuple, QIcon] = {}
SIZE = 20
def transport_icon(kind: str, color: QColor) -> QIcon:
key = (kind, color.name())
if key in _cache:
return _cache[key]
pixmap = QPixmap(SIZE, SIZE)
pixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(pixmap)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.setPen(Qt.PenStyle.NoPen)
painter.setBrush(color)
_DRAWERS[kind](painter, color)
painter.end()
icon = QIcon(pixmap)
_cache[key] = icon
return icon
def _play(p, _color):
p.drawPolygon(QPolygonF([QPointF(5, 3), QPointF(17, 10), QPointF(5, 17)]))
def _pause(p, _color):
p.drawRect(QRectF(5, 3.5, 3.6, 13))
p.drawRect(QRectF(11.4, 3.5, 3.6, 13))
def _next(p, _color):
# Skip-to-next: two triangles plus a trailing bar (bare triangles = ffwd).
p.drawPolygon(QPolygonF([QPointF(2, 4), QPointF(9, 10), QPointF(2, 16)]))
p.drawPolygon(QPolygonF([QPointF(9, 4), QPointF(16, 10), QPointF(9, 16)]))
p.drawRect(QRectF(16.5, 4, 2, 12))
def _previous(p, _color):
# Skip-to-previous: a leading bar plus two triangles (mirror of _next).
p.drawRect(QRectF(1.5, 4, 2, 12))
p.drawPolygon(QPolygonF([QPointF(11, 4), QPointF(4, 10), QPointF(11, 16)]))
p.drawPolygon(QPolygonF([QPointF(18, 4), QPointF(11, 10), QPointF(18, 16)]))
def _shuffle(p, color):
pen = QPen(color, 1.8)
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
p.setPen(pen)
p.setBrush(Qt.BrushStyle.NoBrush)
# Two crossing strands
p.drawLine(QPointF(2, 6), QPointF(6, 6))
p.drawLine(QPointF(6, 6), QPointF(13, 14))
p.drawLine(QPointF(13, 14), QPointF(16, 14))
p.drawLine(QPointF(2, 14), QPointF(6, 14))
p.drawLine(QPointF(6, 14), QPointF(13, 6))
p.drawLine(QPointF(13, 6), QPointF(16, 6))
# Arrowheads
p.setPen(Qt.PenStyle.NoPen)
p.setBrush(color)
p.drawPolygon(QPolygonF([QPointF(15, 3), QPointF(19, 6), QPointF(15, 9)]))
p.drawPolygon(QPolygonF([QPointF(15, 11), QPointF(19, 14), QPointF(15, 17)]))
_DRAWERS = {
"play": _play,
"pause": _pause,
"next": _next,
"previous": _previous,
"shuffle": _shuffle,
}