fixing some bugs with the overview screen
This commit is contained in:
1 parent
98ab8cb755
commit
ee479940b6
3 files changed
+49
-25
No files matched your search
+36
-16
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user