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