v0.79.0: the now-playing panel embosses on hover and a click goes to the current song
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
"""Round 110: the now-playing panel is a Go to Current Song button."""
|
||||
from PyQt6.QtCore import QEvent, QPointF, Qt
|
||||
from PyQt6.QtGui import QEnterEvent, QMouseEvent
|
||||
|
||||
from lintunes.gui.transport import NowPlayingPanel
|
||||
|
||||
|
||||
def _mouse(kind, x=5, y=5):
|
||||
return QMouseEvent(kind, QPointF(x, y), QPointF(x, y),
|
||||
Qt.MouseButton.LeftButton,
|
||||
Qt.MouseButton.LeftButton if kind != QEvent.Type.MouseButtonRelease
|
||||
else Qt.MouseButton.NoButton,
|
||||
Qt.KeyboardModifier.NoModifier)
|
||||
|
||||
|
||||
def _enter(panel):
|
||||
panel.enterEvent(QEnterEvent(QPointF(5, 5), QPointF(5, 5), QPointF(5, 5)))
|
||||
|
||||
|
||||
def test_hover_embosses_and_a_click_goes_to_the_song(qapp):
|
||||
panel = NowPlayingPanel()
|
||||
panel.resize(200, 60)
|
||||
clicks = []
|
||||
panel.clicked.connect(lambda: clicks.append(1))
|
||||
panel.set_clickable(True)
|
||||
assert not panel.property("face")
|
||||
_enter(panel)
|
||||
assert panel.property("face") == "hover"
|
||||
panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress))
|
||||
assert panel.property("face") == "down"
|
||||
panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease))
|
||||
assert clicks == [1] and panel.property("face") == "hover"
|
||||
panel.leaveEvent(QEvent(QEvent.Type.Leave))
|
||||
assert not panel.property("face")
|
||||
|
||||
|
||||
def test_released_outside_is_no_click(qapp):
|
||||
panel = NowPlayingPanel()
|
||||
panel.resize(200, 60)
|
||||
clicks = []
|
||||
panel.clicked.connect(lambda: clicks.append(1))
|
||||
panel.set_clickable(True)
|
||||
_enter(panel)
|
||||
panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress))
|
||||
panel.mouseMoveEvent(_mouse(QEvent.Type.MouseMove, 400, 5))
|
||||
assert not panel.property("face")
|
||||
panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease, 400, 5))
|
||||
assert clicks == []
|
||||
|
||||
|
||||
def test_nothing_playing_is_just_a_panel(qapp):
|
||||
panel = NowPlayingPanel()
|
||||
clicks = []
|
||||
panel.clicked.connect(lambda: clicks.append(1))
|
||||
_enter(panel)
|
||||
panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress))
|
||||
panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease))
|
||||
assert clicks == [] and not panel.property("face")
|
||||
|
||||
|
||||
def test_window_wires_it_to_go_to_current_song(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()
|
||||
library.tracks[1] = Track(track_id=1, name="Song", artist="A")
|
||||
manager = LibraryManager(library, tmp_path / "data")
|
||||
went = []
|
||||
monkeypatch.setattr(MainWindow, "_go_to_current_song",
|
||||
lambda self: went.append(1))
|
||||
window = MainWindow(manager, Preferences(tmp_path / "data"))
|
||||
try:
|
||||
window._transport.now_playing_clicked.emit()
|
||||
assert went == [1]
|
||||
panel = window._transport._now_playing
|
||||
window._transport._on_track_changed(library.tracks[1])
|
||||
assert panel._clickable
|
||||
window._transport.set_dj_mode(True)
|
||||
assert not panel._clickable
|
||||
window._transport.set_dj_mode(False)
|
||||
assert panel._clickable
|
||||
finally:
|
||||
window.close()
|
||||
Reference in New Issue
Block a user