Rearranged some code.
This commit is contained in:
parent
4c0883f694
commit
a23799b6b1
2 changed files with 29 additions and 15 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
from PyQt6.QtCore import pyqtSignal
|
||||
from PyQt6.QtGui import QDropEvent, QIcon, QFont
|
||||
from PyQt6.QtWidgets import QTreeWidget, QAbstractItemView, QFrame
|
||||
from PyQt6.QtWidgets import QTreeWidget, QAbstractItemView
|
||||
|
||||
from .track import TrackItem
|
||||
|
||||
|
@ -10,9 +10,7 @@ from .track import TrackItem
|
|||
class PlaylistView(QTreeWidget):
|
||||
itemDropped = pyqtSignal(QTreeWidget, list)
|
||||
|
||||
normal_font = QFont()
|
||||
bold_font = QFont()
|
||||
bold_font.setBold(True)
|
||||
playing_mark = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart)
|
||||
|
||||
def __init__(self, playlist, dock, parent=None):
|
||||
super().__init__(parent)
|
||||
|
@ -28,8 +26,6 @@ class PlaylistView(QTreeWidget):
|
|||
|
||||
self.setColumnCount(4)
|
||||
|
||||
self.playing_mark = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart)
|
||||
|
||||
headers = [
|
||||
"#",
|
||||
"Title",
|
||||
|
@ -133,20 +129,14 @@ class PlaylistView(QTreeWidget):
|
|||
|
||||
# unmark the previous track in all playlists
|
||||
for item in previous_track.items:
|
||||
item.setIcon(0, QIcon(None))
|
||||
item.setFont(1, self.normal_font)
|
||||
item.setFont(2, self.normal_font)
|
||||
item.setFont(3, self.normal_font)
|
||||
item.unmark()
|
||||
|
||||
if track:
|
||||
playlist_tabs.setTabIcon(index, self.playing_mark) # mark this playlist
|
||||
|
||||
# mark the current track in this playlist
|
||||
item = self.topLevelItem(self.app.player.current_playlist.current_track_index)
|
||||
item.setIcon(0, self.playing_mark)
|
||||
item.setFont(1, self.bold_font)
|
||||
item.setFont(2, self.bold_font)
|
||||
item.setFont(3, self.normal_font)
|
||||
item.mark()
|
||||
|
||||
def append_track(self, track):
|
||||
TrackItem(track, self.topLevelItemCount() - 1, self)
|
||||
|
|
|
@ -1,20 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QFont, QIcon, QPalette
|
||||
from PyQt6.QtWidgets import QTreeWidgetItem
|
||||
|
||||
|
||||
class TrackItem(QTreeWidgetItem):
|
||||
normal_font = QFont()
|
||||
bold_font = QFont()
|
||||
bold_font.setBold(True)
|
||||
|
||||
playing_mark = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart)
|
||||
|
||||
def __init__(self, track, index, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.track = track
|
||||
self.index_user_sort = index
|
||||
|
||||
self.index = index
|
||||
|
||||
self.playlist = parent.playlist
|
||||
|
||||
palette = parent.palette()
|
||||
|
||||
self.highlight_color = palette.color(QPalette.ColorRole.Highlight)
|
||||
self.base_color = palette.color(QPalette.ColorRole.Base)
|
||||
|
||||
track.items.append(self)
|
||||
|
||||
track.set_occurrences()
|
||||
|
@ -31,3 +42,16 @@ class TrackItem(QTreeWidgetItem):
|
|||
self.setText(3, track.tags.album)
|
||||
self.setText(4, str(self.index_user_sort + 1))
|
||||
|
||||
def mark(self):
|
||||
self.setIcon(0, self.playing_mark)
|
||||
self.setFont(1, self.bold_font)
|
||||
self.setFont(2, self.bold_font)
|
||||
self.setFont(3, self.normal_font)
|
||||
|
||||
|
||||
def unmark(self):
|
||||
self.setIcon(0, QIcon(None))
|
||||
self.setFont(1, self.normal_font)
|
||||
self.setFont(2, self.normal_font)
|
||||
self.setFont(3, self.normal_font)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue