Compare commits
2 Commits
79f9a49659
...
15ec91e446
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15ec91e446 | ||
|
|
04788ef923 |
@ -5,6 +5,7 @@ from PyQt5.QtGui import QColor, QDropEvent
|
||||
from PyQt5 import QtWidgets
|
||||
from PyQt5.QtWidgets import (
|
||||
QAbstractItemView,
|
||||
QApplication,
|
||||
QMenu,
|
||||
QMessageBox,
|
||||
QTableWidget,
|
||||
@ -21,6 +22,7 @@ from log import DEBUG, ERROR
|
||||
from model import (
|
||||
Notes, Playdates, Playlists, PlaylistTracks, Session, Settings, Tracks
|
||||
)
|
||||
from songdb import create_track_from_file
|
||||
|
||||
|
||||
class PlaylistTab(QTableWidget):
|
||||
@ -154,6 +156,11 @@ class PlaylistTab(QTableWidget):
|
||||
if row not in self._meta_get_notes():
|
||||
act_setnext = self.menu.addAction("Set next")
|
||||
act_setnext.triggered.connect(lambda: self._set_next(row))
|
||||
act_copypath = self.menu.addAction("Copy track path")
|
||||
act_copypath.triggered.connect(
|
||||
lambda: self._copy_path(row))
|
||||
act_rescan = self.menu.addAction("Rescan track")
|
||||
act_rescan.triggered.connect(lambda: self._rescan(row))
|
||||
self.menu.addSeparator()
|
||||
act_delete = self.menu.addAction('Delete')
|
||||
act_delete.triggered.connect(lambda: self._delete_row(row))
|
||||
@ -545,6 +552,25 @@ class PlaylistTab(QTableWidget):
|
||||
|
||||
self.menu.exec_(self.mapToGlobal(pos))
|
||||
|
||||
def _copy_path(self, row):
|
||||
"""
|
||||
If passed row is track row, copy the track path to the clipboard.
|
||||
Otherwise return None.
|
||||
"""
|
||||
|
||||
DEBUG(f"_copy_path({row})")
|
||||
|
||||
if row in self._meta_get_notes():
|
||||
return None
|
||||
|
||||
track_id = self._get_row_id(row)
|
||||
if track_id:
|
||||
with Session() as session:
|
||||
path = Tracks.get_path(session, track_id)
|
||||
cb = QApplication.clipboard()
|
||||
cb.clear(mode=cb.Clipboard)
|
||||
cb.setText(path, mode=cb.Clipboard)
|
||||
|
||||
def _delete_row(self, row):
|
||||
"Delete row"
|
||||
|
||||
@ -931,6 +957,24 @@ class PlaylistTab(QTableWidget):
|
||||
# Don't dim unplayed tracks
|
||||
self._set_row_bold(row)
|
||||
|
||||
def _rescan(self, row):
|
||||
"""
|
||||
If passed row is track row, rescan it.
|
||||
Otherwise return None.
|
||||
"""
|
||||
|
||||
DEBUG(f"_rescan({row})")
|
||||
|
||||
if row in self._meta_get_notes():
|
||||
return None
|
||||
|
||||
track_id = self._get_row_id(row)
|
||||
if track_id:
|
||||
with Session() as session:
|
||||
track = Tracks.get_track(session, track_id)
|
||||
create_track_from_file(session, track.path)
|
||||
self._update_row(row, track)
|
||||
|
||||
def _save_playlist(self, session):
|
||||
"""
|
||||
Save playlist to database.
|
||||
@ -1076,3 +1120,28 @@ class PlaylistTab(QTableWidget):
|
||||
|
||||
with Session() as session:
|
||||
return os.access(Tracks.get_path(session, track_id), os.R_OK)
|
||||
|
||||
def _update_row(self, row, track):
|
||||
"""
|
||||
Update the passed row with info from the passed track.
|
||||
"""
|
||||
|
||||
DEBUG(f"_update_row({row=}, {track=}")
|
||||
|
||||
item_startgap = self.item(row, self.COL_MSS)
|
||||
item_startgap.setText(str(track.start_gap))
|
||||
if track.start_gap >= 500:
|
||||
item_startgap.setBackground(QColor(Config.COLOUR_LONG_START))
|
||||
else:
|
||||
item_startgap.setBackground(QColor("white"))
|
||||
|
||||
item_title = self.item(row, self.COL_TITLE)
|
||||
item_title.setText(track.title)
|
||||
|
||||
item_artist = self.item(row, self.COL_ARTIST)
|
||||
item_artist.setText(track.artist)
|
||||
|
||||
item_duration = self.item(row, self.COL_DURATION)
|
||||
item_duration.setText(helpers.ms_to_mmss(track.duration))
|
||||
|
||||
self._repaint()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user