summaryrefslogtreecommitdiff
path: root/plugins/Playlist.py
blob: 1a1354584b8a2b076f3f385cfcc86a7e3f68aa17 (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
from PyQt4 import QtGui
from clMonty import monty
from clPlugin import *
from misc import *
from wgPlaylist import Playlist
from wgSongList import clrRowSel

class pluginPlaylist(Plugin):
	o=None
	def __init__(self, winMain):
		Plugin.__init__(self, winMain, 'Playlist')
		self.o=Playlist(winMain, self, ['artist', 'title', 'album'], 'The Playlist'
				, self.onDoubleClick, self.onKeyPress)
		self.o.setMode('playlist')
		monty.addListener('onSongChange', self.onSongChange)
	def getInfo(self):
		return "The playlist showing the songs that will be played."
	
	def getList(self):
		return self.o

	def _getDockWidget(self):
		return self._createDock(self.o)

	def onDoubleClick(self):
		monty.play(self.o.getSelItemID())

	def onKeyPress(self, event):
		# remove selection from playlist using DELETE-key
		if event.matches(QtGui.QKeySequence.Delete):
			ids=self.o.selectedIds()
			self.setStatus('Deleting '+str(len(ids))+' songs from playlist ...')
			doEvents()

			monty.deleteFromPlaylist(ids)

			self.setStatus('')
			doEvents()

			self.getWinMain().fillPlaylist()
		return QtGui.QWidget.keyPressEvent(self.o, event)
	
	def onSongChange(self, params):
		lst=self.o
		lst.colorID(int(params['newSongID']), clrRowSel)

		if params['newSongID']!=-1:
			lst.ensureVisible(params['newSongID'])

	_rowColorModifier=0
	_rowColorAdder=1
	def timerEvent(self, event):
		curSong=monty.getCurrentSong()
		if curSong:
			lst=self.lstPlaylist
			# color current playing song
			lst.colorID(curSong.getID(),
				QtGui.QColor(140-self._rowColorModifier*5,140-self._rowColorModifier*5,180))

			# make sure color changes nicely over time
			self._rowColorModifier=self._rowColorModifier+self._rowColorAdder
			if abs(self._rowColorModifier)>4:
				self._rowColorAdder=-1*self._rowColorAdder