From 745fe184be40ed091b99bf7c083abdfabe6fc88a Mon Sep 17 00:00:00 2001 From: Osmo Salomaa Date: Thu, 12 Mar 2020 21:23:25 +0200 Subject: [PATCH] Add action to set start from video position Closes #148 --- TODO.md | 1 + data/ui/menubar.ui | 4 ++++ gaupol/actions/edit.py | 11 +++++++++++ gaupol/agents/edit.py | 10 ++++++++++ 4 files changed, 26 insertions(+) diff --git a/TODO.md b/TODO.md index 138ab5a0..91cf0bab 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,5 @@ Gaupol 1.7.1/1.8 ================ +* [x] Add action set start from video position (#148) * [x] Add and fix English spell-check special cases diff --git a/data/ui/menubar.ui b/data/ui/menubar.ui index 7cbc1de8..e91f3a77 100644 --- a/data/ui/menubar.ui +++ b/data/ui/menubar.ui @@ -104,6 +104,10 @@ + + Set St_art From Video Position + win.set-start-from-video-position + Set En_d From Video Position win.set-end-from-video-position diff --git a/gaupol/actions/edit.py b/gaupol/actions/edit.py index 7ad592f8..063978d5 100644 --- a/gaupol/actions/edit.py +++ b/gaupol/actions/edit.py @@ -174,6 +174,17 @@ def _affirm_doable(self, application, page, selected_rows): aeidon.util.affirm(application.player.ready) aeidon.util.affirm(len(selected_rows) == 1) +class SetStartFromVideoPositionAction(gaupol.Action): + def __init__(self): + gaupol.Action.__init__(self, "set-start-from-video-position") + self.accelerators = ["U"] + self.action_group = "unsafe" + def _affirm_doable(self, application, page, selected_rows): + aeidon.util.affirm(page is not None) + aeidon.util.affirm(application.player is not None) + aeidon.util.affirm(application.player.ready) + aeidon.util.affirm(len(selected_rows) == 1) + class SplitSubtitleAction(gaupol.Action): def __init__(self): gaupol.Action.__init__(self, "split-subtitle") diff --git a/gaupol/agents/edit.py b/gaupol/agents/edit.py index f3f48d10..3c23c819 100644 --- a/gaupol/agents/edit.py +++ b/gaupol/agents/edit.py @@ -271,6 +271,16 @@ def _on_set_end_from_video_position_activate(self, *args): if pos is None: return page.project.set_end(row, pos) + @aeidon.deco.export + def _on_set_start_from_video_position_activate(self, *args): + """Set subtitle start from video position.""" + page = self.get_current_page() + mode = aeidon.modes.SECONDS + row = page.view.get_selected_rows()[0] + pos = self.player.get_position(mode) + if pos is None: return + page.project.set_start(row, pos) + @aeidon.deco.export def _on_split_subtitle_activate(self, *args): """Split the selected subtitle."""