working on a queue for the main screen

This commit is contained in:
JISAUAY committed 2025-01-24 13:31:02 -06:00
1 parent 3eab7260e6
commit c4cba2af4e
3 files changed
+48 -15

No files matched your search

+40 -9
View File
@@ -19,6 +19,7 @@ import pygame
from textual import on, events
from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, OptionList, DataTable, ProgressBar, Label
from textual.containers import Horizontal, Vertical
from textual.screen import Screen
from textual.widgets.option_list import Option
@@ -201,7 +202,7 @@ class PlaylistSongs(Screen):
BINDINGS = [
('escape', 'die()', "Back"),
('p', 'play()', 'Play Song'),
('q' 'queue()', 'Queue Song')
('q', 'queue()', 'Queue Song')
]
selected_song_id: str | None = None
@@ -281,12 +282,16 @@ class TextualSubpyPlayer(App):
currently_playing: SubSonic.Song | None = None
song_queue: list[SubSonic.Song] = []
playing: bool = False
isPlaying: bool = False
place: int = 0
def compose(self) -> ComposeResult:
yield Label()
yield ProgressBar()
yield Header(icon="")
with Horizontal():
with Vertical(classes="column"):
yield Label(id="playing")
yield ProgressBar()
yield DataTable()
yield Footer()
def on_mount(self) -> None:
@@ -297,21 +302,47 @@ class TextualSubpyPlayer(App):
self.install_screen(Favourites(), name="favourites")
self.install_screen(Playlists(), name="playlists")
queueTable: DataTable = self.query_one(DataTable)
queueTable.cursor_type = "row"
queueTable.add_columns("Title", "Album", "Artist", "Plays", "Duration", "Bitrate")
def on_key(self, event: events.Key) -> None:
# logging.debug(f'Key Pressed {event.name}')
pass
@on(events.ScreenSuspend)
def sus(self, event: events.ScreenSuspend) -> None:
logging.debug('sus')
def on_screen_suspend(self, event: events.ScreenSuspend) -> None:
logging.debug('sus3')
@on(events.ScreenResume)
def screen_resumed(self, event: events.ScreenResume) -> None:
logging.debug('Main screen resumed')
queueTable: DataTable = self.query_one(DataTable)
for row_key, row in queueTable.rows.items():
queueTable.remove_row(row_key)
for song in self.song_queue:
queueTable.add_row(song.title, song.album, song.artist, song.playCount, song.duration, song.bitRate)
def play_song(self, song: SubSonic.Song) -> None:
self.currently_playing = song
self.playing = True
self.isPlaying = True
logging.debug(f"Playing song {song.title} by {song.artist}.")
self.notify(f"Playing \"{song.title}\" by {song.artist}.")
r = conn.stream(song.id)
audio_data = io.BytesIO(r.content)
pygame.mixer.music.load(audio_data)
pygame.mixer.music.play()
# playingLabel: Label = self.query_one(Label)
# playingLabel.
# Set callback loop for progress bar
# self.progress_timer = self.set_interval(1 / 10, self.update_progress, pause=False)
@@ -329,13 +360,13 @@ class TextualSubpyPlayer(App):
if not self.currently_playing:
return None
if self.playing:
if self.isPlaying:
self.place = pygame.mixer.music.get_pos()
pygame.mixer.music.pause()
self.playing = False
self.isPlaying = False
else:
pygame.mixer.music.play(start=self.place)
self.playing = True
pygame.mixer.music.unpause()
self.isPlaying = True
if __name__ == '__main__':
app = TextualSubpyPlayer()