Files
lintunes/lintunes/gui/cassette_art.py
T
travandClaude Opus 5.5 c8c90b830a v0.31.1: one button look — crisper emboss, darken on hover
- The emboss hugs the edges: thin lit and shaded rims, a defined outline
  that's a touch darker along the bottom, and a nearly flat face — shape
  without depth.
- Hover darkens the whole button slightly instead of Qt's pale panel on
  top of it.
- One face for every button (theme.button_face_qss): regular buttons,
  Library and its ▾, the purple friend-mode buttons, and the transport
  boxes. Shuffle and bpm are boxes that are one button, so the whole box
  darkens (bpm's whole box is now its tap target); the play box's three
  tiles each darken on their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:17:05 -07:00

142 lines
5.5 KiB
Python

"""Cassette's two little pictures, painted (no image files to ship or theme).
* The **cassette button**: a small embossed square with a tape glyph. Raised
when off; pressed in and grey when on ("I want this"); a medium grey on
hover over a pressed one, to say a click would let it go. Functionally
it's a checkbox — the tape is reserved for asking friends for songs.
* The **UFO**: a friend's playlist. Light purple when followed, a grey
outline when not.
Plus friend mode's light purple, shared by everything that says "you're in
someone else's library".
"""
from __future__ import annotations
from PyQt6.QtCore import QPointF, QRectF, Qt
from PyQt6.QtGui import (
QBrush, QColor, QIcon, QLinearGradient, QPainter, QPainterPath, QPen,
QPixmap,
)
FRIEND_PURPLE = QColor("#cdb4f2") # button tint in friend mode
FRIEND_PURPLE_DARK = QColor("#9b76d6") # its border / pressed shade
UFO_PURPLE = QColor("#b38ee8")
OFF, ON, PARTIAL = "off", "on", "partial"
ON_GREY = QColor("#9c9c9c")
ON_HOVER_GREY = QColor("#bdbdbd")
def friend_button_qss(selector: str = "QPushButton", padding: str = "3px 12px") -> str:
"""Light purple, with the same face as every other button."""
from lintunes import theme
return theme.button_face_qss(
selector, FRIEND_PURPLE,
extra=f"color: black; padding: {padding}; min-height: 0;")
def button_rect(cell: QRectF, margin: float = 2.0) -> QRectF:
"""The square the button occupies inside a cell (left-aligned)."""
side = max(8.0, min(cell.height(), cell.width()) - 2 * margin)
return QRectF(cell.left() + margin, cell.top() + (cell.height() - side) / 2,
side, side)
def paint_cassette_button(painter: QPainter, rect: QRectF, state: str,
hovered: bool, palette) -> None:
painter.save()
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
base = palette.button().color()
mid = palette.mid().color()
box = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5)
radius = max(2.0, box.width() * 0.18)
gradient = QLinearGradient(box.topLeft(), box.bottomLeft())
if state == OFF:
top = base.lighter(112 if hovered else 106)
gradient.setColorAt(0, top)
gradient.setColorAt(1, base.darker(106))
else:
fill = ON_HOVER_GREY if hovered else ON_GREY
if state == PARTIAL:
fill = QColor(fill).lighter(118)
gradient.setColorAt(0, fill.darker(108)) # pressed in: lit from below
gradient.setColorAt(1, fill.lighter(106))
painter.setBrush(QBrush(gradient))
painter.setPen(QPen(mid, 1))
painter.drawRoundedRect(box, radius, radius)
ink = QColor(palette.text().color())
if state != OFF:
ink = QColor("#303030")
ink.setAlpha(200 if state != OFF else 150)
_paint_tape(painter, box, ink, half=(state == PARTIAL))
painter.restore()
def _paint_tape(painter: QPainter, box: QRectF, ink: QColor, half=False):
"""A cassette: body, label window, two reels."""
w, h = box.width(), box.height()
body = QRectF(box.left() + w * 0.16, box.top() + h * 0.28,
w * 0.68, h * 0.46)
pen = QPen(ink, max(1.0, w / 16))
painter.setPen(pen)
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawRoundedRect(body, body.height() * 0.15, body.height() * 0.15)
reel_r = body.height() * 0.17
cy = body.top() + body.height() * 0.45
for fx in (0.3, 0.7):
painter.drawEllipse(QPointF(body.left() + body.width() * fx, cy),
reel_r, reel_r)
# the bottom trapezoid where the tape shows
path = QPainterPath()
path.moveTo(body.left() + body.width() * 0.22, body.bottom())
path.lineTo(body.left() + body.width() * 0.3, body.bottom() - body.height() * 0.22)
path.lineTo(body.left() + body.width() * 0.7, body.bottom() - body.height() * 0.22)
path.lineTo(body.left() + body.width() * 0.78, body.bottom())
painter.drawPath(path)
if half:
painter.drawLine(QPointF(body.left() + body.width() * 0.4, cy),
QPointF(body.left() + body.width() * 0.6, cy))
def paint_ufo(painter: QPainter, rect: QRectF, color: QColor,
filled: bool = True) -> None:
painter.save()
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
w, h = rect.width(), rect.height()
pen = QPen(color.darker(135) if filled else color, max(1.0, w / 14))
painter.setPen(pen)
dome = QRectF(rect.left() + w * 0.32, rect.top() + h * 0.2,
w * 0.36, h * 0.4)
saucer = QRectF(rect.left() + w * 0.06, rect.top() + h * 0.38,
w * 0.88, h * 0.3)
if filled:
painter.setBrush(color.lighter(125))
else:
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawChord(dome, 0, 180 * 16)
painter.setBrush(color if filled else Qt.BrushStyle.NoBrush)
painter.drawEllipse(saucer)
# three little lights
painter.setBrush(color.lighter(160) if filled else Qt.BrushStyle.NoBrush)
r = w * 0.045
for fx in (0.3, 0.5, 0.7):
painter.drawEllipse(QPointF(rect.left() + w * fx,
saucer.center().y() + saucer.height() * 0.1),
r, r)
painter.restore()
def ufo_icon(size: int = 32, followed: bool = True,
color: QColor | None = None) -> QIcon:
pixmap = QPixmap(size, size)
pixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(pixmap)
paint_ufo(painter, QRectF(1, 1, size - 2, size - 2),
color or (UFO_PURPLE if followed else QColor("#8a8a8a")),
filled=followed)
painter.end()
return QIcon(pixmap)