v0.92.0: no black corners on windows shown before they were polished; Copy beside Shazams that couldn't be imported, to search by hand
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -893,7 +893,8 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
|
|||||||
quit come free) narrating `stage` per song — the `LTPP` postprocess
|
quit come free) narrating `stage` per song — the `LTPP` postprocess
|
||||||
marker is what says "Converting". `ShazamImportWindow` is the song list
|
marker is what says "Converting". `ShazamImportWindow` is the song list
|
||||||
*and* an embedded `identify_dialog.IdentifyPanel` per song as soon as it's
|
*and* an embedded `identify_dialog.IdentifyPanel` per song as soon as it's
|
||||||
imported (its own one-at-a-time `TrackIdentifier` queue; filename
|
imported (a song that didn't make it gets a Copy button in the last
|
||||||
|
column — `search_text`, to search by hand, Round 128) (its own one-at-a-time `TrackIdentifier` queue; filename
|
||||||
candidates are dropped, since the file already wears Shazam's tags).
|
candidates are dropped, since the file already wears Shazam's tags).
|
||||||
**Full Rabbit Sync** (Round 120, beside Sync Music to Rabbit) is the
|
**Full Rabbit Sync** (Round 120, beside Sync Music to Rabbit) is the
|
||||||
music sync, then Import Shazams into the playlist current *at the
|
music sync, then Import Shazams into the playlist current *at the
|
||||||
@@ -1315,7 +1316,10 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
|
|||||||
height, since Qt hides Wayland's tiled state), its gray filled by the installer on the window's `Paint`, and
|
height, since Qt hides Wayland's tiled state), its gray filled by the installer on the window's `Paint`, and
|
||||||
`titlebar._Frame` — a mouse-transparent overlay masked to the edge ring,
|
`titlebar._Frame` — a mouse-transparent overlay masked to the edge ring,
|
||||||
on top of everything — clears outside the curve and paints the soft
|
on top of everything — clears outside the curve and paints the soft
|
||||||
emboss and outline. No line under the title bar, nor under the menu bar
|
emboss and outline. A window shown before anything polished it gets
|
||||||
|
its native surface *before* `Polish`, so `make_frameless` sets an alpha
|
||||||
|
format and remakes the surface (Round 128) — without it the cleared
|
||||||
|
corners were black wedges. No line under the title bar, nor under the menu bar
|
||||||
(`ClickToJumpScrollStyle.drawControl` paints over Fusion's). The main
|
(`ClickToJumpScrollStyle.drawControl` paints over Fusion's). The main
|
||||||
window sets `BLANK_TITLE` (the song is in the panel right under it);
|
window sets `BLANK_TITLE` (the song is in the panel right under it);
|
||||||
`VisualizerWindow` sets `SQUARE` — Kaleidostrobe's GL clears to alpha 0,
|
`VisualizerWindow` sets `SQUARE` — Kaleidostrobe's GL clears to alpha 0,
|
||||||
|
|||||||
@@ -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.91.3"
|
__version__ = "0.92.0"
|
||||||
|
|||||||
@@ -12,11 +12,12 @@ importing, identifying), and below them the Identify proposal for each song
|
|||||||
as soon as it's imported — so tagging starts while the rest download.
|
as soon as it's imported — so tagging starts while the rest download.
|
||||||
Non-modal; Hide only hides it, and the status-bar line brings it back.
|
Non-modal; Hide only hides it, and the status-bar line brings it back.
|
||||||
"""
|
"""
|
||||||
from PyQt6.QtCore import Qt, pyqtSignal
|
from PyQt6.QtCore import QEvent, Qt, QTimer, pyqtSignal
|
||||||
|
from PyQt6.QtGui import QGuiApplication
|
||||||
from PyQt6.QtWidgets import (
|
from PyQt6.QtWidgets import (
|
||||||
QCheckBox, QDialog, QDialogButtonBox, QGroupBox, QHBoxLayout,
|
QCheckBox, QDialog, QDialogButtonBox, QGroupBox, QHBoxLayout,
|
||||||
QHeaderView, QLabel, QPushButton, QSplitter, QStackedWidget,
|
QHeaderView, QLabel, QPushButton, QSplitter, QStackedWidget,
|
||||||
QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget,
|
QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget,
|
||||||
)
|
)
|
||||||
|
|
||||||
from lintunes import shazam
|
from lintunes import shazam
|
||||||
@@ -164,6 +165,45 @@ TAGGED = "Tagged"
|
|||||||
KEPT = "Imported with Shazam's tags"
|
KEPT = "Imported with Shazam's tags"
|
||||||
NOT_IMPORTED = "Downloaded, but couldn't be imported"
|
NOT_IMPORTED = "Downloaded, but couldn't be imported"
|
||||||
SKIPPED = "Skipped"
|
SKIPPED = "Skipped"
|
||||||
|
NOT_FOUND = "Not found"
|
||||||
|
|
||||||
|
|
||||||
|
def is_problem(status: str) -> bool:
|
||||||
|
"""A song that didn't make it into the library."""
|
||||||
|
return status.startswith(("Couldn't", "Downloaded")) or status == NOT_FOUND
|
||||||
|
|
||||||
|
|
||||||
|
class CopyButton(QToolButton):
|
||||||
|
"""Copy, which says "Copied" for a moment after a click."""
|
||||||
|
|
||||||
|
def __init__(self, text: str = ""):
|
||||||
|
super().__init__()
|
||||||
|
self._text = text
|
||||||
|
self.setText("Copied") # as wide as its widest word
|
||||||
|
self.setMinimumWidth(self.sizeHint().width())
|
||||||
|
self.setText("Copy")
|
||||||
|
self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||||
|
self._reset = QTimer(self)
|
||||||
|
self._reset.setSingleShot(True)
|
||||||
|
self._reset.setInterval(1500)
|
||||||
|
self._reset.timeout.connect(self._back)
|
||||||
|
self.clicked.connect(self._copy)
|
||||||
|
|
||||||
|
def _copy(self):
|
||||||
|
QGuiApplication.clipboard().setText(self._text)
|
||||||
|
self.setText("Copied")
|
||||||
|
self._reset.start()
|
||||||
|
|
||||||
|
def _back(self):
|
||||||
|
self.setText("Copy")
|
||||||
|
|
||||||
|
|
||||||
|
def search_text(song) -> str:
|
||||||
|
"""What Copy puts on the clipboard: enough to search for it by hand."""
|
||||||
|
text = song.label()
|
||||||
|
if song.album and song.album.casefold() != song.title.casefold():
|
||||||
|
text += f" ({song.album})"
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
class ShazamImportWindow(QDialog):
|
class ShazamImportWindow(QDialog):
|
||||||
@@ -176,6 +216,7 @@ class ShazamImportWindow(QDialog):
|
|||||||
self.setModal(False)
|
self.setModal(False)
|
||||||
self.resize(780, 720)
|
self.resize(780, 720)
|
||||||
self._rows: dict[str, QTreeWidgetItem] = {}
|
self._rows: dict[str, QTreeWidgetItem] = {}
|
||||||
|
self._songs = {song.request_id: song for song in songs}
|
||||||
self._tracks: dict[str, object] = {}
|
self._tracks: dict[str, object] = {}
|
||||||
self._candidates: dict[str, list] = {}
|
self._candidates: dict[str, list] = {}
|
||||||
self._pending: list[str] = [] # ids ready to tag, in order
|
self._pending: list[str] = [] # ids ready to tag, in order
|
||||||
@@ -189,16 +230,21 @@ class ShazamImportWindow(QDialog):
|
|||||||
|
|
||||||
split = QSplitter(Qt.Orientation.Vertical)
|
split = QSplitter(Qt.Orientation.Vertical)
|
||||||
self._tree = QTreeWidget()
|
self._tree = QTreeWidget()
|
||||||
self._tree.setColumnCount(2)
|
self._tree.setColumnCount(3)
|
||||||
self._tree.setHeaderLabels(["Song", "Status"])
|
self._tree.setHeaderLabels(["Song", "Status", ""])
|
||||||
self._tree.setRootIsDecorated(False)
|
self._tree.setRootIsDecorated(False)
|
||||||
self._tree.setUniformRowHeights(True)
|
self._tree.setUniformRowHeights(True)
|
||||||
header = self._tree.header()
|
header = self._tree.header()
|
||||||
# The song's edge drags; the status (a long reason, often) takes
|
# Every edge drags (v0.73.2). The last column holds Copy, at the
|
||||||
# what's left.
|
# right edge, on the songs that didn't make it, so they can be
|
||||||
|
# looked for by hand; the status (a long reason, often) fills what
|
||||||
|
# the other two leave whenever the list changes width.
|
||||||
header.setSectionResizeMode(QHeaderView.ResizeMode.Interactive)
|
header.setSectionResizeMode(QHeaderView.ResizeMode.Interactive)
|
||||||
|
header.setStretchLastSection(False)
|
||||||
header.resizeSection(0, 420)
|
header.resizeSection(0, 420)
|
||||||
header.setStretchLastSection(True)
|
header.setSectionResizeMode(2, QHeaderView.ResizeMode.Fixed)
|
||||||
|
header.resizeSection(2, CopyButton().minimumWidth() + 8)
|
||||||
|
self._tree.viewport().installEventFilter(self)
|
||||||
for song in songs:
|
for song in songs:
|
||||||
item = QTreeWidgetItem([song.label(), WAITING])
|
item = QTreeWidgetItem([song.label(), WAITING])
|
||||||
item.setToolTip(0, f"{song.label()}\nShazamed {_when(song)}")
|
item.setToolTip(0, f"{song.label()}\nShazamed {_when(song)}")
|
||||||
@@ -255,6 +301,15 @@ class ShazamImportWindow(QDialog):
|
|||||||
layout.addLayout(buttons)
|
layout.addLayout(buttons)
|
||||||
self._refresh_summary()
|
self._refresh_summary()
|
||||||
|
|
||||||
|
def eventFilter(self, obj, event):
|
||||||
|
if (event.type() == QEvent.Type.Resize
|
||||||
|
and obj is self._tree.viewport()):
|
||||||
|
header = self._tree.header()
|
||||||
|
header.resizeSection(1, max(
|
||||||
|
header.minimumSectionSize(), obj.width()
|
||||||
|
- header.sectionSize(0) - header.sectionSize(2)))
|
||||||
|
return super().eventFilter(obj, event)
|
||||||
|
|
||||||
# ---- fed by MainWindow ----
|
# ---- fed by MainWindow ----
|
||||||
|
|
||||||
def status(self, rid: str) -> str:
|
def status(self, rid: str) -> str:
|
||||||
@@ -269,8 +324,27 @@ class ShazamImportWindow(QDialog):
|
|||||||
self._tree.scrollToItem(item)
|
self._tree.scrollToItem(item)
|
||||||
item.setText(1, text)
|
item.setText(1, text)
|
||||||
item.setToolTip(1, text)
|
item.setToolTip(1, text)
|
||||||
|
has_copy = self._tree.itemWidget(item, 2) is not None
|
||||||
|
if is_problem(text) and not has_copy:
|
||||||
|
cell = QWidget()
|
||||||
|
cell_layout = QHBoxLayout(cell)
|
||||||
|
cell_layout.setContentsMargins(0, 0, 4, 0)
|
||||||
|
cell_layout.addStretch(1)
|
||||||
|
cell_layout.addWidget(self._copy_button(rid))
|
||||||
|
self._tree.setItemWidget(item, 2, cell)
|
||||||
|
elif not is_problem(text) and has_copy:
|
||||||
|
self._tree.removeItemWidget(item, 2)
|
||||||
self._refresh_summary()
|
self._refresh_summary()
|
||||||
|
|
||||||
|
def _copy_button(self, rid: str) -> QToolButton:
|
||||||
|
song = self._songs.get(rid)
|
||||||
|
if song is None:
|
||||||
|
return CopyButton()
|
||||||
|
button = CopyButton(search_text(song))
|
||||||
|
button.setToolTip(f"Copy “{search_text(song)}” to search for it "
|
||||||
|
"yourself")
|
||||||
|
return button
|
||||||
|
|
||||||
def failed(self, rid: str, reason: str):
|
def failed(self, rid: str, reason: str):
|
||||||
self.set_stage(rid, f"Couldn't import: {reason}")
|
self.set_stage(rid, f"Couldn't import: {reason}")
|
||||||
|
|
||||||
@@ -302,7 +376,7 @@ class ShazamImportWindow(QDialog):
|
|||||||
|
|
||||||
def finish(self, cancelled: bool):
|
def finish(self, cancelled: bool):
|
||||||
self._done = True
|
self._done = True
|
||||||
leftover = SKIPPED if cancelled else "Not found"
|
leftover = SKIPPED if cancelled else NOT_FOUND
|
||||||
for rid, item in self._rows.items():
|
for rid, item in self._rows.items():
|
||||||
text = item.text(1)
|
text = item.text(1)
|
||||||
if text == WAITING or (rid not in self._tracks and not
|
if text == WAITING or (rid not in self._tracks and not
|
||||||
@@ -379,9 +453,7 @@ class ShazamImportWindow(QDialog):
|
|||||||
total = len(statuses)
|
total = len(statuses)
|
||||||
imported = len(self._tracks)
|
imported = len(self._tracks)
|
||||||
tagged = statuses.count(TAGGED)
|
tagged = statuses.count(TAGGED)
|
||||||
problems = sum(1 for s in statuses
|
problems = sum(1 for s in statuses if is_problem(s))
|
||||||
if s.startswith(("Couldn't", "Downloaded"))
|
|
||||||
or s == "Not found")
|
|
||||||
text = f"{imported} of {total} songs imported"
|
text = f"{imported} of {total} songs imported"
|
||||||
if tagged:
|
if tagged:
|
||||||
text += f" · {tagged} tagged"
|
text += f" · {tagged} tagged"
|
||||||
|
|||||||
@@ -548,11 +548,24 @@ class TitleBarInstaller(QObject):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def make_frameless(window: QWidget):
|
def make_frameless(window: QWidget):
|
||||||
window.setProperty(_DONE, "frameless")
|
window.setProperty(_DONE, "frameless")
|
||||||
# Before the flag, which recreates the native window: an alpha
|
# An alpha channel is what lets the corners be round.
|
||||||
# channel is what lets the corners be round.
|
|
||||||
if not window.property(SQUARE):
|
if not window.property(SQUARE):
|
||||||
window.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
window.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
||||||
window.setWindowFlag(Qt.WindowType.FramelessWindowHint, True)
|
window.setWindowFlag(Qt.WindowType.FramelessWindowHint, True)
|
||||||
|
# A window shown without being polished first is polished *inside*
|
||||||
|
# show(), after its native surface was made: Qt then never asks
|
||||||
|
# that surface for an alpha channel, so the cleared corners come
|
||||||
|
# out black. Ask, and make the surface again; it isn't on screen
|
||||||
|
# yet, so nothing flickers.
|
||||||
|
handle = window.windowHandle()
|
||||||
|
if (handle is not None and not window.property(SQUARE)
|
||||||
|
and handle.format().alphaBufferSize() < 8):
|
||||||
|
surface = handle.requestedFormat()
|
||||||
|
surface.setAlphaBufferSize(8)
|
||||||
|
handle.setFormat(surface)
|
||||||
|
if handle.format().alphaBufferSize() < 8: # already made
|
||||||
|
handle.destroy()
|
||||||
|
handle.create()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_bar(window: QWidget) -> TitleBar:
|
def add_bar(window: QWidget) -> TitleBar:
|
||||||
|
|||||||
@@ -544,8 +544,12 @@ def test_every_column_edge_can_be_dragged(qapp):
|
|||||||
from lintunes.gui import shazam_import as ui
|
from lintunes.gui import shazam_import as ui
|
||||||
window = ui.ShazamImportWindow([_song("a")])
|
window = ui.ShazamImportWindow([_song("a")])
|
||||||
preview = ui.ShazamPreviewDialog(_Reader([_song("a")]), set(), [], None)
|
preview = ui.ShazamPreviewDialog(_Reader([_song("a")]), set(), [], None)
|
||||||
for tree in (window._tree, preview._tree):
|
header = preview._tree.header()
|
||||||
header = tree.header()
|
|
||||||
for i in range(header.count() - 1):
|
for i in range(header.count() - 1):
|
||||||
assert header.sectionResizeMode(i) == QHeaderView.ResizeMode.Interactive
|
assert header.sectionResizeMode(i) == QHeaderView.ResizeMode.Interactive
|
||||||
assert header.stretchLastSection()
|
assert header.stretchLastSection()
|
||||||
|
# Round 128: the import window's last column is Copy, a fixed button;
|
||||||
|
# the song and status edges still drag, and the status fills the rest.
|
||||||
|
header = window._tree.header()
|
||||||
|
for i in (0, 1):
|
||||||
|
assert header.sectionResizeMode(i) == QHeaderView.ResizeMode.Interactive
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
"""Round 128.
|
||||||
|
|
||||||
|
- A window shown without being polished first got its native surface before
|
||||||
|
the title-bar installer asked for an alpha channel, so the cleared corners
|
||||||
|
outside the curve came out black.
|
||||||
|
- Importing Shazams: a song that couldn't be imported gets a Copy button
|
||||||
|
(right-hand column) that puts "Artist — Title (Album)" on the clipboard,
|
||||||
|
to search for it by hand.
|
||||||
|
"""
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from PyQt6.QtWidgets import QDialog, QToolButton
|
||||||
|
|
||||||
|
from lintunes.gui import shazam_import as ui
|
||||||
|
from lintunes.gui import titlebar
|
||||||
|
from lintunes.shazam import ShazamSong
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_window_shown_unpolished_still_gets_alpha(qapp):
|
||||||
|
installer = titlebar.install(qapp)
|
||||||
|
try:
|
||||||
|
dialog = QDialog() # shown at once: created, then polished
|
||||||
|
dialog.show()
|
||||||
|
qapp.processEvents()
|
||||||
|
assert dialog.windowHandle().format().alphaBufferSize() == 8
|
||||||
|
dialog.close()
|
||||||
|
finally:
|
||||||
|
qapp.removeEventFilter(installer)
|
||||||
|
|
||||||
|
|
||||||
|
def _song(rid, **kw):
|
||||||
|
return ShazamSong(request_id=rid, when=datetime(2026, 10, 1, 20, 15), **kw)
|
||||||
|
|
||||||
|
|
||||||
|
def _copy_in(window, rid):
|
||||||
|
cell = window._tree.itemWidget(window._rows[rid], 2)
|
||||||
|
return cell.findChild(QToolButton) if cell is not None else None
|
||||||
|
|
||||||
|
|
||||||
|
def test_songs_that_failed_get_a_copy_button(qapp):
|
||||||
|
window = ui.ShazamImportWindow([
|
||||||
|
_song("a", title="America Latina"),
|
||||||
|
_song("b", title="Ghor Bari", artist="Kalyani Ghosh", album="Songs"),
|
||||||
|
_song("c", title="Digital Love", artist="Daft Punk")])
|
||||||
|
assert _copy_in(window, "a") is None
|
||||||
|
window.failed("a", "nothing found that's just the song")
|
||||||
|
window.set_stage("b", "Downloading…")
|
||||||
|
window.finish(cancelled=False) # b never landed: Not found
|
||||||
|
window.imported("c", object())
|
||||||
|
assert _copy_in(window, "c") is None
|
||||||
|
|
||||||
|
_copy_in(window, "b").click()
|
||||||
|
assert qapp.clipboard().text() == "Kalyani Ghosh — Ghor Bari (Songs)"
|
||||||
|
_copy_in(window, "a").click()
|
||||||
|
assert qapp.clipboard().text() == "America Latina"
|
||||||
|
|
||||||
|
# A row that recovers loses it again.
|
||||||
|
window.set_stage("a", ui.IMPORTING)
|
||||||
|
assert _copy_in(window, "a") is None
|
||||||
Reference in New Issue
Block a user