From 7f1469fbb080576f542a36b8beaf23cd481ec57a Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Wed, 13 Mar 2019 11:37:49 +0100 Subject: [PATCH] Add controlls for looping the playlist --- grzegorz_clients/api.py | 9 +++++++++ grzegorz_clients/remi_ui.py | 25 +++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/grzegorz_clients/api.py b/grzegorz_clients/api.py index 92bdb7c..3a891c5 100644 --- a/grzegorz_clients/api.py +++ b/grzegorz_clients/api.py @@ -104,6 +104,15 @@ def playlist_move(index1:int, index2:int): args = urlencode(locals()) return f"playlist/move?{args}", None +@request_get +def get_playlist_looping(): + return f"playlist/loop" + +@request_post +def playlist_set_looping(looping:bool): + return f"playlist/loop?loop={str(bool(looping)).lower()}", None + + @request_get def get_playback_pos(): return f"time" diff --git a/grzegorz_clients/remi_ui.py b/grzegorz_clients/remi_ui.py index a81bc4c..db9da71 100644 --- a/grzegorz_clients/remi_ui.py +++ b/grzegorz_clients/remi_ui.py @@ -50,6 +50,9 @@ class RemiApp(App): self.playlist.table = gui.Table() self.playlist.table.append_from_list([['#', 'Name', "length", "", "", ""]], fill_title=True) + self.playlist.looping = gui.CheckBoxLabel("loop playlist") + self.playlist.looping.set_on_click_listener(self.on_playlist_set_looping) + self.playlist.shuffle = gui.Button("SHUFFLE") self.playlist.shuffle.set_on_click_listener(self.on_playlist_clear_shuffle) @@ -167,13 +170,20 @@ class RemiApp(App): right_container.append(self.playlist.table) + playlist_controls = gui.HBox() + playlist_controls.style["width"] = "100%" + playlist_controls.style["justify-content"] = "space-between" + playlist_controls.style["margin-right"] = "0.25em" + playlist_controls.style["margin-bottom"] = "0.8em" + + playlist_controls.append(self.playlist.looping) + playlist_button_container = gui.HBox() playlist_button_container.append(self.playlist.shuffle) playlist_button_container.append(self.playlist.clear) - playlist_button_container.style["margin-left"] = "auto" - playlist_button_container.style["margin-right"] = "0.25em" - playlist_button_container.style["margin-bottom"] = "0.8em" - right_container.append(playlist_button_container) + playlist_controls.append(playlist_button_container) + + right_container.append(playlist_controls) return root_container @@ -238,6 +248,11 @@ class RemiApp(App): def on_table_item_remove_click(self, row_widget, playlist_item): api.playlist_remove(playlist_item["index"]) @call_as_thread + def on_playlist_set_looping(self, row_widget): + toggled = not row_widget.get_value() + api.playlist_set_looping(toggled) + row_widget.set_value(toggled) + @call_as_thread def on_playlist_clear_shuffle(self, row_widget): api.playlist_shuffle() @call_as_thread @@ -250,6 +265,8 @@ class RemiApp(App): is_playing = api.is_playing() self.set_playing(is_playing) + self.playlist.looping.set_value(api.get_playlist_looping()) + if is_playing: # update seekbar and timestamp try: playback_pos = api.get_playback_pos()