From ee479940b6eefe8b5ae2655986ce9a7d2affcc05 Mon Sep 17 00:00:00 2001 From: 0x01FE Date: Fri, 24 Jan 2025 14:41:01 -0600 Subject: [PATCH] fixing some bugs with the overview screen --- main.tcss | 4 ++++ screens-test.py | 52 ++++++++++++++++++++++++++++++++++--------------- textual.log | 18 ++++++++--------- 3 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 main.tcss diff --git a/main.tcss b/main.tcss new file mode 100644 index 0000000..9c063e7 --- /dev/null +++ b/main.tcss @@ -0,0 +1,4 @@ +.info { + width: 30%; + padding-right: 2; +} diff --git a/screens-test.py b/screens-test.py index e10038f..bd2df94 100644 --- a/screens-test.py +++ b/screens-test.py @@ -63,16 +63,18 @@ class AlbumSongs(Screen): self.selected_song_id = event.row_key.value def action_play(self) -> None: - app.play_song(self._find_selected_song()) + song_index = self._find_selected_song() + app.play_song(self.songs[song_index]) + app.song_queue = self.songs[song_index + 1:] def action_queue(self) -> None: app.queue_song(self._find_selected_song()) - # Find the song that was selected - def _find_selected_song(self) -> SubSonic.Song: - for song in self.songs: + # Returns index of selected song + def _find_selected_song(self) -> int: + for i, song in enumerate(self.songs): if song.id == self.selected_song_id: - return song + return i # Pops and uninstalls self def action_die(self) -> None: @@ -225,16 +227,18 @@ class PlaylistSongs(Screen): self.selected_song_id = event.row_key.value def action_play(self) -> None: - app.play_song(self._find_selected_song()) + song_index = self._find_selected_song() + app.play_song(self.songs[song_index]) + app.song_queue = self.songs[song_index + 1:] def action_queue(self) -> None: app.queue_song(self._find_selected_song()) - # Find the song that was selected - def _find_selected_song(self) -> SubSonic.Song: - for song in self.songs: + # Returns index of selected song + def _find_selected_song(self) -> int: + for i, song in enumerate(self.songs): if song.id == self.selected_song_id: - return song + return i class Favourites(Screen): songs: list[SubSonic.Song] | None = None @@ -256,11 +260,12 @@ class Favourites(Screen): songTable.add_row(song.title, song.album, song.artist, song.playCount, song.duration, song.bitRate, key=song.id) class MainView(Screen): + CSS_PATH = 'main.tcss' def compose(self) -> ComposeResult: yield Header(icon="") with Horizontal(): - with Vertical(classes="column"): + with Vertical(classes="info"): yield Label("Playing") yield DataTable(id="currently_playing") yield ProgressBar() @@ -270,6 +275,7 @@ class MainView(Screen): yield Footer() def on_mount(self) -> None: + app.sub_title = "Overview" queueTable: DataTable = self.query_one("#queue") queueTable.cursor_type = "row" queueTable.add_columns("Title", "Album", "Artist", "Plays", "Duration", "Bitrate") @@ -284,16 +290,20 @@ class MainView(Screen): @on(events.ScreenResume) def screen_resumed(self, event: events.ScreenResume) -> None: + app.sub_title = "Overview" # Update Queue Table - queueTable: DataTable = self.query_one(DataTable) - for row_key, row in queueTable.rows.items(): - queueTable.remove_row(row_key) + queueTable: DataTable = self.query_one('#queue') + self._clear_table('#queue') - for song in app.song_queue: + queue: list[SubSonic.Song] = [] + queue.extend(app.user_queue) + queue.extend(app.song_queue) + for song in queue: queueTable.add_row(song.title, song.album, song.artist, song.playCount, song.duration, song.bitRate) # Update Currently Playing Table + self._clear_table('#currently_playing') if app.currently_playing: song = app.currently_playing currentlyPlaying: DataTable = self.query_one('#currently_playing') @@ -305,6 +315,15 @@ class MainView(Screen): currentlyPlaying.add_row("Track Number", song.trackNumber) currentlyPlaying.add_row("Bit Rate", song.bitRate) + def _clear_table(self, table_id: str) -> None: + table: DataTable = self.query_one(table_id) + + row_keys = [] + for row_key, row in table.rows.items(): + row_keys.append(row_key) + + for row_key in row_keys: + table.remove_row(row_key) class TextualSubpyPlayer(App): @@ -327,6 +346,7 @@ class TextualSubpyPlayer(App): currently_playing: SubSonic.Song | None = None song_queue: list[SubSonic.Song] = [] + user_queue: list[SubSonic.Song] = [] isPlaying: bool = False place: int = 0 @@ -363,7 +383,7 @@ class TextualSubpyPlayer(App): def queue_song(self, song: SubSonic.Song) -> None: logging.debug(f'Queue\'d song "{song.title}" by {song.artist}.') - self.song_queue.append(song) + self.user_queue.append(song) def action_play_pause_song(self) -> None: self.play_pause_song() diff --git a/textual.log b/textual.log index 7cf9bd6..c105bfb 100644 --- a/textual.log +++ b/textual.log @@ -1,9 +1,9 @@ -[2025-01-24 14:13:51,689] DEBUG in selector_events: Using selector: EpollSelector -[2025-01-24 14:13:53,465] DEBUG in screens-test: sus -[2025-01-24 14:13:53,503] DEBUG in connectionpool: Starting new HTTPS connection (1): music.0x01fe.net:443 -[2025-01-24 14:13:53,724] DEBUG in connectionpool: https://music.0x01fe.net:443 "GET /rest/getPlaylists?u=pseudo&t=2906549f2dd426cd73b88e461d73472b&s=6D4FZXTN&v=1.16.1&c=testing&f=json HTTP/1.1" 200 705 -[2025-01-24 14:13:54,681] DEBUG in connectionpool: Starting new HTTPS connection (1): music.0x01fe.net:443 -[2025-01-24 14:13:54,852] DEBUG in connectionpool: https://music.0x01fe.net:443 "GET /rest/getPlaylist?u=pseudo&t=4caaa96b81eab5329f9b063d7ac830ff&s=9WROPV8Z&v=1.16.1&c=testing&f=json&id=e6e8ff27-2a60-4e33-8aa1-09586191166a HTTP/1.1" 200 None -[2025-01-24 14:13:56,439] DEBUG in screens-test: Playing song Chang’e by King Gizzard & The Lizard Wizard. -[2025-01-24 14:13:56,441] DEBUG in connectionpool: Starting new HTTPS connection (1): music.0x01fe.net:443 -[2025-01-24 14:13:56,647] DEBUG in connectionpool: https://music.0x01fe.net:443 "GET /rest/stream?u=pseudo&t=6e30cb84d1ae2aaa3bb12c9461150982&s=3EEVNYDL&v=1.16.1&c=testing&id=d926c1f739d868662d17a5e3fa1cfd09 HTTP/1.1" 200 9563445 +[2025-01-24 14:38:51,125] DEBUG in selector_events: Using selector: EpollSelector +[2025-01-24 14:38:51,902] DEBUG in screens-test: sus +[2025-01-24 14:38:51,930] DEBUG in connectionpool: Starting new HTTPS connection (1): music.0x01fe.net:443 +[2025-01-24 14:38:52,091] DEBUG in connectionpool: https://music.0x01fe.net:443 "GET /rest/getPlaylists?u=pseudo&t=3b3e07bd0a56711c9db81acfb74b5560&s=2Q2MV419&v=1.16.1&c=testing&f=json HTTP/1.1" 200 705 +[2025-01-24 14:38:52,947] DEBUG in connectionpool: Starting new HTTPS connection (1): music.0x01fe.net:443 +[2025-01-24 14:38:53,121] DEBUG in connectionpool: https://music.0x01fe.net:443 "GET /rest/getPlaylist?u=pseudo&t=174305d05353398cf608a65562db736f&s=GQLIDGEJ&v=1.16.1&c=testing&f=json&id=e6e8ff27-2a60-4e33-8aa1-09586191166a HTTP/1.1" 200 None +[2025-01-24 14:38:54,045] DEBUG in screens-test: Playing song Theia by King Gizzard & The Lizard Wizard. +[2025-01-24 14:38:54,046] DEBUG in connectionpool: Starting new HTTPS connection (1): music.0x01fe.net:443 +[2025-01-24 14:38:54,249] DEBUG in connectionpool: https://music.0x01fe.net:443 "GET /rest/stream?u=pseudo&t=61c596042c3be872619f0f39ddcc645d&s=LAPQRCLD&v=1.16.1&c=testing&id=9e28af41e8bfcf423a5a958cd7aca5cc HTTP/1.1" 200 8314893