def _on_new_project_activate(self, *args): """Create a new project.""" if gaupol.fields.TRAN_TEXT in gaupol.conf.editor.visible_fields: gaupol.conf.editor.visible_fields.remove(gaupol.fields.TRAN_TEXT) page = gaupol.Page(next(self.counter)) page.project.insert_subtitles((0, ), register=None) self.add_page(page)
def test__on_response__time_positive(self): page = gaupol.Page() page.project.open_main(self.new_subrip_file(), "ascii") self.application.add_page(page) self.dialog = gaupol.SplitDialog(self.application.window, self.application) self.dialog.show() self.dialog._subtitle_spin.set_value(5) self.dialog.response(Gtk.ResponseType.OK)
def _open_file(self, path, encodings, doc, check_open=True): """Open file at `path` and return corresponding page if successful.""" self._check_file_exists(path) if check_open: self._check_file_not_open(path) self._check_file_size(path) basename = os.path.basename(path) page = (gaupol.Page() if doc == aeidon.documents.MAIN else self.get_current_page()) for encoding in encodings: with aeidon.util.silent(UnicodeError): n = self._try_open_file(page, doc, path, encoding) self._check_sort_count(path, n) return page # Report if all codecs failed to decode file. self._show_encoding_error_dialog(basename) raise gaupol.Default
def _split_project(self): """Split the current project in two.""" gaupol.util.set_cursor_busy(self.application.window) index = self._subtitle_spin.get_value_as_int() - 1 src = self.application.get_current_page() dst = gaupol.Page(next(self.application.counter)) subtitles = [x.copy() for x in src.project.subtitles[index:]] indices = list(range(len(subtitles))) dst.project.insert_subtitles(indices, subtitles) dst.reload_view_all() self._remove_from_source(src, index) self._shift_destination(src, dst) self.application.add_page(dst) message = _('Split {amount:d} subtitles to project "{name}"').format( amount=len(dst.project.subtitles), name=dst.untitle) self.application.flash_message(message) gaupol.util.set_cursor_normal(self.application.window)
def _prepare_page(self): """Prepare page properties for speech recognition.""" if self._page is None: self._page = gaupol.Page(next(self.application.counter)) self.application.add_page(self._page) video_path = self._video_button.get_filename() self._page.project.video_path = video_path # Set project's main_file attribute to a SubRip file so that # previewing is possible wihtout a need to save the file. Set # the path to VIDEO.#.srt, so that the file can be easily saved # to the same directory, but without risk of overwriting anything. base = video_path[:video_path.rfind(".")] for i in itertools.count(1): path = "{}.{:d}.srt".format(base, i) if not os.path.isfile(path): break file = aeidon.files.new(aeidon.formats.SUBRIP, path, "utf_8") self._page.project.main_file = file self._page.project.main_changed = 1 if self._page.project.subtitles: indices = list(range(len(self._page.project.subtitles))) self._page.project.remove_subtitles(indices, register=None)
def new_page(self): """Return a new page with two open documents.""" page = gaupol.Page() page.project.open_main(self.new_subrip_file(), "ascii") page.project.open_translation(self.new_microdvd_file(), "ascii") return page
def _on_new_project_activate(self, *args): """Create a new project.""" page = gaupol.Page(next(self.counter)) page.project.insert_subtitles((0,), register=None) self.add_page(page)