From 10981abb88f617fcfc65fdf93fd167aa54a0c87e Mon Sep 17 00:00:00 2001 From: et0h Date: Sun, 13 Sep 2020 18:44:16 +0100 Subject: [PATCH] Tweaks, refactoring and fixes for console improvements (#327) --- syncplay/client.py | 5 ++++- syncplay/messages_de.py | 3 +++ syncplay/messages_en.py | 4 ++++ syncplay/messages_es.py | 3 +++ syncplay/messages_it.py | 3 +++ syncplay/messages_pt_BR.py | 3 +++ syncplay/messages_pt_PT.py | 3 +++ syncplay/messages_ru.py | 3 +++ syncplay/ui/consoleUI.py | 20 +++++++++----------- syncplay/ui/gui.py | 2 +- 10 files changed, 36 insertions(+), 13 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index f596ad5..60dc7c6 100755 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -1892,9 +1892,12 @@ class SyncplayPlaylist(): def deleteAtIndex(self, index): new_playlist = self._playlist.copy() - if index < len(new_playlist): + if index >= 0 and index < len(new_playlist): del new_playlist[index] self.changePlaylist(new_playlist) + else: + raise TypeError("Invalid index") + @needsSharedPlaylistsEnabled def undoPlaylistChange(self): diff --git a/syncplay/messages_de.py b/syncplay/messages_de.py index b7a7961..10087c7 100755 --- a/syncplay/messages_de.py +++ b/syncplay/messages_de.py @@ -512,4 +512,7 @@ de = { "playlist-instruction-item-message": "Zieh eine Datei hierher, um sie zur geteilten Playlist hinzuzufügen.", "sharedplaylistenabled-tooltip": "Raumleiter können Dateien zu einer geteilten Playlist hinzufügen und es so erleichtern, gemeinsam das Gleiche zu gucken. Konfiguriere Medienverzeichnisse unter „Diverse“", + + "playlist-empty-error": "Playlist is currently empty.", # TO DO: Translate + "playlist-invalid-index-error": "Invalid playlist index", # TO DO: Translate } diff --git a/syncplay/messages_en.py b/syncplay/messages_en.py index ed61b42..5d06ea9 100755 --- a/syncplay/messages_en.py +++ b/syncplay/messages_en.py @@ -180,6 +180,7 @@ en = { "load-playlist-from-file-argument": "loads playlist from text file (one entry per line)", + # Client labels "config-window-title": "Syncplay configuration", @@ -512,4 +513,7 @@ en = { "playlist-instruction-item-message": "Drag file here to add it to the shared playlist.", "sharedplaylistenabled-tooltip": "Room operators can add files to a synced playlist to make it easy for everyone to watching the same thing. Configure media directories under 'Misc'.", + + "playlist-empty-error": "Playlist is currently empty.", + "playlist-invalid-index-error": "Invalid playlist index", } diff --git a/syncplay/messages_es.py b/syncplay/messages_es.py index b595c32..6696a6b 100644 --- a/syncplay/messages_es.py +++ b/syncplay/messages_es.py @@ -512,4 +512,7 @@ es = { "playlist-instruction-item-message": "Desplazar aquí el archivo para agregarlo a la lista de reproducción compartida.", "sharedplaylistenabled-tooltip": "Los operadores de la sala pueden agregar archivos a una lista de reproducción sincronizada, para que visualizar la misma cosa sea más sencillo para todos. Configurar directorios multimedia en 'Misc'.", + + "playlist-empty-error": "Playlist is currently empty.", # TO DO: Translate + "playlist-invalid-index-error": "Invalid playlist index", # TO DO: Translate } diff --git a/syncplay/messages_it.py b/syncplay/messages_it.py index 8782d34..3df17f1 100755 --- a/syncplay/messages_it.py +++ b/syncplay/messages_it.py @@ -512,4 +512,7 @@ it = { "playlist-instruction-item-message": "Trascina qui i file per aggiungerli alla playlist condivisa.", "sharedplaylistenabled-tooltip": "Gli operatori della stanza possono aggiungere i file a una playlist sincronizzata per garantire che tutti i partecipanti stiano guardando la stessa cosa. Configura le cartelle multimediali alla voce 'Miscellanea'.", + + "playlist-empty-error": "Playlist is currently empty.", # TO DO: Translate + "playlist-invalid-index-error": "Invalid playlist index", # TO DO: Translate } diff --git a/syncplay/messages_pt_BR.py b/syncplay/messages_pt_BR.py index 303d48b..bb29dca 100644 --- a/syncplay/messages_pt_BR.py +++ b/syncplay/messages_pt_BR.py @@ -512,4 +512,7 @@ pt_BR = { "playlist-instruction-item-message": "Arraste um arquivo aqui para adicioná-lo à playlist compartilhada.", "sharedplaylistenabled-tooltip": "Operadores da sala podem adicionar arquivos para a playlist compartilhada para tornar mais fácil para todo mundo assistir a mesma coisa. Configure os diretórios de mídia em 'Miscelânea'.", + + "playlist-empty-error": "Playlist is currently empty.", # TO DO: Translate + "playlist-invalid-index-error": "Invalid playlist index", # TO DO: Translate } diff --git a/syncplay/messages_pt_PT.py b/syncplay/messages_pt_PT.py index 5682135..5bfddea 100644 --- a/syncplay/messages_pt_PT.py +++ b/syncplay/messages_pt_PT.py @@ -512,4 +512,7 @@ pt_PT = { "playlist-instruction-item-message": "Arraste um ficheiro aqui para adicioná-lo à playlist compartilhada.", "sharedplaylistenabled-tooltip": "Operadores da sala podem adicionar ficheiros para a playlist compartilhada para tornar mais fácil para todo mundo assistir a mesma coisa. Configure os pastas de mídia em 'Miscelânea'.", + + "playlist-empty-error": "Playlist is currently empty.", # TO DO: Translate + "playlist-invalid-index-error": "Invalid playlist index", # TO DO: Translate } diff --git a/syncplay/messages_ru.py b/syncplay/messages_ru.py index a1e169b..0ac82ea 100755 --- a/syncplay/messages_ru.py +++ b/syncplay/messages_ru.py @@ -513,4 +513,7 @@ ru = { "playlist-instruction-item-message": "Перетащите сюда файлы, чтобы добавить их в общий список.", "sharedplaylistenabled-tooltip": "Оператор комнаты может добавлять файлы в список общего воспроизведения для удобного совместного просмотра. Папки воспроизведения настраиваются во вкладке 'Файл'.", + + "playlist-empty-error": "Playlist is currently empty.", # TO DO: Translate + "playlist-invalid-index-error": "Invalid playlist index", # TO DO: Translate } diff --git a/syncplay/ui/consoleUI.py b/syncplay/ui/consoleUI.py index f0c463a..700639f 100755 --- a/syncplay/ui/consoleUI.py +++ b/syncplay/ui/consoleUI.py @@ -24,11 +24,6 @@ class ConsoleUI(threading.Thread): self._syncplayClient = client def addFileToPlaylist(self, file): - if not isURL(file): - if not self._syncplayClient.fileSwitch.findFilepath(file): - print(f"{file} is not in any media directory") - return - self._syncplayClient.playlist.addToPlaylist(file) def drop(self): @@ -206,24 +201,27 @@ class ConsoleUI(threading.Thread): if i is not None and i in range(len(playlist_elements)): playlist_elements[i] = " *" + playlist_elements[i] - print(*playlist_elements, sep='\n') + self.showMessage("\n".join(playlist_elements), True) else: - print("playlist is currently empty.") + self.showMessage(getMessage("playlist-empty-error"), True) elif command.group('command') in constants.COMMANDS_SELECT: try: index = int(command.group('parameter').strip()) - 1 + + if index < 0 or index >= len(self._syncplayClient.playlist._playlist): + raise TypeError("Invalid playlist index") self._syncplayClient.playlist.changeToPlaylistIndex(index, resetPosition=True) self._syncplayClient.rewindFile() - except TypeError: - print("invalid index") + except (TypeError, AttributeError): + self.showErrorMessage(getMessage("playlist-invalid-index-error")) elif command.group('command') in constants.COMMANDS_DELETE: try: index = int(command.group('parameter').strip()) - 1 self._syncplayClient.playlist.deleteAtIndex(index) - except TypeError: - print("invalid index") + except (TypeError, AttributeError): + self.showErrorMessage(getMessage("playlist-invalid-index-error")) else: if self._tryAdvancedCommands(data): diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index c2add97..b9423a1 100755 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -1924,7 +1924,7 @@ class MainWindow(QtWidgets.QMainWindow): self.playlist.setPlaylistIndexFilename(filename) def addFileToPlaylist(self, filePath, index=-1): - if not isURL: + if not isURL(filePath): self.removePlaylistNote() filename = os.path.basename(filePath) if self.noPlaylistDuplicates(filename):