v0.80.0: Speakers and Identify Track toolbar items (Customize Toolbar, not in the default bar)
This commit is contained in:
@@ -210,7 +210,11 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
|
||||
spacers always; Restore Defaults). Moves are `QDrag`s with
|
||||
`toolbar.MIME`; a toolbar item dropped anywhere that refuses it is
|
||||
removed. Library and the view's header are row-1-only and can't be removed.
|
||||
The light/dark button (`theme` item) is not in the default rows.
|
||||
The light/dark button (`theme` item) is not in the default rows, nor
|
||||
are (Round 112) `speakers` — a menu of Connections' Chromecast and
|
||||
AirPlay actions, lit while either plays (`set_speakers_active`) — and
|
||||
`identify` (a cassette with an "i"): Identify Track on the playing
|
||||
song, or the shown list's selection when nothing is on.
|
||||
The transport-bar visualizer tile (`gui/visualizer.py`, Round 86): a
|
||||
click opens it big, and while big the tile stays blank; hovering paints
|
||||
two controls over it — a colour wheel (left: colour / gray / off) and ▲/▼
|
||||
|
||||
@@ -179,6 +179,39 @@ def _moon(p, _color):
|
||||
p.drawPath(disc.subtracted(bite))
|
||||
|
||||
|
||||
def _speakers(p, color):
|
||||
"""Choose a speaker: a loudspeaker with two sound waves."""
|
||||
p.drawPolygon(QPolygonF([
|
||||
QPointF(2.5, 7.5), QPointF(5.5, 7.5), QPointF(10.0, 3.5),
|
||||
QPointF(10.0, 16.5), QPointF(5.5, 12.5), QPointF(2.5, 12.5),
|
||||
]))
|
||||
pen = QPen(color, 1.6)
|
||||
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
||||
p.setPen(pen)
|
||||
p.setBrush(Qt.BrushStyle.NoBrush)
|
||||
for radius in (3.2, 6.4): # arcs centred on the cone's mouth
|
||||
p.drawArc(QRectF(10.0 - radius, 10.0 - radius, radius * 2, radius * 2),
|
||||
-50 * 16, 100 * 16)
|
||||
|
||||
|
||||
def _identify(p, color):
|
||||
"""Identify Track: a cassette with a lowercase "i" between its reels."""
|
||||
pen = QPen(color, 1.5)
|
||||
pen.setJoinStyle(Qt.PenJoinStyle.RoundJoin)
|
||||
p.setPen(pen)
|
||||
p.setBrush(Qt.BrushStyle.NoBrush)
|
||||
p.drawRoundedRect(QRectF(1.5, 4.0, 17.0, 12.0), 1.8, 1.8)
|
||||
for x in (5.6, 14.4):
|
||||
p.drawEllipse(QPointF(x, 9.0), 1.9, 1.9)
|
||||
# where the tape shows, along the bottom
|
||||
p.drawPolyline(QPolygonF([QPointF(4.5, 16.0), QPointF(6.0, 13.6),
|
||||
QPointF(14.0, 13.6), QPointF(15.5, 16.0)]))
|
||||
p.setPen(Qt.PenStyle.NoPen)
|
||||
p.setBrush(color)
|
||||
p.drawEllipse(QPointF(10.0, 6.4), 1.05, 1.05) # the i's dot
|
||||
p.drawRoundedRect(QRectF(9.2, 8.2, 1.6, 4.0), 0.5, 0.5)
|
||||
|
||||
|
||||
_DRAWERS = {
|
||||
"play": _play,
|
||||
"pause": _pause,
|
||||
@@ -191,4 +224,6 @@ _DRAWERS = {
|
||||
"airplay": _airplay,
|
||||
"sun": _sun,
|
||||
"moon": _moon,
|
||||
"speakers": _speakers,
|
||||
"identify": _identify,
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ from PyQt6.QtWidgets import (
|
||||
QMainWindow, QSplitter, QStackedWidget, QWidget, QVBoxLayout, QLineEdit,
|
||||
QPlainTextEdit, QTextEdit, QAbstractSpinBox, QComboBox, QApplication,
|
||||
QLabel, QMessageBox, QFileDialog, QProgressBar, QPushButton, QDialog,
|
||||
QDialogButtonBox, QHBoxLayout,
|
||||
QDialogButtonBox, QHBoxLayout, QMenu,
|
||||
)
|
||||
from PyQt6.QtCore import QRect, Qt, QEvent, QObject, QTimer, pyqtSignal
|
||||
from PyQt6.QtGui import QAction, QKeySequence
|
||||
@@ -324,6 +324,8 @@ class MainWindow(QMainWindow):
|
||||
# Wiring
|
||||
self._transport.play_clicked.connect(self.play_pause)
|
||||
self._transport.now_playing_clicked.connect(self._go_to_current_song)
|
||||
self._transport.speakers_clicked.connect(self._show_speaker_menu)
|
||||
self._transport.identify_clicked.connect(self._identify_from_toolbar)
|
||||
self._sidebar.library_selected.connect(self._show_library)
|
||||
self._sidebar.friend_selector_clicked.connect(
|
||||
self._cassette.show_friend_menu)
|
||||
@@ -378,6 +380,10 @@ class MainWindow(QMainWindow):
|
||||
self._airplay.disconnected.connect(
|
||||
lambda reason: self.statusBar().showMessage(
|
||||
reason or "Stopped AirPlay — playing here again", 8000))
|
||||
# The toolbar's speakers button is lit while either plays.
|
||||
for controller in (self._cast, self._airplay):
|
||||
controller.connected.connect(self._show_speakers_state)
|
||||
controller.disconnected.connect(self._show_speakers_state)
|
||||
self._airplay.failed.connect(
|
||||
lambda msg: QMessageBox.warning(self, "AirPlay", msg))
|
||||
manager.library_reloaded.connect(self._on_library_reloaded)
|
||||
@@ -694,6 +700,37 @@ class MainWindow(QMainWindow):
|
||||
self._cast.disconnect()
|
||||
self._airplay.connect_to(dialog.selected_device)
|
||||
|
||||
def _show_speaker_menu(self, button):
|
||||
"""The toolbar's speakers button: Connections' Chromecast and AirPlay
|
||||
entries (each "Disconnect from …" while it plays), under the button."""
|
||||
self._refresh_connection_actions()
|
||||
menu = QMenu(self)
|
||||
menu.addAction(self._cast_action)
|
||||
menu.addAction(self._airplay_action)
|
||||
menu.exec(button.mapToGlobal(button.rect().bottomLeft()))
|
||||
|
||||
def _show_speakers_state(self, *_):
|
||||
for controller in (self._cast, self._airplay):
|
||||
if controller.is_connected():
|
||||
self._transport.set_speakers_active(True, controller.device_name())
|
||||
return
|
||||
self._transport.set_speakers_active(False)
|
||||
|
||||
def _identify_from_toolbar(self):
|
||||
"""The toolbar's Identify button: the playing song — the bar is about
|
||||
what's on — or, with nothing on, the songs selected in the list."""
|
||||
track = self.player.current_track
|
||||
if track is not None and not isinstance(track.track_id, str) \
|
||||
and track.track_id in self._manager.library.tracks:
|
||||
ids = [track.track_id]
|
||||
else:
|
||||
ids = self._content.currentWidget().table.selected_track_ids()
|
||||
if not ids:
|
||||
self.statusBar().showMessage(
|
||||
"Identify Track: play a song or select one first", 6000)
|
||||
return
|
||||
self._identify_tracks(ids)
|
||||
|
||||
def _on_cast_connecting(self, device):
|
||||
self.statusBar().showMessage(f"Connecting to {device.name}…", 8000)
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ ITEMS = {
|
||||
"now_playing": ("Now Playing", (0, 1), True),
|
||||
"dj": ("DJ Mode", (0, 1), True),
|
||||
"theme": ("Light / Dark", (0, 1), True),
|
||||
"speakers": ("Speakers", (0, 1), True),
|
||||
"identify": ("Identify Track", (0, 1), True),
|
||||
"library": ("Library", (1,), False),
|
||||
"view": ("Search / Playlist Name", (1,), False),
|
||||
"seek": ("Seek Bar", (0, 1), True),
|
||||
|
||||
@@ -473,6 +473,8 @@ class TransportBar(QWidget):
|
||||
dj_toggled = pyqtSignal(bool)
|
||||
volume_level_changed = pyqtSignal(float) # the slider, 0..1 perceptual
|
||||
now_playing_clicked = pyqtSignal() # Go to Current Song
|
||||
speakers_clicked = pyqtSignal(QWidget) # pop the speaker menu under it
|
||||
identify_clicked = pyqtSignal()
|
||||
|
||||
def __init__(self, player, manager, prefs, cast=None, airplay=None,
|
||||
parent=None):
|
||||
@@ -651,6 +653,24 @@ class TransportBar(QWidget):
|
||||
self._boxes.append(theme_box)
|
||||
self._show_theme_kind()
|
||||
|
||||
# Not in the bar by default either: a speaker menu (Chromecast /
|
||||
# AirPlay, lit while one plays) and Identify Track.
|
||||
self._speakers_on = False
|
||||
self._speakers_btn = FlashButton("speakers")
|
||||
self._speakers_btn.setCheckable(True) # lit = playing on a speaker
|
||||
self._speakers_btn.setToolTip("Play on a speaker")
|
||||
self._speakers_btn.setMinimumWidth(50)
|
||||
self._speakers_btn.clicked.connect(self._on_speakers)
|
||||
speakers_box = _box(self._speakers_btn, bg=box_bg, margins=(3, 3, 3, 3),
|
||||
height=CONTROL_HEIGHT, split=True)
|
||||
self._identify_btn = FlashButton("identify")
|
||||
self._identify_btn.setToolTip("Identify Track")
|
||||
self._identify_btn.setMinimumWidth(50)
|
||||
self._identify_btn.clicked.connect(self.identify_clicked)
|
||||
identify_box = _box(self._identify_btn, bg=box_bg, margins=(3, 3, 3, 3),
|
||||
height=CONTROL_HEIGHT, split=True)
|
||||
self._boxes += [speakers_box, identify_box]
|
||||
|
||||
# Library button · the current view's header · seek row. MainWindow
|
||||
# hands over the first two (see set_sidebar_header / set_view_header)
|
||||
# and says where the sidebar ends (track_split).
|
||||
@@ -666,7 +686,9 @@ class TransportBar(QWidget):
|
||||
"repeat": repeat_box, "visualizer": self._visualizer,
|
||||
"volume": self._volume_slider,
|
||||
"now_playing": self._now_playing, "dj": dj_box,
|
||||
"theme": theme_box, "bpm": self._bpm_button, "seek": seek}
|
||||
"theme": theme_box, "speakers": speakers_box,
|
||||
"identify": identify_box,
|
||||
"bpm": self._bpm_button, "seek": seek}
|
||||
self._natural, self._least = {}, {}
|
||||
for item, widget in self._items.items():
|
||||
self._natural[item] = max(widget.sizeHint().width(), widget.minimumWidth())
|
||||
@@ -1058,6 +1080,19 @@ class TransportBar(QWidget):
|
||||
elif choice is not None:
|
||||
self._save_toolbar(toolbar.set_size(self._rows, item, *choice))
|
||||
|
||||
# ---- speakers ----
|
||||
|
||||
def _on_speakers(self):
|
||||
self._speakers_btn.setChecked(self._speakers_on) # a click isn't a toggle
|
||||
self.speakers_clicked.emit(self._speakers_btn)
|
||||
|
||||
def set_speakers_active(self, on: bool, name: str = ""):
|
||||
"""Lit while playing on a Chromecast or AirPlay speaker."""
|
||||
self._speakers_on = on
|
||||
self._speakers_btn.setChecked(on)
|
||||
self._speakers_btn.setToolTip(f"Playing on {name}" if on and name
|
||||
else "Play on a speaker")
|
||||
|
||||
# ---- light / dark ----
|
||||
|
||||
def _toggle_dark(self):
|
||||
@@ -1082,7 +1117,8 @@ class TransportBar(QWidget):
|
||||
self._apply_now_playing_font()
|
||||
self._apply_dj_button_style()
|
||||
self._on_dj_button_icon(self.dj_button.isChecked())
|
||||
self._theme_btn.refresh_icons()
|
||||
for button in (self._theme_btn, self._speakers_btn, self._identify_btn):
|
||||
button.refresh_icons()
|
||||
self._show_theme_kind()
|
||||
self._visualizer.update() # dim-mode bar color may have changed
|
||||
self.apply_toolbar()
|
||||
|
||||
@@ -109,3 +109,88 @@ def test_cancel_transfer_is_always_a_button(qapp):
|
||||
button = _CancelSyncButton()
|
||||
assert not button.isFlat()
|
||||
assert "border: none" not in button.styleSheet()
|
||||
|
||||
|
||||
# ---- the Speakers and Identify toolbar items ----
|
||||
|
||||
def _bar(tmp_path):
|
||||
from test_round101 import _bar as make
|
||||
return make(tmp_path)
|
||||
|
||||
|
||||
def test_speakers_and_identify_are_offered_but_not_shown(qapp, tmp_path):
|
||||
from lintunes.gui import toolbar
|
||||
rows = toolbar.default_config()
|
||||
for item in ("speakers", "identify"):
|
||||
assert toolbar.find(rows, item) is None
|
||||
assert item in toolbar.palette_ids(rows)
|
||||
|
||||
|
||||
def test_they_can_be_dropped_in(qapp, tmp_path):
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
bar, prefs = _bar(tmp_path)
|
||||
bar.drop_item("speakers", 0, 2)
|
||||
bar.drop_item("identify", 1, 3)
|
||||
QApplication.processEvents()
|
||||
assert bar._speakers_btn.parentWidget().isVisible()
|
||||
assert bar._identify_btn.parentWidget().isVisible()
|
||||
clicked = []
|
||||
bar.identify_clicked.connect(lambda: clicked.append("identify"))
|
||||
bar.speakers_clicked.connect(lambda button: clicked.append(button))
|
||||
bar._identify_btn.click()
|
||||
bar._speakers_btn.click()
|
||||
assert clicked == ["identify", bar._speakers_btn]
|
||||
assert not bar._speakers_btn.isChecked() # a click doesn't light it
|
||||
bar.set_speakers_active(True, "Kitchen")
|
||||
assert bar._speakers_btn.isChecked()
|
||||
bar._speakers_btn.click()
|
||||
assert bar._speakers_btn.isChecked() # nor put it out
|
||||
bar.set_speakers_active(False)
|
||||
assert not bar._speakers_btn.isChecked()
|
||||
|
||||
|
||||
def test_identify_takes_the_playing_song_else_the_selection(qapp, tmp_path,
|
||||
monkeypatch):
|
||||
from lintunes.gui.main_window import MainWindow
|
||||
from lintunes.library_manager import LibraryManager
|
||||
from lintunes.models.library import Library
|
||||
from lintunes.models.track import Track
|
||||
from lintunes.preferences import Preferences
|
||||
library = Library()
|
||||
for tid in (1, 2):
|
||||
library.tracks[tid] = Track(track_id=tid, name=f"S{tid}")
|
||||
asked = []
|
||||
monkeypatch.setattr(MainWindow, "_identify_tracks",
|
||||
lambda self, ids: asked.append(ids))
|
||||
window = MainWindow(LibraryManager(library, tmp_path / "data"),
|
||||
Preferences(tmp_path / "data"))
|
||||
try:
|
||||
table = window._content.currentWidget().table
|
||||
monkeypatch.setattr(table, "selected_track_ids", lambda: [2])
|
||||
window._identify_from_toolbar()
|
||||
window.player._current_track = library.tracks[1]
|
||||
window._identify_from_toolbar()
|
||||
assert asked == [[2], [1]]
|
||||
finally:
|
||||
window.player._current_track = None
|
||||
window.close()
|
||||
|
||||
|
||||
def test_the_speaker_menu_lights_the_button(qapp, tmp_path, monkeypatch):
|
||||
from lintunes.gui.main_window import MainWindow
|
||||
from lintunes.library_manager import LibraryManager
|
||||
from lintunes.models.library import Library
|
||||
from lintunes.preferences import Preferences
|
||||
window = MainWindow(LibraryManager(Library(), tmp_path / "data"),
|
||||
Preferences(tmp_path / "data"))
|
||||
try:
|
||||
monkeypatch.setattr(window._airplay, "is_connected", lambda: True)
|
||||
monkeypatch.setattr(window._airplay, "device_name", lambda: "Den")
|
||||
window._airplay.connected.emit("Den")
|
||||
assert window._transport._speakers_btn.isChecked()
|
||||
assert "Den" in window._transport._speakers_btn.toolTip()
|
||||
monkeypatch.setattr(window._airplay, "is_connected", lambda: False)
|
||||
window._airplay.disconnected.emit("")
|
||||
assert not window._transport._speakers_btn.isChecked()
|
||||
finally:
|
||||
window.close()
|
||||
|
||||
Reference in New Issue
Block a user