switched screens to be modes so resume event would work for main screen
This commit is contained in:
1 parent
c4cba2af4e
commit
98ab8cb755
2 files changed
+75
-60
No files matched your search
+66
-54
@@ -74,7 +74,6 @@ class AlbumSongs(Screen):
|
||||
if song.id == self.selected_song_id:
|
||||
return song
|
||||
|
||||
|
||||
# Pops and uninstalls self
|
||||
def action_die(self) -> None:
|
||||
app.pop_screen()
|
||||
@@ -115,9 +114,6 @@ class ArtistAlbums(Screen):
|
||||
app.uninstall_screen("artistAlbums")
|
||||
|
||||
class Artists(Screen):
|
||||
BINDINGS = [
|
||||
('escape', 'app.pop_screen', "Back")
|
||||
]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield OptionList(id="Artists")
|
||||
@@ -136,9 +132,6 @@ class Artists(Screen):
|
||||
app.push_screen('artistAlbums')
|
||||
|
||||
class Albums(Screen):
|
||||
BINDINGS = [
|
||||
('escape', 'app.pop_screen', "Back")
|
||||
]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield DataTable()
|
||||
@@ -160,10 +153,6 @@ class Albums(Screen):
|
||||
app.push_screen('albumSongs')
|
||||
|
||||
class Playlists(Screen):
|
||||
BINDINGS = [
|
||||
('escape', 'app.pop_screen', "Back")
|
||||
]
|
||||
|
||||
playlists: list[SubSonic.Playlist] | None = None
|
||||
selected_playlist_id: str = None
|
||||
|
||||
@@ -197,7 +186,6 @@ class Playlists(Screen):
|
||||
if playlist.id == self.selected_playlist_id:
|
||||
return playlist
|
||||
|
||||
|
||||
class PlaylistSongs(Screen):
|
||||
BINDINGS = [
|
||||
('escape', 'die()', "Back"),
|
||||
@@ -249,10 +237,6 @@ class PlaylistSongs(Screen):
|
||||
return song
|
||||
|
||||
class Favourites(Screen):
|
||||
BINDINGS = [
|
||||
('escape', 'app.pop_screen', "Back")
|
||||
]
|
||||
|
||||
songs: list[SubSonic.Song] | None = None
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
@@ -271,62 +255,90 @@ class Favourites(Screen):
|
||||
for song in self.songs:
|
||||
songTable.add_row(song.title, song.album, song.artist, song.playCount, song.duration, song.bitRate, key=song.id)
|
||||
|
||||
class MainView(Screen):
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(icon="")
|
||||
with Horizontal():
|
||||
with Vertical(classes="column"):
|
||||
yield Label("Playing")
|
||||
yield DataTable(id="currently_playing")
|
||||
yield ProgressBar()
|
||||
with Vertical(classes="column"):
|
||||
yield Label("Queue")
|
||||
yield DataTable(id="queue")
|
||||
yield Footer()
|
||||
|
||||
def on_mount(self) -> None:
|
||||
queueTable: DataTable = self.query_one("#queue")
|
||||
queueTable.cursor_type = "row"
|
||||
queueTable.add_columns("Title", "Album", "Artist", "Plays", "Duration", "Bitrate")
|
||||
|
||||
currentlyPlaying: DataTable = self.query_one('#currently_playing')
|
||||
currentlyPlaying.cursor_type = "row"
|
||||
currentlyPlaying.add_columns("", "")
|
||||
|
||||
@on(events.ScreenSuspend)
|
||||
def sus(self, event: events.ScreenSuspend) -> None:
|
||||
logging.debug('sus')
|
||||
|
||||
@on(events.ScreenResume)
|
||||
def screen_resumed(self, event: events.ScreenResume) -> None:
|
||||
|
||||
# Update Queue Table
|
||||
queueTable: DataTable = self.query_one(DataTable)
|
||||
for row_key, row in queueTable.rows.items():
|
||||
queueTable.remove_row(row_key)
|
||||
|
||||
for song in app.song_queue:
|
||||
queueTable.add_row(song.title, song.album, song.artist, song.playCount, song.duration, song.bitRate)
|
||||
|
||||
# Update Currently Playing Table
|
||||
if app.currently_playing:
|
||||
song = app.currently_playing
|
||||
currentlyPlaying: DataTable = self.query_one('#currently_playing')
|
||||
currentlyPlaying.add_row("Title", song.title)
|
||||
currentlyPlaying.add_row("Artist", song.artist)
|
||||
currentlyPlaying.add_row("Album", song.album)
|
||||
currentlyPlaying.add_row("Plays", song.playCount if song.playCount else 0)
|
||||
currentlyPlaying.add_row("Duration", song.duration)
|
||||
currentlyPlaying.add_row("Track Number", song.trackNumber)
|
||||
currentlyPlaying.add_row("Bit Rate", song.bitRate)
|
||||
|
||||
|
||||
|
||||
class TextualSubpyPlayer(App):
|
||||
BINDINGS = [
|
||||
("space", "play_pause_song()", "⏯️"),
|
||||
("f1", "push_screen('artists')", "Artists"),
|
||||
("f2", "push_screen('albums')", "Albums"),
|
||||
("f3", "push_screen('favourites')", "Favourites"),
|
||||
("f4", "push_screen('playlists')", "Playlists")
|
||||
("f1", "switch_mode('main')", "Overview"),
|
||||
("f2", "switch_mode('artists')", "Artists"),
|
||||
("f3", "switch_mode('albums')", "Albums"),
|
||||
("f4", "switch_mode('favourites')", "Favourites"),
|
||||
("f5", "switch_mode('playlists')", "Playlists")
|
||||
]
|
||||
|
||||
MODES = {
|
||||
"main" : MainView,
|
||||
"artists" : Artists,
|
||||
"albums" : Albums,
|
||||
"favourites" : Favourites,
|
||||
"playlists" : Playlists
|
||||
}
|
||||
|
||||
currently_playing: SubSonic.Song | None = None
|
||||
song_queue: list[SubSonic.Song] = []
|
||||
isPlaying: bool = False
|
||||
place: int = 0
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(icon="")
|
||||
with Horizontal():
|
||||
with Vertical(classes="column"):
|
||||
yield Label(id="playing")
|
||||
yield ProgressBar()
|
||||
yield DataTable()
|
||||
yield Footer()
|
||||
|
||||
def on_mount(self) -> None:
|
||||
logging.debug("mount called")
|
||||
self.title = "SubPy"
|
||||
self.install_screen(Artists(), name="artists")
|
||||
self.install_screen(Albums(), name="albums")
|
||||
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")
|
||||
self.switch_mode('main')
|
||||
|
||||
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.isPlaying = True
|
||||
|
||||
Reference in new issue
Block a user