WIP: V3: All headers displaying
This commit is contained in:
parent
978b83ba67
commit
5fb5e12bb8
@ -56,6 +56,15 @@ class Config(object):
|
||||
FADEOUT_DB = -10
|
||||
FADEOUT_SECONDS = 5
|
||||
FADEOUT_STEPS_PER_SECOND = 5
|
||||
HEADER_ARTIST = "Artist"
|
||||
HEADER_BITRATE = "bps"
|
||||
HEADER_DURATION = "Length"
|
||||
HEADER_END_TIME = "End"
|
||||
HEADER_LAST_PLAYED = "Last played"
|
||||
HEADER_NOTE = "Notes"
|
||||
HEADER_START_GAP = "Gap"
|
||||
HEADER_START_TIME = "Start"
|
||||
HEADER_TITLE = "Title"
|
||||
HIDE_AFTER_PLAYING_OFFSET = 5000
|
||||
INFO_TAB_TITLE_LENGTH = 15
|
||||
LAST_PLAYED_TODAY_STRING = "Today"
|
||||
|
||||
@ -12,6 +12,7 @@ from PyQt6.QtCore import (
|
||||
from PyQt6.QtGui import (
|
||||
QBrush,
|
||||
QColor,
|
||||
QFont,
|
||||
)
|
||||
|
||||
from config import Config
|
||||
@ -37,7 +38,7 @@ class Col(Enum):
|
||||
DURATION = auto()
|
||||
START_TIME = auto()
|
||||
END_TIME = auto()
|
||||
LASTPLAYED = auto()
|
||||
LAST_PLAYED = auto()
|
||||
BITRATE = auto()
|
||||
NOTE = auto()
|
||||
|
||||
@ -101,12 +102,35 @@ class PlaylistModel(QAbstractTableModel):
|
||||
def __repr__(self) -> str:
|
||||
return f"<PlaylistModel: playlist_id={self.playlist_id}>"
|
||||
|
||||
def background_role(self, row: int, column: int, prd: PlaylistRowData) -> QBrush:
|
||||
"""Return background setting"""
|
||||
|
||||
# Handle entire row colouring
|
||||
# Header row
|
||||
if not prd.path:
|
||||
return QBrush(QColor(Config.COLOUR_NOTES_PLAYLIST))
|
||||
# Unreadable track file
|
||||
if file_is_unreadable(prd.path):
|
||||
return QBrush(QColor(Config.COLOUR_UNREADABLE))
|
||||
|
||||
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 QBrush()
|
||||
|
||||
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: int = Qt.ItemDataRole.DisplayRole):
|
||||
"""Return data to view"""
|
||||
|
||||
@ -181,7 +205,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
return QVariant("FIXME")
|
||||
if column == Col.END_TIME.value:
|
||||
return QVariant("FIXME")
|
||||
if column == Col.LASTPLAYED.value:
|
||||
if column == Col.LAST_PLAYED.value:
|
||||
return QVariant(prd.lastplayed)
|
||||
if column == Col.BITRATE.value:
|
||||
return QVariant(prd.bitrate)
|
||||
@ -190,48 +214,45 @@ class PlaylistModel(QAbstractTableModel):
|
||||
|
||||
return QVariant()
|
||||
|
||||
def background_role(self, row: int, column: int, prd: PlaylistRowData) -> QBrush:
|
||||
"""Return background setting"""
|
||||
def headerData(
|
||||
self,
|
||||
section: int,
|
||||
orientation: Qt.Orientation,
|
||||
role: int = Qt.ItemDataRole.DisplayRole,
|
||||
) -> QVariant:
|
||||
"""
|
||||
Return text for headers
|
||||
"""
|
||||
|
||||
# Handle entire row colouring
|
||||
if file_is_unreadable(prd.path):
|
||||
return QBrush(QColor(Config.COLOUR_UNREADABLE))
|
||||
|
||||
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))
|
||||
if role == Qt.ItemDataRole.DisplayRole:
|
||||
if orientation == Qt.Orientation.Horizontal:
|
||||
if section == Col.START_GAP.value:
|
||||
return QVariant(Config.HEADER_START_GAP)
|
||||
elif section == Col.TITLE.value:
|
||||
return QVariant(Config.HEADER_TITLE)
|
||||
elif section == Col.ARTIST.value:
|
||||
return QVariant(Config.HEADER_ARTIST)
|
||||
elif section == Col.DURATION.value:
|
||||
return QVariant(Config.HEADER_DURATION)
|
||||
elif section == Col.START_TIME.value:
|
||||
return QVariant(Config.HEADER_START_TIME)
|
||||
elif section == Col.END_TIME.value:
|
||||
return QVariant(Config.HEADER_END_TIME)
|
||||
elif section == Col.LAST_PLAYED.value:
|
||||
return QVariant(Config.HEADER_LAST_PLAYED)
|
||||
elif section == Col.BITRATE.value:
|
||||
return QVariant(Config.HEADER_BITRATE)
|
||||
elif section == Col.NOTE.value:
|
||||
return QVariant(Config.HEADER_NOTE)
|
||||
else:
|
||||
return QBrush(QColor(Config.COLOUR_BITRATE_OK))
|
||||
return QVariant(str(section + 1))
|
||||
|
||||
return QBrush()
|
||||
elif role == Qt.ItemDataRole.FontRole:
|
||||
boldfont = QFont()
|
||||
boldfont.setBold(True)
|
||||
return QVariant(boldfont)
|
||||
|
||||
# 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 not rowdata.played:
|
||||
# font = QFont()
|
||||
# font.setBold(True)
|
||||
# return QVariant(font)
|
||||
|
||||
# return QVariant()
|
||||
return QVariant()
|
||||
|
||||
def refresh_data(self):
|
||||
"""Populate dicts for data calls"""
|
||||
@ -241,7 +262,7 @@ class PlaylistModel(QAbstractTableModel):
|
||||
for p in PlaylistRows.deep_rows(session, self.playlist_id):
|
||||
self.playlist_rows[p.plr_rownum] = PlaylistRowData(p)
|
||||
|
||||
def rowCount(self, index: QModelIndex) -> int:
|
||||
def rowCount(self, index: QModelIndex = QModelIndex()) -> int:
|
||||
"""Standard function for view"""
|
||||
|
||||
return len(self.playlist_rows)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user