diff --git a/app/musicmuster.py b/app/musicmuster.py index f72c582..747e1cd 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -14,7 +14,7 @@ import sys # # from PyQt5.QtCore import QDate, QEvent, QProcess, Qt, QTime, QTimer, QUrl from PyQt5.QtCore import Qt -# from PyQt5.QtGui import QColor +from PyQt5.QtGui import QColor # from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView from PyQt5.QtWidgets import ( QApplication, @@ -42,7 +42,7 @@ from models import ( Tracks ) from playlists import PlaylistTab -# from sqlalchemy.orm.exc import DetachedInstanceError +from sqlalchemy.orm.exc import DetachedInstanceError # from ui.dlg_search_database_ui import Ui_Dialog from ui.dlg_SelectPlaylist_ui import Ui_dlgSelectPlaylist # from ui.downloadcsv_ui import Ui_DateSelect @@ -52,18 +52,17 @@ from ui.main_window_ui import Ui_MainWindow # # # log = logging.getLogger(Config.LOG_NAME) -# class TrackData: -# def __init__(self, track): -# self.id = track.id -# self.title = track.title -# self.artist = track.artist -# self.duration = track.duration -# self.start_gap = track.start_gap -# self.fade_at = track.fade_at -# self.silence_at = track.silence_at -# self.path = track.path -# self.mtime = track.mtime -# self.lastplayed = track.lastplayed +class TrackData: + def __init__(self, track): + self.id = track.id + self.title = track.title + self.artist = track.artist + self.duration = track.duration + self.start_gap = track.start_gap + self.fade_at = track.fade_at + self.silence_at = track.silence_at + self.path = track.path + self.mtime = track.mtime class Window(QMainWindow, Ui_MainWindow): @@ -77,14 +76,14 @@ class Window(QMainWindow, Ui_MainWindow): # self.disable_play_next_controls() # # self.music: music.Music = music.Music() -# self.current_track: Optional[Tracks] = None -# self.current_track_playlist_tab: Optional[PlaylistTab] = None -# self.info_tabs: Optional[Dict[str, QWebView]] = {} -# self.next_track: Optional[Tracks] = None -# self.next_track_playlist_tab: Optional[PlaylistTab] = None -# self.previous_track: Optional[Tracks] = None -# self.previous_track_position: Optional[int] = None -# + self.current_track: Optional[TrackData] = None + self.current_track_playlist_tab: Optional[PlaylistTab] = None + self.info_tabs: Optional[Dict[str, QWebView]] = {} + self.next_track: Optional[TrackData] = None + self.next_track_playlist_tab: Optional[PlaylistTab] = None + self.previous_track: Optional[TrackData] = None + self.previous_track_position: Optional[int] = None + # self.set_main_window_size() self.lblSumPlaytime = QLabel("") self.statusbar.addPermanentWidget(self.lblSumPlaytime) @@ -118,10 +117,10 @@ class Window(QMainWindow, Ui_MainWindow): # return # # @staticmethod -# def kae(): +# def print_current_database(): # with Session() as session: # db = session.bind.engine.url.database -# print(f"kae(): {db=}") +# print(f"{db=}") # # @staticmethod # def check_audacity() -> None: @@ -757,14 +756,14 @@ class Window(QMainWindow, Ui_MainWindow): # """Select all unplayed tracks in playlist""" # # self.visible_playlist_tab().select_unplayed_tracks() -# -# def set_tab_colour(self, widget, colour) -> None: -# """ -# Find the tab containing the widget and set the text colour -# """ -# -# idx: int = self.tabPlaylist.indexOf(widget) -# self.tabPlaylist.tabBar().setTabTextColor(idx, colour) + + def set_tab_colour(self, widget: PlaylistTab, colour: QColor) -> None: + """ + Find the tab containing the widget and set the text colour + """ + + idx = self.tabPlaylist.indexOf(widget) + self.tabPlaylist.tabBar().setTabTextColor(idx, colour) # # def song_info_search(self) -> None: # """ @@ -849,9 +848,6 @@ class Window(QMainWindow, Ui_MainWindow): """ - # ***kae - return - # Clear next track if on another tab if self.next_track_playlist_tab != playlist_tab: # We need to reset the ex-next-track playlist @@ -964,36 +960,32 @@ class Window(QMainWindow, Ui_MainWindow): # else: # if self.playing: # self.stop_playing() -# -# def update_headers(self) -> None: -# """ -# Update last / current / next track headers -# -# If multiple tracks are played quickly in succession, it's possible -# for the self.{previous,current,next} track to not be in the session. -# Unlikely to happen in normal use so handle by blanking title. -# """ -# -# try: -# self.hdrPreviousTrack.setText( -# f"{self.previous_track.title} - {self.previous_track.artist}" -# ) -# except (AttributeError, DetachedInstanceError): -# self.hdrPreviousTrack.setText("") -# -# try: -# self.hdrCurrentTrack.setText( -# f"{self.current_track.title} - {self.current_track.artist}" -# ) -# except (AttributeError, DetachedInstanceError): -# self.hdrCurrentTrack.setText("") -# -# try: -# self.hdrNextTrack.setText( -# f"{self.next_track.title} - {self.next_track.artist}" -# ) -# except (AttributeError, DetachedInstanceError): -# self.hdrNextTrack.setText("") + + def update_headers(self) -> None: + """ + Update last / current / next track headers + """ + + try: + self.hdrPreviousTrack.setText( + f"{self.previous_track.title} - {self.previous_track.artist}" + ) + except (AttributeError, DetachedInstanceError): + self.hdrPreviousTrack.setText("") + + try: + self.hdrCurrentTrack.setText( + f"{self.current_track.title} - {self.current_track.artist}" + ) + except (AttributeError, DetachedInstanceError): + self.hdrCurrentTrack.setText("") + + try: + self.hdrNextTrack.setText( + f"{self.next_track.title} - {self.next_track.artist}" + ) + except (AttributeError, DetachedInstanceError): + self.hdrNextTrack.setText("") # # # class DbDialog(QDialog): diff --git a/app/playlists.py b/app/playlists.py index 688371a..e5377f5 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -701,7 +701,7 @@ class PlaylistTab(QTableWidget): # We possibly don't need to save the playlist here, but row # numbers may have changed during population, and it's cheap to do - # KAE self.save_playlist(session) + # self.save_playlist(session) self.update_display(session) def remove_selected_rows(self) -> None: