def show_musics(self, playmid): self.clean_table() r = server.getServer('playlists/'+playmid, {'id':playmid}) #http://nullege.com/codes/show/src@p@y@pyqt5-HEAD@examples@[email protected]/193/PyQt5.QtWidgets.QTableWidget.setSelectionBehavior if len(r['payload']['musics']) == 0: self.clean_table() else: self.tableWidget.setRowCount(len(r['payload']['musics'])) self.tableWidget.setColumnCount(1) self.tableWidget.setHorizontalHeaderLabels(['Musica']) self.tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.tableWidget.horizontalHeader().setStretchLastSection(True) self.tableWidget.cellDoubleClicked.connect(self.select_music) i = 0 self.musics_in_current_playlist_by_index = {} for music in r['payload']['musics']: self.musics_in_current_playlist_by_index[i] = { 'id': music['id'], 'file_name': music['file_name'], 'name': music['name'] } musica = QTableWidgetItem(music['name']) file_path = QTableWidgetItem(music['file_name']) musica.setFlags(musica.flags() & ~Qt.ItemIsEditable) self.tableWidget.setItem(i, 0, musica) self.tableWidget.setItem(i, 1, file_path) i+=1
def get_library(self): self.clean_table() r = server.getServer('musics/', {'token':session_lib.get_token()}) if len(r['payload']['musics']) == 0: self.clean_table() else: self.tableWidget.setRowCount(len(r['payload']['musics'])) self.tableWidget.setColumnCount(1) self.tableWidget.setHorizontalHeaderLabels(['Musica']) self.tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.tableWidget.horizontalHeader().setStretchLastSection(True) self.tableWidget.cellDoubleClicked.connect(self.select_music) i = 0 self.musics_in_current_playlist_by_index = {} for music in r['payload']['musics']: self.musics_in_current_playlist_by_index[i] = { 'id': music['id'], 'file_name': music['file_name'], 'name': music['name'] } musica = QTableWidgetItem(music['name']) file_path = QTableWidgetItem(music['file_name']) musica.setFlags(musica.flags() & ~Qt.ItemIsEditable) self.tableWidget.setItem(i, 0, musica) self.tableWidget.setItem(i, 1, file_path) i+=1
def populate(self): self.comboBox.clear() r = server.getServer('user/playlists', {'token':session_lib.get_token()}) playlists = r['payload']['playlists'] for p in playlists: self.comboBox.addItem(p['name'],(p['id'])) self.pushButton.clicked.connect(self.add_to_playlist)
def user_playlist(self): self.listWidget.clear() r = server.getServer('user/playlists', {'token':session_lib.get_token()}) playlists = r['payload']['playlists'] self.listWidget.itemClicked.connect(self.playlist_changed) my_item2 = QListWidgetItem() my_item2.setText('Browse Music') my_item2.setIcon(QIcon("images/browse-music.png")) my_item2.setData(Qt.UserRole, 0) self.listWidget.addItem(my_item2) #http://stackoverflow.com/questions/13536839/qt-how-to-improve-my-contextmenu self.listWidget.setContextMenuPolicy(Qt.CustomContextMenu) self.listWidget.customContextMenuRequested.connect(self.handleContext) for p in playlists: my_item=QListWidgetItem() my_item.setText(p['name']) self.listWidget.addItem(my_item) myObject=str(p['id']) my_item.setIcon(QIcon("images/playlist-icon.png")) my_item.setData(Qt.UserRole, myObject)
def get_library(self): from functools import partial self.clean_table() r = server.getServer('musics/', {'token':session_lib.get_token()}) if len(r['payload']['musics']) == 0: self.clean_table() else: self.tableWidget.setRowCount(len(r['payload']['musics'])) self.tableWidget.setColumnCount(2) self.tableWidget.setHorizontalHeaderLabels(['Add to Playlist','Musica']) #self.tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.tableWidget.horizontalHeader().setStretchLastSection(True) self.tableWidget.cellDoubleClicked.connect(self.select_music) row = 0 self.musics_in_current_playlist_by_index = {} for music in r['payload']['musics']: self.musics_in_current_playlist_by_index[row] = { 'id': music['id'], 'file_name': music['file_name'], 'name': music['name'] } #add_to_playlist = QTableWidgetItem() #add_to_playlist.setIcon(QIcon("images/playlist-icon.png")) musica = QTableWidgetItem(music['name']) file_path = QTableWidgetItem(music['file_name']) musica.setFlags(musica.flags() & ~Qt.ItemIsEditable) self.tableWidget.setItem(row, 1, musica) #self.tableWidget.setItem(row, 1, file_path) #self.tableWidget.setItem(row, 0, add_to_playlist) #add_to_playlist_button = QtWidgets.QPushButton('Add') add_to_playlist_button = QtWidgets.QPushButton('Add') add_to_playlist_button.setIcon(QIcon("images/add-to-playlist.png")) self.tableWidget.setCellWidget(row,0,add_to_playlist_button) add_to_playlist_button.clicked.connect(self.handle_music_to_p) #cbk = partial(self.lol, add_to_playlist_button) #button.clicked.connect(cbk) #add_to_playlist_button.clicked.connect(cbk) row+=1