class ResultsModel QtCore QAbstractItemModel tracks def data self inde

 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
class ResultsModel(QtCore.QAbstractItemModel):
tracks = []
def data(self, index, role):
if role != QtCore.Qt.DisplayRole:
return QtCore.QVariant()
track = self.tracks[index.row()]
if index.column() == 0:
return QtCore.QVariant(track.artist)
if index.column() == 1:
return QtCore.QVariant(track.title)
if index.column() == 2:
return QtCore.QVariant(track.length)
def index(self, row, column, parent = QtCore.QModelIndex()):
if row>len(self.tracks)-1:
return QtCore.QModelIndex()
track = self.tracks[row]
item = ''
if column == 0:
item = track.artist
if column == 1:
item = track.title
if column == 2:
item = track.length
return self.createIndex(row, column, item)
def parent(self, index):
return QtCore.QModelIndex()
def rowCount(self, parent = QtCore.QModelIndex()):
return len(self.tracks)
def columnCount(self, parent = QtCore.QModelIndex()):
return 3
def search(self, login, target):
parser = SearchResultParser(login, target)
parser.parse_base_page()
self.tracks = parser.tracks