def test_get_middle__seconds(self): for x, y, z in ((300, 400, 350.0), (300, 401, 350.5), (-300, -400, -350.0), (-300, 401, 50.5)): x = aeidon.as_seconds(x) y = aeidon.as_seconds(y) assert self.calc.get_middle(x, y) == z
def test_get_middle__seconds(self): for x, y, z in (( 300, 400, 350.0), ( 300, 401, 350.5), (-300, -400, -350.0), (-300, 401, 50.5)): x = aeidon.as_seconds(x) y = aeidon.as_seconds(y) assert self.calc.get_middle(x, y) == z
def scale_positions(self, value): """Multiply start and end positions by `value`.""" if self._mode == aeidon.modes.TIME: start = self.start_seconds * value end = self.end_seconds * value self.start = aeidon.as_seconds(start) self.end = aeidon.as_seconds(end) if self._mode == aeidon.modes.FRAME: start = round(self._start * value, 0) end = round(self._end * value, 0) self.start = aeidon.as_frame(start) self.end = aeidon.as_frame(end)
def convert_framerate(self, framerate): """Set framerate and convert positions to it.""" coefficient = framerate.value / self._framerate.value if self._mode == aeidon.modes.TIME: start = self.start_seconds / coefficient end = self.end_seconds / coefficient self.start = aeidon.as_seconds(start) self.end = aeidon.as_seconds(end) if self._mode == aeidon.modes.FRAME: start = round(coefficient * self.start_frame, 0) end = round(coefficient * self.end_frame, 0) self.start = aeidon.as_frame(start) self.end = aeidon.as_frame(end) self.framerate = framerate
def _append_subtitle(self, index): """Create subtitle from `index` and append to page.""" if index < 0: index += len(self._starts) advance = gaupol.conf.speech_recognition.advance_length advance = aeidon.as_seconds(advance / 1000) # ms to s subtitle = aeidon.Subtitle(mode=aeidon.modes.TIME) start = self._starts[index] - advance start = max(start, self._stops[index - 1] if index > 0 else 0.0) subtitle.start = aeidon.as_seconds(start) subtitle.end = aeidon.as_seconds(self._stops[index]) subtitle.main_text = self._texts[index] or ("[{:d}]".format(index + 1)) indices = (len(self._page.project.subtitles), ) self._page.project.insert_subtitles(indices, (subtitle, ), register=None)
def _on_view_renderer_edited(self, renderer, path, value, column): """Save changes made while editing cell.""" self._set_unsafe_enabled(True) self.show_message(None) page = self.get_current_page() row = gaupol.util.tree_path_to_row(path) col = page.view.get_columns().index(column) if page.view.is_position_column(col): if not value: return if page.edit_mode == aeidon.modes.FRAME: with aeidon.util.silent(ValueError): value = aeidon.as_frame(value) if col == page.view.columns.START: return page.project.set_start(row, value) if col == page.view.columns.END: return page.project.set_end(row, value) if col == page.view.columns.DURATION: if page.edit_mode == aeidon.modes.TIME: value = value.replace(",", ".") with aeidon.util.silent(ValueError): value = aeidon.as_seconds(value) return page.project.set_duration(row, value) doc = page.text_column_to_document(col) page.project.set_text(row, doc, value) self.update_gui()
def _append_subtitle(self, index): """Create subtitle from `index` and append to page.""" if index < 0: index += len(self._starts) advance = gaupol.conf.speech_recognition.advance_length advance = aeidon.as_seconds(advance/1000) # ms to s subtitle = aeidon.Subtitle(mode=aeidon.modes.TIME) start = self._starts[index] - advance start = max(start, self._stops[index-1] if index > 0 else 0.0) subtitle.start = aeidon.as_seconds(start) subtitle.end = aeidon.as_seconds(self._stops[index]) subtitle.main_text = self._texts[index] or ("[{:d}]".format(index+1)) indices = (len(self._page.project.subtitles),) self._page.project.insert_subtitles(indices, (subtitle,), register=None)
def _on_view_renderer_edited(self, renderer, path, value, column): """Save changes made while editing cell.""" self._set_unsafe_sensitivities(True) self.show_message(None) page = self.get_current_page() row = gaupol.util.tree_path_to_row(path) col = page.view.get_columns().index(column) if page.view.is_position_column(col): if not value: return if page.edit_mode == aeidon.modes.FRAME: try: value = aeidon.as_frame(value) except ValueError: return if col == page.view.columns.START: return page.project.set_start(row, value) if col == page.view.columns.END: return page.project.set_end(row, value) if col == page.view.columns.DURATION: if page.edit_mode == aeidon.modes.TIME: value = value.replace(",", ".") try: value = aeidon.as_seconds(value) except ValueError: return return page.project.set_duration(row, value) doc = page.text_column_to_document(col) page.project.set_text(row, doc, value)
def get_middle(self, x, y): """Return time, frame or seconds halfway between `x` and `y`.""" if aeidon.is_time(x): x = self.time_to_seconds(x) y = self.to_seconds(y) return self.seconds_to_time((x + y) / 2) if aeidon.is_frame(x): y = self.to_frame(y) return aeidon.as_frame(round((x + y) / 2, 0)) if aeidon.is_seconds(x): y = self.to_seconds(y) return aeidon.as_seconds(((x + y) / 2)) raise ValueError("Invalid type for x: {}".format(repr(type(x))))
def get_middle(self, x, y): """Return time, frame or seconds halfway between `x` and `y`.""" if aeidon.is_time(x): x = self.time_to_seconds(x) y = self.to_seconds(y) return self.seconds_to_time((x+y)/2) if aeidon.is_frame(x): y = self.to_frame(y) return aeidon.as_frame(round((x+y)/2, 0)) if aeidon.is_seconds(x): y = self.to_seconds(y) return aeidon.as_seconds(((x+y)/2)) raise ValueError("Invalid type for x: {}" .format(repr(type(x))))
def round(self, pos, ndigits): """ Round `pos` to given precision in decimal digits. `ndigits` may be negative. For frames zero will be used if given `ndigits` is greater than zero. """ if aeidon.is_time(pos): pos = self.time_to_seconds(pos) pos = round(pos, ndigits) return self.seconds_to_time(pos) if aeidon.is_frame(pos): ndigits = min(0, ndigits) pos = round(pos, ndigits) return aeidon.as_frame(pos) if aeidon.is_seconds(pos): pos = round(pos, ndigits) return aeidon.as_seconds(pos) raise ValueError("Invalid type for pos: {}".format(repr(type(pos))))
def round(self, pos, ndigits): """ Round `pos` to given precision in decimal digits. `ndigits` may be negative. For frames zero will be used if given `ndigits` is greater than zero. """ if aeidon.is_time(pos): pos = self.time_to_seconds(pos) pos = round(pos, ndigits) return self.seconds_to_time(pos) if aeidon.is_frame(pos): ndigits = min(0, ndigits) pos = round(pos, ndigits) return aeidon.as_frame(pos) if aeidon.is_seconds(pos): pos = round(pos, ndigits) return aeidon.as_seconds(pos) raise ValueError("Invalid type for pos: {}" .format(repr(type(pos))))
def get_middle(self, x, y): """ Return time, frame or seconds halfway between `x` and `y`. >>> calc = aeidon.Calculator() >>> calc.get_middle(0, 100) 50 >>> calc.get_middle("00:00:00.000", "00:00:10.000") '00:00:05.000' """ if aeidon.is_time(x): x = self.time_to_seconds(x) y = self.to_seconds(y) return self.seconds_to_time((x + y) / 2) if aeidon.is_frame(x): y = self.to_frame(y) return aeidon.as_frame(round((x + y) / 2, 0)) if aeidon.is_seconds(x): y = self.to_seconds(y) return aeidon.as_seconds(((x + y) / 2)) raise ValueError("Invalid type for x: {}".format(repr(type(x))))
def get_middle(self, x, y): """ Return time, frame or seconds halfway between `x` and `y`. >>> calc = aeidon.Calculator() >>> calc.get_middle(0, 100) 50 >>> calc.get_middle("00:00:00.000", "00:00:10.000") '00:00:05.000' """ if aeidon.is_time(x): x = self.time_to_seconds(x) y = self.to_seconds(y) return self.seconds_to_time((x+y)/2) if aeidon.is_frame(x): y = self.to_frame(y) return aeidon.as_frame(round((x+y)/2, 0)) if aeidon.is_seconds(x): y = self.to_seconds(y) return aeidon.as_seconds(((x+y)/2)) raise ValueError("Invalid type for x: {}" .format(repr(type(x))))
def duration_seconds(self, value): """Set duration from `value`.""" self.duration = aeidon.as_seconds(value)
def frame_to_seconds(self, frame): """Convert `frame` to seconds.""" return aeidon.as_seconds(frame / self._framerate)
def test_is_time(self): assert aeidon.is_time(aeidon.as_time("12:34:56.789")) assert not aeidon.is_time(aeidon.as_frame(13)) assert not aeidon.is_time(aeidon.as_seconds(13))
def test_is_earlier__seconds(self): a = aeidon.as_seconds(1) b = aeidon.as_seconds(2) assert self.calc.is_earlier(a, b) assert not self.calc.is_earlier(a, a) assert not self.calc.is_earlier(b, a)
def end_seconds(self, value): """Set end position from `value`.""" self.end = aeidon.as_seconds(value)
def test_to_time(self): self.calc = aeidon.Calculator(aeidon.framerates.FPS_25_000) time = "00:00:01.000" assert self.calc.to_time(aeidon.as_time(time)) == time assert self.calc.to_time(aeidon.as_frame(25)) == time assert self.calc.to_time(aeidon.as_seconds(1.0)) == time
def test_to_seconds(self): self.calc = aeidon.Calculator(aeidon.framerates.FPS_25_000) assert self.calc.to_seconds(aeidon.as_time("00:00:01.000")) == 1.0 assert self.calc.to_seconds(aeidon.as_frame(25)) == 1.0 assert self.calc.to_seconds(aeidon.as_seconds(1.0)) == 1.0
def start_seconds(self, value): """Set start position from `value`.""" self.start = aeidon.as_seconds(value)
def _get_amount(self): """Return the amount of seconds to shift.""" return aeidon.as_seconds(self._amount_spin.get_value())