def test_get_middle__frame(self): for x, y, z in ((300, 400, 350), (300, 401, 350), (-300, -400, -350), (-300, 401, 50)): x = aeidon.as_frame(x) y = aeidon.as_frame(y) assert self.calc.get_middle(x, y) == z
def _output_edited(self): """Return ``True`` if output of either point has been edited.""" in_1 = aeidon.as_frame(self._input_entry_1.get_text()) in_2 = aeidon.as_frame(self._input_entry_2.get_text()) out_1 = aeidon.as_frame(self._output_spin_1.get_value_as_int()) out_2 = aeidon.as_frame(self._output_spin_2.get_value_as_int()) return (out_1 != in_1 or out_2 != in_2)
def test_get_middle__frame(self): for x, y, z in (( 300, 400, 350), ( 300, 401, 350), (-300, -400, -350), (-300, 401, 50)): x = aeidon.as_frame(x) y = aeidon.as_frame(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 _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 _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_frame(self, value): """Set duration from `value`.""" self.duration = aeidon.as_frame(value)
def end_frame(self, value): """Set end position from `value`.""" self.end = aeidon.as_frame(value)
def _get_second_point(self): """Return row, output frame of the second sync point.""" return (self._subtitle_spin_2.get_value_as_int() - 1, aeidon.as_frame(self._output_spin_2.get_value_as_int()))
def _get_first_point(self): """Return row, output frame of the first sync point.""" return (self._subtitle_spin_1.get_value_as_int() - 1, aeidon.as_frame(self._output_spin_1.get_value_as_int()))
def test_is_earlier__frame(self): a = aeidon.as_frame(1) b = aeidon.as_frame(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 start_frame(self, value): """Set start position from `value`.""" self.start = aeidon.as_frame(value)
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 _get_amount(self): """Return the amount of frames to shift.""" return aeidon.as_frame(self._amount_spin.get_value_as_int())
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_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