Session sanity

This commit is contained in:
Keith Edmunds 2022-03-04 22:59:01 +00:00
parent 2186b3eb09
commit a882d409cb
2 changed files with 51 additions and 63 deletions

View File

@ -186,7 +186,8 @@ class Window(QMainWindow, Ui_MainWindow):
self.btnDatabase.clicked.connect(self.search_database)
self.btnFade.clicked.connect(self.fade)
self.btnPlay.clicked.connect(self.play_next)
self.btnSetNext.clicked.connect(self.this_is_the_next_track)
self.btnSetNext.clicked.connect(
lambda: self.tabPlaylist.currentWidget().set_selected_as_next())
self.btnSongInfo.clicked.connect(self.song_info_search)
self.btnStop.clicked.connect(self.stop)
self.spnVolume.valueChanged.connect(self.change_volume)
@ -356,19 +357,6 @@ class Window(QMainWindow, Ui_MainWindow):
self.stop_playing(fade=True)
def insert_note(self):
"Add non-track row to playlist"
dlg = QInputDialog(self)
dlg.setInputMode(QInputDialog.TextInput)
dlg.setLabelText("Note:")
dlg.resize(500, 100)
ok = dlg.exec()
if ok:
with Session() as session:
note = self.create_note(session, dlg.textValue())
self.visible_playlist_tab()._insert_note(session, note)
def load_last_playlists(self):
"""Load the playlists that we loaded at end of last session"""
@ -398,7 +386,8 @@ class Window(QMainWindow, Ui_MainWindow):
playlists = [p for p in Playlists.get_all(session)
if p.id != visible_tab_id]
dlg = SelectPlaylistDialog(self, playlists=playlists)
dlg = SelectPlaylistDialog(self, playlists=playlists,
session=session)
dlg.exec()
if not dlg.plid:
return
@ -573,7 +562,8 @@ class Window(QMainWindow, Ui_MainWindow):
with Session() as session:
playlists = Playlists.get_closed(session)
dlg = SelectPlaylistDialog(self, playlists=playlists)
dlg = SelectPlaylistDialog(self, playlists=playlists,
session=session)
dlg.exec()
if dlg.plid:
p = Playlists.get_by_id(session=session, playlist_id=dlg.plid)
@ -675,7 +665,7 @@ class Window(QMainWindow, Ui_MainWindow):
self.end_of_track_actions()
def this_is_the_next_track(self, playlist_tab: PlaylistTab,
track: Tracks) -> None:
track: Tracks, session) -> None:
"""
This is notification from a playlist tab that it holds the next
track to be played.
@ -691,39 +681,38 @@ class Window(QMainWindow, Ui_MainWindow):
"""
with Session() as session:
# Clear next track if on another tab
if self.next_track_playlist_tab != playlist_tab:
# We need to reset the ex-next-track playlist
if self.next_track_playlist_tab:
self.next_track_playlist_tab.clear_next(session)
# Clear next track if on another tab
if self.next_track_playlist_tab != playlist_tab:
# We need to reset the ex-next-track playlist
if self.next_track_playlist_tab:
self.next_track_playlist_tab.clear_next(session)
# Reset tab colour if on other tab
if (self.next_track_playlist_tab !=
self.current_track_playlist_tab):
self.set_tab_colour(
self.next_track_playlist_tab,
QColor(Config.COLOUR_NORMAL_TAB))
# Reset tab colour if on other tab
if (self.next_track_playlist_tab !=
self.current_track_playlist_tab):
self.set_tab_colour(
self.next_track_playlist_tab,
QColor(Config.COLOUR_NORMAL_TAB))
# Note next playlist tab
self.next_track_playlist_tab = playlist_tab
# Note next playlist tab
self.next_track_playlist_tab = playlist_tab
# Set next playlist_tab tab colour if it isn't the
# currently-playing tab
if (self.next_track_playlist_tab !=
self.current_track_playlist_tab):
self.set_tab_colour(
self.next_track_playlist_tab,
QColor(Config.COLOUR_NEXT_TAB))
# Set next playlist_tab tab colour if it isn't the
# currently-playing tab
if (self.next_track_playlist_tab !=
self.current_track_playlist_tab):
self.set_tab_colour(
self.next_track_playlist_tab,
QColor(Config.COLOUR_NEXT_TAB))
# Note next track
self.next_track = track
# Note next track
self.next_track = track
# Update headers
self.update_headers()
# Update headers
self.update_headers()
# Populate 'info' tabs
self.open_info_tabs()
# Populate 'info' tabs
self.open_info_tabs()
def tick(self) -> None:
"""
@ -935,7 +924,7 @@ class DbDialog(QDialog):
class SelectPlaylistDialog(QDialog):
def __init__(self, parent=None, playlists=None): # review
def __init__(self, parent=None, playlists=None, session=None):
super().__init__(parent)
if playlists is None:
@ -945,16 +934,16 @@ class SelectPlaylistDialog(QDialog):
self.ui.lstPlaylists.itemDoubleClicked.connect(self.list_doubleclick)
self.ui.buttonBox.accepted.connect(self.open)
self.ui.buttonBox.rejected.connect(self.close)
self.session = session
self.plid = None
with Session() as session:
record = Settings.get_int_settings(
session, "select_playlist_dialog_width")
width = record.f_int or 800
record = Settings.get_int_settings(
session, "select_playlist_dialog_height")
height = record.f_int or 600
self.resize(width, height)
record = Settings.get_int_settings(
self.session, "select_playlist_dialog_width")
width = record.f_int or 800
record = Settings.get_int_settings(
self.session, "select_playlist_dialog_height")
height = record.f_int or 600
self.resize(width, height)
for (plid, plname) in [(a.id, a.name) for a in playlists]:
p = QListWidgetItem()
@ -963,16 +952,15 @@ class SelectPlaylistDialog(QDialog):
self.ui.lstPlaylists.addItem(p)
def __del__(self): # review
with Session() as session:
record = Settings.get_int_settings(
session, "select_playlist_dialog_height")
if record.f_int != self.height():
record.update(session, {'f_int': self.height()})
record = Settings.get_int_settings(
self.session, "select_playlist_dialog_height")
if record.f_int != self.height():
record.update(self.session, {'f_int': self.height()})
record = Settings.get_int_settings(
session, "select_playlist_dialog_width")
if record.f_int != self.width():
record.update(session, {'f_int': self.width()})
record = Settings.get_int_settings(
self.session, "select_playlist_dialog_width")
if record.f_int != self.width():
record.update(self.session, {'f_int': self.width()})
def list_doubleclick(self, entry): # review
self.plid = entry.data(Qt.UserRole)

View File

@ -1442,7 +1442,7 @@ class PlaylistTab(QTableWidget):
self.update_display(session)
# Notify musicmuster
self.musicmuster.this_is_the_next_track(self, track)
self.musicmuster.this_is_the_next_track(self, track, session)
def _set_row_bold(self, row: int, bold: bool = True) -> None:
"""Make row bold (bold=True) or not bold"""