forked from Wobbl/Wobuzz
OOPed the way playlist views are created.
This commit is contained in:
parent
88b846f3b6
commit
028c38b1b6
7 changed files with 61 additions and 67 deletions
|
@ -1,8 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtCore import pyqtSignal
|
||||
from PyQt6.QtGui import QDropEvent
|
||||
from PyQt6.QtGui import QDropEvent, QIcon
|
||||
from PyQt6.QtWidgets import QTreeWidget, QAbstractItemView
|
||||
from .track import TrackItem
|
||||
|
||||
|
||||
class PlaylistView(QTreeWidget):
|
||||
|
@ -12,12 +13,17 @@ class PlaylistView(QTreeWidget):
|
|||
super().__init__(parent)
|
||||
|
||||
self.playlist = playlist
|
||||
self.app = playlist.app
|
||||
|
||||
playlist.view = self
|
||||
|
||||
self.setDragDropMode(QAbstractItemView.DragDropMode.InternalMove)
|
||||
self.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
|
||||
|
||||
self.setColumnCount(4)
|
||||
|
||||
self.play_icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart)
|
||||
|
||||
headers = [
|
||||
"",
|
||||
"#",
|
||||
|
@ -29,6 +35,10 @@ class PlaylistView(QTreeWidget):
|
|||
|
||||
self.setHeaderLabels(headers)
|
||||
|
||||
self.load_tracks()
|
||||
|
||||
self.itemActivated.connect(self.on_track_activation)
|
||||
|
||||
def update_track_numbers(self):
|
||||
pass
|
||||
|
||||
|
@ -41,3 +51,19 @@ class PlaylistView(QTreeWidget):
|
|||
|
||||
event.accept()
|
||||
|
||||
def load_tracks(self):
|
||||
for track in self.playlist.tracks:
|
||||
track_item = TrackItem(track, self)
|
||||
|
||||
def on_track_activation(self, item, column):
|
||||
index = self.indexOfTopLevelItem(item)
|
||||
self.app.player.play_track_in_playlist(index)
|
||||
|
||||
def on_track_change(self, previous_track, track):
|
||||
# unmark the previous track and mark the current track as playing
|
||||
if previous_track:
|
||||
previous_track.item.setIcon(0, QIcon(None))
|
||||
|
||||
if track:
|
||||
track.item.setIcon(0, self.play_icon)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue