v0.45.0: copying songs pastes into other apps as a song list
Ctrl+C (and Cut) on selected songs now also puts plain text on the clipboard — one "Artist - Title" per line, in the order the table shows — so a whole playlist pastes into a message or a document. Pasting back into a playlist still reads the songs themselves, as before.
This commit is contained in:
@@ -227,3 +227,58 @@ class TestLaserDiagram:
|
||||
assert pitched[2].x() != pytest.approx(square[2].x())
|
||||
# A square screen's vertical edges are vertical.
|
||||
assert square[1].x() == pytest.approx(square[2].x())
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# 5. Copying songs gives other apps a song list
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def _table(tracks, playlist_mode=True):
|
||||
from lintunes.gui.track_table import TrackTableView
|
||||
table = TrackTableView(playlist_mode=playlist_mode)
|
||||
table.set_source_playlist("PID")
|
||||
table.set_tracks(tracks)
|
||||
return table
|
||||
|
||||
|
||||
def _songs():
|
||||
from lintunes.models import Track
|
||||
return [Track(track_id=1, name="Low Tide", artist="The Wheelhouse"),
|
||||
Track(track_id=2, name="Café Noir", artist="Marguerite Vaux"),
|
||||
Track(track_id=3, name="Orphan Take", artist="")]
|
||||
|
||||
|
||||
class TestCopyAsText:
|
||||
def test_select_all_copy_pastes_as_a_list(self, qapp):
|
||||
from lintunes.gui.track_table import parse_tracks_mime
|
||||
table = _table(_songs())
|
||||
table.selectAll()
|
||||
table.copy_selection()
|
||||
mime = QApplication.clipboard().mimeData()
|
||||
assert mime.text() == ("The Wheelhouse - Low Tide\n"
|
||||
"Marguerite Vaux - Café Noir\n"
|
||||
"Orphan Take")
|
||||
# …and pasting into a playlist still reads the songs themselves.
|
||||
assert parse_tracks_mime(mime)["track_ids"] == [1, 2, 3]
|
||||
|
||||
def test_the_list_follows_the_order_shown(self, qapp):
|
||||
from PyQt6.QtCore import Qt
|
||||
table = _table(_songs(), playlist_mode=False)
|
||||
name = table.model_.fields.index("name")
|
||||
table.sortByColumn(name, Qt.SortOrder.AscendingOrder)
|
||||
table.selectAll()
|
||||
table.copy_selection()
|
||||
assert QApplication.clipboard().text().splitlines() == [
|
||||
"Marguerite Vaux - Café Noir", "The Wheelhouse - Low Tide",
|
||||
"Orphan Take"]
|
||||
|
||||
def test_cut_carries_the_list_too(self, qapp):
|
||||
table = _table(_songs())
|
||||
table.selectRow(0)
|
||||
table.cut_selection()
|
||||
assert QApplication.clipboard().text() == "The Wheelhouse - Low Tide"
|
||||
|
||||
def test_untitled_song(self, qapp):
|
||||
from lintunes.gui.track_table import song_line
|
||||
from lintunes.models import Track
|
||||
assert song_line(Track(track_id=9, name="", artist="X")) == "X - Untitled"
|
||||
|
||||
Reference in New Issue
Block a user