From 77346f08755b544747a7667fa1d186384a8fd82a Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 4 Mar 2018 04:09:09 +0100 Subject: [PATCH] Add responsiveness and current timestamp --- grzegorz_clients/remi_ui.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/grzegorz_clients/remi_ui.py b/grzegorz_clients/remi_ui.py index 2f1719d..608a46e 100644 --- a/grzegorz_clients/remi_ui.py +++ b/grzegorz_clients/remi_ui.py @@ -2,7 +2,7 @@ import random, os, time, shutil, sys from threading import Timer import remi.gui as gui from remi import App -from .utils import Namespace, call_as_thread, get_youtube_metadata +from .utils import Namespace, call_as_thread, get_youtube_metadata, seconds_to_timestamp from . import api #globals: @@ -46,6 +46,8 @@ class RemiApp(App): self.playback.seek_slider = gui.Slider(0, 0, 100, 1, width="85%", height=20, margin='10px') self.playback.seek_slider.set_oninput_listener(self.change_seek) + self.playback.timestamp = gui.Label("--:-- - --:--") + container.append(self.playback.playing) playbackContainer = gui.HBox() @@ -58,6 +60,7 @@ class RemiApp(App): playbackContainer.append(volume_container) container.append(playbackContainer) container.append(self.playback.seek_slider) + container.append(self.playback.timestamp) #playlist self.playlist = Namespace() @@ -145,6 +148,13 @@ class RemiApp(App): slider_pos = playback_pos["current"] / playback_pos["total"] * 100 if self.playback.seek_slider.get_value() != slider_pos: self.playback.seek_slider.set_value(slider_pos) + self.playback.timestamp.set_text( + seconds_to_timestamp(playback_pos["current"]) + + " - " + + seconds_to_timestamp(playback_pos["total"]) + ) + else: + self.playback.timestamp.set_text("--:-- - --:--") if times_called[0] % 5 == 0: volume = api.get_volume() @@ -159,8 +169,9 @@ class RemiApp(App): def playlist_update(self): playlist = api.get_playlist() + N = len(playlist) table = [] - for item in playlist: + for i, playlist_item in enumerate(playlist): name = playlist_item["filename"] length = "--:--" if "data" in playlist_item: @@ -169,6 +180,10 @@ class RemiApp(App): if "length" in playlist_item["data"]: length = playlist_item["data"]["length"] + if playlist_item.get("current", False): + self.playback.previous.set_enabled(i != 0) + self.playback.next.set_enabled(i != N-1) + table.append([ playlist_item["index"], name,