From b9789e36eb79307ddc0567d63b36c2419a414461 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 30 Dec 2010 15:11:14 +0100 Subject: Songinfo: basic support for displaying stickers It's ugly and uneditable and should probably be rewritten. --- nephilim/plugins/Songinfo.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'nephilim') diff --git a/nephilim/plugins/Songinfo.py b/nephilim/plugins/Songinfo.py index 074bb30..88496f6 100644 --- a/nephilim/plugins/Songinfo.py +++ b/nephilim/plugins/Songinfo.py @@ -69,6 +69,7 @@ class Songinfo(Plugin): for tag in self.tags: metadata[tag] = song[tag] if tag in song else '' self.o.set_metadata(metadata) + self.mpclient.sticker_list(song['file'], self.o.set_stickers) class SonginfoWidget(QtGui.QWidget): @@ -86,13 +87,19 @@ class SonginfoWidget(QtGui.QWidget): QtGui.QWidget.__init__(self) self.plugin = plugin self._labels = {} + + self._st_label = QtGui.QLabel('Stickers:', self) + self._st_label.setAlignment(QtCore.Qt.AlignHCenter) + + self._stickers = StickersList(self.plugin.mpclient, self) + self.setLayout(QtGui.QGridLayout()) self.layout().setColumnStretch(1, 1) def set_tagtypes(self, tagtypes): """Setup labels for each tagtype in the list.""" # clear old data - for i in range(self.layout().rowCount()): + for i in range(len(self._labels)): it = self.layout().itemAtPosition(i, 0) it1 = self.layout().itemAtPosition(i, 1) if it: @@ -102,6 +109,8 @@ class SonginfoWidget(QtGui.QWidget): self.layout().removeItem(it1) it1.widget().setParent(None) self._labels = {} + self.layout().removeWidget(self._st_label) + self.layout().removeWidget(self._stickers) for tag in tagtypes: label = QtGui.QLabel('%s'%tag) #TODO sort known tags @@ -113,15 +122,22 @@ class SonginfoWidget(QtGui.QWidget): self.layout().addWidget(label1, len(self._labels), 1) self._labels[tag] = label1 + self.layout().addWidget(self._st_label, self.layout().rowCount(), 0, 1, 2) + self.layout().addWidget(self._stickers, self.layout().rowCount(), 0, 1, 2) + def set_metadata(self, metadata): """Set displayed metadata, which is provided in a dict of { tag : value }.""" for tag in metadata: self._labels[tag].setText(metadata[tag]) + def set_stickers(self, stickers): + """Set displayed stickers from a (key, value) iterator.""" + self._stickers.set_stickers(stickers) def clear(self): """ Clear displayed metadata. """ for label in self._labels.values(): label.clear() + self._stickers.clear() class SettingsWidgetSonginfo(Plugin.SettingsWidget): #### PRIVATE #### @@ -172,3 +188,24 @@ class SettingsWidgetSonginfo(Plugin.SettingsWidget): it = QtGui.QListWidgetItem(tag) it.setCheckState(QtCore.Qt.Unchecked) self._taglist.addItem(it) + +class StickersList(QtGui.QTreeWidget): + + #### PUBLIC #### + mpclient = None + + def __init__(self, mpclient, parent): + QtGui.QTreeWidget.__init__(self, parent) + self.mpclient = mpclient + + self.setAlternatingRowColors(True) + self.setRootIsDecorated(False) + self.setColumnCount(2) + self.setHeaderLabels(['key', 'value']) + + def set_stickers(self, stickers): + """Set displayed stickers from a (key, value) iterator.""" + self.clear() + for key, value in stickers: + it = QtGui.QTreeWidgetItem([key, value]) + self.addTopLevelItem(it) -- cgit v1.2.3