summaryrefslogtreecommitdiff
path: root/plugins/SongStatus.py
blob: a03476e9ce58d4339fbf5bda570dab0c4ca7dc40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from PyQt4 import QtGui
from clMonty import monty
from clPlugin import *
from traceback import print_exc

SS_DEFAULT_FORMAT='<font size="4">now $state</font>'\
'$if($title,<font size="8" color="blue">$title</font>'\
'<br />by <font size="8" color="green">$artist</font>'\
'<br /><font size="5" color="red">[$album # $track]</font>)'\
'$if($length,<br /><font size="4">$time/$length</font>)'

class wgSongStatus(QtGui.QWidget):
	"""Displays the status of the current song, if playing."""
	" label containing the info"
	lblInfo=None
	def __init__(self, parent=None):
		QtGui.QWidget.__init__(self, parent)

		self.lblInfo=QtGui.QLabel()
		self.setMinimumWidth(400)
		
		layout=QtGui.QHBoxLayout()
		self.setLayout(layout)

		layout.addWidget(self.lblInfo)

		monty.addListener('onSongChange', self.update)
		monty.addListener('onTimeChange', self.update)
		monty.addListener('onStateChange', self.update)
		monty.addListener('onConnect', self.update)
		monty.addListener('onDisconnect', self.update)
	
	def update(self, params):
		status=monty.getStatus()
		song=monty.getCurrentSong()

		values={'state':''}
		try:
			values['state']={'play':'playing', 'stop':'stopped', 'pause':'paused'}[status['state']]
			if 'time' in status:
				values['length']=sec2min(status['length'])
				values['time']=sec2min(status['time'])
		except:
			pass
		
		txt=format(settings.get('songstatus.format', SS_DEFAULT_FORMAT), song, values)
		self.lblInfo.setText(txt)
		
	def text(self):
		return self.lblInfo.text()

class pluginSongStatus(Plugin):
	o=None
	def __init__(self, winMain):
		Plugin.__init__(self, winMain, 'SongStatus')
	def _load(self):
		self.o=wgSongStatus(None)
	def getInfo(self):
		return "Show information about the current song."
	
	def _getDockWidget(self):
		return self._createDock(self.o)

	def _getSettings(self):
		format=QtGui.QTextEdit()
		format.insertPlainText(settings.get('songstatus.format', SS_DEFAULT_FORMAT))
		return [
				['songstatus.format', 'Format', 'Format of the song status. Possible tags: $title, $artist, $album, $track, $time, $length, $state', format]
			]
	def afterSaveSettings(self):
		self.o.update(None)