From 1d215fd0452b253c1900a11eb3dcb9af195f1583 Mon Sep 17 00:00:00 2001 From: trav Date: Mon, 19 Oct 2026 22:10:47 -0700 Subject: [PATCH] v0.67.3: the rating column is never narrower than five stars --- lintunes/__init__.py | 2 +- lintunes/gui/track_table.py | 23 ++++++++++++++++++++--- tests/test_round100.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 tests/test_round100.py diff --git a/lintunes/__init__.py b/lintunes/__init__.py index 82a0cc2..e8b48d9 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.67.2" +__version__ = "0.67.3" diff --git a/lintunes/gui/track_table.py b/lintunes/gui/track_table.py index 333131a..75ba613 100644 --- a/lintunes/gui/track_table.py +++ b/lintunes/gui/track_table.py @@ -245,6 +245,13 @@ def rating_slot_width(fm: QFontMetrics) -> int: return max(fm.horizontalAdvance("★"), fm.horizontalAdvance("•")) + 4 +def rating_min_width(fm: QFontMetrics) -> int: + """Narrowest the rating column may be: all five slots plus the left pad + and as much again on the right, so five stars never spill into the next + column.""" + return 5 * rating_slot_width(fm) + 2 * RATING_LEFT_PAD + + def rating_slot_at(x: int, slot_w: int) -> int: """Which slot (1..5) an x offset within the rating cell lands on.""" if slot_w <= 0: @@ -970,11 +977,21 @@ class TrackTableView(QTableView): self.sort_changed.emit(field, order == Qt.SortOrder.AscendingOrder) def _on_section_resized(self, section, _old, new_width): - if self._suppress_signals or section >= len(self.model_.fields): + if section >= len(self.model_.fields): return header = self.horizontalHeader() - if (header.stretchLastSection() - and section == header.logicalIndex(header.count() - 1)): + stretched = (header.stretchLastSection() + and section == header.logicalIndex(header.count() - 1)) + if self.model_.fields[section] == "rating" and not stretched: + # Never narrower than five stars (a saved width or a drag alike); + # the resize re-enters here with the clamped width. + least = rating_min_width(QFontMetrics(self.font())) + if new_width < least: + header.resizeSection(section, least) + return + if self._suppress_signals: + return + if stretched: # The last column is stretch-sized, so Qt re-fires this every time # the viewport changes width — resizing the window or dragging the # splitter would otherwise rewrite the whole playlist JSON (and hand diff --git a/tests/test_round100.py b/tests/test_round100.py new file mode 100644 index 0000000..84f1c6f --- /dev/null +++ b/tests/test_round100.py @@ -0,0 +1,35 @@ +"""Round 100: the rating column is never narrower than five stars.""" +from PyQt6.QtGui import QFontMetrics + +from lintunes.gui.track_table import TrackTableView, rating_min_width +from lintunes.models.playlist import PlaylistSettings + + +def _view(widths): + view = TrackTableView(playlist_mode=False) + view.apply_settings(PlaylistSettings( + visible_columns=["name", "rating", "date_added"], sort_column="name", + column_widths=widths)) + return view + + +def test_saved_narrow_width_is_widened(qapp): + view = _view({"rating": 20}) + least = rating_min_width(QFontMetrics(view.font())) + assert view.columnWidth(view.model_.fields.index("rating")) == least + + +def test_dragging_narrower_snaps_back_and_saves_the_minimum(qapp): + view = _view({}) + col = view.model_.fields.index("rating") + saved = [] + view.column_width_changed.connect(lambda f, w: saved.append((f, w))) + view.horizontalHeader().resizeSection(col, 10) + least = rating_min_width(QFontMetrics(view.font())) + assert view.columnWidth(col) == least + assert saved == [("rating", least)] + + +def test_wider_widths_are_left_alone(qapp): + view = _view({"rating": 200}) + assert view.columnWidth(view.model_.fields.index("rating")) == 200