WIP: manage templates: template rows have different background

This commit is contained in:
Keith Edmunds 2025-02-22 19:42:48 +00:00
parent 5f396a0993
commit c1448dfdd5
3 changed files with 17 additions and 7 deletions

View File

@ -31,6 +31,7 @@ class Config(object):
COLOUR_NORMAL_TAB = "#000000"
COLOUR_NOTES_PLAYLIST = "#b8daff"
COLOUR_ODD_PLAYLIST = "#f2f2f2"
COLOUR_TEMPLATE_ROW = "#FFAF68"
COLOUR_UNREADABLE = "#dc3545"
COLOUR_WARNING_TIMER = "#ffc107"
DBFS_SILENCE = -50

View File

@ -870,7 +870,9 @@ class Window(QMainWindow):
self.signals.search_songfacts_signal.connect(self.open_songfacts_browser)
self.signals.search_wikipedia_signal.connect(self.open_wikipedia_browser)
def create_playlist(self, session: Session, template_id: int) -> Optional[Playlists]:
def create_playlist(
self, session: Session, template_id: int
) -> Optional[Playlists]:
"""Create new playlist"""
# Get a name for this new playlist
@ -894,7 +896,7 @@ class Window(QMainWindow):
return None
def create_playlist_tab(self, playlist: Playlists) -> int:
def create_playlist_tab(self, playlist: Playlists, is_template: bool = False) -> int:
"""
Take the passed playlist, create a playlist tab and
add tab to display. Return index number of tab.
@ -903,7 +905,7 @@ class Window(QMainWindow):
log.debug(f"create_playlist_tab({playlist=})")
# Create model and proxy model
base_model = PlaylistModel(playlist.id)
base_model = PlaylistModel(playlist.id, is_template)
proxy_model = PlaylistProxyModel()
proxy_model.setSourceModel(base_model)
@ -1238,7 +1240,7 @@ class Window(QMainWindow):
)
# Simply load the template as a playlist. Any changes
# made will persist
idx = self.create_playlist_tab(template)
idx = self.create_playlist_tab(template, is_template=True)
self.playlist_section.tabPlaylist.setCurrentIndex(idx)
def favourite(template_id: int, favourite: bool) -> None:
@ -1259,7 +1261,7 @@ class Window(QMainWindow):
new_template = self.create_playlist(session, template_id)
if new_template:
self.open_playlist(session, new_template)
self.open_playlist(session, new_template, is_template=True)
def rename(template_id: int) -> Optional[str]:
"""rename template"""
@ -1419,10 +1421,12 @@ class Window(QMainWindow):
if playlist:
self.open_playlist(session, playlist)
def open_playlist(self, session: Session, playlist: Playlists) -> None:
def open_playlist(
self, session: Session, playlist: Playlists, is_template: bool = False
) -> None:
"""Open passed playlist"""
idx = self.create_playlist_tab(playlist)
idx = self.create_playlist_tab(playlist, is_template)
playlist.mark_open()
session.commit()

View File

@ -75,12 +75,14 @@ class PlaylistModel(QAbstractTableModel):
def __init__(
self,
playlist_id: int,
is_template: bool,
*args: Optional[QObject],
**kwargs: Optional[QObject],
) -> None:
log.debug("PlaylistModel.__init__()")
self.playlist_id = playlist_id
self.is_template = is_template
super().__init__(*args, **kwargs)
self.playlist_rows: dict[int, RowAndTrack] = {}
@ -224,6 +226,9 @@ class PlaylistModel(QAbstractTableModel):
if note_background:
return QBrush(QColor(note_background))
if self.is_template:
return QBrush(QColor(Config.COLOUR_TEMPLATE_ROW))
return QBrush()
def begin_reset_model(self, playlist_id: int) -> None: