v0.100.0: songs a playlist already has are skipped quietly — the status bar says so for ten seconds with an Add Anyway button, instead of a prompt every time (Preferences › General › Playlists brings the prompt back)

This commit is contained in:
2026-11-21 02:15:27 -08:00
parent 6797910d76
commit 5f6f01d91c
9 changed files with 350 additions and 3 deletions
+7 -1
View File
@@ -295,7 +295,13 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
to the window too — an action added to a menu later must be as well.
`track_table.py` is the shared track grid (drag/drop, copy/paste, drop
indicator). `playlist_ops.py::add_tracks_with_dup_check` is the single funnel
for every add-to-playlist path. `theme.py` applies the palette (highlight
for every add-to-playlist path; since Round 132 it adds only the songs a
playlist doesn't have and says so in the status bar
(`gui/duplicate_notice.py`, found as `window().duplicate_notice`: 10 s,
then a fade; the cursor holds it) with **Add Anyway**, which makes the
playlist what adding everything would have (or appends the duplicates if
it changed since). Pref `ask_on_duplicates` brings the old modal back.
`theme.py` applies the palette (highlight
colors, UI scales) from prefs.
- **`lintunes/gui/visualizer.py`** + **`visualizer_styles.py`** — the
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.99.1"
__version__ = "0.100.0"
+99
View File
@@ -0,0 +1,99 @@
"""The status bar's "already in the playlist" notice (Round 132).
Adding songs a playlist already has used to stop everything with a modal
prompt. Now (unless the ``ask_on_duplicates`` preference brings the prompt
back) playlist_ops adds only the new songs and this says so in the status
bar, with an Add Anyway button that adds the rest. It shows for ``SHOW_MS``
and then fades out; the cursor over it holds it, so it never vanishes from
under a click.
"""
from PyQt6.QtCore import QPropertyAnimation, QTimer
from PyQt6.QtWidgets import (
QGraphicsOpacityEffect, QHBoxLayout, QLabel, QPushButton, QWidget)
SHOW_MS = 10_000
FADE_MS = 600
# After the cursor leaves, a little longer to come back to it.
LINGER_MS = 3_000
def message(name: str, skipped: int, added: int) -> str:
songs = "1 song was" if skipped == 1 else f"{skipped} songs were"
if added:
return (f"{songs} already in “{name}” — "
"only the new ones were added")
return f"{songs} already in “{name}” — nothing was added"
class DuplicateNotice(QWidget):
def __init__(self, prefs, parent=None):
super().__init__(parent)
self._prefs = prefs
self._action = None
layout = QHBoxLayout(self)
layout.setContentsMargins(0, 0, 6, 0)
layout.setSpacing(6)
self.label = QLabel()
layout.addWidget(self.label)
self.button = QPushButton("Add Anyway")
# The shared button face, only shrunk to fit the status bar
# (main_window._CancelSyncButton's rule).
self.button.setStyleSheet("QPushButton { padding: 0 6px; "
"min-height: 0; }")
self.button.clicked.connect(self._add_anyway)
layout.addWidget(self.button)
self._effect = QGraphicsOpacityEffect(self)
self._effect.setOpacity(1.0)
self.setGraphicsEffect(self._effect)
self._fade = QPropertyAnimation(self._effect, b"opacity", self)
self._fade.setDuration(FADE_MS)
self._fade.setStartValue(1.0)
self._fade.setEndValue(0.0)
self._fade.finished.connect(self.dismiss)
self._timer = QTimer(self)
self._timer.setSingleShot(True)
self._timer.timeout.connect(self._fade.start)
self.hide()
def quiet(self) -> bool:
"""Whether duplicates are skipped quietly (vs. asked about)."""
return not bool(self._prefs.get("ask_on_duplicates", False))
def show_skipped(self, name: str, skipped: int, added: int, action):
"""Say ``skipped`` songs were left out of ``name``; ``action`` adds
them. A newer add replaces whatever was showing."""
self._fade.stop()
self._effect.setOpacity(1.0)
self._action = action
self.label.setText(message(name, skipped, added))
self.button.setEnabled(True)
self.show()
self._timer.start(SHOW_MS)
def dismiss(self):
self._timer.stop()
self._fade.stop()
self._action = None
self.hide()
self._effect.setOpacity(1.0)
def _add_anyway(self):
action = self._action
self.dismiss()
if action is not None:
action()
def enterEvent(self, event):
if self.isVisible():
self._timer.stop()
self._fade.stop()
self._effect.setOpacity(1.0)
super().enterEvent(event)
def leaveEvent(self, event):
if self.isVisible() and self._action is not None:
self._timer.start(LINGER_MS)
super().leaveEvent(event)
+6
View File
@@ -38,6 +38,7 @@ from lintunes.gui import menu_bar, sounds, titlebar
from lintunes.gui.device_sync_dialog import (
DeviceSyncSettingsDialog, resolve_sync_playlists,
)
from lintunes.gui.duplicate_notice import DuplicateNotice
from lintunes.gui.export_dialog import ExportKindDialog, WebMixDialog
from lintunes.gui.identify_batch_dialog import IdentifyBatchDialog
from lintunes.gui.identify_dialog import IdentifyDialog
@@ -267,6 +268,11 @@ class MainWindow(QMainWindow):
# is added *last* owns the corner and never moves. The cancel button
# goes there deliberately: it is the one widget the user aims at, and
# the label beside it is as wide as the song title of the moment.
# "Already in the playlist — Add Anyway" (gui/duplicate_notice.py),
# found by playlist_ops through window().duplicate_notice. Permanent,
# so a passing showMessage can't hide it before it's read.
self.duplicate_notice = DuplicateNotice(self._prefs)
self.statusBar().addPermanentWidget(self.duplicate_notice)
self._sync_label = _StatusLabel()
self._sync_label.hide()
# A click brings back a hidden link-import progress window.
+68 -1
View File
@@ -1,8 +1,14 @@
"""Shared playlist-add logic with a duplicate-confirmation prompt.
"""Shared playlist-add logic with the duplicate guard.
All GUI paths that add tracks to a playlist (sidebar drop, drop onto an open
playlist's track list, paste) route through here so the duplicate guard is
consistent for single- and multi-track adds.
Since Round 132 the guard is quiet by default: only the songs the playlist
doesn't have yet go in, and the window's status bar says so for a while with
an Add Anyway button (``MainWindow.duplicate_notice``). The old modal prompt
comes back with the ``ask_on_duplicates`` preference, and is what a caller
with no such window (a test passing ``parent=None``) still gets.
"""
from PyQt6.QtWidgets import QMessageBox
@@ -36,6 +42,9 @@ def add_tracks_with_dup_check(manager, parent, pid, track_ids,
existing = playlist.track_ids
if has_duplicates(track_ids, existing):
notice = _quiet_notice(parent)
if notice is not None:
return _add_quietly(manager, notice, pid, track_ids, position)
to_add = _resolve_duplicates(parent, track_ids, existing)
else:
to_add = list(track_ids)
@@ -65,3 +74,61 @@ def _resolve_duplicates(parent, track_ids, existing) -> list[int]:
if clicked is skip:
return filter_for_add(track_ids, existing, add_duplicates=False)
return [] # dialog dismissed (Escape / close) -> add nothing
def _quiet_notice(parent):
"""The window's status-bar notice when duplicates are to be skipped
quietly, else None (ask with the dialog)."""
if parent is None:
return None
notice = getattr(parent.window(), "duplicate_notice", None)
if notice is None or not notice.quiet():
return None
return notice
def full_add(before, track_ids, position):
"""``before`` with every one of ``track_ids`` inserted at ``position``
(None or past the end appends) — what adding them all would make."""
after = list(before)
if position is None or position >= len(after):
after.extend(track_ids)
else:
after[position:position] = track_ids
return after
def _add_quietly(manager, notice, pid, track_ids, position) -> list[int]:
"""Add only the new songs and offer the rest in the status bar."""
playlist = manager.library.playlists[pid]
before = list(playlist.track_ids)
to_add = filter_for_add(track_ids, before, add_duplicates=False)
skipped = len(track_ids) - len(to_add)
if to_add:
manager.add_tracks_to_playlist(pid, to_add, position)
quiet_after = list(playlist.track_ids)
everything = full_add(before, list(track_ids), position)
def add_anyway():
add_skipped(manager, pid, quiet_after, everything,
[tid for tid in track_ids if tid in set(before)])
notice.show_skipped(playlist.name, skipped, len(to_add), add_anyway)
return to_add
def add_skipped(manager, pid, quiet_after, everything, duplicates):
"""Add Anyway: make the playlist what adding everything would have made.
If the playlist is still exactly as the quiet add left it, it becomes
``everything`` (the songs in the order they were dropped, at the drop
position) as one more undo step. If something changed it since, the
duplicates are appended instead, so nothing anyone did since is undone.
"""
playlist = manager.library.playlists.get(pid)
if playlist is None:
return
if list(playlist.track_ids) == quiet_after:
manager.replace_playlist_tracks(pid, everything, "Add to Playlist")
else:
manager.add_tracks_to_playlist(pid, duplicates)
+17
View File
@@ -138,6 +138,7 @@ class PreferencesDialog(QDialog):
self._headings = []
general = [self._build_playback_group(), self._build_import_group(),
self._build_playlists_group(),
self._build_sound_group(), self._build_wrapped_group()]
if self._music_folder is not None:
general.insert(0, self._build_music_group())
@@ -317,6 +318,22 @@ class PreferencesDialog(QDialog):
self._compress_cassette.setEnabled(on)
self._prefs.set("import_compress", on)
def _build_playlists_group(self) -> QGroupBox:
group = QGroupBox("Playlists")
column = QVBoxLayout(group)
self._dup_check = QCheckBox(
"Ask before adding a song a playlist already has")
self._dup_check.setChecked(
bool(self._prefs.get("ask_on_duplicates", False)))
self._dup_check.toggled.connect(
lambda on: self._prefs.set("ask_on_duplicates", on))
column.addWidget(self._dup_check)
column.addWidget(self._note(
"When it's off, only the songs the playlist doesn't have yet are "
"added, and the status bar says so for a few seconds with an "
"Add Anyway button."))
return group
def _build_sound_group(self) -> QGroupBox:
group = QGroupBox("Sound effects")
row = QHBoxLayout(group)
+13
View File
@@ -370,6 +370,19 @@ class LibraryManager(QObject):
if undoable:
self._push_track_ids("Add to Playlist", pid, before, after)
def replace_playlist_tracks(self, pid: str, track_ids: list[int],
label: str):
"""Set a regular playlist's songs to ``track_ids`` as one undo step
(playlist_ops' Add Anyway)."""
playlist = self.library.playlists.get(pid)
if not playlist or playlist.playlist_type == PlaylistType.FOLDER \
or playlist.is_smart:
return
before = list(playlist.track_ids)
after = [tid for tid in track_ids if tid in self.library.tracks]
self._set_track_ids(pid, after)
self._push_track_ids(label, pid, before, after)
def remove_tracks_from_playlist(self, pid: str, rows: list[int]):
playlist = self.library.playlists.get(pid)
if not playlist or playlist.is_smart:
+4
View File
@@ -92,6 +92,10 @@ DEFAULTS = {
"import_compress": False,
"import_compress_kbps": 256,
"import_compress_cassette": False, # ...songs from Cassette friends too
# Adding songs a playlist already has: False = add only the new ones and
# say so in the status bar with Add Anyway (gui/duplicate_notice.py);
# True = the old prompt that asks every time.
"ask_on_duplicates": False,
# The quiet "tink" when a sync, export or URL import finishes.
"sound_effects": True,
# The yearly Wrapped (storage/listen_history.py). Synced on purpose: one
+135
View File
@@ -0,0 +1,135 @@
"""Round 132: songs a playlist already has are skipped quietly.
Adding them no longer stops everything with a modal prompt: only the new
songs go in, and the status bar says so for ten seconds with an Add Anyway
button (gui/duplicate_notice.py). ``ask_on_duplicates`` brings the prompt
back.
"""
from unittest.mock import patch
import pytest
from lintunes.gui import duplicate_notice, playlist_ops
from lintunes.gui.playlist_ops import add_tracks_with_dup_check, full_add
from lintunes.library_manager import LibraryManager
from lintunes.models.library import Library
from lintunes.models.playlist import Playlist
from lintunes.models.track import Track
from lintunes.preferences import Preferences
@pytest.fixture
def window(qapp, tmp_path):
from lintunes.gui.main_window import MainWindow
library = Library(tracks={tid: Track(track_id=tid, name=f"t{tid}")
for tid in range(1, 6)})
library.playlists["PID"] = Playlist(name="Mix", persistent_id="PID",
track_ids=[1, 2])
manager = LibraryManager(library, tmp_path)
win = MainWindow(manager, Preferences(tmp_path))
win.resize(1000, 700)
win.show()
qapp.processEvents()
yield win
win.duplicate_notice.dismiss()
win.close()
def _playlist(win):
return win._manager.library.playlists["PID"]
def _no_dialog():
return patch.object(playlist_ops, "_resolve_duplicates",
side_effect=AssertionError("asked"))
def test_full_add_matches_the_manager():
assert full_add([1, 2], [3, 1], None) == [1, 2, 3, 1]
assert full_add([1, 2], [3, 1], 1) == [1, 3, 1, 2]
assert full_add([1, 2], [3], 9) == [1, 2, 3]
def test_messages():
assert duplicate_notice.message("Mix", 1, 2) == (
"1 song was already in “Mix” — only the new ones were added")
assert duplicate_notice.message("Mix", 3, 0) == (
"3 songs were already in “Mix” — nothing was added")
def test_only_new_songs_are_added_and_the_status_bar_says_so(window):
with _no_dialog():
added = add_tracks_with_dup_check(
window._manager, window._playlist_view, "PID", [3, 1, 4])
assert added == [3, 4]
assert _playlist(window).track_ids == [1, 2, 3, 4]
notice = window.duplicate_notice
assert notice.isVisible()
assert "only the new ones" in notice.label.text()
def test_add_anyway_makes_what_adding_everything_would_have(window):
with _no_dialog():
add_tracks_with_dup_check(
window._manager, window._playlist_view, "PID", [3, 1, 4],
position=1)
assert _playlist(window).track_ids == [1, 3, 4, 2]
window.duplicate_notice.button.click()
assert _playlist(window).track_ids == [1, 3, 1, 4, 2]
assert not window.duplicate_notice.isVisible()
# One undo takes back the duplicates, the next the rest.
window._manager.undo_stack.undo()
assert _playlist(window).track_ids == [1, 3, 4, 2]
window._manager.undo_stack.undo()
assert _playlist(window).track_ids == [1, 2]
def test_add_anyway_after_another_edit_only_appends_the_duplicates(window):
with _no_dialog():
add_tracks_with_dup_check(
window._manager, window._playlist_view, "PID", [1, 3])
window._manager.add_tracks_to_playlist("PID", [5])
window.duplicate_notice.button.click()
assert _playlist(window).track_ids == [1, 2, 3, 5, 1]
def test_all_duplicates_adds_nothing_but_still_offers(window):
with _no_dialog():
added = add_tracks_with_dup_check(
window._manager, window._playlist_view, "PID", [2])
assert added == []
assert _playlist(window).track_ids == [1, 2]
assert "nothing was added" in window.duplicate_notice.label.text()
window.duplicate_notice.button.click()
assert _playlist(window).track_ids == [1, 2, 2]
def test_it_fades_away_after_ten_seconds(window, qapp):
notice = window.duplicate_notice
with _no_dialog():
add_tracks_with_dup_check(
window._manager, window._playlist_view, "PID", [1])
assert notice._timer.isActive()
assert notice._timer.interval() == duplicate_notice.SHOW_MS == 10_000
notice._timer.timeout.emit() # ten seconds pass
assert notice._fade.state() == notice._fade.State.Running
notice._fade.setCurrentTime(duplicate_notice.FADE_MS)
qapp.processEvents()
assert not notice.isVisible()
def test_the_pref_brings_the_prompt_back(window):
window._prefs.set("ask_on_duplicates", True)
with patch.object(playlist_ops, "_resolve_duplicates",
return_value=[3]) as asked:
added = add_tracks_with_dup_check(
window._manager, window._playlist_view, "PID", [1, 3])
asked.assert_called_once()
assert added == [3]
assert not window.duplicate_notice.isVisible()
def test_quiet_is_the_default():
from lintunes.preferences import DEFAULTS
assert DEFAULTS["ask_on_duplicates"] is False