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
This commit is contained in:
2026-11-08 20:54:26 -08:00
parent bf68e99b8d
commit 8afcd4433b
6 changed files with 173 additions and 21 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.91.3"
__version__ = "0.92.0"
+83 -11
View File
@@ -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.
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 (
QCheckBox, QDialog, QDialogButtonBox, QGroupBox, QHBoxLayout,
QHeaderView, QLabel, QPushButton, QSplitter, QStackedWidget,
QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget,
QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget,
)
from lintunes import shazam
@@ -164,6 +165,45 @@ TAGGED = "Tagged"
KEPT = "Imported with Shazam's tags"
NOT_IMPORTED = "Downloaded, but couldn't be imported"
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):
@@ -176,6 +216,7 @@ class ShazamImportWindow(QDialog):
self.setModal(False)
self.resize(780, 720)
self._rows: dict[str, QTreeWidgetItem] = {}
self._songs = {song.request_id: song for song in songs}
self._tracks: dict[str, object] = {}
self._candidates: dict[str, list] = {}
self._pending: list[str] = [] # ids ready to tag, in order
@@ -189,16 +230,21 @@ class ShazamImportWindow(QDialog):
split = QSplitter(Qt.Orientation.Vertical)
self._tree = QTreeWidget()
self._tree.setColumnCount(2)
self._tree.setHeaderLabels(["Song", "Status"])
self._tree.setColumnCount(3)
self._tree.setHeaderLabels(["Song", "Status", ""])
self._tree.setRootIsDecorated(False)
self._tree.setUniformRowHeights(True)
header = self._tree.header()
# The song's edge drags; the status (a long reason, often) takes
# what's left.
# Every edge drags (v0.73.2). The last column holds Copy, at the
# 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.setStretchLastSection(False)
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:
item = QTreeWidgetItem([song.label(), WAITING])
item.setToolTip(0, f"{song.label()}\nShazamed {_when(song)}")
@@ -255,6 +301,15 @@ class ShazamImportWindow(QDialog):
layout.addLayout(buttons)
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 ----
def status(self, rid: str) -> str:
@@ -269,8 +324,27 @@ class ShazamImportWindow(QDialog):
self._tree.scrollToItem(item)
item.setText(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()
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):
self.set_stage(rid, f"Couldn't import: {reason}")
@@ -302,7 +376,7 @@ class ShazamImportWindow(QDialog):
def finish(self, cancelled: bool):
self._done = True
leftover = SKIPPED if cancelled else "Not found"
leftover = SKIPPED if cancelled else NOT_FOUND
for rid, item in self._rows.items():
text = item.text(1)
if text == WAITING or (rid not in self._tracks and not
@@ -379,9 +453,7 @@ class ShazamImportWindow(QDialog):
total = len(statuses)
imported = len(self._tracks)
tagged = statuses.count(TAGGED)
problems = sum(1 for s in statuses
if s.startswith(("Couldn't", "Downloaded"))
or s == "Not found")
problems = sum(1 for s in statuses if is_problem(s))
text = f"{imported} of {total} songs imported"
if tagged:
text += f" · {tagged} tagged"
+15 -2
View File
@@ -548,11 +548,24 @@ class TitleBarInstaller(QObject):
@staticmethod
def make_frameless(window: QWidget):
window.setProperty(_DONE, "frameless")
# Before the flag, which recreates the native window: an alpha
# channel is what lets the corners be round.
# An alpha channel is what lets the corners be round.
if not window.property(SQUARE):
window.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
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
def add_bar(window: QWidget) -> TitleBar: