scrub optimization
This commit is contained in:
@@ -144,54 +144,54 @@ class Timeline(GObject.Object):
|
||||
|
||||
|
||||
class TimelineControls(Gtk.Box):
|
||||
"""Slider + LIVE toggle. Scrub mode is always paused (seek-only, like a video editor).
|
||||
"""Scrub bar + time labels + LIVE toggle.
|
||||
|
||||
LIVE button is a toggle — active style when live=True.
|
||||
Slider is insensitive in live mode.
|
||||
The scrub bar shows segment blocks; labels and LIVE button sit below.
|
||||
"""
|
||||
|
||||
def __init__(self, timeline, **kwargs):
|
||||
super().__init__(orientation=Gtk.Orientation.HORIZONTAL, spacing=4, **kwargs)
|
||||
super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=2, **kwargs)
|
||||
self._timeline = timeline
|
||||
self._dragging = False
|
||||
|
||||
self.set_margin_start(4)
|
||||
self.set_margin_end(4)
|
||||
self.set_margin_top(2)
|
||||
self.set_margin_bottom(4)
|
||||
|
||||
# Current time label
|
||||
# Scrub bar (segment blocks)
|
||||
from cht.ui.scrub_bar import ScrubBar
|
||||
self._scrub_bar = ScrubBar()
|
||||
self.append(self._scrub_bar)
|
||||
|
||||
# Bottom row: time label + duration + LIVE button
|
||||
bottom = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=4)
|
||||
|
||||
self._time_label = Gtk.Label(label="00:00")
|
||||
self._time_label.set_width_chars(6)
|
||||
self.append(self._time_label)
|
||||
bottom.append(self._time_label)
|
||||
|
||||
# Slider — disabled in live mode, scrub-seeks on release
|
||||
self._slider = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
self._slider.set_hexpand(True)
|
||||
self._slider.set_range(0, 1)
|
||||
self._slider.set_draw_value(False)
|
||||
self._slider.connect("value-changed", self._on_slider_value_changed)
|
||||
spacer = Gtk.Box()
|
||||
spacer.set_hexpand(True)
|
||||
bottom.append(spacer)
|
||||
|
||||
press_ctrl = Gtk.GestureClick()
|
||||
press_ctrl.connect("pressed", self._on_slider_pressed)
|
||||
press_ctrl.connect("released", self._on_slider_released)
|
||||
press_ctrl.set_propagation_phase(Gtk.PropagationPhase.CAPTURE)
|
||||
self._slider.add_controller(press_ctrl)
|
||||
self.append(self._slider)
|
||||
|
||||
# Duration label
|
||||
self._duration_label = Gtk.Label(label="00:00 / 00:00")
|
||||
self._duration_label.set_width_chars(14)
|
||||
self.append(self._duration_label)
|
||||
bottom.append(self._duration_label)
|
||||
|
||||
# LIVE toggle button
|
||||
self._live_btn = Gtk.Button(label="LIVE")
|
||||
self._live_btn.connect("clicked", self._on_live_clicked)
|
||||
self.append(self._live_btn)
|
||||
bottom.append(self._live_btn)
|
||||
|
||||
self.append(bottom)
|
||||
|
||||
timeline.connect("changed", self._on_changed)
|
||||
GLib.timeout_add(1000, self._tick_total)
|
||||
|
||||
@property
|
||||
def scrub_bar(self):
|
||||
"""Access the ScrubBar widget for signal connections."""
|
||||
return self._scrub_bar
|
||||
|
||||
def set_live_toggle_callback(self, cb):
|
||||
"""Override the LIVE button handler."""
|
||||
self._live_toggle_cb = cb
|
||||
@@ -202,32 +202,16 @@ class TimelineControls(Gtk.Box):
|
||||
else:
|
||||
self._timeline.toggle_live()
|
||||
|
||||
def _on_slider_value_changed(self, slider):
|
||||
if self._dragging:
|
||||
self._time_label.set_text(self._fmt_time(slider.get_value()))
|
||||
|
||||
def _on_slider_pressed(self, gesture, n_press, x, y):
|
||||
self._dragging = True
|
||||
|
||||
def _on_slider_released(self, gesture, n_press, x, y):
|
||||
if self._dragging:
|
||||
self._dragging = False
|
||||
self._timeline.seek(self._slider.get_value())
|
||||
|
||||
def _on_changed(self, timeline):
|
||||
s = timeline.state
|
||||
|
||||
self._slider.set_sensitive(not s.live)
|
||||
|
||||
if s.live:
|
||||
self._live_btn.add_css_class("suggested-action")
|
||||
else:
|
||||
self._live_btn.remove_css_class("suggested-action")
|
||||
|
||||
if not self._dragging:
|
||||
self._slider.set_range(0, max(s.duration, 0.1))
|
||||
self._slider.set_value(s.cursor)
|
||||
|
||||
self._scrub_bar.set_cursor(s.cursor)
|
||||
self._scrub_bar.set_scene_markers(s.scene_markers)
|
||||
self._time_label.set_text(self._fmt_time(s.cursor))
|
||||
self._update_duration_label()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user