forked from trav/lintunes
The export dialog gains an accent color — the hover background on links and
tracklist rows, and the player's progress fill — and the rest of the bar loses
its 2010 gold so that choice is the only color in it.
The accent travels as a `:root { --accent }` custom property declared in
index.html, which player.css reads as `var(--accent, #8c764a)`. That keeps the
stylesheet in the verbatim copyfile loop: index.html is still the only rendered
template. `normalize_accent` is the injection gate — the value lands raw inside
a <style> block and string.Template escapes nothing — and `contrast_text` flips
the hover text black or white, since the old page hard-coded white and a pale
accent made it unreadable.
The bar itself is now fixed light gray with black text. Its sprite glyphs are
pale lavender and yellow, drawn for the dark gold bar, so they're recolored
with `filter: brightness(0)` rather than by editing the GIF — which still ships
byte-identical, spinner and all.
Not persisted: the picker opens on #8c764a every time, so an export nobody
touches looks exactly like the mixes already online.
Claude-Session: https://claude.ai/code/session_01JBSM2bFC6UToiEg8BE4dqj
165 lines
6.3 KiB
Python
165 lines
6.3 KiB
Python
"""The two dialogs behind File → Export Playlist…
|
|
|
|
`ExportKindDialog` asks folder-or-website; `WebMixDialog` collects the bits of
|
|
a web mix that can't be inferred — title, blurb, hero image, accent color.
|
|
Per-track liner notes are deliberately absent: the hand-made mixes carry a numbered paragraph
|
|
per track, which is far too much to type into a form, so the generated
|
|
index.html leaves a commented-out block in the right place instead.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from PyQt6.QtCore import Qt
|
|
from PyQt6.QtGui import QColor
|
|
from PyQt6.QtWidgets import (
|
|
QColorDialog, QDialog, QDialogButtonBox, QFileDialog, QFormLayout,
|
|
QHBoxLayout, QLabel, QLineEdit, QPlainTextEdit, QPushButton, QRadioButton,
|
|
QVBoxLayout)
|
|
|
|
from lintunes import theme
|
|
from lintunes.export import exporter
|
|
|
|
_IMAGE_FILTER = "Images (*.png *.jpg *.jpeg *.gif *.webp)"
|
|
|
|
|
|
class ExportKindDialog(QDialog):
|
|
"""Folder of music files, or a self-contained web mix."""
|
|
|
|
def __init__(self, playlist_name: str, parent=None):
|
|
super().__init__(parent)
|
|
self.setWindowTitle("Export Playlist")
|
|
self.setMinimumWidth(420)
|
|
layout = QVBoxLayout(self)
|
|
|
|
layout.addWidget(QLabel(f"Export “{playlist_name}” as:"))
|
|
|
|
self._folder = QRadioButton("A folder of music files")
|
|
self._folder.setChecked(True)
|
|
layout.addWidget(self._folder)
|
|
hint = QLabel("The audio files, named “Artist - Title”, plus an .m3u "
|
|
"playlist. Files are copied exactly as they are.")
|
|
hint.setWordWrap(True)
|
|
hint.setIndent(24)
|
|
hint.setEnabled(False)
|
|
layout.addWidget(hint)
|
|
|
|
self._web = QRadioButton("A website")
|
|
layout.addWidget(self._web)
|
|
web_hint = QLabel(
|
|
"A self-contained page with a player and the tracklist, ready to "
|
|
"copy into a web directory. Anything a browser can't play is "
|
|
"converted to FLAC, losslessly.")
|
|
web_hint.setWordWrap(True)
|
|
web_hint.setIndent(24)
|
|
web_hint.setEnabled(False)
|
|
layout.addWidget(web_hint)
|
|
|
|
layout.addSpacing(8)
|
|
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok
|
|
| QDialogButtonBox.StandardButton.Cancel)
|
|
buttons.button(QDialogButtonBox.StandardButton.Ok).setText("Continue")
|
|
buttons.accepted.connect(self.accept)
|
|
buttons.rejected.connect(self.reject)
|
|
layout.addWidget(buttons)
|
|
|
|
def kind(self) -> str:
|
|
return exporter.WEB if self._web.isChecked() else exporter.FOLDER
|
|
|
|
|
|
class WebMixDialog(QDialog):
|
|
"""Title, description, hero image and accent color for a web mix.
|
|
|
|
The accent isn't remembered between exports: it opens on
|
|
``exporter.DEFAULT_ACCENT`` every time, so an export nobody touched comes
|
|
out looking exactly like the mixes already online.
|
|
"""
|
|
|
|
def __init__(self, playlist_name: str, parent=None):
|
|
super().__init__(parent)
|
|
self.setWindowTitle("Export Web Mix")
|
|
self.setMinimumWidth(520)
|
|
layout = QVBoxLayout(self)
|
|
form = QFormLayout()
|
|
form.setFieldGrowthPolicy(
|
|
QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow)
|
|
|
|
self._title = QLineEdit(playlist_name)
|
|
form.addRow("Title:", self._title)
|
|
|
|
self._description = QPlainTextEdit()
|
|
self._description.setPlainText(exporter.DEFAULT_DESCRIPTION)
|
|
self._description.setMinimumHeight(140)
|
|
form.addRow("Description:", self._description)
|
|
|
|
image_row = QHBoxLayout()
|
|
self._image = QLineEdit()
|
|
self._image.setPlaceholderText("(a gray placeholder)")
|
|
self._image.setReadOnly(True)
|
|
image_row.addWidget(self._image, stretch=1)
|
|
browse = QPushButton("Browse…")
|
|
browse.clicked.connect(self._choose_image)
|
|
image_row.addWidget(browse)
|
|
clear = QPushButton("Clear")
|
|
clear.clicked.connect(lambda: self._image.clear())
|
|
image_row.addWidget(clear)
|
|
form.addRow("Image:", image_row)
|
|
|
|
color_row = QHBoxLayout()
|
|
self._accent = exporter.DEFAULT_ACCENT
|
|
self._accent_button = QPushButton()
|
|
self._accent_button.clicked.connect(self._choose_accent)
|
|
color_row.addWidget(self._accent_button)
|
|
reset = QPushButton("Reset")
|
|
reset.clicked.connect(
|
|
lambda: self._set_accent(exporter.DEFAULT_ACCENT))
|
|
color_row.addWidget(reset)
|
|
color_row.addStretch()
|
|
form.addRow("Accent:", color_row)
|
|
self._set_accent(self._accent)
|
|
layout.addLayout(form)
|
|
|
|
note = QLabel(
|
|
"The accent colors the hover background on links and tracklist "
|
|
"rows, and the player's progress bar. "
|
|
"The description is plain HTML — links and <br> work. "
|
|
"Per-track liner notes aren't asked for here; index.html has a "
|
|
"commented-out block in the right spot for them.")
|
|
note.setWordWrap(True)
|
|
note.setTextFormat(Qt.TextFormat.RichText)
|
|
note.setEnabled(False)
|
|
layout.addWidget(note)
|
|
|
|
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok
|
|
| QDialogButtonBox.StandardButton.Cancel)
|
|
buttons.button(QDialogButtonBox.StandardButton.Ok).setText("Export")
|
|
buttons.accepted.connect(self.accept)
|
|
buttons.rejected.connect(self.reject)
|
|
layout.addWidget(buttons)
|
|
|
|
def _choose_image(self):
|
|
start = str(Path(self._image.text()).parent) if self._image.text() else ""
|
|
name, _filter = QFileDialog.getOpenFileName(
|
|
self, "Choose Image", start, _IMAGE_FILTER)
|
|
if name:
|
|
self._image.setText(name)
|
|
|
|
def _set_accent(self, color_hex: str):
|
|
self._accent = exporter.normalize_accent(color_hex)
|
|
self._accent_button.setIcon(theme.swatch_icon(self._accent))
|
|
self._accent_button.setText(self._accent)
|
|
|
|
def _choose_accent(self):
|
|
color = QColorDialog.getColor(
|
|
QColor(self._accent), self, "Accent Color")
|
|
if color.isValid():
|
|
self._set_accent(color.name())
|
|
|
|
def values(self) -> dict:
|
|
text = self._image.text().strip()
|
|
return {
|
|
"title": self._title.text().strip(),
|
|
"description": self._description.toPlainText().strip(),
|
|
"image": Path(text) if text else None,
|
|
"accent": self._accent,
|
|
}
|