Pull in recent V3 updates

This commit is contained in:
Keith Edmunds 2024-04-27 19:33:35 +01:00
parent e4a9520908
commit 2e8fae99ed
7 changed files with 53 additions and 34 deletions

View File

@ -183,14 +183,19 @@ class PlaylistTrack:
Called when track starts playing
"""
self.start_time = dt.datetime.now()
now = dt.datetime.now()
self.start_time = now
if self.duration:
self.end_time = self.start_time + dt.timedelta(milliseconds=self.duration)
# Calculate time fade_graph should start updating
if self.fade_at:
update_graph_at_ms = max(0, self.fade_at - Config.FADE_CURVE_MS_BEFORE_FADE - 1)
self.fade_graph_start_updates = now + timedelta(milliseconds=update_graph_at_ms)
update_graph_at_ms = max(
0, self.fade_at - Config.FADE_CURVE_MS_BEFORE_FADE - 1
)
self.fade_graph_start_updates = now + dt.timedelta(
milliseconds=update_graph_at_ms
)
class AddFadeCurve(QObject):

View File

@ -1,17 +1,15 @@
# Standard library imports
# PyQt imports
# Third party imports
# App imports
from typing import Optional
# PyQt imports
from PyQt6.QtCore import QEvent, Qt
from PyQt6.QtWidgets import QDialog, QListWidgetItem
# Third party imports
from sqlalchemy.orm.session import Session
# App imports
from classes import MusicMusterSignals
from sqlalchemy.orm import scoped_session
from helpers import (
ask_yes_no,
get_relative_date,
@ -28,7 +26,7 @@ class TrackSelectDialog(QDialog):
def __init__(
self,
session: scoped_session,
session: Session,
new_row_number: int,
source_model: PlaylistModel,
add_to_header: Optional[bool] = False,

View File

@ -48,7 +48,7 @@ from PyQt6.QtWidgets import (
# Third party imports
from pygame import mixer
import pipeclient
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm.session import Session
import stackprinter # type: ignore
# App imports
@ -562,7 +562,7 @@ class Window(QMainWindow, Ui_MainWindow):
self.timer1000.timeout.connect(self.tick_1000ms)
def create_playlist(
self, session: scoped_session, playlist_name: Optional[str] = None
self, session: Session, playlist_name: Optional[str] = None
) -> Optional[Playlists]:
"""Create new playlist"""
@ -1405,7 +1405,7 @@ class Window(QMainWindow, Ui_MainWindow):
self.tabPlaylist.currentWidget().scroll_to_top(display_row)
def solicit_playlist_name(
self, session: scoped_session, default: str = ""
self, session: Session, default: str = ""
) -> Optional[str]:
"""Get name of new playlist from user"""
@ -1508,7 +1508,7 @@ class Window(QMainWindow, Ui_MainWindow):
# Update volume fade curve
if (
track_sequence.now.fade_graph_start_updates is None
or track_sequence.now.fade_graph_start_updates > datetime.now()
or track_sequence.now.fade_graph_start_updates > dt.datetime.now()
):
return
@ -1640,7 +1640,7 @@ class CartDialog(QDialog):
"""Edit cart details"""
def __init__(
self, musicmuster: Window, session: scoped_session, cart: Carts, *args, **kwargs
self, musicmuster: Window, session: Session, cart: Carts, *args, **kwargs
) -> None:
"""
Manage carts

View File

@ -160,7 +160,7 @@ class PipeClient:
def _write_pipe_open(self) -> None:
"""Open _write_pipe."""
self._write_pipe = open(WRITE_NAME, 'w')
self._write_pipe = open(WRITE_NAME, "w")
def _read_thread_start(self) -> None:
"""Start read_pipe thread."""
@ -204,8 +204,8 @@ class PipeClient:
"""Read FIFO in worker thread."""
# Thread will wait at this read until it connects.
# Connection should occur as soon as _write_pipe has connected.
with open(READ_NAME, 'r') as read_pipe:
message = ''
with open(READ_NAME, "r") as read_pipe:
message = ""
pipe_ok = True
while pipe_ok:
line = read_pipe.readline()

