From 7fdf7a66a9061d496b57a89c46972e14c0fa0607 Mon Sep 17 00:00:00 2001 From: The Wobbler Date: Fri, 28 Feb 2025 19:28:07 +0100 Subject: [PATCH] Fixed https://teapot.informationsanarchistik.de/Wobbl/Wobuzz/issues/12 --- wobuzz/player/playlist.py | 3 +++ wobuzz/player/track.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/wobuzz/player/playlist.py b/wobuzz/player/playlist.py index f52af29..445c9da 100644 --- a/wobuzz/player/playlist.py +++ b/wobuzz/player/playlist.py @@ -309,6 +309,9 @@ class Playlist: for view in self.views.values(): # close views (and PyQt automatically closes the corresponding tabs) view.deleteLater() + for track in self.tracks: # remove items that corresponded to the track and this playlist + track.delete_items(self) + self.app.utils.unique_names.remove(self.title) self.app.library.playlists.remove(self) diff --git a/wobuzz/player/track.py b/wobuzz/player/track.py index 89bcf7e..bf74933 100644 --- a/wobuzz/player/track.py +++ b/wobuzz/player/track.py @@ -22,7 +22,7 @@ class Track: self.duration = 0 self.items = [] - self.occurrences = {} # all occurrences in playlists categorized by playlist and track widget + self.occurrences = {} # all occurrences in playlists categorized by playlist and id of the track widget if cache: self.cache() @@ -94,3 +94,14 @@ class Track: # return the remaining part of the track's audio and the duration of the remaining part return sound, len(remaining_audio) + + def delete_items(self, playlist): + """ + Deletes all QTreeWidgetItems that correspond to this track and the given playlist. + """ + + for item in self.items: + if id(item) in self.occurrences[playlist]: + self.items.remove(item) + + self.occurrences.pop(playlist)