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 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 logincheck(self): self.username = str(self.lineEdit.text()) self.password = str(self.lineEdit_2.text()) if (self.username == "" or self.password == ""): QtWidgets.QMessageBox.information(self, "Campo Vazio", "Por favor preencha todos os campos.") return #TESTAR LOCALMENTE """ elif (self.username == 'ruben' and self.password == '123'): QtWidgets.QMessageBox.information(self, "Sucesso", "Bem vindo/a: %s"% self.username) self.accept() """ else: response = requests.post('https://192.168.1.65:8080/auth/login', {'user_name':self.username,'password':self.password}, verify=False) print(self.username,self.password) print(response.content) if response.json()['success'] == True: # print('token->', response.json()['token']) #session_lib.set_token(response.json()['token']) print ('session_lib.token->',session_lib.get_token()) QtWidgets.QMessageBox.information(self, "Sucesso", "Bem vindo/a: \'%s\'"% self.username) self.accept() else: print ('erro')
def delete_playlist(self, pid): print("DDDDDDDDDDDpid", pid) r = server.postServer('playlists/delete', {'playlist_id':int(pid),'token':session_lib.get_token()}) print(r) #if r['success'] is True: #time.sleep(2) self.user_playlist()
def window(self): if self._window is None: if session_lib.get_token() == "": self._window = Login() return self._window else: response, ok = server.postServer( 'auth/check_token', {'token' : session_lib.get_token()} ) if response['success'] == True: username = response['payload']['user']['name'] self._window = Pytunes(username) else: print('fail') return self._window
def addbutton(self): playlist_name = self.lineEdit.text() print(playlist_name) response, ok = server.postServer( 'playlists/add', {'playlist_name':playlist_name, 'token':session_lib.get_token()} ) print(response) if response['success'] == True: self.close() time.sleep(0.05) self.user_interface.user_playlist()
def teste(self): response = requests.post('https://192.168.1.65:8080/auth/login', {'user_name':'ruben','password':'******'}, verify=False) #print(self.username,self.password) if response.json()['success'] == True: print('token->', response.json()) #session_lib.set_token(response.json()['token']) print ('session_lib.token->',session_lib.get_token()) QtWidgets.QMessageBox.information(self, "Sucesso", "Bem vindo/a: \'%s\'"% self.username) self.accept() else: print ('erro')
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
def add_to_playlist(self): playlist_id = self.comboBox.itemData(self.comboBox.currentIndex()) #print(self.comboBox.itemData(self.comboBox.currentIndex())) r, ok = server.postServer("playlists/"+str(playlist_id)+"/add_music", {'token':session_lib.get_token(), 'music_id':self.music_id}) print(r) if r['success'] is True: self.close()
def delete_playlist(self, pid): r = server.postServer('playlists/delete', {'playlist_id':int(pid),'token':session_lib.get_token()}) self.user_playlist()