View File

@ -1569,7 +1569,7 @@ class PlaylistProxyModel(QSortFilterProxyModel):
self,
proposed_row_number: Optional[int],
track_id: Optional[int] = None,
note: Optional[str] = None,
note: str = "",
) -> None:
return self.source_model.insert_row(proposed_row_number, track_id, note)

View File

@ -79,12 +79,13 @@ class TestMMMiscTracks(unittest.TestCase):
self.model.insert_row(proposed_row_number=END_ROW, note="-")
prd = self.model.playlist_rows[START_ROW]
qv_value = self.model.display_role(START_ROW, playlistmodel.HEADER_NOTES_COLUMN, prd)
qv_value = self.model.display_role(
START_ROW, playlistmodel.HEADER_NOTES_COLUMN, prd
)
assert qv_value.value() == "start [1 tracks, 4:23 unplayed]"
class TestMMMiscNoPlaylist(unittest.TestCase):
PLAYLIST_NAME = "tracks playlist"
test_tracks = [
"testdata/isa.mp3",
@ -121,10 +122,13 @@ class TestMMMiscNoPlaylist(unittest.TestCase):
_ = str(prd)
assert (
model.edit_role(model.rowCount() - 1, playlistmodel.Col.TITLE.value, prd)
model.edit_role(
model.rowCount() - 1, playlistmodel.Col.TITLE.value, prd
)
== metadata["title"]
)
class TestMMMiscRowMove(unittest.TestCase):
PLAYLIST_NAME = "rowmove playlist"
ROWS_TO_CREATE = 11
@ -292,7 +296,6 @@ class TestMMMiscRowMove(unittest.TestCase):
self.model.add_track_to_header(insert_row, prd.track_id)
def test_reverse_row_groups_one_row(self):
rows_to_move = [3]
result = self.model._reversed_contiguous_row_groups(rows_to_move)
@ -301,7 +304,6 @@ class TestMMMiscRowMove(unittest.TestCase):
assert result[0] == [3]
def test_reverse_row_groups_multiple_row(self):
rows_to_move = [2, 3, 4, 5, 7, 9, 10, 13, 17, 20, 21]
result = self.model._reversed_contiguous_row_groups(rows_to_move)
@ -357,7 +359,6 @@ class TestMMMiscRowMove(unittest.TestCase):
assert [int(a) for a in row_notes] == [0, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def test_move_multiple_rows_between_playlists_to_end(self):
from_rows = [1, 3, 4]
to_row = 2
destination_playlist = "destination"
@ -382,7 +383,22 @@ class TestMMMiscRowMove(unittest.TestCase):
assert len(model_src.playlist_rows) == self.ROWS_TO_CREATE - len(from_rows)
assert len(model_dst.playlist_rows) == self.ROWS_TO_CREATE + len(from_rows)
assert [int(a) for a in row_notes] == [0, 1, 3, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
assert [int(a) for a in row_notes] == [
0,
1,
3,
4,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
]
# # def test_edit_header(monkeypatch, session): # edit header row in middle of playlist

View File

@ -41,13 +41,14 @@ def qtbot_adapter(qapp, request):
# Wrapper to handle setup/teardown operations
def with_updown(function):
def test_wrapper(self, *args, **kwargs):
if callable(getattr(self, 'up', None)):
if callable(getattr(self, "up", None)):
self.up()
try:
function(self, *args, **kwargs)
finally:
if callable(getattr(self, 'down', None)):
if callable(getattr(self, "down", None)):
self.down()
test_wrapper.__doc__ = function.__doc__
return test_wrapper
@ -103,12 +104,11 @@ class MyTestCase(unittest.TestCase):
# },
# ]
# for track in tracks:
# db_track = models.Tracks(session=session, **track)
# session.add(db_track)
# session.commit()
# for track in tracks:
# db_track = models.Tracks(session=session, **track)
# session.add(db_track)
# session.commit()
# def test_save_and_restore(qtbot, session):