Added tools for reading and writing WOBUZZM3U and made the sorting parameters human readable.

This commit is contained in:
The Wobbler 2025-03-07 18:59:51 +01:00
parent f7995aee9e
commit 9e20e21e6f
5 changed files with 219 additions and 40 deletions

View file

@ -5,6 +5,7 @@ from PyQt6.QtGui import QDropEvent, QIcon
from PyQt6.QtWidgets import QTreeWidget, QAbstractItemView
from .track import TrackItem
from ..wobuzzm3u import WBZM3UData
class PlaylistView(QTreeWidget):
@ -50,34 +51,36 @@ class PlaylistView(QTreeWidget):
return
sorting = self.playlist.sorting
last_sort_section_index, order = sorting[4]
last_order = sorting[4]
if last_sort_section_index == section_index:
order = not order # invert order
if last_order.sort_by + 1 == section_index:
order = WBZM3UData.SortOrder(last_order.sort_by, not last_order.ascending) # invert order on 2nd click
self.playlist.sorting[4] = (section_index, order) # set sorting
self.playlist.sorting[4] = order # set sorting
# convert True/False to Qt.SortOrder.AscendingOrder/Qt.SortOrder.DescendingOrder
qorder = Qt.SortOrder.AscendingOrder if order else Qt.SortOrder.DescendingOrder
qorder = Qt.SortOrder.AscendingOrder if order.ascending else Qt.SortOrder.DescendingOrder
self.header.setSortIndicator(section_index, qorder)
else:
del sorting[0] # remove first sort
sorting.append((section_index, True)) # last sort is this section index, ascending
# last sort is this section index + 1, ascending
sorting.append(WBZM3UData.SortOrder(section_index - 1, True))
self.header.setSortIndicator(section_index, Qt.SortOrder.AscendingOrder)
self.sort()
def sort(self):
for index, order in self.playlist.sorting:
for order in self.playlist.sorting:
# convert True/False to Qt.SortOrder.AscendingOrder/Qt.SortOrder.DescendingOrder
qorder = Qt.SortOrder.AscendingOrder if order else Qt.SortOrder.DescendingOrder
qorder = Qt.SortOrder.AscendingOrder if order.ascending else Qt.SortOrder.DescendingOrder
# somehow, QTreeWidget.sortItems() cant be called from a thread, so we have to use a signal to execute it
# in the main thread
self.sort_signal.emit(index, qorder)
self.sort_signal.emit(order.sort_by + 1, qorder)
# self.sortItems(index, qorder)
self.on_sort()
@ -98,10 +101,11 @@ class PlaylistView(QTreeWidget):
track.setText(4, str(i)) # 4 = user sort index
if user_sort:
if not self.playlist.sorting[4][0] == 4: # set last sort to user sort
# set last sort to user sort
if not self.playlist.sorting[4].sort_by == WBZM3UData.SortOrder.custom_sorting:
del self.playlist.sorting[0]
self.playlist.sorting.append((4, True))
self.playlist.sorting.append(WBZM3UData.SortOrder(WBZM3UData.SortOrder.custom_sorting, True))
self.header.setSortIndicator(4, Qt.SortOrder.AscendingOrder)