"""Round 92: a twice-as-tall scrubber, buttons that darken clearly while held (the transport's included — the play box is three touching buttons), and the album art's border a crisp 1 px of the lists' grey.""" from types import SimpleNamespace from unittest.mock import MagicMock from PyQt6.QtCore import Qt from PyQt6.QtGui import QColor, QPixmap from PyQt6.QtWidgets import QSlider, QStyle, QStyleOptionSlider from lintunes import theme from tests.test_round49 import _FakePlayer def _rects(qapp, tall): from lintunes.gui.track_table import ClickToJumpScrollStyle style = ClickToJumpScrollStyle() slider = QSlider(Qt.Orientation.Horizontal) slider.setStyle(style) slider.setProperty("tall", tall) slider.resize(200, slider.sizeHint().height()) option = QStyleOptionSlider() slider.initStyleOption(option) cc, sc = QStyle.ComplexControl.CC_Slider, QStyle.SubControl return (slider.sizeHint().height(), style.subControlRect(cc, option, sc.SC_SliderGroove, slider), style.subControlRect(cc, option, sc.SC_SliderHandle, slider)) def test_the_scrubber_is_twice_as_tall(qapp): hint, groove, handle = _rects(qapp, False) tall_hint, tall_groove, tall_handle = _rects(qapp, True) assert tall_hint == 2 * hint assert tall_groove.height() == 2 * groove.height() assert tall_handle.height() == 2 * handle.height() assert tall_handle.width() == handle.width() assert tall_handle.top() >= 0 def test_held_is_clearly_darker_than_hover(): assert theme.PRESSED_DARKER - 100 >= 2 * (theme.HOVER_DARKER - 100) qss = theme.button_face_qss("QPushButton", QColor("#c0c0c0")) pressed = qss.split("QPushButton:pressed {", 1)[1].split("}", 1)[0] assert QColor("#c0c0c0").darker(theme.PRESSED_DARKER).name() in pressed def test_transport_buttons_carry_their_own_face(qapp): from lintunes.gui.transport import TransportBar from lintunes.preferences import Preferences import tempfile from pathlib import Path player = MagicMock() player.repeat_mode.return_value = "off" with tempfile.TemporaryDirectory() as d: bar = TransportBar(player, MagicMock(), Preferences(Path(d))) assert [b.property("tile") for b in (bar._prev_btn, bar._play_btn, bar._next_btn)] == [ "first", "middle", "last"] assert bar._shuffle_btn.property("tile") is None qss = bar._shuffle_btn.parentWidget().styleSheet() assert "QFrame#transportBox > QToolButton:pressed" in qss assert "QFrame#transportBox > QToolButton:hover" in qss assert "rgba(" not in qss # no grey patch on hover def test_the_art_meets_one_pixel_of_frame_grey(qapp): from lintunes.gui.sidebar import NO_ART_GAP, SidebarArt, frame_color art = SidebarArt(_FakePlayer()) art.resize(100, 100 + NO_ART_GAP) pink = QPixmap(50, 50) pink.fill(QColor("#e8457a")) art._track = SimpleNamespace(track_id=1) art._pixmap = pink image = art.grab().toImage() middle = NO_ART_GAP + 50 line = frame_color(art.palette()).name() assert image.pixelColor(0, middle).name() == line assert image.pixelColor(1, middle).name() == "#e8457a" assert image.pixelColor(50, NO_ART_GAP).name() == line assert image.pixelColor(50, NO_ART_GAP + 1).name() == "#e8457a"