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.btnDatabase.clicked.connect(self.search_database)
self.btnFade.clicked.connect(self.fade) self.btnFade.clicked.connect(self.fade)
self.btnPlay.clicked.connect(self.play_next) 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.btnSongInfo.clicked.connect(self.song_info_search)
self.btnStop.clicked.connect(self.stop) self.btnStop.clicked.connect(self.stop)
self.spnVolume.valueChanged.connect(self.change_volume) self.spnVolume.valueChanged.connect(self.change_volume)
@ -356,19 +357,6 @@ class Window(QMainWindow, Ui_MainWindow):
self.stop_playing(fade=True) 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): def load_last_playlists(self):
"""Load the playlists that we loaded at end of last session""" """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) playlists = [p for p in Playlists.get_all(session)
if p.id != visible_tab_id] if p.id != visible_tab_id]
dlg = SelectPlaylistDialog(self, playlists=playlists) dlg = SelectPlaylistDialog(self, playlists=playlists,
session=session)
dlg.exec() dlg.exec()
if not dlg.plid: if not dlg.plid:
return return
@ -573,7 +562,8 @@ class Window(QMainWindow, Ui_MainWindow):
with Session() as session: with Session() as session:
playlists = Playlists.get_closed(session) playlists = Playlists.get_closed(session)
dlg = SelectPlaylistDialog(self, playlists=playlists) dlg = SelectPlaylistDialog(self, playlists=playlists,
session=session)
dlg.exec() dlg.exec()
if dlg.plid: if dlg.plid:
p = Playlists.get_by_id(session=session, playlist_id=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() self.end_of_track_actions()
def this_is_the_next_track(self, playlist_tab: PlaylistTab, 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 This is notification from a playlist tab that it holds the next
track to be played. track to be played.
@ -691,7 +681,6 @@ class Window(QMainWindow, Ui_MainWindow):
""" """
with Session() as session:
# Clear next track if on another tab # Clear next track if on another tab
if self.next_track_playlist_tab != playlist_tab: if self.next_track_playlist_tab != playlist_tab:
# We need to reset the ex-next-track playlist # We need to reset the ex-next-track playlist
@ -935,7 +924,7 @@ class DbDialog(QDialog):
class SelectPlaylistDialog(QDialog): class SelectPlaylistDialog(QDialog):
def __init__(self, parent=None, playlists=None): # review def __init__(self, parent=None, playlists=None, session=None):
super().__init__(parent) super().__init__(parent)
if playlists is None: if playlists is None:
@ -945,14 +934,14 @@ class SelectPlaylistDialog(QDialog):
self.ui.lstPlaylists.itemDoubleClicked.connect(self.list_doubleclick) self.ui.lstPlaylists.itemDoubleClicked.connect(self.list_doubleclick)
self.ui.buttonBox.accepted.connect(self.open) self.ui.buttonBox.accepted.connect(self.open)
self.ui.buttonBox.rejected.connect(self.close) self.ui.buttonBox.rejected.connect(self.close)
self.session = session
self.plid = None self.plid = None
with Session() as session:
record = Settings.get_int_settings( record = Settings.get_int_settings(
session, "select_playlist_dialog_width") self.session, "select_playlist_dialog_width")
width = record.f_int or 800 width = record.f_int or 800
record = Settings.get_int_settings( record = Settings.get_int_settings(
session, "select_playlist_dialog_height") self.session, "select_playlist_dialog_height")
height = record.f_int or 600 height = record.f_int or 600
self.resize(width, height) self.resize(width, height)
@ -963,16 +952,15 @@ class SelectPlaylistDialog(QDialog):
self.ui.lstPlaylists.addItem(p) self.ui.lstPlaylists.addItem(p)
def __del__(self): # review def __del__(self): # review
with Session() as session:
record = Settings.get_int_settings( record = Settings.get_int_settings(
session, "select_playlist_dialog_height") self.session, "select_playlist_dialog_height")
if record.f_int != self.height(): if record.f_int != self.height():
record.update(session, {'f_int': self.height()}) record.update(self.session, {'f_int': self.height()})
record = Settings.get_int_settings( record = Settings.get_int_settings(
session, "select_playlist_dialog_width") self.session, "select_playlist_dialog_width")
if record.f_int != self.width(): if record.f_int != self.width():
record.update(session, {'f_int': self.width()}) record.update(self.session, {'f_int': self.width()})
def list_doubleclick(self, entry): # review def list_doubleclick(self, entry): # review
self.plid = entry.data(Qt.UserRole) self.plid = entry.data(Qt.UserRole)

View File

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