mpclient: change info from function to var.
[nephilim.git] / nephilim / plugins / Songinfo.py
blob960f179a759fdb338b8eea16970a9b51bf0c1d62
2 # Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
4 # Nephilim is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # Nephilim is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
18 from PyQt4 import QtGui, QtCore
20 from ..plugin import Plugin
22 class Songinfo(Plugin):
23 # public, const
24 info = 'Displays song metadata provided by MPD.'
26 # public, read-only
27 o = None
28 def _load(self):
29 self.o = SonginfoWidget(self)
31 def _unload(self):
32 self.o = None
34 def _get_dock_widget(self):
35 return self._create_dock(self.o)
37 class SonginfoWidget(QtGui.QWidget):
38 plugin = None
39 labels = {}
41 def __init__(self, plugin):
42 QtGui.QWidget.__init__(self)
43 self.plugin = plugin
45 self.setLayout(QtGui.QVBoxLayout())
47 for item in 'track', 'title', 'album', 'disc', 'artist', 'composer', 'date', 'genre', 'file':
48 self.labels[item] = QtGui.QLabel('<b>%s</b>:'%item)
49 self.labels[item].setWordWrap(True)
50 self.layout().addWidget(self.labels[item])
52 self.plugin.mpclient.song_changed.connect(self.on_song_change)
54 def on_song_change(self):
55 song = self.plugin.mpclient.current_song()
56 if not song:
57 for item in self.labels:
58 self.labels[item].setText('<b>%s</b>:'%item)
59 else:
60 for item in self.labels:
61 self.labels[item].setText('<b>%s</b>: %s'%(item, unicode(song.tag(item))))