Tab info for previous / current / next track

This commit is contained in:
Keith Edmunds 2021-08-21 20:47:55 +01:00
parent 8fa85dd47f
commit 834ad68e00
2 changed files with 55 additions and 8 deletions

View File

@ -22,6 +22,7 @@ class Config(object):
ERRORS_TO = ['kae@midnighthax.com'] ERRORS_TO = ['kae@midnighthax.com']
FADE_STEPS = 20 FADE_STEPS = 20
FADE_TIME = 3000 FADE_TIME = 3000
INFO_TAB_TITLE_LENGTH = 15
LOG_LEVEL_STDERR = logging.INFO LOG_LEVEL_STDERR = logging.INFO
LOG_LEVEL_SYSLOG = logging.DEBUG LOG_LEVEL_SYSLOG = logging.DEBUG
LOG_NAME = "musicmuster" LOG_NAME = "musicmuster"
@ -30,6 +31,7 @@ class Config(object):
MAIL_SERVER = os.environ.get('MAIL_SERVER') or "woodlands.midnighthax.com" MAIL_SERVER = os.environ.get('MAIL_SERVER') or "woodlands.midnighthax.com"
MAIL_USERNAME = os.environ.get('MAIL_USERNAME') MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') is not None MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') is not None
MAX_INFO_TABS = 3
MILLISECOND_SIGFIGS = 0 MILLISECOND_SIGFIGS = 0
MYSQL_CONNECT = os.environ.get('MYSQL_CONNECT') or "mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_dev" # noqa E501 MYSQL_CONNECT = os.environ.get('MYSQL_CONNECT') or "mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_dev" # noqa E501
NORMALISE_ON_IMPORT = True NORMALISE_ON_IMPORT = True

View File

@ -9,8 +9,9 @@ import urllib.parse
from datetime import datetime, timedelta from datetime import datetime, timedelta
from log import DEBUG, EXCEPTION from log import DEBUG, EXCEPTION
from PyQt5.QtCore import Qt, QTimer from PyQt5.QtCore import Qt, QTimer, QUrl
from PyQt5.QtGui import QFontMetrics, QPainter from PyQt5.QtGui import QFontMetrics, QPainter
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QApplication, QApplication,
QDialog, QDialog,
@ -63,6 +64,7 @@ class Window(QMainWindow, Ui_MainWindow):
self.music = music.Music() self.music = music.Music()
self.current_track = None self.current_track = None
self.current_track_playlist_tab = None self.current_track_playlist_tab = None
self.info_tabs = {}
self.next_track = None self.next_track = None
self.next_track_playlist_tab = None self.next_track_playlist_tab = None
self.previous_track = None self.previous_track = None
@ -263,6 +265,42 @@ class Window(QMainWindow, Ui_MainWindow):
# Enable controls # Enable controls
self.enable_play_next_controls() self.enable_play_next_controls()
def ensure_info_tabs(self, title_list):
"""
Ensure we have info tabs for each of the passed titles
"""
for title in title_list:
if title in self.info_tabs.keys():
# We already have a tab for this track
continue
# import ipdb; ipdb.set_trace()
if len(self.info_tabs) >= Config.MAX_INFO_TABS:
# Find an unneeded info tab
try:
old_title = list(
set(self.info_tabs.keys()) - set(title_list)
)[0]
except IndexError:
DEBUG(
f"ensure_info_tabs({title_list}): unable to add "
f"{title=}"
)
return
# Assign redundant widget a new title
widget = self.info_tabs[title] = self.info_tabs[old_title]
idx = self.tabPlaylist.indexOf(widget)
self.tabPlaylist.setTabText(
idx, title[:Config.INFO_TAB_TITLE_LENGTH])
del self.info_tabs[old_title]
else:
widget = self.info_tabs[title] = QWebView()
self.tabPlaylist.addTab(
widget, title[:Config.INFO_TAB_TITLE_LENGTH])
str = urllib.parse.quote_plus(title)
url = f"https://www.wikipedia.org/w/index.php?search={str}"
widget.setUrl(QUrl(url))
def export_playlist_tab(self): def export_playlist_tab(self):
"Export the current playlist to an m3u file" "Export the current playlist to an m3u file"
@ -667,32 +705,39 @@ class Window(QMainWindow, Ui_MainWindow):
self.stop_playing() self.stop_playing()
def update_headers(self): def update_headers(self):
"Update last / current / next track headers" """
Update last / current / next track headers.
Ensure a Wikipedia tab for each title.
"""
titles = []
try: try:
self.hdrPreviousTrack.setText( self.hdrPreviousTrack.setText(
f"{self.previous_track.title} - " f"{self.previous_track.title} - {self.previous_track.artist}"
f"{self.previous_track.artist}"
) )
titles.append(self.previous_track.title)
except AttributeError: except AttributeError:
self.hdrPreviousTrack.setText("") self.hdrPreviousTrack.setText("")
try: try:
self.hdrCurrentTrack.setText( self.hdrCurrentTrack.setText(
f"{self.current_track.title} - " f"{self.current_track.title} - {self.current_track.artist}"
f"{self.current_track.artist}"
) )
titles.append(self.current_track.title)
except AttributeError: except AttributeError:
self.hdrCurrentTrack.setText("") self.hdrCurrentTrack.setText("")
try: try:
self.hdrNextTrack.setText( self.hdrNextTrack.setText(
f"{self.next_track.title} - " f"{self.next_track.title} - {self.next_track.artist}"
f"{self.next_track.artist}"
) )
titles.append(self.next_track.title)
except AttributeError: except AttributeError:
self.hdrNextTrack.setText("") self.hdrNextTrack.setText("")
self.ensure_info_tabs(titles)
class DbDialog(QDialog): class DbDialog(QDialog):
def __init__(self, parent, session): def __init__(self, parent, session):