From e46dbddf36d6768c597c190992454daa4555bb8a Mon Sep 17 00:00:00 2001 From: Jonas Weinz Date: Sun, 31 Jan 2021 13:52:26 +0100 Subject: [PATCH] add duration time label --- src/gtk_mediathek_player/main_window.py | 3 +- src/gtk_mediathek_player/player_widget.py | 37 ++++++++++++++--------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/gtk_mediathek_player/main_window.py b/src/gtk_mediathek_player/main_window.py index e0c083f..53c6909 100644 --- a/src/gtk_mediathek_player/main_window.py +++ b/src/gtk_mediathek_player/main_window.py @@ -60,7 +60,8 @@ class MainApp(Gtk.Window): def _on_keypress(self, widget, event): if event.keyval == Gdk.KEY_space: - self._player_widget.toogle_play() + if self.get_active_pane() == "player": + self._player_widget.toogle_play() if event.keyval == Gdk.KEY_F11: self.toggle_fullscreen() diff --git a/src/gtk_mediathek_player/player_widget.py b/src/gtk_mediathek_player/player_widget.py index 7a127bc..e40743f 100644 --- a/src/gtk_mediathek_player/player_widget.py +++ b/src/gtk_mediathek_player/player_widget.py @@ -45,7 +45,14 @@ class PlayerWidget(Gtk.Overlay): if self._duration is not None: - self._slider.set_value(self._videoarea.get_position()) + position = self._videoarea.get_position() + + self._slider.set_value(position) + + position_string = tools.seconds_to_timestring(int(position)) + duration_string = tools.seconds_to_timestring(int(self._duration)) + + self._duration_text.set_markup(f"{position_string}/{duration_string}") self._is_update = False @@ -83,15 +90,7 @@ class PlayerWidget(Gtk.Overlay): box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self._controls = Gtk.Revealer() - # bbox.pack_start(self._play_button, - # expand=False, - # fill=False, - # padding=0) - - # bbox.pack_start(self._stop_button, - # expand=False, - # fill=False, - # padding=0) + self._duration_text = Gtk.Label("--/--") bbox.pack_start(self._play_pause_button, expand=False, @@ -103,11 +102,18 @@ class PlayerWidget(Gtk.Overlay): fill=False, padding=0) + box.pack_end(self._duration_text, + expand=False, + fill=False, + padding=0) + box.pack_end(self._slider, expand=True, fill=True, padding=0) + box.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(.0,.0,.0,.8)) + self._controls.add(box) self._controls.set_valign(Gtk.Align.END) @@ -115,10 +121,9 @@ class PlayerWidget(Gtk.Overlay): self._controls.set_reveal_child(True) style_context = self._controls.get_style_context() - style_context.add_class(Gtk.STYLE_CLASS_TITLEBAR) + style_context.add_class(Gtk.STYLE_CLASS_OSD) + - #self._play_button.connect("clicked", self.play) - #self._stop_button.connect("clicked", self.pause) self._play_pause_button.connect("clicked", self.toogle_play) @@ -133,15 +138,19 @@ class PlayerWidget(Gtk.Overlay): def stop(self, _=None): state = self.get_state() + self._videoarea.stop() if state == Gst.State.PLAYING or state == Gst.State.PAUSED: new_icon = tools.get_icon("media-playback-start") self._play_pause_button.props.image = new_icon - self._videoarea.stop() self._duration = None def toogle_play(self, _=None): state = self.get_state() + if state == Gst.State.NULL: + # do nothing + return + if state == Gst.State.PLAYING: self.pause()