v0.95.0: the now-playing panel puts the title beside artist-over-album when it all fits, and keeps the stack (now with an ellipsis) when it doesn't

This commit is contained in:
2026-11-17 19:22:10 -08:00
parent 81b6fa509f
commit cea9daa09f
4 changed files with 173 additions and 20 deletions
+5
View File
@@ -239,6 +239,11 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
Go to Current Song button while a song is on (not in DJ mode): raised 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 in the hover face under the cursor, sunk and darker while held. Its
face is a `face` property, since a QFrame has no `:pressed`. face is a `face` property, since a QFrame has no `:pressed`.
Its words are `transport.NowPlayingText` (Round 130): the title on the
left with artist over album beside it when all of it fits the width,
else the old stack (title over "Artist — Album", elided with "…").
Decided from the text's widths on every resize and song; DJ mode's
lines (`set_lines`) always stack.
**The look is `~/Documents/shared-resources/design.html`** (canonical **The look is `~/Documents/shared-resources/design.html`** (canonical
since Round 118; read it before UI work). **No pointing-hand (finger) since Round 118; read it before UI work). **No pointing-hand (finger)
cursor** (Round 110), with one exception (Round 118): a clickable cursor** (Round 110), with one exception (Round 118): a clickable
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux.""" """LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.94.0" __version__ = "0.95.0"
+120 -19
View File
@@ -153,6 +153,114 @@ class NowPlayingPanel(QFrame):
super().mouseReleaseEvent(event) super().mouseReleaseEvent(event)
class NowPlayingText(QWidget):
"""The now-playing panel's words (Round 130). With room for the song's
title *beside* its artist and album, the title sits on the left and the
artist over the album on its right, the group centred. Without it, the
old stack: the title over one "Artist — Album" line. Which one is decided
from the text's own widths on every resize and every new song, so the
side-by-side shape is only ever used when nothing in it is cut off.
The labels' fonts are set by ``TransportBar._apply_now_playing_font``,
which calls ``arrange()`` after."""
GAP = 18 # between the title and the artist/album column
LINE_GAP = 2 # between stacked lines
def __init__(self, parent=None):
super().__init__(parent)
self.title = QLabel(self)
self.artist = QLabel(self) # "Artist — Album" when stacked
self.album = QLabel(self)
self._song: tuple[str, str, str] | None = None
self._lines = ("", "")
self.side = False # side by side, as last arranged
self.arrange()
def sizeHint(self):
return QSize(200, self.minimumSizeHint().height())
def minimumSizeHint(self):
return QSize(0, self.title.fontMetrics().height() + self.LINE_GAP
+ self.artist.fontMetrics().height())
def set_song(self, title: str, artist: str, album: str):
self._song = (title or "", artist or "", album or "")
self.arrange()
def set_lines(self, top: str, bottom: str):
"""Two fixed lines, always stacked (DJ mode, nothing playing)."""
self._song = None
self._lines = (top or "", bottom or "")
self.arrange()
def _width(self, label: QLabel, text: str) -> int:
return label.fontMetrics().horizontalAdvance(text) if text else 0
def fits_side(self, width: int) -> bool:
if self._song is None:
return False
title, artist, album = self._song
if not title or not (artist or album):
return False
right = max(self._width(self.artist, artist),
self._width(self.album, album))
return self._width(self.title, title) + self.GAP + right <= width
def resizeEvent(self, event):
super().resizeEvent(event)
self.arrange()
def arrange(self):
w, h = self.width(), self.height()
self.side = self.fits_side(w)
left = Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter
centre = Qt.AlignmentFlag.AlignCenter
if self.side:
title, artist, album = self._song
self.title.setText(title)
self.artist.setText(artist)
self.album.setText(album)
tw = self._width(self.title, title)
rw = max(self._width(self.artist, artist),
self._width(self.album, album))
x = max(0, (w - (tw + self.GAP + rw)) // 2)
self.title.setAlignment(left)
self.title.setGeometry(x, 0, tw + 1, h)
column = [lab for lab, text in ((self.artist, artist),
(self.album, album)) if text]
heights = [lab.fontMetrics().height() for lab in column]
y = (h - sum(heights) - self.LINE_GAP * (len(column) - 1)) // 2
for lab, lh in zip(column, heights):
lab.setAlignment(left)
lab.setGeometry(x + tw + self.GAP, y, rw + 1, lh)
y += lh + self.LINE_GAP
self.artist.setVisible(bool(artist))
self.album.setVisible(bool(album))
self.title.show()
return
if self._song is not None:
title, artist, album = self._song
top = title
bottom = " — ".join(p for p in (artist, album) if p)
else:
top, bottom = self._lines
# Too long for the panel: an ellipsis, never both ends cut off.
elide = Qt.TextElideMode.ElideRight
self.title.setText(self.title.fontMetrics().elidedText(top, elide, w))
self.artist.setText(self.artist.fontMetrics().elidedText(bottom,
elide, w))
self.album.hide()
th = self.title.fontMetrics().height()
ah = self.artist.fontMetrics().height()
y = (h - th - self.LINE_GAP - ah) // 2
for lab, lh in ((self.title, th), (self.artist, ah)):
lab.setAlignment(centre)
lab.setGeometry(0, y, w, lh)
lab.show()
y += lh + self.LINE_GAP
# Title sits this many points above the artist/album line, both following the # Title sits this many points above the artist/album line, both following the
# UI-scale app font (see theme.UI_SCALES). # UI-scale app font (see theme.UI_SCALES).
TITLE_PT_BUMP = 2 TITLE_PT_BUMP = 2
@@ -571,17 +679,11 @@ class TransportBar(QWidget):
np = QVBoxLayout(self._now_playing) np = QVBoxLayout(self._now_playing)
np.setContentsMargins(12, 6, 12, 6) np.setContentsMargins(12, 6, 12, 6)
np.setSpacing(2) np.setSpacing(2)
np.addStretch(1) self._np_text = NowPlayingText()
self._title_label = self._np_text.title
self._title_label = QLabel("") self._artist_label = self._np_text.artist
self._title_label.setAlignment(Qt.AlignmentFlag.AlignCenter) self._album_label = self._np_text.album
np.addWidget(self._title_label) np.addWidget(self._np_text)
self._artist_label = QLabel("")
self._artist_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
np.addWidget(self._artist_label)
np.addStretch(1)
self._apply_now_playing_font() self._apply_now_playing_font()
seek = QWidget() seek = QWidget()
@@ -784,8 +886,9 @@ class TransportBar(QWidget):
return self._volume_slider.value() / 100 return self._volume_slider.value() / 100
def set_dj_titles(self, text: str): def set_dj_titles(self, text: str):
self._title_label.setText(text or "DJ mode") self._np_text.set_lines(text or "DJ mode",
self._artist_label.setText("Drag songs onto the records" if not text else "DJ mode") "Drag songs onto the records" if not text
else "DJ mode")
# ---- repeat ---- # ---- repeat ----
@@ -1148,11 +1251,12 @@ class TransportBar(QWidget):
base_pt = self.font().pointSize() base_pt = self.font().pointSize()
text_color = theme.gray(theme.gray_value(self._prefs, "color_now_playing_text")) text_color = theme.gray(theme.gray_value(self._prefs, "color_now_playing_text"))
for label, delta in ((self._title_label, TITLE_PT_BUMP), for label, delta in ((self._title_label, TITLE_PT_BUMP),
(self._artist_label, 0)): (self._artist_label, 0), (self._album_label, 0)):
font = QFont(family) if family else QFont(self.font()) font = QFont(family) if family else QFont(self.font())
font.setPointSize(max(1, base_pt + delta)) font.setPointSize(max(1, base_pt + delta))
label.setFont(font) label.setFont(font)
label.setStyleSheet(f"color: {text_color.name()};") label.setStyleSheet(f"color: {text_color.name()};")
self._np_text.arrange()
# ---- player events ---- # ---- player events ----
@@ -1162,15 +1266,12 @@ class TransportBar(QWidget):
if self._dj_on: if self._dj_on:
return # the panel names the decks' songs meanwhile return # the panel names the decks' songs meanwhile
if track is None: if track is None:
self._title_label.setText("") self._np_text.set_lines("", "")
self._artist_label.setText("")
self._slider.setRange(0, 0) self._slider.setRange(0, 0)
self._elapsed_label.setText("") self._elapsed_label.setText("")
self._remaining_label.setText("") self._remaining_label.setText("")
return return
self._title_label.setText(track.name) self._np_text.set_song(track.name, track.artist, track.album)
parts = [p for p in (track.artist, track.album) if p]
self._artist_label.setText(" — ".join(parts))
def _on_playing_changed(self, playing): def _on_playing_changed(self, playing):
self._play_btn.set_kind("pause" if playing else "play") self._play_btn.set_kind("pause" if playing else "play")
+47
View File
@@ -268,3 +268,50 @@ def test_the_new_playlist_gets_its_cover(window, qapp, fake, mp3_file,
_pump(qapp, lambda: saved) _pump(qapp, lambda: saved)
assert playlist_art.find(manager.data_dir, playlist.persistent_id) \ assert playlist_art.find(manager.data_dir, playlist.persistent_id) \
== saved[0] == saved[0]
# --------------------------------------------------------------------------
# E. the now-playing words: side by side when they fit, stacked when not
def test_title_beside_artist_over_album_when_there_is_room(qapp):
from lintunes.gui.transport import NowPlayingText
from PyQt6.QtWidgets import QWidget
holder = QWidget() # a window would get a title bar
holder.resize(1000, 100)
text = NowPlayingText(holder)
holder.show()
text.set_song("Tomorrow's Girls", "Donald Fagen", "Kamakiriad")
text.resize(900, 50)
text.arrange()
assert text.side
assert text.title.geometry().right() < text.artist.geometry().left()
assert text.artist.geometry().left() == text.album.geometry().left()
assert text.artist.geometry().bottom() < text.album.geometry().top()
assert (text.artist.text(), text.album.text()) == ("Donald Fagen",
"Kamakiriad")
text.resize(text.title.fontMetrics().horizontalAdvance(
"Tomorrow's Girls") + 20, 50) # too narrow: the stack
assert not text.side and text.album.isHidden()
assert text.artist.text().startswith("Donald Fagen") # maybe elided
assert text.title.geometry().bottom() < text.artist.geometry().top()
text.resize(600, 50)
text.set_lines("DJ mode", "x")
text.set_song("Tomorrow's Girls", "Donald Fagen", "Kamakiriad")
assert text.side
def test_fixed_lines_and_a_bare_title_always_stack(qapp):
from lintunes.gui.transport import NowPlayingText
from PyQt6.QtWidgets import QWidget
holder = QWidget() # a window would get a title bar
holder.resize(1000, 100)
text = NowPlayingText(holder)
holder.show()
text.resize(900, 50)
text.set_lines("DJ mode", "Drag songs onto the records")
assert not text.side and text.artist.text() == "Drag songs onto the records"
text.set_song("Untitled", "", "")
assert not text.side and text.artist.text() == ""
text.set_song("Song", "", "Album only")
assert text.side and not text.album.isHidden() and text.artist.isHidden()