From 8e03ecb3ed3f26f81e892c2393b2521a9523fdc7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 4 Oct 2010 20:34:16 +0200 Subject: Playlist: highlight current song. --- TODO | 1 - nephilim/plugins/Playlist.py | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 0122561..97623fa 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ alpha: -- highlight current song in playlist - support for more playlists other TODO: diff --git a/nephilim/plugins/Playlist.py b/nephilim/plugins/Playlist.py index dc26f0c..7a36158 100644 --- a/nephilim/plugins/Playlist.py +++ b/nephilim/plugins/Playlist.py @@ -66,6 +66,8 @@ class PlaylistTree(QtGui.QTreeWidget): _menu = None # add same... menu _same_menu = None + # currently playing song item (highlighted + _cur_song = None def __init__(self, plugin): QtGui.QTreeWidget.__init__(self) @@ -95,6 +97,7 @@ class PlaylistTree(QtGui.QTreeWidget): self.header().geometriesChanged.connect(self._save_state) self.plugin.mpclient.playlist_changed.connect(lambda :self.plugin.mpclient.playlist(self.fill)) self.plugin.mpclient.connect_changed.connect(self._update_menu) + self.plugin.mpclient.song_changed.connect(self._update_cur_song) def _save_state(self): self.plugin.settings.setValue(self.plugin.name + '/header_state', self.header().saveState()) @@ -102,14 +105,28 @@ class PlaylistTree(QtGui.QTreeWidget): def _song_activated(self, item): self.plugin.mpclient.play(item.song['id']) + def _update_cur_song(self, song): + if self._cur_song: + self._cur_song.set_current(False) + + if not song: + self._cur_song = None + return + + self._cur_song = self.topLevelItem(int(song['pos'])) + if self._cur_song: + self._cur_song.set_current(True) + def fill(self, songs): columns = self.plugin.settings.value(self.plugin.name + '/columns') + self._cur_song = None self.clear() for song in songs: item = PlaylistSongItem(PlaylistEntryRef(self.plugin.mpclient, song['id'])) for i in range(len(columns)): item.setText(i, song['?' + columns[i]]) self.addTopLevelItem(item) + self._update_cur_song(self.plugin.mpclient.cur_song) def keyPressEvent(self, event): if event.matches(QtGui.QKeySequence.Delete): @@ -170,3 +187,12 @@ class PlaylistSongItem(QtGui.QTreeWidgetItem): def __init__(self, song): QtGui.QTreeWidgetItem.__init__(self) self.song = song + + def set_current(self, val): + font = QtGui.QFont() + if val: + font.setBold(True) + font.setItalic(True) + + for i in xrange(self.columnCount()): + self.setFont(i, font) -- cgit v1.2.3