class ResultsModel QtCore QAbstractItemModel tracks def __init__ self

 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
class ResultsModel(QtCore.QAbstractItemModel):
tracks = []
# def __init__(self, parent = None):
# self.tracks = []
# pass
def data(self, index, role):
print 'called data!', index.column, index.row
if role != QtCore.Qt.DisplayRole:
return QtCore.QVariant()
track = self.tracks[index.row()]
if index.column == 0:
return track.artist
if index.column == 1:
return track.title
if index.column == 2:
return track.length
# def headerData(self, section, orientation, role = QtCore.Qt.DisplayRole):
# pass
def index(self, row, column, parent = 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)#, unique_names = True, only_one_artist = sys.argv[1])
parser.parse_base_page()
self.tracks = parser.tracks