From 1749f0a0b84b981186cc6448621b896ce5baa8bc Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Thu, 13 Mar 2025 10:41:56 +0000 Subject: [PATCH] Actually add tracks chosen from query --- app/classes.py | 7 ++----- app/musicmuster.py | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/classes.py b/app/classes.py index 6909986..4424bdf 100644 --- a/app/classes.py +++ b/app/classes.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from enum import auto, Enum import functools import threading -from typing import NamedTuple, Optional +from typing import NamedTuple # Third party imports @@ -97,10 +97,7 @@ class MusicMusterSignals(QObject): """ Class for all MusicMuster signals. See: - https://zetcode.com/gui/pyqt5/eventssignals/ - - https://stackoverflow.com/questions/62654525/ - emit-a-signal-from-another-class-to-main-class - and Singleton class at - https://refactoring.guru/design-patterns/singleton/python/example#example-0 + - https://stackoverflow.com/questions/62654525/emit-a-signal-from-another-class-to-main-class """ begin_reset_model_signal = pyqtSignal(int) diff --git a/app/musicmuster.py b/app/musicmuster.py index 1429b3d..565b3fe 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -72,7 +72,7 @@ from classes import ( from config import Config from dialogs import TrackSelectDialog from file_importer import FileImporter -from helpers import file_is_unreadable, get_name +from helpers import ask_yes_no, file_is_unreadable, get_name from log import log from models import db, Playdates, PlaylistRows, Playlists, Queries, Settings, Tracks from music_manager import RowAndTrack, track_sequence @@ -1431,7 +1431,27 @@ class Window(QMainWindow): # Keep a reference else it will be gc'd self.query_dialog = QueryDialog(session, query_id) - self.query_dialog.exec() + if self.query_dialog.exec(): + new_row_number = self.current_row_or_end() + base_model = self.current.base_model + for track_id in self.query_dialog.selected_tracks: + # Check whether track is already in playlist + move_existing = False + existing_prd = base_model.is_track_in_playlist(track_id) + if existing_prd is not None: + if ask_yes_no( + "Duplicate row", + "Track already in playlist. " "Move to new location?", + default_yes=True, + ): + move_existing = True + + if move_existing and existing_prd: + base_model.move_track_add_note(new_row_number, existing_prd, note="") + else: + base_model.insert_row(new_row_number, track_id) + + new_row_number += 1 # # # # # # # # # # Playlist management functions # # # # # # # # # #