Example #1
0
 def _on_paste_texts_activate(self, *args):
     """Paste texts from the clipboard."""
     page = self.get_current_page()
     text = self.x_clipboard.wait_for_text()
     if text:
         # Update all clipboards in case text is being
         # copied from the external clipboard.
         page.project.clipboard.set_string(text)
         self._sync_clipboards(page)
     if page.project.clipboard.is_empty(): return
     rows = page.view.get_selected_rows()
     row, col = page.view.get_focus()
     doc = page.text_column_to_document(col)
     length = len(page.project.subtitles)
     # Ensure that even if new subtitles need to be inserted,
     # focus and scroll position are not moved to the end.
     rect = page.view.get_visible_rect()
     window = page.view.get_bin_window()
     window.freeze_updates()
     rows = page.project.paste_texts(rows[0], doc)
     rows = page.view.get_selected_rows()
     page.view.set_focus(row, col)
     page.view.select_rows(rows)
     page.view.scroll_to_point(rect.x, rect.y)
     window.thaw_updates()
     count = len(page.project.subtitles) - length
     if count <= 0: return
     self.flash_message(
         n_("Inserted {:d} subtitle to fit clipboard contents",
            "Inserted {:d} subtitles to fit clipboard contents",
            count).format(count))
Example #2
0
    def _prepare_confirmation_page(self, doc, changes):
        """Present `changes` and activate confirmation page."""
        count = len(changes)
        title = n_("Confirm {:d} Change", "Confirm {:d} Changes",
                   count).format(count)

        self.set_page_title(self._confirmation_page, title)
        self._confirmation_page.application = self.application
        self._confirmation_page.doc = doc
        self._confirmation_page.populate_tree_view(changes)
        self.set_page_complete(self._progress_page, True)
Example #3
0
    def _prepare_confirmation_page(self, doc, changes):
        """Present `changes` and activate confirmation page."""
        count = len(changes)
        title = n_("Confirm {:d} Change",
                   "Confirm {:d} Changes",
                   count).format(count)

        self.set_page_title(self._confirmation_page, title)
        self._confirmation_page.application = self.application
        self._confirmation_page.doc = doc
        self._confirmation_page.populate_tree_view(changes)
        self.set_page_complete(self._progress_page, True)
Example #4
0
 def replace_all(self):
     """Replace all matches of pattern."""
     count = 0
     target = gaupol.conf.search.target
     for page in self.application.get_target_pages(target):
         self._set_pattern(page)
         self._set_replacement(page)
         try:
             count += page.project.replace_all()
         except re.error as error:
             self._show_regex_error_dialog_replacement(str(error))
             break
     self._reset_properties()
     self._statuslabel.flash_text(
         n_("Found and replaced {:d} occurence",
            "Found and replaced {:d} occurences", count).format(count))
Example #5
0
 def replace_all(self):
     """Replace all matches of pattern."""
     count = 0
     target = gaupol.conf.search.target
     for page in self.application.get_target_pages(target):
         self._set_pattern(page)
         self._set_replacement(page)
         try:
             count += page.project.replace_all()
         except re.error as error:
             self._show_regex_error_dialog_replacement(str(error))
             break
     self._reset_properties()
     self._statuslabel.flash_text(n_(
         "Found and replaced {:d} occurence",
         "Found and replaced {:d} occurences",
         count).format(count))
Example #6
0
 def _adjust_durations(self):
     """Adjust durations of subtitles."""
     conf = gaupol.conf.duration_adjust
     target = self._get_target()
     for page in self.application.get_target_pages(target):
         self.application.set_current_page(page)
         rows = page.project.adjust_durations(
             indices=self.application.get_target_rows(target),
             speed=conf.speed,
             lengthen=conf.lengthen,
             shorten=conf.shorten,
             maximum=(conf.maximum if conf.use_maximum else None),
             minimum=(conf.minimum if conf.use_minimum else None),
             gap=(conf.gap if conf.use_gap else None))
         self.application.flash_message(n_(
             "Adjusted duration of {:d} subtitle",
             "Adjusted durations of {:d} subtitles",
             len(rows)).format(len(rows)))
Example #7
0
File: edit.py Project: azmym/gaupol
 def _on_paste_texts_activate(self, *args):
     """Paste texts from the clipboard."""
     page = self.get_current_page()
     rows = page.view.get_selected_rows()
     row, col = page.view.get_focus()
     doc = page.text_column_to_document(col)
     length = len(page.project.subtitles)
     # Ensure that even if new subtitles need to be inserted,
     # focus and scroll position are not moved to the end.
     rect = page.view.get_visible_rect()
     window = page.view.get_bin_window()
     window.freeze_updates()
     rows = page.project.paste_texts(rows[0], doc)
     rows = page.view.get_selected_rows()
     page.view.set_focus(row, col)
     page.view.select_rows(rows)
     page.view.scroll_to_point(rect.x, rect.y)
     window.thaw_updates()
     count = len(page.project.subtitles) - length
     if count <= 0: return
     self.flash_message(n_(
         "Inserted {:d} subtitle to fit clipboard contents",
         "Inserted {:d} subtitles to fit clipboard contents",
         count).format(count))