Show overlay
This commit is contained in:
parent
561f68d221
commit
8508b13382
2 changed files with 43 additions and 0 deletions
lazy_player
|
@ -20,10 +20,29 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
list_store: Gtk.StringList
|
list_store: Gtk.StringList
|
||||||
video_widget: Gtk.Picture
|
video_widget: Gtk.Picture
|
||||||
pipeline: Gst.Pipeline
|
pipeline: Gst.Pipeline
|
||||||
|
overlay_tick_callback_id: int
|
||||||
|
overlay_label: Gtk.Label
|
||||||
|
overlay_hide_time: float
|
||||||
|
|
||||||
def __init__(self, *args: Any, **kwargs: Any):
|
def __init__(self, *args: Any, **kwargs: Any):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# For overlay text timeout
|
||||||
|
self.overlay_hide_time = 0.0
|
||||||
|
self.overlay_label = Gtk.Label()
|
||||||
|
self.overlay_label.set_name("overlay-text")
|
||||||
|
self.overlay_label.set_valign(Gtk.Align.CENTER)
|
||||||
|
self.overlay_label.set_halign(Gtk.Align.CENTER)
|
||||||
|
self.overlay_label.set_visible(False)
|
||||||
|
|
||||||
|
def update_overlay(widget: Gtk.Widget, frame_clock: Gdk.FrameClock, data: Any) -> bool:
|
||||||
|
current_time = frame_clock.get_frame_time() / 1_000_000
|
||||||
|
if current_time >= self.overlay_hide_time:
|
||||||
|
self.overlay_label.set_visible(False)
|
||||||
|
return True
|
||||||
|
|
||||||
|
self.overlay_tick_callback_id = self.add_tick_callback(update_overlay, None)
|
||||||
|
|
||||||
# Make window fullscreen and borderless
|
# Make window fullscreen and borderless
|
||||||
self.set_decorated(False)
|
self.set_decorated(False)
|
||||||
self.fullscreen()
|
self.fullscreen()
|
||||||
|
@ -51,6 +70,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
overlay_box.set_vexpand(True)
|
overlay_box.set_vexpand(True)
|
||||||
overlay_box.set_hexpand(True)
|
overlay_box.set_hexpand(True)
|
||||||
overlay_box.append(self.video_widget)
|
overlay_box.append(self.video_widget)
|
||||||
|
overlay_box.append(self.overlay_label)
|
||||||
|
|
||||||
# Setup GStreamer pipeline
|
# Setup GStreamer pipeline
|
||||||
self.pipeline = Gst.Pipeline.new("video-player")
|
self.pipeline = Gst.Pipeline.new("video-player")
|
||||||
|
@ -123,6 +143,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
playbin.set_property("uri", f"file://{os.path.abspath(string)}")
|
playbin.set_property("uri", f"file://{os.path.abspath(string)}")
|
||||||
self.pipeline.set_state(Gst.State.PLAYING)
|
self.pipeline.set_state(Gst.State.PLAYING)
|
||||||
self.stack.set_visible_child_name("overlay")
|
self.stack.set_visible_child_name("overlay")
|
||||||
|
self.show_overlay_text(string)
|
||||||
|
|
||||||
self.list_view.connect("activate", on_activate)
|
self.list_view.connect("activate", on_activate)
|
||||||
|
|
||||||
|
@ -243,6 +264,19 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, new_pos
|
Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, new_pos
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def show_overlay_text(self, text: str, timeout_seconds: float = 1.0) -> None:
|
||||||
|
"""Show text in a centered overlay that disappears after timeout"""
|
||||||
|
self.overlay_label.set_text(text)
|
||||||
|
self.overlay_label.set_visible(True)
|
||||||
|
|
||||||
|
# Set absolute time when overlay should hide
|
||||||
|
frame_clock = self.get_frame_clock()
|
||||||
|
if frame_clock is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
frame_time = frame_clock.get_frame_time() / 1_000_000 # Convert to seconds
|
||||||
|
self.overlay_hide_time = frame_time + timeout_seconds
|
||||||
|
|
||||||
def _populate_file_list(self) -> None:
|
def _populate_file_list(self) -> None:
|
||||||
# TODO: Implement proper version sort (strverscmp equivalent)
|
# TODO: Implement proper version sort (strverscmp equivalent)
|
||||||
|
|
||||||
|
|
|
@ -7,3 +7,12 @@ listview > row {
|
||||||
#black-overlay {
|
#black-overlay {
|
||||||
background-color: black;
|
background-color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#overlay-text {
|
||||||
|
color: white;
|
||||||
|
font-size: 48px;
|
||||||
|
font-family: monospace;
|
||||||
|
background-color: rgba(64, 64, 64, 0.25);
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue