|
|
|
|
@ -10,6 +10,7 @@ from PyQt6.QtCore import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
from PyQt6.QtGui import (
|
|
|
|
|
QBrush,
|
|
|
|
|
QColor,
|
|
|
|
|
QFont,
|
|
|
|
|
)
|
|
|
|
|
@ -40,7 +41,6 @@ class Col(Enum):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PlaylistRowData:
|
|
|
|
|
|
|
|
|
|
def __init__(self, plr: PlaylistRows) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Populate PlaylistRowData from database PlaylistRows record
|
|
|
|
|
@ -91,20 +91,18 @@ class PlaylistModel(QAbstractTableModel):
|
|
|
|
|
self.refresh_data()
|
|
|
|
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
|
|
|
return (
|
|
|
|
|
f"<PlaylistModel: playlist_id={self.playlist_id}>"
|
|
|
|
|
)
|
|
|
|
|
return f"<PlaylistModel: playlist_id={self.playlist_id}>"
|
|
|
|
|
|
|
|
|
|
def columnCount(self, parent: QModelIndex) -> int:
|
|
|
|
|
def columnCount(self, parent: QModelIndex = QModelIndex()) -> int:
|
|
|
|
|
"""Standard function for view"""
|
|
|
|
|
|
|
|
|
|
return 9
|
|
|
|
|
|
|
|
|
|
def data(self, index: QModelIndex, role: Qt.ItemDataRole.DisplayRole):
|
|
|
|
|
# def data(self, index: QModelIndex, role: Qt.ItemDataRole.DisplayRole):
|
|
|
|
|
def data(self, index: QModelIndex, role: int = Qt.ItemDataRole.DisplayRole):
|
|
|
|
|
"""Return data to view"""
|
|
|
|
|
|
|
|
|
|
if not index.isValid() or not (
|
|
|
|
|
0 <= index.row() < len(self.playlist_rows)):
|
|
|
|
|
if not index.isValid() or not (0 <= index.row() < len(self.playlist_rows)):
|
|
|
|
|
return QVariant()
|
|
|
|
|
|
|
|
|
|
row = index.row()
|
|
|
|
|
@ -132,7 +130,7 @@ class PlaylistModel(QAbstractTableModel):
|
|
|
|
|
elif role == Qt.ItemDataRole.TextAlignmentRole:
|
|
|
|
|
pass
|
|
|
|
|
elif role == Qt.ItemDataRole.BackgroundRole:
|
|
|
|
|
pass
|
|
|
|
|
return self.background_role(row, column, prd)
|
|
|
|
|
elif role == Qt.ItemDataRole.ForegroundRole:
|
|
|
|
|
pass
|
|
|
|
|
elif role == Qt.ItemDataRole.CheckStateRole:
|
|
|
|
|
@ -169,43 +167,49 @@ class PlaylistModel(QAbstractTableModel):
|
|
|
|
|
|
|
|
|
|
return QVariant()
|
|
|
|
|
|
|
|
|
|
def background_role(self, row: int, column: int, prd: PlaylistRowData) -> QBrush:
|
|
|
|
|
""" Return background setting """
|
|
|
|
|
|
|
|
|
|
if role == Qt.ItemDataRole.BackgroundRole:
|
|
|
|
|
if rowdata.path and file_is_unreadable(rowdata.path):
|
|
|
|
|
return QVariant(QColor(Config.COLOUR_UNREADABLE))
|
|
|
|
|
elif row == self.current_row:
|
|
|
|
|
return QVariant(QColor(Config.COLOUR_CURRENT_PLAYLIST))
|
|
|
|
|
elif row == self.next_row:
|
|
|
|
|
return QVariant(QColor(Config.COLOUR_NEXT_PLAYLIST))
|
|
|
|
|
elif column == BITRATE:
|
|
|
|
|
if rowdata.bitrate:
|
|
|
|
|
if rowdata.bitrate < Config.BITRATE_LOW_THRESHOLD:
|
|
|
|
|
cell_colour = Config.COLOUR_BITRATE_LOW
|
|
|
|
|
elif rowdata.bitrate < Config.BITRATE_OK_THRESHOLD:
|
|
|
|
|
cell_colour = Config.COLOUR_BITRATE_MEDIUM
|
|
|
|
|
else:
|
|
|
|
|
cell_colour = Config.COLOUR_BITRATE_OK
|
|
|
|
|
return QVariant(QColor(cell_colour))
|
|
|
|
|
if column == Col.START_GAP.value:
|
|
|
|
|
if prd.start_gap and prd.start_gap >= Config.START_GAP_WARNING_THRESHOLD:
|
|
|
|
|
return QBrush(QColor(Config.COLOUR_LONG_START))
|
|
|
|
|
if column == Col.BITRATE.value:
|
|
|
|
|
if prd.bitrate < Config.BITRATE_LOW_THRESHOLD:
|
|
|
|
|
return QBrush(QColor(Config.COLOUR_BITRATE_LOW))
|
|
|
|
|
elif prd.bitrate and prd.bitrate < Config.BITRATE_OK_THRESHOLD:
|
|
|
|
|
return QBrush(QColor(Config.COLOUR_BITRATE_MEDIUM))
|
|
|
|
|
else:
|
|
|
|
|
return QBrush(QColor(Config.COLOUR_BITRATE_OK))
|
|
|
|
|
|
|
|
|
|
# Return a QColor, QIcon or QPixmap. QColor puts a coloured
|
|
|
|
|
# block to left of text
|
|
|
|
|
return QBrush()
|
|
|
|
|
|
|
|
|
|
return QVariant()
|
|
|
|
|
# if rowdata.path and file_is_unreadable(rowdata.path):
|
|
|
|
|
# return QVariant(QColor(Config.COLOUR_UNREADABLE))
|
|
|
|
|
# elif row == self.current_row:
|
|
|
|
|
# return QVariant(QColor(Config.COLOUR_CURRENT_PLAYLIST))
|
|
|
|
|
# elif row == self.next_row:
|
|
|
|
|
# return QVariant(QColor(Config.COLOUR_NEXT_PLAYLIST))
|
|
|
|
|
# elif column == BITRATE:
|
|
|
|
|
# if rowdata.bitrate:
|
|
|
|
|
# if rowdata.bitrate < Config.BITRATE_LOW_THRESHOLD:
|
|
|
|
|
# cell_colour = Config.COLOUR_BITRATE_LOW
|
|
|
|
|
# elif rowdata.bitrate < Config.BITRATE_OK_THRESHOLD:
|
|
|
|
|
# cell_colour = Config.COLOUR_BITRATE_MEDIUM
|
|
|
|
|
# else:
|
|
|
|
|
# cell_colour = Config.COLOUR_BITRATE_OK
|
|
|
|
|
# return QVariant(QColor(cell_colour))
|
|
|
|
|
|
|
|
|
|
# Text colour, not currently used
|
|
|
|
|
return QVariant()
|
|
|
|
|
|
|
|
|
|
if not rowdata.played:
|
|
|
|
|
font = QFont()
|
|
|
|
|
font.setBold(True)
|
|
|
|
|
return QVariant(font)
|
|
|
|
|
# if not rowdata.played:
|
|
|
|
|
# font = QFont()
|
|
|
|
|
# font.setBold(True)
|
|
|
|
|
# return QVariant(font)
|
|
|
|
|
|
|
|
|
|
return QVariant()
|
|
|
|
|
# return QVariant()
|
|
|
|
|
|
|
|
|
|
def refresh_data(self):
|
|
|
|
|
"""Populate dicts for data calls"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Populate self.playlist_rows with playlist data
|
|
|
|
|
with Session() as session:
|
|
|
|
|
for p in PlaylistRows.deep_rows(session, self.playlist_id):
|
|
|
|
|
|