From 1ad6956abee16015df5323f87b56692acce9b78f Mon Sep 17 00:00:00 2001 From: trav Date: Sun, 25 Oct 2026 14:02:33 -0700 Subject: [PATCH] v0.79.0: the now-playing panel embosses on hover and a click goes to the current song --- CLAUDE.md | 4 ++ lintunes/__init__.py | 2 +- lintunes/gui/main_window.py | 1 + lintunes/gui/transport.py | 86 +++++++++++++++++++++++++++++++++++-- tests/test_round110.py | 85 ++++++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 tests/test_round110.py diff --git a/CLAUDE.md b/CLAUDE.md index 886c61a..a4eb8c9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -229,6 +229,10 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal panel draws the cover to the outline's centre and the 1 px line over it in the lists' grey (`frame_color`); inset by half a pixel, the clip left a pale blend that read as a 2 px border on vivid covers. + The now-playing panel (`transport.NowPlayingPanel`, Round 110) is a + Go to Current Song button while a song is on (not in DJ mode): raised + in the hover face under the cursor, sunk and darker while held. Its + face is a `face` property, since a QFrame has no `:pressed`. The playlist list's frame is a `sidebar.RoundedFrame` (Round 91): the panels' 8 px corners, painted *over* the list by a mouse-transparent overlay (window color outside the curve, then Fusion's own frame line, diff --git a/lintunes/__init__.py b/lintunes/__init__.py index 70c7ad3..19bcf2f 100644 --- a/lintunes/__init__.py +++ b/lintunes/__init__.py @@ -1,3 +1,3 @@ """LinTunes — iTunes-style music library manager and player for Linux.""" -__version__ = "0.78.0" +__version__ = "0.79.0" diff --git a/lintunes/gui/main_window.py b/lintunes/gui/main_window.py index 79b3ff6..c4ea2a6 100644 --- a/lintunes/gui/main_window.py +++ b/lintunes/gui/main_window.py @@ -321,6 +321,7 @@ class MainWindow(QMainWindow): # Wiring self._transport.play_clicked.connect(self.play_pause) + self._transport.now_playing_clicked.connect(self._go_to_current_song) self._sidebar.library_selected.connect(self._show_library) self._sidebar.friend_selector_clicked.connect( self._cassette.show_friend_menu) diff --git a/lintunes/gui/transport.py b/lintunes/gui/transport.py index 6710333..e1bb3ee 100644 --- a/lintunes/gui/transport.py +++ b/lintunes/gui/transport.py @@ -77,8 +77,83 @@ TILE_STYLE = "".join( def _nowplaying_style(bg: QColor) -> str: - """Debossed: pushed in as far as the buttons stand out.""" - return theme.deboss_qss("QFrame#nowPlayingBox", bg, radius=8) + """Debossed: pushed in as far as the buttons stand out. While a song is + on it is also a button (Go to Current Song): under the cursor it stands + out in the buttons' hover face, and held it sinks, darker.""" + sel = "QFrame#nowPlayingBox" + hover = bg.darker(theme.HOVER_DARKER) + down = bg.darker(theme.PRESSED_DARKER) + return (theme.deboss_qss(sel, bg, radius=8) + + f'{sel}[face="hover"] {{ {theme.emboss_edges(hover)}' + f" background: {theme.emboss_gradient(hover)}; }}" + + f'{sel}[face="down"] {{ {theme.deboss_edges(down)}' + f" background: {theme.emboss_gradient(down, pressed=True)}; }}") + + +class NowPlayingPanel(QFrame): + """The now-playing panel. A QFrame has no :pressed in a style sheet, and + its :hover can't be switched off, so the face is a property.""" + + clicked = pyqtSignal() + + def __init__(self, parent=None): + super().__init__(parent) + self.setObjectName("nowPlayingBox") + self._clickable = False + self._inside = False + self._held = False + + def set_clickable(self, on: bool): + self._clickable = on + self._held = self._held and on + self.setCursor(Qt.CursorShape.PointingHandCursor if on + else Qt.CursorShape.ArrowCursor) + self.setToolTip("Go to Current Song" if on else "") + self._refresh() + + def _refresh(self): + face = "" + if self._clickable and self._inside: + face = "down" if self._held else "hover" + if (self.property("face") or "") != face: + self.setProperty("face", face) + self.style().unpolish(self) + self.style().polish(self) + self.update() + + def enterEvent(self, event): + super().enterEvent(event) + self._inside = True + self._refresh() + + def leaveEvent(self, event): + super().leaveEvent(event) + self._inside = False + self._refresh() + + def mousePressEvent(self, event): + if self._clickable and event.button() == Qt.MouseButton.LeftButton: + self._held = True + self._refresh() + return + super().mousePressEvent(event) + + def mouseMoveEvent(self, event): + if self._held: # the press grabs the mouse: no enter/leave + self._inside = self.rect().contains(event.position().toPoint()) + self._refresh() + super().mouseMoveEvent(event) + + def mouseReleaseEvent(self, event): + if self._held and event.button() == Qt.MouseButton.LeftButton: + self._held = False + self._inside = self.rect().contains(event.position().toPoint()) + self._refresh() + if self._inside and self._clickable: + self.clicked.emit() + return + super().mouseReleaseEvent(event) + # Title sits this many points above the artist/album line, both following the # UI-scale app font (see theme.UI_SCALES). @@ -385,6 +460,7 @@ class TransportBar(QWidget): play_clicked = pyqtSignal() # MainWindow decides what "play" means dj_toggled = pyqtSignal(bool) volume_level_changed = pyqtSignal(float) # the slider, 0..1 perceptual + now_playing_clicked = pyqtSignal() # Go to Current Song def __init__(self, player, manager, prefs, cast=None, airplay=None, parent=None): @@ -475,8 +551,8 @@ class TransportBar(QWidget): # White rounded now-playing panel: holds only the song title and the # artist/album line, centered, filling the zone above the seek row. - self._now_playing = QFrame() - self._now_playing.setObjectName("nowPlayingBox") + self._now_playing = NowPlayingPanel() + self._now_playing.clicked.connect(self.now_playing_clicked) self._apply_now_playing_bg() np = QVBoxLayout(self._now_playing) np.setContentsMargins(12, 6, 12, 6) @@ -658,6 +734,7 @@ class TransportBar(QWidget): self._on_dj_button_icon(on) self._dj_on = on if on: + self._now_playing.set_clickable(False) self.set_dj_titles(titles) else: self._on_track_changed(self._current_track) @@ -1030,6 +1107,7 @@ class TransportBar(QWidget): def _on_track_changed(self, track): self._current_track = track + self._now_playing.set_clickable(track is not None and not self._dj_on) if self._dj_on: return # the panel names the decks' songs meanwhile if track is None: diff --git a/tests/test_round110.py b/tests/test_round110.py new file mode 100644 index 0000000..d6b7015 --- /dev/null +++ b/tests/test_round110.py @@ -0,0 +1,85 @@ +"""Round 110: the now-playing panel is a Go to Current Song button.""" +from PyQt6.QtCore import QEvent, QPointF, Qt +from PyQt6.QtGui import QEnterEvent, QMouseEvent + +from lintunes.gui.transport import NowPlayingPanel + + +def _mouse(kind, x=5, y=5): + return QMouseEvent(kind, QPointF(x, y), QPointF(x, y), + Qt.MouseButton.LeftButton, + Qt.MouseButton.LeftButton if kind != QEvent.Type.MouseButtonRelease + else Qt.MouseButton.NoButton, + Qt.KeyboardModifier.NoModifier) + + +def _enter(panel): + panel.enterEvent(QEnterEvent(QPointF(5, 5), QPointF(5, 5), QPointF(5, 5))) + + +def test_hover_embosses_and_a_click_goes_to_the_song(qapp): + panel = NowPlayingPanel() + panel.resize(200, 60) + clicks = [] + panel.clicked.connect(lambda: clicks.append(1)) + panel.set_clickable(True) + assert not panel.property("face") + _enter(panel) + assert panel.property("face") == "hover" + panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress)) + assert panel.property("face") == "down" + panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease)) + assert clicks == [1] and panel.property("face") == "hover" + panel.leaveEvent(QEvent(QEvent.Type.Leave)) + assert not panel.property("face") + + +def test_released_outside_is_no_click(qapp): + panel = NowPlayingPanel() + panel.resize(200, 60) + clicks = [] + panel.clicked.connect(lambda: clicks.append(1)) + panel.set_clickable(True) + _enter(panel) + panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress)) + panel.mouseMoveEvent(_mouse(QEvent.Type.MouseMove, 400, 5)) + assert not panel.property("face") + panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease, 400, 5)) + assert clicks == [] + + +def test_nothing_playing_is_just_a_panel(qapp): + panel = NowPlayingPanel() + clicks = [] + panel.clicked.connect(lambda: clicks.append(1)) + _enter(panel) + panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress)) + panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease)) + assert clicks == [] and not panel.property("face") + + +def test_window_wires_it_to_go_to_current_song(qapp, tmp_path, monkeypatch): + from lintunes.gui.main_window import MainWindow + from lintunes.library_manager import LibraryManager + from lintunes.models.library import Library + from lintunes.models.track import Track + from lintunes.preferences import Preferences + library = Library() + library.tracks[1] = Track(track_id=1, name="Song", artist="A") + manager = LibraryManager(library, tmp_path / "data") + went = [] + monkeypatch.setattr(MainWindow, "_go_to_current_song", + lambda self: went.append(1)) + window = MainWindow(manager, Preferences(tmp_path / "data")) + try: + window._transport.now_playing_clicked.emit() + assert went == [1] + panel = window._transport._now_playing + window._transport._on_track_changed(library.tracks[1]) + assert panel._clickable + window._transport.set_dj_mode(True) + assert not panel._clickable + window._transport.set_dj_mode(False) + assert panel._clickable + finally: + window.close()