summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2010-12-30 15:11:14 +0100
committerAnton Khirnov <anton@khirnov.net>2011-09-04 20:17:35 +0200
commitb9789e36eb79307ddc0567d63b36c2419a414461 (patch)
tree66fe656571f5fddb26e3c1d28b5dc8a6cd1c1b56
parent5301413d16aced488cbc768c6c765afb21b90d06 (diff)
Songinfo: basic support for displaying stickers
It's ugly and uneditable and should probably be rewritten.
-rw-r--r--nephilim/plugins/Songinfo.py39
1 files changed, 38 insertions, 1 deletions
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('<b>Stickers:</b>', 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('<b>%s</b>'%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)