adding keypress events, unify play pause button
This commit is contained in:
parent
d777c3ecbe
commit
a605de6f49
@ -2,7 +2,7 @@ from . import mediathek_request as mr
|
||||
from . import tools
|
||||
from . import search_widget
|
||||
from . import player_widget
|
||||
from gi.repository import Gtk, GLib
|
||||
from gi.repository import Gtk, GLib, Gdk
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
@ -48,6 +48,8 @@ class MainApp(Gtk.Window):
|
||||
|
||||
self.set_active_pane("search")
|
||||
|
||||
self.connect("key-press-event", self._on_keypress)
|
||||
|
||||
GLib.timeout_add_seconds(1, self.update)
|
||||
|
||||
def on_mouse_move(self, _, __):
|
||||
@ -56,6 +58,12 @@ class MainApp(Gtk.Window):
|
||||
if self._fullscreen:
|
||||
self._revealer.set_reveal_child(True)
|
||||
|
||||
def _on_keypress(self, widget, event):
|
||||
if event.keyval == Gdk.KEY_space:
|
||||
self._player_widget.toogle_play()
|
||||
if event.keyval == Gdk.KEY_F11:
|
||||
self.toggle_fullscreen()
|
||||
|
||||
def update(self):
|
||||
if self._seconds_after_mouse_move > 1:
|
||||
self._revealer.set_reveal_child(False)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from . import tools
|
||||
from . import gst_widget
|
||||
from gi.repository import Gtk, GLib, Gst
|
||||
from gi.repository import Gtk, GLib, Gst, Gdk
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
@ -73,23 +73,30 @@ class PlayerWidget(Gtk.Overlay):
|
||||
|
||||
self._play_button = tools.new_button_with_icon('media-playback-start')
|
||||
|
||||
|
||||
self._stop_button = tools.new_button_with_icon('media-playback-stop')
|
||||
|
||||
self._play_pause_button = tools.new_button_with_icon(
|
||||
'media-playback-pause')
|
||||
|
||||
bbox = Gtk.ButtonBox(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
bbox.set_layout(Gtk.ButtonBoxStyle.EXPAND)
|
||||
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._play_button,
|
||||
# expand=False,
|
||||
# fill=False,
|
||||
# padding=0)
|
||||
|
||||
bbox.pack_start(self._stop_button,
|
||||
expand=False,
|
||||
fill=False,
|
||||
padding=0)
|
||||
# bbox.pack_start(self._stop_button,
|
||||
# expand=False,
|
||||
# fill=False,
|
||||
# padding=0)
|
||||
|
||||
bbox.pack_start(self._play_pause_button,
|
||||
expand=False,
|
||||
fill=False,
|
||||
padding=0)
|
||||
|
||||
box.pack_start(bbox,
|
||||
expand=False,
|
||||
@ -101,10 +108,8 @@ class PlayerWidget(Gtk.Overlay):
|
||||
fill=True,
|
||||
padding=0)
|
||||
|
||||
|
||||
self._controls.add(box)
|
||||
|
||||
|
||||
self._controls.set_valign(Gtk.Align.END)
|
||||
self._controls.set_transition_type(Gtk.RevealerTransitionType.SLIDE_UP)
|
||||
self._controls.set_reveal_child(True)
|
||||
@ -112,24 +117,41 @@ class PlayerWidget(Gtk.Overlay):
|
||||
style_context = self._controls.get_style_context()
|
||||
style_context.add_class(Gtk.STYLE_CLASS_TITLEBAR)
|
||||
|
||||
self._play_button.connect("clicked", self.play)
|
||||
self._stop_button.connect("clicked", self.pause)
|
||||
#self._play_button.connect("clicked", self.play)
|
||||
#self._stop_button.connect("clicked", self.pause)
|
||||
|
||||
self._play_pause_button.connect("clicked", self.toogle_play)
|
||||
|
||||
def play_from_uri(self, uri: str):
|
||||
self._videoarea.load_from_uri(uri)
|
||||
|
||||
def play(self, _=None):
|
||||
if self.get_state() != Gst.State.PLAYING:
|
||||
new_icon = tools.get_icon("media-playback-pause")
|
||||
self._play_pause_button.props.image = new_icon
|
||||
self._videoarea.play()
|
||||
|
||||
def stop(self, _=None):
|
||||
state = self.get_state()
|
||||
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.PLAYING:
|
||||
self.pause()
|
||||
|
||||
elif state == Gst.State.PAUSED:
|
||||
self.play()
|
||||
|
||||
def pause(self, _=None):
|
||||
if self.get_state() == Gst.State.PLAYING:
|
||||
new_icon = tools.get_icon("media-playback-start")
|
||||
self._play_pause_button.props.image = new_icon
|
||||
self._videoarea.pause()
|
||||
|
||||
def get_state(self):
|
||||
|
@ -8,13 +8,19 @@ def new_button_with_icon(freedesktop_icon: str) -> Gtk.Button:
|
||||
return button
|
||||
|
||||
|
||||
def get_icon(freedesktop_icon: str) -> Gtk.Image:
|
||||
icon = Gtk.Image.new_from_icon_name(freedesktop_icon, Gtk.IconSize.BUTTON)
|
||||
return icon
|
||||
|
||||
|
||||
def new_radio_button_with_icon(freedesktop_icon: str,
|
||||
ref_widget=None) -> Gtk.RadioButton:
|
||||
if ref_widget is None:
|
||||
button = Gtk.RadioButton()
|
||||
else:
|
||||
button = Gtk.RadioButton.new_from_widget(ref_widget)
|
||||
icon = Gtk.Image.new_from_icon_name(freedesktop_icon, Gtk.IconSize.LARGE_TOOLBAR)
|
||||
icon = Gtk.Image.new_from_icon_name(
|
||||
freedesktop_icon, Gtk.IconSize.LARGE_TOOLBAR)
|
||||
button.props.image = icon
|
||||
return button
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user