parent
2475f817f9
commit
f898e4645b
@ -59,6 +59,7 @@ class Config(object):
|
||||
HIDE_AFTER_PLAYING_OFFSET = 5000
|
||||
INFO_TAB_TITLE_LENGTH = 15
|
||||
LAST_PLAYED_TODAY_STRING = "Today"
|
||||
LAST_PLAYED_TOOLTIP_DATE_FORMAT = "%a, %d %b %Y"
|
||||
LOG_LEVEL_STDERR = logging.INFO
|
||||
LOG_LEVEL_SYSLOG = logging.INFO
|
||||
LOG_NAME = "musicmuster"
|
||||
|
||||
@ -129,6 +129,20 @@ class Playdates(dbtables.PlaydatesTable):
|
||||
session.add(self)
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def last_playdates(session: Session, track_id: int, limit=5) -> Sequence["Playdates"]:
|
||||
"""
|
||||
Return a list of the last limit playdates for this track, sorted
|
||||
earliest to latest.
|
||||
"""
|
||||
|
||||
return session.scalars(
|
||||
Playdates.select()
|
||||
.where(Playdates.track_id == track_id)
|
||||
.order_by(Playdates.lastplayed.asc())
|
||||
.limit(limit)
|
||||
).all()
|
||||
|
||||
@staticmethod
|
||||
def last_played(session: Session, track_id: int) -> dt.datetime:
|
||||
"""Return datetime track last played or None"""
|
||||
|
||||
@ -349,10 +349,11 @@ class PlaylistModel(QAbstractTableModel):
|
||||
|
||||
# Dispatch to role-specific functions
|
||||
dispatch_table = {
|
||||
int(Qt.ItemDataRole.BackgroundRole): self.background_role,
|
||||
int(Qt.ItemDataRole.DisplayRole): self.display_role,
|
||||
int(Qt.ItemDataRole.EditRole): self.edit_role,
|
||||
int(Qt.ItemDataRole.FontRole): self.font_role,
|
||||
int(Qt.ItemDataRole.BackgroundRole): self.background_role,
|
||||
int(Qt.ItemDataRole.ToolTipRole): self.tooltip_role,
|
||||
}
|
||||
|
||||
if role in dispatch_table:
|
||||
@ -361,7 +362,6 @@ class PlaylistModel(QAbstractTableModel):
|
||||
# Document other roles but don't use them
|
||||
if role in [
|
||||
Qt.ItemDataRole.DecorationRole,
|
||||
Qt.ItemDataRole.ToolTipRole,
|
||||
Qt.ItemDataRole.StatusTipRole,
|
||||
Qt.ItemDataRole.WhatsThisRole,
|
||||
Qt.ItemDataRole.SizeHintRole,
|
||||
@ -860,7 +860,9 @@ class PlaylistModel(QAbstractTableModel):
|
||||
# number of rows being move from above the destination row
|
||||
# otherwise rows below the destination row will end up above the
|
||||
# moved rows.
|
||||
adjusted_to_row = to_row_number - len([a for a in from_rows if a <= to_row_number])
|
||||
adjusted_to_row = to_row_number - len(
|
||||
[a for a in from_rows if a <= to_row_number]
|
||||
)
|
||||
|
||||
# Put the from_row row numbers into the row_map. Ultimately the
|
||||
# total number of elements in the playlist doesn't change, so
|
||||
@ -1377,6 +1379,27 @@ class PlaylistModel(QAbstractTableModel):
|
||||
def supportedDropActions(self) -> Qt.DropAction:
|
||||
return Qt.DropAction.MoveAction | Qt.DropAction.CopyAction
|
||||
|
||||
def tooltip_role(self, row: int, column: int, prd: PlaylistRowData) -> QVariant:
|
||||
"""
|
||||
Return tooltip. Currently only used for last_played column.
|
||||
"""
|
||||
|
||||
if column != Col.LAST_PLAYED.value:
|
||||
return QVariant()
|
||||
with db.Session() as session:
|
||||
track_id = self.playlist_rows[row].track_id
|
||||
if not track_id:
|
||||
return QVariant()
|
||||
playdates = Playdates.last_playdates(session, track_id)
|
||||
return QVariant(
|
||||
"<br>".join(
|
||||
[
|
||||
a.lastplayed.strftime(Config.LAST_PLAYED_TOOLTIP_DATE_FORMAT)
|
||||
for a in playdates
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
def update_track_times(self) -> None:
|
||||
"""
|
||||
Update track start/end times in self.playlist_rows
|
||||
|
||||
Loading…
Reference in New Issue
Block a user