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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
from PyQt4 import QtGui
from clPlugin import *
from traceback import print_exc
import format
SONGSTATUS_FORMAT_DEFAULT='<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
format=None
p=None
def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self, parent)
self.p=p
self.lblInfo=QtGui.QLabel()
self.setMinimumWidth(400)
layout=QtGui.QHBoxLayout()
self.setLayout(layout)
layout.addWidget(self.lblInfo)
self.updateFormat()
def update(self, params):
status=self.monty.getStatus()
song=self.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
if song:
self.lblInfo.setText(self.format(format.params(song, values)))
def updateFormat(self):
try:
self.format=format.compile(self.p.getSetting('format'))
except Exception, e:
self.format=lambda p: "Invalid format: %s"%(e)
def text(self):
return self.lblInfo.text()
class pluginSongStatus(Plugin):
o=None
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'SongStatus')
self.addMontyListener('onSongChange', self.update)
self.addMontyListener('onTimeChange', self.update)
self.addMontyListener('onStateChange', self.update)
self.addMontyListener('onConnect', self.update)
self.addMontyListener('onDisconnect', self.update)
def _load(self):
self.o=wgSongStatus(self, None)
self.update(None)
def _unload(self):
self.o=None
def getInfo(self):
return "Show information about the current song."
def update(self, params):
self.o.update(params)
def _getDockWidget(self):
return self._createDock(self.o)
def _getSettings(self):
format=QtGui.QTextEdit()
format.insertPlainText(self.getSetting('format'))
return [
['format', 'Format', 'Format of the song status. Possible tags: $title, $artist, $album, $track, $time, $length, $state', format]
]
def afterSaveSettings(self):
self.o.updateFormat()
self.o.update(None)
|