Fix adding a new note
This commit is contained in:
parent
0465fb45c4
commit
21c7b234fb
@ -287,8 +287,9 @@ class PlaylistTracks(Base):
|
||||
@staticmethod
|
||||
def move_track(from_playlist_id, row, to_playlist_id):
|
||||
DEBUG(
|
||||
f"PlaylistTracks.move_tracks({from_playlist_id=}, {row=}, "
|
||||
f"{to_playlist_id=})"
|
||||
"PlaylistTracks.move_tracks(from_playlist_id="
|
||||
f"{from_playlist_id}, row={row}, "
|
||||
f"to_playlist_id={to_playlist_id})"
|
||||
)
|
||||
new_row = (
|
||||
session.query(func.max(PlaylistTracks.row)).filter(
|
||||
|
||||
@ -25,7 +25,7 @@ import helpers
|
||||
import music
|
||||
|
||||
from config import Config
|
||||
from model import Playdates, Playlists, PlaylistTracks, Settings, Tracks
|
||||
from model import Notes, Playdates, Playlists, PlaylistTracks, Settings, Tracks
|
||||
from playlists import Playlist
|
||||
from songdb import add_path_to_db
|
||||
from ui.dlg_search_database_ui import Ui_Dialog
|
||||
@ -170,6 +170,23 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
index = self.tabPlaylist.currentIndex()
|
||||
self.tabPlaylist.removeTab(index)
|
||||
|
||||
def create_note(self, text):
|
||||
"""
|
||||
Create note
|
||||
|
||||
If a row is selected, set note row to be rows above. Otherwise,
|
||||
set note row to be end of playlist.
|
||||
|
||||
Return note.
|
||||
"""
|
||||
|
||||
row = self.visible_playlist().get_selected_row()
|
||||
if row is None:
|
||||
row = self.visible_playlist().rowCount()
|
||||
DEBUG(f"musicmuster.create_note(text={text}): row={row}")
|
||||
|
||||
return Notes.add_note(self.visible_playlist().db.id, row, text)
|
||||
|
||||
def disable_play_next_controls(self):
|
||||
DEBUG("disable_play_next_controls()")
|
||||
self.actionPlay_next.setEnabled(False)
|
||||
@ -196,13 +213,16 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
dlg.resize(500, 100)
|
||||
ok = dlg.exec()
|
||||
if ok:
|
||||
self.visible_playlist().add_note(dlg.textValue())
|
||||
note = self.create_note(dlg.textValue())
|
||||
self.visible_playlist().add_note(note)
|
||||
|
||||
def load_last_playlists(self):
|
||||
"Load the playlists that we loaded at end of last session"
|
||||
|
||||
for playlist in Playlists.get_last_used():
|
||||
DEBUG(f"load_last_playlists(), {playlist.name=}, {playlist.id=}")
|
||||
DEBUG(
|
||||
f"load_last_playlists(), playlist.name={playlist.name}, "
|
||||
f"playlist.id={playlist.id}")
|
||||
self.load_playlist(playlist)
|
||||
|
||||
def load_playlist(self, playlist_db):
|
||||
|
||||
@ -221,7 +221,7 @@ class Playlist(QTableWidget):
|
||||
row = self.currentRow()
|
||||
else:
|
||||
row = self.rowCount()
|
||||
DEBUG(f"add_track({track=}), {row=}")
|
||||
DEBUG(f"add_track(track={track}), row={row}")
|
||||
|
||||
self.insertRow(row)
|
||||
|
||||
@ -266,6 +266,14 @@ class Playlist(QTableWidget):
|
||||
next_row = self._meta_get_next()
|
||||
return self._get_row_id(next_row)
|
||||
|
||||
def get_selected_row(self):
|
||||
"Return row number of first selected row, or None if none selected"
|
||||
|
||||
if not self.selectionModel().hasSelection():
|
||||
return None
|
||||
else:
|
||||
return self.selectionModel().selectedRows()[0]
|
||||
|
||||
def get_selected_rows_and_tracks(self):
|
||||
"Return a list of selected (rows, track_id) tuples"
|
||||
|
||||
@ -370,7 +378,7 @@ class Playlist(QTableWidget):
|
||||
Notes object.
|
||||
"""
|
||||
|
||||
DEBUG(f"_add_to_playlist({data=})")
|
||||
DEBUG(f"_add_to_playlist(data={data})")
|
||||
|
||||
if isinstance(data, Tracks):
|
||||
self.add_track(data, repaint=repaint)
|
||||
@ -643,7 +651,8 @@ class Playlist(QTableWidget):
|
||||
|
||||
DEBUG(
|
||||
f"playlist[{self.db.id}:{self.db.name}]."
|
||||
f"_repaint({clear_selection=}, {save_playlist=})"
|
||||
f"_repaint(clear_selection={clear_selection}, "
|
||||
f"save_playlist={save_playlist})"
|
||||
)
|
||||
|
||||
if clear_selection:
|
||||
|
||||
@ -37,3 +37,4 @@ traitlets==5.0.5
|
||||
typing-extensions==3.7.4.3
|
||||
wcwidth==0.2.5
|
||||
zipp==3.4.1
|
||||
slugify==0.0.1
|
||||
|
||||
2
run_debug.sh
Executable file
2
run_debug.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
gdb -ex r --args /home/kae/git/musicmuster/.direnv/python-3.7.3/bin/python app/musicmuster.py
|
||||
Loading…
Reference in New Issue
Block a user