Compare commits
3 Commits
ad717aeb2c
...
1abe377b4c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1abe377b4c | ||
|
|
9eac5caf09 | ||
|
|
70f693a86b |
@ -74,7 +74,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
with Session() as session:
|
||||
for fname in dlg.selectedFiles():
|
||||
track = add_path_to_db(session, fname)
|
||||
self.visible_playlist()._add_to_playlist(track)
|
||||
self.visible_playlist().add_to_playlist(session, track)
|
||||
|
||||
def set_main_window_size(self):
|
||||
|
||||
@ -470,6 +470,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
DEBUG("musicmuster.stop()")
|
||||
|
||||
self.stop_playing(fade=False)
|
||||
self.enable_play_next_controls()
|
||||
|
||||
def stop_playing(self, fade=True):
|
||||
"Stop playing current track"
|
||||
@ -622,7 +623,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
class DbDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.session = Session()
|
||||
self.ui = Ui_Dialog()
|
||||
self.ui.setupUi(self)
|
||||
self.ui.searchString.textEdited.connect(self.chars_typed)
|
||||
@ -632,20 +632,22 @@ class DbDialog(QDialog):
|
||||
self.ui.btnClose.clicked.connect(self.close)
|
||||
self.ui.matchList.itemSelectionChanged.connect(self.selection_changed)
|
||||
|
||||
record = Settings.get_int(self.session, "dbdialog_width")
|
||||
width = record.f_int or 800
|
||||
record = Settings.get_int(self.session, "dbdialog_height")
|
||||
height = record.f_int or 600
|
||||
self.resize(width, height)
|
||||
with Session() as session:
|
||||
record = Settings.get_int(session, "dbdialog_width")
|
||||
width = record.f_int or 800
|
||||
record = Settings.get_int(session, "dbdialog_height")
|
||||
height = record.f_int or 600
|
||||
self.resize(width, height)
|
||||
|
||||
def __del__(self):
|
||||
record = Settings.get_int(self.session, "dbdialog_height")
|
||||
if record.f_int != self.height():
|
||||
record.update(self.session, {'f_int': self.height()})
|
||||
with Session() as session:
|
||||
record = Settings.get_int(session, "dbdialog_height")
|
||||
if record.f_int != self.height():
|
||||
record.update(session, {'f_int': self.height()})
|
||||
|
||||
record = Settings.get_int(self.session, "dbdialog_width")
|
||||
if record.f_int != self.width():
|
||||
record.update(self.session, {'f_int': self.width()})
|
||||
record = Settings.get_int(session, "dbdialog_width")
|
||||
if record.f_int != self.width():
|
||||
record.update(session, {'f_int': self.width()})
|
||||
|
||||
def add_selected(self):
|
||||
if not self.ui.matchList.selectedItems():
|
||||
@ -660,18 +662,19 @@ class DbDialog(QDialog):
|
||||
self.close()
|
||||
|
||||
def chars_typed(self, s):
|
||||
if len(s) >= 3:
|
||||
matches = Tracks.search_titles(self.session, s)
|
||||
self.ui.matchList.clear()
|
||||
if matches:
|
||||
for track in matches:
|
||||
t = QListWidgetItem()
|
||||
t.setText(
|
||||
f"{track.title} - {track.artist} "
|
||||
f"[{helpers.ms_to_mmss(track.duration)}]"
|
||||
)
|
||||
t.setData(Qt.UserRole, track.id)
|
||||
self.ui.matchList.addItem(t)
|
||||
if len(s) > 0:
|
||||
with Session() as session:
|
||||
matches = Tracks.search_titles(session, s)
|
||||
self.ui.matchList.clear()
|
||||
if matches:
|
||||
for track in matches:
|
||||
t = QListWidgetItem()
|
||||
t.setText(
|
||||
f"{track.title} - {track.artist} "
|
||||
f"[{helpers.ms_to_mmss(track.duration)}]"
|
||||
)
|
||||
t.setData(Qt.UserRole, track.id)
|
||||
self.ui.matchList.addItem(t)
|
||||
|
||||
def double_click(self, entry):
|
||||
track_id = entry.data(Qt.UserRole)
|
||||
@ -680,8 +683,9 @@ class DbDialog(QDialog):
|
||||
self.select_searchtext()
|
||||
|
||||
def add_track(self, track_id):
|
||||
track = Tracks.track_from_id(self.session, track_id)
|
||||
self.parent().visible_playlist()._add_to_playlist(track)
|
||||
with Session() as session:
|
||||
track = Tracks.track_from_id(session, track_id)
|
||||
self.parent().visible_playlist().add_to_playlist(session, track)
|
||||
# Select search text to make it easier for next search
|
||||
self.select_searchtext()
|
||||
|
||||
@ -695,7 +699,8 @@ class DbDialog(QDialog):
|
||||
|
||||
item = self.ui.matchList.currentItem()
|
||||
track_id = item.data(Qt.UserRole)
|
||||
self.ui.dbPath.setText(Tracks.get_path(self.session, track_id))
|
||||
with Session() as session:
|
||||
self.ui.dbPath.setText(Tracks.get_path(session, track_id))
|
||||
|
||||
|
||||
class SelectPlaylistDialog(QDialog):
|
||||
|
||||
@ -141,6 +141,8 @@ class Playlist(QTableWidget):
|
||||
f"Moved row(s) {rows} to become row {drop_row}"
|
||||
)
|
||||
|
||||
with Session() as session:
|
||||
self._save_playlist(session)
|
||||
self._repaint()
|
||||
|
||||
def eventFilter(self, source, event):
|
||||
@ -165,7 +167,7 @@ class Playlist(QTableWidget):
|
||||
|
||||
# ########## Externally called functions ##########
|
||||
|
||||
def add_note(self, note, repaint=True):
|
||||
def add_note(self, session, note, repaint=True):
|
||||
"""
|
||||
Add note to playlist
|
||||
|
||||
@ -211,9 +213,23 @@ class Playlist(QTableWidget):
|
||||
self.scrollToItem(titleitem, QAbstractItemView.PositionAtCenter)
|
||||
|
||||
if repaint:
|
||||
self._save_playlist(session)
|
||||
self._repaint(clear_selection=False)
|
||||
|
||||
def add_track(self, track, repaint=True):
|
||||
def add_to_playlist(self, session, data, repaint=True):
|
||||
"""
|
||||
Add data to playlist. Data may be either a Tracks object or a
|
||||
Notes object.
|
||||
"""
|
||||
|
||||
DEBUG(f"add_to_playlist(session={session}, data={data})")
|
||||
|
||||
if isinstance(data, Tracks):
|
||||
self.add_track(session, data, repaint=repaint)
|
||||
elif isinstance(data, Notes):
|
||||
self.add_note(session, data, repaint=repaint)
|
||||
|
||||
def add_track(self, session, track, repaint=True):
|
||||
"""
|
||||
Add track to playlist
|
||||
|
||||
@ -250,6 +266,7 @@ class Playlist(QTableWidget):
|
||||
self.scrollToItem(titleitem, QAbstractItemView.PositionAtCenter)
|
||||
|
||||
if repaint:
|
||||
self._save_playlist(session)
|
||||
self._repaint(clear_selection=False)
|
||||
|
||||
def clear_current(self):
|
||||
@ -353,12 +370,13 @@ class Playlist(QTableWidget):
|
||||
|
||||
# Now add data in row order
|
||||
for item in sorted(data, key=lambda x: x[0]):
|
||||
self._add_to_playlist(item[1], repaint=False)
|
||||
self.add_to_playlist(session, item[1], repaint=False)
|
||||
|
||||
# Scroll to top
|
||||
scroll_to = self.item(0, self.COL_INDEX)
|
||||
self.scrollToItem(scroll_to, QAbstractItemView.PositionAtTop)
|
||||
|
||||
self._save_playlist(session)
|
||||
self._repaint()
|
||||
|
||||
def repaint(self):
|
||||
@ -442,19 +460,6 @@ class Playlist(QTableWidget):
|
||||
|
||||
# ########## Internally called functions ##########
|
||||
|
||||
def _add_to_playlist(self, data, repaint=True):
|
||||
"""
|
||||
Add data to playlist. Data may be either a Tracks object or a
|
||||
Notes object.
|
||||
"""
|
||||
|
||||
DEBUG(f"_add_to_playlist(data={data})")
|
||||
|
||||
if isinstance(data, Tracks):
|
||||
self.add_track(data, repaint=repaint)
|
||||
elif isinstance(data, Notes):
|
||||
self.add_note(data, repaint=repaint)
|
||||
|
||||
def _calculate_next_start_time(self, session, row, start):
|
||||
"Return this row's end time given its start time"
|
||||
|
||||
@ -490,7 +495,7 @@ class Playlist(QTableWidget):
|
||||
DEBUG("playlist._delete_row(): Can't delete next track")
|
||||
return
|
||||
|
||||
else:
|
||||
with Session() as session:
|
||||
title = self.item(row, self.COL_TITLE).text()
|
||||
|
||||
msg = QMessageBox(self)
|
||||
@ -500,14 +505,14 @@ class Playlist(QTableWidget):
|
||||
msg.setDefaultButton(QMessageBox.Cancel)
|
||||
msg.setWindowTitle("Delete row")
|
||||
if msg.exec() == QMessageBox.Yes:
|
||||
with Session() as session:
|
||||
id = self._get_row_id(row)
|
||||
if row in self._meta_get_notes():
|
||||
Notes.delete_note(session, id)
|
||||
else:
|
||||
PlaylistTracks.remove_track(session, self.db.id, row)
|
||||
self.removeRow(row)
|
||||
id = self._get_row_id(row)
|
||||
if row in self._meta_get_notes():
|
||||
Notes.delete_note(session, id)
|
||||
else:
|
||||
PlaylistTracks.remove_track(session, self.db.id, row)
|
||||
self.removeRow(row)
|
||||
|
||||
self._save_playlist(session)
|
||||
self._repaint()
|
||||
|
||||
def _drop_on(self, event):
|
||||
@ -716,20 +721,17 @@ class Playlist(QTableWidget):
|
||||
self._repaint(save_playlist=False)
|
||||
self.master_process.set_next_track(track_id)
|
||||
|
||||
def _repaint(self, clear_selection=True, save_playlist=True):
|
||||
"Set row colours, fonts, etc, and save playlist"
|
||||
def _repaint(self, clear_selection=True):
|
||||
"Set row colours, fonts, etc"
|
||||
|
||||
DEBUG(
|
||||
f"playlist[{self.db.id}:{self.db.name}]."
|
||||
f"_repaint(clear_selection={clear_selection}, "
|
||||
f"save_playlist={save_playlist})"
|
||||
f"_repaint(clear_selection={clear_selection}"
|
||||
)
|
||||
|
||||
with Session() as session:
|
||||
if clear_selection:
|
||||
self.clearSelection()
|
||||
if save_playlist:
|
||||
self._save_playlist(session)
|
||||
|
||||
current = self._meta_get_current()
|
||||
next = self._meta_get_next()
|
||||
@ -874,7 +876,10 @@ class Playlist(QTableWidget):
|
||||
playlist_tracks[row] = self._get_row_id(row)
|
||||
|
||||
# Database
|
||||
for track in self.db.tracks:
|
||||
# Workaround for issue #10
|
||||
# for track in self.db.tracks:
|
||||
for track in session.query(PlaylistTracks).filter(
|
||||
PlaylistTracks.playlist_id == self.db.id).all():
|
||||
database_tracks[track.row] = track.track_id
|
||||
|
||||
# Tracks rows to add to database
|
||||
|
||||
Loading…
Reference in New Issue
Block a user