WIP: add track to header
Logic works; playlistrow.py doesn't yet update database but prints a message saying db needs to be updated.
This commit is contained in:
parent
0ea12eb9d9
commit
38b166737b
@ -194,7 +194,7 @@ class MusicMusterSignals(QObject):
|
||||
search_songfacts_signal = pyqtSignal(str)
|
||||
search_wikipedia_signal = pyqtSignal(str)
|
||||
show_warning_signal = pyqtSignal(str, str)
|
||||
signal_add_track_to_header = pyqtSignal(int, int)
|
||||
signal_add_track_to_header = pyqtSignal(InsertTrack)
|
||||
signal_begin_insert_rows = pyqtSignal(InsertRows)
|
||||
signal_end_insert_rows = pyqtSignal(int)
|
||||
signal_insert_track = pyqtSignal(InsertTrack)
|
||||
|
||||
@ -111,6 +111,8 @@ class TrackInsertDialog(QDialog):
|
||||
# height = record.f_int or 600
|
||||
# self.resize(width, height)
|
||||
|
||||
self.signals = MusicMusterSignals()
|
||||
|
||||
def update_list(self, text: str) -> None:
|
||||
self.track_list.clear()
|
||||
if text.strip() == "":
|
||||
@ -145,7 +147,6 @@ class TrackInsertDialog(QDialog):
|
||||
return
|
||||
|
||||
insert_track_data = InsertTrack(self.playlist_id, track_id, note_text)
|
||||
self.signals.signal_insert_track.emit(insert_track_data)
|
||||
|
||||
self.title_edit.clear()
|
||||
self.note_edit.clear()
|
||||
@ -153,17 +154,13 @@ class TrackInsertDialog(QDialog):
|
||||
self.title_edit.setFocus()
|
||||
|
||||
if self.add_to_header:
|
||||
self.signals.signal_add_track_to_header.emit(insert_track_data)
|
||||
self.accept()
|
||||
else:
|
||||
self.signals.signal_insert_track.emit(insert_track_data)
|
||||
|
||||
def add_and_close_clicked(self):
|
||||
track_id = self.get_selected_track_id()
|
||||
if track_id is not None:
|
||||
note_text = self.note_edit.text()
|
||||
insert_track_data = InsertTrack(
|
||||
playlist_id=self.playlist_id, track_id=self.track_id, note=self.note
|
||||
)
|
||||
insert_track_data = InsertTrack(self.playlist_id, track_id, note_text)
|
||||
self.signals.signal_insert_track.emit(insert_track_data)
|
||||
self.add_clicked()
|
||||
self.accept()
|
||||
|
||||
def selection_changed(self) -> None:
|
||||
|
||||
@ -34,6 +34,7 @@ from classes import (
|
||||
ApplicationError,
|
||||
Col,
|
||||
InsertRows,
|
||||
InsertTrack,
|
||||
MusicMusterSignals,
|
||||
)
|
||||
from config import Config
|
||||
@ -144,16 +145,12 @@ class PlaylistModel(QAbstractTableModel):
|
||||
return header_row
|
||||
|
||||
@log_call
|
||||
def add_track_to_header(
|
||||
self, playlist_id: int, track_id: int, note: str = ""
|
||||
) -> None:
|
||||
def add_track_to_header(self, track_details: InsertTrack) -> None:
|
||||
"""
|
||||
Handle signal_add_track_to_header
|
||||
"""
|
||||
|
||||
log.debug(f"{self}: add_track_to_header({playlist_id=}, {track_id=}, {note=}")
|
||||
|
||||
if playlist_id != self.playlist_id:
|
||||
if track_details.playlist_id != self.playlist_id:
|
||||
return
|
||||
|
||||
if not self.selected_rows:
|
||||
@ -173,8 +170,8 @@ class PlaylistModel(QAbstractTableModel):
|
||||
return
|
||||
|
||||
if selected_row.note:
|
||||
selected_row.note += " " + note
|
||||
selected_row.track_id = track_id
|
||||
selected_row.note += " " + track_details.note
|
||||
selected_row.track_id = track_details.track_id
|
||||
|
||||
# Update local copy
|
||||
self.refresh_row(selected_row.row_number)
|
||||
|
||||
@ -110,13 +110,13 @@ class PlaylistRow:
|
||||
Adding a track_id should only happen to a header row.
|
||||
"""
|
||||
|
||||
if self.track_id:
|
||||
if self.track_id > 0:
|
||||
raise ApplicationError("Attempting to add track to row with existing track ({self=}")
|
||||
|
||||
# TODO: set up write access to track_id. Should only update if
|
||||
# track_id == 0. Need to update all other track fields at the
|
||||
# same time.
|
||||
print("set track_id attribute for {self=}, {value=}")
|
||||
print(f"set track_id attribute for {self=}, {value=}")
|
||||
pass
|
||||
|
||||
# Expose PlaylistRowDTO fields as properties
|
||||
@ -127,7 +127,7 @@ class PlaylistRow:
|
||||
@note.setter
|
||||
def note(self, value: str) -> None:
|
||||
# TODO set up write access to db
|
||||
print("set note attribute for {self=}, {value=}")
|
||||
print(f"set note attribute for {self=}, {value=}")
|
||||
# self.dto.note = value
|
||||
|
||||
@property
|
||||
@ -137,7 +137,7 @@ class PlaylistRow:
|
||||
@played.setter
|
||||
def played(self, value: bool = True) -> None:
|
||||
# TODO set up write access to db
|
||||
print("set played attribute for {self=}")
|
||||
print(f"set played attribute for {self=}")
|
||||
# self.dto.played = value
|
||||
|
||||
@property
|
||||
|
||||
@ -35,7 +35,14 @@ from PyQt6.QtWidgets import (
|
||||
|
||||
# App imports
|
||||
from audacity_controller import AudacityController
|
||||
from classes import ApplicationError, Col, MusicMusterSignals, PlaylistStyle, TrackInfo
|
||||
from classes import (
|
||||
ApplicationError,
|
||||
Col,
|
||||
InsertTrack,
|
||||
MusicMusterSignals,
|
||||
PlaylistStyle,
|
||||
TrackInfo
|
||||
)
|
||||
from config import Config
|
||||
from dialogs import TrackInsertDialog
|
||||
from helpers import (
|
||||
@ -513,18 +520,12 @@ class PlaylistTab(QTableView):
|
||||
def _add_track(self) -> None:
|
||||
"""Add a track to a section header making it a normal track row"""
|
||||
|
||||
model_row_number = self.source_model_selected_row_number()
|
||||
if model_row_number is None:
|
||||
return
|
||||
|
||||
with db.Session() as session:
|
||||
dlg = TrackInsertDialog(
|
||||
parent=self.musicmuster,
|
||||
playlist_id=self.playlist_id,
|
||||
add_to_header=True,
|
||||
)
|
||||
dlg.exec()
|
||||
session.commit()
|
||||
dlg = TrackInsertDialog(
|
||||
parent=self.musicmuster,
|
||||
playlist_id=self.playlist_id,
|
||||
add_to_header=True,
|
||||
)
|
||||
dlg.exec()
|
||||
|
||||
def _build_context_menu(self, item: QTableWidgetItem) -> None:
|
||||
"""Used to process context (right-click) menu, which is defined here"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user