Set start correctly when note edited
This commit is contained in:
parent
d8072ae73f
commit
54cfb1191a
@ -80,7 +80,7 @@ class Notes(Base):
|
||||
Update note details. If text=None, don't change text.
|
||||
"""
|
||||
|
||||
DEBUG(f"update_note(id={id}, row={row}, text={text})")
|
||||
DEBUG(f"Notes.update_note(id={id}, row={row}, text={text})")
|
||||
|
||||
note = session.query(cls).filter(cls.id == id).one()
|
||||
note.row = row
|
||||
|
||||
@ -17,7 +17,7 @@ import os
|
||||
|
||||
from config import Config
|
||||
from datetime import datetime, timedelta
|
||||
from helpers import get_relative_date, open_in_audacity, show_warning
|
||||
from helpers import get_relative_date, open_in_audacity
|
||||
from log import DEBUG, ERROR
|
||||
from model import (
|
||||
Notes, Playdates, Playlists, PlaylistTracks, Session, Settings, Tracks
|
||||
@ -232,10 +232,12 @@ class PlaylistTab(QTableWidget):
|
||||
start_time = None
|
||||
try:
|
||||
start_time = datetime.strptime(note.note[-9:], " %H:%M:%S").time()
|
||||
DEBUG(f"Note contains valid time={start_time}")
|
||||
DEBUG(
|
||||
f"playlist.inset_note(): Note contains valid time={start_time}"
|
||||
)
|
||||
except ValueError:
|
||||
DEBUG(
|
||||
f"Note on row {row} ('{note.note}') "
|
||||
f"playlist.inset_note(): Note on row {row} ('{note.note}') "
|
||||
"does not contain valid time"
|
||||
)
|
||||
|
||||
@ -621,6 +623,9 @@ class PlaylistTab(QTableWidget):
|
||||
|
||||
if not self.editing_cell:
|
||||
return
|
||||
# If we update start time, _cell_changed will be called
|
||||
if column not in [self.COL_TITLE, self.COL_ARTIST]:
|
||||
return
|
||||
|
||||
new = self.item(row, column).text()
|
||||
|
||||
@ -629,7 +634,28 @@ class PlaylistTab(QTableWidget):
|
||||
row_id = self._get_row_id(row)
|
||||
with Session() as session:
|
||||
if row in self._meta_get_notes():
|
||||
# Save change to database
|
||||
DEBUG(
|
||||
f"Notes.update_note: saving new note text '{new=}'",
|
||||
True
|
||||
)
|
||||
Notes.update_note(session, row_id, row, new)
|
||||
# Set/clear row start time accordingly
|
||||
try:
|
||||
start_dt = datetime.strptime(new[-9:], " %H:%M:%S")
|
||||
start_time = start_dt.time()
|
||||
self._set_row_start_time(row, start_time)
|
||||
DEBUG(
|
||||
f"_cell_changed:Note {new} contains valid "
|
||||
f"time={start_time}"
|
||||
)
|
||||
except ValueError:
|
||||
# Reset row start time in case it used to have one
|
||||
self._set_row_start_time(row, None)
|
||||
DEBUG(
|
||||
f"_cell_changed:Note {new} does not contain "
|
||||
"start time"
|
||||
)
|
||||
else:
|
||||
track = Tracks.get_track(session, row_id)
|
||||
if column == self.COL_ARTIST:
|
||||
@ -647,6 +673,11 @@ class PlaylistTab(QTableWidget):
|
||||
def _cell_edit_ended(self):
|
||||
DEBUG("_cell_edit_ended()")
|
||||
self.editing_cell = False
|
||||
|
||||
# Call repaint to update start times, such as when a note has
|
||||
# been edited
|
||||
self._repaint()
|
||||
|
||||
self.master_process.enable_play_next_controls()
|
||||
|
||||
def _delete_rows(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user