Compare commits

..

No commits in common. "ed4a106bec618cd692dfa576a79056de7d79bc4c" and "046b6898823fda4dea280066bf9c5d5b9197f8a2" have entirely different histories.

3 changed files with 20 additions and 45 deletions

View File

@ -59,13 +59,12 @@ def fade_point(
return int(trim_ms)
def file_is_readable(path: Optional[str]) -> bool:
def file_is_readable(path: str) -> bool:
"""
Returns True if passed path is readable, else False
"""
if not path:
return False
vlc cannot read files with a colon in the path
"""
return os.access(path, os.R_OK)

View File

@ -1092,16 +1092,6 @@ class Window(QMainWindow, Ui_MainWindow):
# Disable play next controls
self.disable_play_next_controls()
# If previous track playlist is showing and that's not the
# current track playlist, we need to update the display to
# reset the current track highlighting
if (
self.previous_track.playlist_tab == self.visible_playlist_tab()
and
self.current_track.playlist_tab != self.visible_playlist_tab()
):
self.visible_playlist_tab().update_display(session)
# Update headers
self.update_headers()

View File

@ -38,7 +38,7 @@ from PyQt5.QtWidgets import (
)
from config import Config
from dbconfig import Session, scoped_session
from dbconfig import Session
from helpers import (
ask_yes_no,
file_is_readable,
@ -126,7 +126,7 @@ class PlaylistTab(QTableWidget):
ROW_DURATION = Qt.UserRole + 2
PLAYLISTROW_ID = Qt.UserRole + 3
def __init__(self, musicmuster: QMainWindow, session: scoped_session,
def __init__(self, musicmuster: QMainWindow, session: Session,
playlist_id: int, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.musicmuster = musicmuster
@ -554,7 +554,7 @@ class PlaylistTab(QTableWidget):
return [self._get_playlistrow_id(a) for a in self._get_selected_rows()]
def get_selected_playlistrows(self, session: scoped_session) -> Optional[List]:
def get_selected_playlistrows(self, session: Session) -> Optional[List]:
"""
Return a list of PlaylistRows of the selected rows
"""
@ -562,7 +562,7 @@ class PlaylistTab(QTableWidget):
plr_ids = self.get_selected_playlistrow_ids()
return [session.get(PlaylistRows, a) for a in plr_ids]
def insert_header(self, session: scoped_session, note: str,
def insert_header(self, session: Session, note: str,
repaint: bool = True) -> None:
"""
Insert section header into playlist tab.
@ -579,7 +579,7 @@ class PlaylistTab(QTableWidget):
self.insert_row(session, plr, repaint)
self.save_playlist(session)
def insert_row(self, session: scoped_session, plr: PlaylistRows,
def insert_row(self, session: Session, plr: PlaylistRows,
repaint: bool = True) -> None:
"""
Insert passed playlist row (plr) into playlist tab.
@ -668,7 +668,7 @@ class PlaylistTab(QTableWidget):
if repaint:
self.update_display(session)
def insert_track(self, session: scoped_session, track: Tracks,
def insert_track(self, session: Session, track: Tracks,
note: str = None, repaint: bool = True) -> None:
"""
Insert track into playlist tab.
@ -705,7 +705,7 @@ class PlaylistTab(QTableWidget):
# Let display update, then save playlist
QTimer.singleShot(0, lambda: self.save_playlist(session))
def play_started(self, session: scoped_session) -> None:
def play_started(self, session: Session) -> None:
"""
Notification from musicmuster that track has started playing.
@ -718,15 +718,7 @@ class PlaylistTab(QTableWidget):
- Update display
"""
current_row = self._get_current_track_row_number()
if not current_row:
return
search_from = current_row + 1
# Mark current row as played
self._set_played_row(session, current_row)
search_from = self._get_current_track_row_number() + 1
next_row = self._find_next_track_row(session, search_from)
if next_row:
self._set_next(session, next_row)
@ -734,7 +726,7 @@ class PlaylistTab(QTableWidget):
# Update display
self.update_display(session)
def populate_display(self, session: scoped_session, playlist_id: int,
def populate_display(self, session: Session, playlist_id: int,
scroll_to_top: bool = True) -> None:
"""
Populate display from the associated playlist ID
@ -748,9 +740,6 @@ class PlaylistTab(QTableWidget):
# Add the rows
playlist = session.get(Playlists, playlist_id)
if not playlist:
return
for plr in playlist.rows:
self.insert_row(session, plr, repaint=False)
@ -786,7 +775,7 @@ class PlaylistTab(QTableWidget):
# Reset drag mode
self.setDragEnabled(False)
def save_playlist(self, session: scoped_session) -> None:
def save_playlist(self, session: Session) -> None:
"""
Get the PlaylistRow objects for each row in the display. Correct
the row_number and playlist_id if necessary. Remove any row
@ -952,7 +941,7 @@ class PlaylistTab(QTableWidget):
with Session() as session:
self.update_display(session)
def update_display(self, session: scoped_session) -> None:
def update_display(self, session: Session) -> None:
"""
Set row colours, fonts, etc
@ -1274,7 +1263,7 @@ class PlaylistTab(QTableWidget):
return (index.row() + 1 if self._is_below(event.pos(), index)
else index.row())
def _find_next_track_row(self, session: scoped_session,
def _find_next_track_row(self, session: Session,
starting_row: int = None) -> Optional[int]:
"""
Find next track to play. If a starting row is given, start there;
@ -1355,7 +1344,7 @@ class PlaylistTab(QTableWidget):
return playlistrow_id
def _get_playlistrow_object(self, session: scoped_session, row: int) -> int:
def _get_playlistrow_object(self, session: Session, row: int) -> int:
"""Return the playlistrow object associated with this row"""
playlistrow_id = (self.item(row, USERDATA).data(self.PLAYLISTROW_ID))
@ -1526,7 +1515,7 @@ class PlaylistTab(QTableWidget):
)
raise AttributeError(f"Multiple '{metadata}' metadata {matches}")
def _move_row(self, session: scoped_session, plr: PlaylistRows,
def _move_row(self, session: Session, plr: PlaylistRows,
new_row_number: int) -> None:
"""Move playlist row to new_row_number using parent copy/paste"""
@ -1737,7 +1726,7 @@ class PlaylistTab(QTableWidget):
else:
self.musicmuster.lblSumPlaytime.setText("")
def _set_column_widths(self, session: scoped_session) -> None:
def _set_column_widths(self, session: Session) -> None:
"""Column widths from settings"""
for column_name, data in columns.items():
@ -1753,7 +1742,7 @@ class PlaylistTab(QTableWidget):
else:
self.setColumnWidth(idx, Config.DEFAULT_COLUMN_WIDTH)
def _set_next(self, session: scoped_session, row_number: int) -> None:
def _set_next(self, session: Session, row_number: int) -> None:
"""
Set passed row as next playlist row to play.
@ -1788,13 +1777,10 @@ class PlaylistTab(QTableWidget):
self.clear_selection()
self.update_display(session)
def _set_played_row(self, session: scoped_session, row: int) -> None:
def _set_played_row(self, session: Session, row: int) -> None:
"""Mark this row as played"""
plr = session.get(PlaylistRows, self._get_playlistrow_id(row))
if not plr:
return
plr.played = True
session.commit()