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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
from PyQt4 import QtGui, QtCore
from wgSongList import SongList
from misc import *
class Playlist(QtGui.QWidget):
"""The Playlist widget is a list optimized for displaying a playlist, with filtering."""
name=None # name of this playlist
txtFilter=None # filter input
cmbMode=None # what mode? library, playlist?
lstSongs=None # list
winMain=None # the main window
onKeyPress=None
_timerID=None
def __init__(self, parent, wMain, headers, name, onDoubleClick, onKeyPress):
QtGui.QWidget.__init__(self, parent)
self.name=name
self.winMain=wMain
self.onKeyPress=onKeyPress
self.txtFilter=QtGui.QLineEdit()
self.cmbMode=QtGui.QComboBox()
self.cmbMode.addItem('playlist')
self.cmbMode.addItem('artist')
self.cmbMode.addItem('artist/album')
self.cmbMode.addItem('artist/date/album')
self.cmbMode.addItem('album')
self.cmbMode.addItem('genre')
self.cmbMode.addItem('genre/artist')
self.cmbMode.addItem('genre/artist/album')
self.lstSongs=SongList(parent, headers, onDoubleClick)
frame=QtGui.QVBoxLayout()
frame.addWidget(self.cmbMode)
frame.addWidget(self.txtFilter)
frame.addWidget(self.lstSongs)
self.setLayout(frame)
self.connect(self.txtFilter, QtCore.SIGNAL('textChanged(const QString&)'), self.txtFilterChange)
self.connect(self.txtFilter, QtCore.SIGNAL('editingFinished()'), self.txtFilterQuit)
self.connect(self.cmbMode, QtCore.SIGNAL('currentIndexChanged(const QString&)'), self.onModeChangeChange)
_prevTxtFilter=None
def timerEvent(self, event):
if self.txtFilter.text()!=self._prevTxtFilter:
# only filter after a little while
self.filter()
def keyPressEvent(self, event):
self.onKeyPress(event)
def txtFilterChange(self):
if self._timerID==None:
# only start filtering after a little while
self._timerID=self.startTimer(500)
def txtFilterQuit(self):
if self._timerID:
self.killTimer(self._timerID)
self._timerID=None
def update(self, songs):
"""Update the list of songs."""
self.lstSongs.updateSongs(songs)
if len(self.txtFilter.text()):
self.filter()
def setMode(self, mode, levels=''):
"""Set the mode of showing the list."""
if mode=='playlist':
self.cmbMode.setCurrentIndex(0)
else:
self.cmbMode.setCurrentIndex(self.cmbMode.findText(levels))
def selectedSongs(self):
"""Get the selected songs."""
return self.lstSongs.selectedSongs()
def selectedIds(self):
"""Get the selected songIDs."""
return map(lambda song: song._data['id'], self.lstSongs.selectedSongs())
def getSelItemID(self):
"""Get the id of the first selected song."""
try:
return self.lstSongs.selectedSongs()[0].getID()
except:
return -1
def filter(self):
"""Filter the songs according to the inputbox."""
self.lstSongs.filter(str(self.txtFilter.text()).strip().lower())
def colorID(self, id, clr):
"""Color song with ID $id with color $clr."""
self.lstSongs.colorID(id, clr)
def onModeChangeChange(self, value):
if value=='playlist':
self.lstSongs.setMode('playlist')
else:
self.lstSongs.setMode('library', str(value))
self.filter()
def showColumn(self, column, show=True):
"""Show or hide column $column."""
self.lstSongs.showColumn(column, show)
def selectRow(self, row):
"""Select row $row."""
self.lstSongs.selectRow(row)
def ensureVisible(self, id):
"""Make sure song with ID $id is visible."""
self.lstSongs.ensureVisible(id)
|