Пример #1
0
    def _init_tree_view(self):
        """Initialize the character encoding tree view."""
        scroller = Gtk.ScrolledWindow()
        scroller.set_policy(*((Gtk.PolicyType.AUTOMATIC,)*2))
        scroller.set_shadow_type(Gtk.ShadowType.NONE)
        scroller.add(self._tree_view)
        box = self.get_content_area()
        gaupol.util.pack_start_expand(box, scroller)
        box.show_all()
        selection = self._tree_view.get_selection()
        selection.set_mode(Gtk.SelectionMode.SINGLE)
        store = Gtk.ListStore(str, str, str)
        for item in aeidon.encodings.get_valid():
            store.append((item[0], item[2], item[1]))
        store.set_sort_column_id(1, Gtk.SortType.ASCENDING)
        self._tree_view.set_model(store)
        column = Gtk.TreeViewColumn(_("Description"),
                                    Gtk.CellRendererText(),
                                    text=1)

        column.set_clickable(True)
        column.set_sort_column_id(1)
        self._tree_view.append_column(column)
        column = Gtk.TreeViewColumn(_("Encoding"),
                                    Gtk.CellRendererText(),
                                    text=2)

        column.set_clickable(True)
        column.set_sort_column_id(2)
        self._tree_view.append_column(column)
        aeidon.util.connect(self, "_tree_view", "row-activated")
Пример #2
0
 def _init_dialog(self, parent):
     """Initialize the dialog."""
     self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
     self.add_button(_("_Shift"), Gtk.ResponseType.OK)
     self.set_default_response(Gtk.ResponseType.OK)
     self.set_transient_for(parent)
     self.set_modal(True)
Пример #3
0
 def _on_load_video_activate(self, *args):
     """Load a video file."""
     gaupol.util.set_cursor_busy(self.window)
     page = self.get_current_page()
     dialog = gaupol.VideoDialog(
         self.window, title=_("Load Video"), button_label=_("_Load"))
     if page.project.main_file is not None:
         directory = os.path.dirname(page.project.main_file.path)
         dialog.set_current_folder(directory)
     if page.project.video_path is not None:
         dialog.set_filename(page.project.video_path)
     gaupol.util.set_cursor_normal(self.window)
     response = gaupol.util.run_dialog(dialog)
     path = dialog.get_filename()
     dialog.destroy()
     if response != Gtk.ResponseType.OK: return
     page.project.video_path = path
     if self.player is None:
         self._init_player_widgets()
         self._init_cache_updates()
         self._init_update_handlers()
         self._update_subtitle_cache()
     else: # Player exists
         if self.player.is_playing():
             self.get_action("play-pause").activate()
         adjustment = self.seekbar.get_adjustment()
         adjustment.set_value(0)
         self.player.stop()
     self.player.set_path(path)
     # Playback initialization can fail, e.g. due to missing codecs,
     # in which case the player itself has shown an error dialog.
     if not self.player.ready: return
     self._update_languages_menu()
     self.update_gui()
     self.player.play()
Пример #4
0
 def _show_io_error_dialog(self, message):
     """Show an error dialog after failing to write file."""
     title = _('Failed to save subtitle file to temporary directory "{}"').format(tempfile.gettempdir())
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #5
0
    def _init_tree_view(self):
        """Initialize the character encoding tree view."""
        scroller = Gtk.ScrolledWindow()
        scroller.set_policy(*((Gtk.PolicyType.AUTOMATIC, ) * 2))
        scroller.set_shadow_type(Gtk.ShadowType.NONE)
        scroller.add(self._tree_view)
        box = self.get_content_area()
        gaupol.util.pack_start_expand(box, scroller)
        box.show_all()
        selection = self._tree_view.get_selection()
        selection.set_mode(Gtk.SelectionMode.SINGLE)
        store = Gtk.ListStore(str, str, str)
        for item in aeidon.encodings.get_valid():
            store.append((item[0], item[2], item[1]))
        store.set_sort_column_id(1, Gtk.SortType.ASCENDING)
        self._tree_view.set_model(store)
        column = Gtk.TreeViewColumn(_("Description"),
                                    Gtk.CellRendererText(),
                                    text=1)

        column.set_clickable(True)
        column.set_sort_column_id(1)
        self._tree_view.append_column(column)
        column = Gtk.TreeViewColumn(_("Encoding"),
                                    Gtk.CellRendererText(),
                                    text=2)

        column.set_clickable(True)
        column.set_sort_column_id(2)
        self._tree_view.append_column(column)
        aeidon.util.connect(self, "_tree_view", "row-activated")
Пример #6
0
class FieldDuration(aeidon.EnumerationItem):
    is_position = True
    is_text = False
    # TRANSLATORS: 'Dur.' is short for duration. It is used in the header
    # of a tree view column that contains numbers five characters wide.
    label = _("Dur.")
    tooltip = _("Duration")
Пример #7
0
    def replace_all(self, register=-1):
        """
        Replace all matches of pattern and return amount of replacements made.

        Raise :exc:`re.error` if bad replacement.
        """
        counts = {}
        for doc in self._docs:
            counts[doc] = 0
            new_indices = []
            new_texts = []
            for index, subtitle in enumerate(self.subtitles):
                text = subtitle.get_text(doc)
                self._finder.set_text(text)
                sub_count = self._finder.replace_all()
                if sub_count > 0:
                    new_indices.append(index)
                    new_texts.append(self._finder.text)
                    counts[doc] += sub_count
            if not new_indices: continue
            self.replace_texts(new_indices,
                               doc,
                               new_texts,
                               register=register)

            self.set_action_description(register, _("Replacing all"))
        if (len(list(counts.keys())) == 2) and all(counts.values()):
            self.group_actions(register, 2, _("Replacing all"))
        return sum(counts.values())
Пример #8
0
 def _show_process_error_dialog(self, message):
     """Show an error dialog after failing to launch video player."""
     title = _("Failed to launch video player")
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #9
0
 def _show_io_error_dialog(self, basename, message):
     """Show an error dialog after failing to write file."""
     title = _('Failed to save file "{}"').format(basename)
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #10
0
 def _show_regex_error_dialog_pattern(self, message):
     """Show an error dialog if regex pattern failed to compile."""
     title = _("Error in regular expression pattern")
     dialog = gaupol.ErrorDialog(self._dialog, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #11
0
 def _populate_encoding_combo(self, custom=None):
     """Populate the encoding combo box, including custom encoding."""
     encodings = list(gaupol.conf.encoding.visible)
     locale = aeidon.encodings.get_locale_code()
     encodings.insert(0, locale)
     encodings.append(custom)
     while None in encodings:
         encodings.remove(None)
     encodings = aeidon.util.get_unique(encodings)
     encodings = encodings or ["utf_8"]
     for i, encoding in enumerate(encodings):
         name = aeidon.encodings.code_to_long_name(encoding)
         encodings[i] = (encoding, name)
     if locale is not None:
         name = aeidon.encodings.get_locale_long_name()
         encodings[0] = (locale, name)
     a = (0 if locale is None else 1)
     encodings[a:] = sorted(encodings[a:], key=lambda x: x[1])
     separator = gaupol.COMBO_SEPARATOR
     if self._use_autodetection:
         encodings.append((separator, separator))
         encodings.append(("auto", _("Auto-detected")))
     encodings.append((separator, separator))
     encodings.append(("other", _("Other…")))
     self._encoding_combo.get_model().clear()
     store = self._encoding_combo.get_model()
     for encoding in encodings:
         store.append(tuple(encoding))
Пример #12
0
    def replace_all(self, register=-1):
        """
        Replace all matches of pattern and return amount of replacements made.

        Raise :exc:`re.error` if bad replacement.
        """
        counts = {}
        for doc in self._docs:
            counts[doc] = 0
            new_indices = []
            new_texts = []
            for index, subtitle in enumerate(self.subtitles):
                text = subtitle.get_text(doc)
                self._finder.set_text(text)
                sub_count = self._finder.replace_all()
                if sub_count > 0:
                    new_indices.append(index)
                    new_texts.append(self._finder.text)
                    counts[doc] += sub_count
            if not new_indices: continue
            self.replace_texts(new_indices, doc, new_texts, register=register)

            self.set_action_description(register, _("Replacing all"))
        if len(list(counts.keys())) == 2 and all(counts.values()):
            self.group_actions(register, 2, _("Replacing all"))
        return sum(counts.values())
Пример #13
0
 def _init_filters(self):
     """Initialize file filters."""
     file_filter = Gtk.FileFilter()
     file_filter.set_name(_("All files"))
     file_filter.add_pattern("*")
     self.add_filter(file_filter)
     file_filter = Gtk.FileFilter()
     file_filter.set_name(_("All supported files"))
     for format in aeidon.formats:
         pattern = "*."
         for x in format.extension[1:]:
             pattern += "[{}{}]".format(x.upper(), x.lower())
         file_filter.add_pattern(pattern)
     self.add_filter(file_filter)
     self.set_filter(file_filter)
     for format in aeidon.formats:
         extension = format.extension
         pattern = "*."
         for x in extension[1:]:
             pattern += "[{}{}]".format(x.upper(), x.lower())
         format = format.label
         name = _("{format} (*{extension})").format(**locals())
         file_filter = Gtk.FileFilter()
         file_filter.set_name(name)
         file_filter.add_pattern(pattern)
         self.add_filter(file_filter)
Пример #14
0
 def _show_regex_error_dialog_replacement(self, message):
     """Show an error dialog if regex replacement is invalid."""
     title = _("Error in regular expression replacement")
     dialog = gaupol.ErrorDialog(self._dialog, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #15
0
 def _show_regex_error_dialog_pattern(self, message):
     """Show an error dialog if regex pattern failed to compile."""
     title = _("Error in regular expression pattern")
     dialog = gaupol.ErrorDialog(self._dialog, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #16
0
 def __init__(self, parent):
     """Initialize an :class:`AboutDialog` instance."""
     GObject.GObject.__init__(self)
     self.set_title(_("About Gaupol"))
     self.set_transient_for(parent)
     self.set_artists(("Osmo Salomaa <*****@*****.**>", ))
     self.set_authors(("Osmo Salomaa <*****@*****.**>", ))
     self.set_comments(_("Subtitle editor"))
     self.set_copyright("Copyright © 2005-2017 Osmo Salomaa")
     self.set_license_type(Gtk.License.GPL_3_0)
     self.set_logo_icon_name("gaupol")
     self.set_program_name("Gaupol")
     # TRANSLATORS: This is a special message that shouldn't be translated
     # literally. It is used in the about dialog to give credits to the
     # translators. Thus, you should translate it to your name and email
     # address. You can also include other translators who have contributed
     # to this translation; in that case, please write them on separate
     # lines seperated by newlines (\n).
     self.set_translator_credits(_("translator-credits"))
     self.set_version(gaupol.__version__)
     self.set_website(gaupol.HOMEPAGE_URL)
     self.set_website_label(_("Gaupol Website"))
     self.set_wrap_license(True)
     with aeidon.util.silent(Exception, tb=True):
         # Add donate button to the bottom of the dialog.
         # This can fail if the dialog structure changes.
         box = self.get_content_area()
         button = Gtk.LinkButton(label=_("Donate"))
         button.set_uri("https://www.paypal.me/otsaloma")
         button.show()
         box.pack_start(button, expand=False, fill=False, padding=0)
         switcher = self.get_header_bar().get_children()[0]
         switcher.get_children()[0].grab_focus()
Пример #17
0
 def _show_regex_error_dialog_replacement(self, message):
     """Show an error dialog if regex replacement is invalid."""
     title = _("Error in regular expression replacement")
     dialog = gaupol.ErrorDialog(self._dialog, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #18
0
 def _init_filters(self):
     """Initialize file filters."""
     file_filter = Gtk.FileFilter()
     file_filter.set_name(_("All files"))
     file_filter.add_pattern("*")
     self.add_filter(file_filter)
     file_filter = Gtk.FileFilter()
     file_filter.set_name(_("All supported files"))
     for format in aeidon.formats:
         pattern = "*."
         for x in format.extension[1:]:
             pattern += "[{}{}]".format(x.upper(), x.lower())
         file_filter.add_pattern(pattern)
     self.add_filter(file_filter)
     self.set_filter(file_filter)
     for format in aeidon.formats:
         extension = format.extension
         pattern = "*."
         for x in extension[1:]:
             pattern += "[{}{}]".format(x.upper(), x.lower())
         format = format.label
         name = _("{format} (*{extension})").format(**locals())
         file_filter = Gtk.FileFilter()
         file_filter.set_name(name)
         file_filter.add_pattern(pattern)
         self.add_filter(file_filter)
Пример #19
0
 def set_uri(self, uri):
     """Set the URI of the file to play."""
     self.ready = False
     self._playbin.props.uri = uri
     # XXX: On Windows, we'd need HWND instead of XID,
     # but there seems to be no clear way to do this.
     # http://stackoverflow.com/q/23021327/653825
     self._xid = self.widget.get_window().get_xid()
     self.subtitle_text = ""
     try:
         # Find out the exact framerate to be able
         # to convert between position types.
         from gi.repository import GstPbutils
         discoverer = GstPbutils.Discoverer()
         self._info = discoverer.discover_uri(uri)
         stream = self._info.get_video_streams()[0]
         num = float(stream.get_framerate_num())
         denom = float(stream.get_framerate_denom())
         self.calc = aeidon.Calculator(num/denom)
         self.ready = True
     except Exception as error:
         title = _("Failed to initialize playback")
         dialog = gaupol.ErrorDialog(None, title, str(error))
         dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
         dialog.set_default_response(Gtk.ResponseType.OK)
         gaupol.util.flash_dialog(dialog)
Пример #20
0
 def _show_io_error_dialog(self, basename, message):
     """Show an error dialog after failing to write file."""
     title = _('Failed to save file "{}"').format(basename)
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #21
0
 def _populate_encoding_combo(self, custom=None):
     """Populate the encoding combo box, including custom encoding."""
     encodings = list(gaupol.conf.encoding.visible)
     locale = aeidon.encodings.get_locale_code()
     encodings.insert(0, locale)
     encodings.append(custom)
     while None in encodings:
         encodings.remove(None)
     encodings = aeidon.util.get_unique(encodings)
     encodings = encodings or ["utf_8"]
     for i, encoding in enumerate(encodings):
         name = aeidon.encodings.code_to_long_name(encoding)
         encodings[i] = (encoding, name)
     if locale is not None:
         name = aeidon.encodings.get_locale_long_name()
         encodings[0] = (locale, name)
     a = (0 if locale is None else 1)
     encodings[a:] = sorted(encodings[a:], key=lambda x: x[1])
     separator = gaupol.COMBO_SEPARATOR
     if self._use_autodetection:
         encodings.append((separator, separator))
         encodings.append(("auto", _("Auto-detected")))
     encodings.append((separator, separator))
     encodings.append(("other", _("Other…")))
     self._encoding_combo.get_model().clear()
     store = self._encoding_combo.get_model()
     for encoding in encodings:
         store.append(tuple(encoding))
Пример #22
0
 def set_uri(self, uri):
     """Set the URI of the file to play."""
     self.ready = False
     self._playbin.props.uri = uri
     self.subtitle_text = ""
     try:
         # Find out the exact framerate to be able
         # to convert between position types.
         from gi.repository import GstPbutils
         discoverer = GstPbutils.Discoverer()
         self._info = discoverer.discover_uri(uri)
         streams = self._info.get_stream_list()
         stream_types = [x.get_stream_type_nick() for x in streams]
         if "video" not in stream_types:
             raise Exception(_("No video streams found"))
         stream = self._info.get_video_streams()[0]
         num = float(stream.get_framerate_num())
         denom = float(stream.get_framerate_denom())
         self.calc = aeidon.Calculator(num/denom)
         self.ready = True
     except Exception as error:
         title = _("Failed to initialize playback")
         dialog = gaupol.ErrorDialog(None, title, str(error))
         dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
         dialog.set_default_response(Gtk.ResponseType.OK)
         gaupol.util.flash_dialog(dialog)
     else:
         # Make stream tags available from _playbin
         self._playbin.set_state(Gst.State.PAUSED)
         self._playbin.get_state(Gst.CLOCK_TIME_NONE)
Пример #23
0
 def _show_process_error_dialog(self, message):
     """Show an error dialog after failing to launch video player."""
     title = _("Failed to launch video player")
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #24
0
 def _on_apply(self, *args):
     """Apply accepted changes to projects."""
     gaupol.util.set_cursor_busy(self)
     edits = removals = 0
     changes = self._confirmation_page.get_confirmed_changes()
     changed_pages = aeidon.util.get_unique([x[0] for x in changes])
     field = self._introduction_page.get_field()
     doc = gaupol.util.text_field_to_document(field)
     description = _("Correcting texts")
     register = aeidon.registers.DO
     for page in changed_pages:
         indices = [x[1] for x in changes if x[0] is page]
         texts = [x[3] for x in changes if x[0] is page]
         if indices and texts:
             page.project.replace_texts(indices, doc, texts)
             page.project.set_action_description(register, description)
             edits += len(indices)
         indices = [x for i, x in enumerate(indices) if not texts[i]]
         if indices and gaupol.conf.text_assistant.remove_blank:
             page.project.remove_subtitles(indices)
             page.project.group_actions(register, 2, description)
             removals += len(indices)
         page.view.columns_autosize()
     edits = edits - removals
     message = _("Edited {edits:d} and removed {removals:d} subtitles")
     self.application.flash_message(message.format(**locals()))
     gaupol.util.set_cursor_normal(self)
Пример #25
0
 def _init_dialog(self, parent):
     """Initialize the dialog."""
     self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
     self.add_button(_("_Split"), Gtk.ResponseType.OK)
     self.set_default_response(Gtk.ResponseType.OK)
     self.set_transient_for(parent)
     self.set_modal(True)
Пример #26
0
 def set_uri(self, uri):
     """Set the URI of the file to play."""
     self.ready = False
     self._playbin.props.uri = uri
     # XXX: On Windows, we'd need HWND instead of XID,
     # but there seems to be no clear way to do this.
     # http://stackoverflow.com/q/23021327/653825
     self._xid = self.widget.get_window().get_xid()
     self.subtitle_text = ""
     try:
         # Find out the exact framerate to be able
         # to convert between position types.
         from gi.repository import GstPbutils
         discoverer = GstPbutils.Discoverer()
         self._info = discoverer.discover_uri(uri)
         stream = self._info.get_video_streams()[0]
         num = float(stream.get_framerate_num())
         denom = float(stream.get_framerate_denom())
         self.calc = aeidon.Calculator(num / denom)
         self.ready = True
     except Exception as error:
         title = _("Failed to initialize playback")
         dialog = gaupol.ErrorDialog(None, title, str(error))
         dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
         dialog.set_default_response(Gtk.ResponseType.OK)
         gaupol.util.flash_dialog(dialog)
Пример #27
0
 def _show_encoding_error_dialog(self):
     """Show an error dialog after failing to encode file."""
     title = _('Failed to encode subtitle file to temporary directory "{}"').format(tempfile.gettempdir())
     message = _("Subtitle data could not be encoded to a temporary file for preview with the current character encoding. Please first save the subtitle file with a different character encoding.")
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #28
0
 def _init_dialog(self):
     """Initialize the dialog."""
     self.add_button(_("_Report Bug"), Gtk.ResponseType.HELP)
     self.add_button(_("_Quit"), Gtk.ResponseType.NO)
     self.add_button(_("_Close"), Gtk.ResponseType.CLOSE)
     self.set_default_response(Gtk.ResponseType.CLOSE)
     self.set_modal(True)
     aeidon.util.connect(self, self, "response")
Пример #29
0
 def _show_error_dialog(self, message):
     """Show an error dialog after failing to load dictionary."""
     title = _('Failed to load dictionary for language "{}"')
     title = title.format(self._language_name)
     dialog = gaupol.ErrorDialog(self._dialog, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #30
0
 def _show_parse_error_dialog(self, basename, format):
     """Show an error dialog after failing to parse file."""
     title = _('Failed to parse file "{}"').format(basename)
     message = _("Please check that the file you are trying to open is a valid {} file.").format(format.label)
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #31
0
 def _show_format_error_dialog(self, basename):
     """Show an error dialog after failing to recognize file format."""
     title = _('Failed to recognize format of file "{}"').format(basename)
     message = _("Please check that the file you are trying to open is a subtitle file of a format supported by Gaupol.")
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #32
0
 def _show_error_dialog(self, message):
     """Show an error dialog after failing to load dictionary."""
     title = _('Failed to load dictionary for language "{}"')
     title = title.format(self._language_name)
     dialog = gaupol.ErrorDialog(self._dialog, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #33
0
 def _init_dialog(self):
     """Initialize the dialog."""
     self.add_button(_("_Report Bug"), Gtk.ResponseType.HELP)
     self.add_button(_("_Quit"), Gtk.ResponseType.NO)
     self.add_button(_("_Close"), Gtk.ResponseType.CLOSE)
     self.set_default_response(Gtk.ResponseType.CLOSE)
     self.set_modal(True)
     aeidon.util.connect(self, self, "response")
Пример #34
0
 def _show_encoding_error_dialog(self, basename):
     """Show an error dialog after failing to decode file."""
     title = _('Failed to decode file "{}" with all attempted codecs').format(basename)
     message = _("Please try to open the file with a different character encoding.")
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #35
0
 def _init_dialog(self, parent):
     """Initialize the dialog."""
     self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
     self.add_button(_("_OK"), Gtk.ResponseType.OK)
     self.set_default_response(Gtk.ResponseType.OK)
     self.set_transient_for(parent)
     self.set_modal(True)
     self.set_title(_("Character Encodings"))
Пример #36
0
 def _init_dialog(self, parent):
     """Initialize the dialog."""
     self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
     self.add_button(_("_OK"), Gtk.ResponseType.OK)
     self.set_default_response(Gtk.ResponseType.OK)
     self.set_transient_for(parent)
     self.set_modal(True)
     self.set_title(_("Character Encodings"))
Пример #37
0
 def _init_dialog(self, parent):
     """Initialize the dialog."""
     self.add_button(_("Close _Without Saving"), Gtk.ResponseType.NO)
     self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
     self.add_button(_("_Save"), Gtk.ResponseType.YES)
     self.set_default_response(Gtk.ResponseType.YES)
     self.set_transient_for(parent)
     self.set_modal(True)
     aeidon.util.connect(self, self, "response")
Пример #38
0
 def _init_dialog(self, parent, title):
     """Initialize the dialog."""
     self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
     self.add_button(_("_Open"), Gtk.ResponseType.OK)
     self.set_default_response(Gtk.ResponseType.OK)
     self.set_transient_for(parent)
     self.set_title(title)
     self.connect("response", self._on_response)
     self.set_action(Gtk.FileChooserAction.OPEN)
Пример #39
0
 def _init_position_combo(self):
     """Initialize the position combo box."""
     store = Gtk.ListStore(str)
     self._position_combo.set_model(store)
     store.append((_("Above selection"),))
     store.append((_("Below selection"),))
     renderer = Gtk.CellRendererText()
     self._position_combo.pack_start(renderer, expand=True)
     self._position_combo.add_attribute(renderer, "text", 0)
Пример #40
0
 def _init_position_combo(self):
     """Initialize the position combo box."""
     store = Gtk.ListStore(str)
     self._position_combo.set_model(store)
     store.append((_("Above selection"), ))
     store.append((_("Below selection"), ))
     renderer = Gtk.CellRendererText()
     self._position_combo.pack_start(renderer, expand=True)
     self._position_combo.add_attribute(renderer, "text", 0)
Пример #41
0
 def _show_io_error_dialog(self, message):
     """Show an error dialog after failing to write file."""
     title = _(
         'Failed to save subtitle file to temporary directory "{}"').format(
             tempfile.gettempdir())
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #42
0
 def _show_encoding_error_dialog(self, basename, codec):
     """Show an error dialog after failing to encode file."""
     codec = aeidon.encodings.code_to_name(codec)
     title = _('Failed to encode file "{basename}" with codec "{codec}"').format(**locals())
     message = _("Please try to save the file with a different character encoding.")
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #43
0
 def _init_dialog(self, parent):
     """Initialize the dialog."""
     self.add_button(_("Close _Without Saving"), Gtk.ResponseType.NO)
     self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
     self.add_button(_("_Save"), Gtk.ResponseType.YES)
     self.set_default_response(Gtk.ResponseType.YES)
     self.set_transient_for(parent)
     self.set_modal(True)
     aeidon.util.connect(self, self, "response")
Пример #44
0
 def _show_error_dialog(self, message):
     """Show an error dialog after failing to load dictionary."""
     name = gaupol.conf.spell_check.language
     name = aeidon.locales.code_to_name(name)
     title = _('Failed to load dictionary for language "{}"').format(name)
     dialog = gaupol.ErrorDialog(self.get_parent(), title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #45
0
 def _init_columns_combo(self):
     """Initalize the columns target combo box."""
     store = Gtk.ListStore(str)
     self._columns_combo.set_model(store)
     store.append((_("Correct texts in the text column"),))
     store.append((_("Correct texts in the translation column"),))
     renderer = Gtk.CellRendererText()
     self._columns_combo.pack_start(renderer, expand=True)
     self._columns_combo.add_attribute(renderer, "text", 0)
Пример #46
0
    def __init__(self):
        """Initialize a :class:`DebugDialog` instance."""
        GObject.GObject.__init__(self,
                                 message_type=Gtk.MessageType.ERROR,
                                 text=_("Something went wrong"),
                                 secondary_text=_("You have probably discovered a bug. Please report it by providing the below information and a description of what you were doing."))

        self._text_view = Gtk.TextView()
        self._init_dialog()
        self._init_text_view()
Пример #47
0
 def _init_subtitles_combo(self):
     """Initalize the subtitles target combo box."""
     store = Gtk.ListStore(str)
     self._subtitles_combo.set_model(store)
     store.append((_("Correct texts in selected subtitles"),))
     store.append((_("Correct texts in current project"),))
     store.append((_("Correct texts in all open projects"),))
     renderer = Gtk.CellRendererText()
     self._subtitles_combo.pack_start(renderer, expand=True)
     self._subtitles_combo.add_attribute(renderer, "text", 0)
Пример #48
0
 def _show_size_warning_dialog(self, basename, size):
     """Show a warning dialog when trying to open a large file."""
     title = _('Open abnormally large file "{}"?').format(basename)
     message = _("Size of the file is {:.1f} MB, which is abnormally large for a text-based subtitle file. Please, check that you are not trying to open a binary file.").format(size)
     dialog = gaupol.WarningDialog(self.window, title, message)
     dialog.add_button(_("_Cancel"), Gtk.ResponseType.NO)
     dialog.add_button(_("_Open"), Gtk.ResponseType.YES)
     dialog.set_default_response(Gtk.ResponseType.NO)
     response = gaupol.util.flash_dialog(dialog)
     gaupol.util.raise_default(response != Gtk.ResponseType.YES)
Пример #49
0
 def __init__(self, parent):
     """Initialize an :class:`AddFramerateDialog` instance."""
     directory = os.path.abspath(os.path.dirname(__file__))
     ui_file_path = os.path.join(directory, "add-framerate-dialog.ui")
     gaupol.BuilderDialog.__init__(self, ui_file_path)
     self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
     self.add_button(_("_Add"), Gtk.ResponseType.OK)
     self.set_default_response(Gtk.ResponseType.OK)
     self.set_transient_for(parent)
     self.set_modal(True)
Пример #50
0
 def _show_player_not_found_error_dialog(self):
     """Show an error dialog if video player not found."""
     title = _("Video player not found")
     message = _(
         "Please install one of the supported video players: mpv (recommended), MPlayer or VLC. See the preferences dialog to choose the video player or to customize the command."
     )
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #51
0
 def _show_format_error_dialog(self, basename):
     """Show an error dialog after failing to recognize file format."""
     title = _('Failed to recognize format of file "{}"').format(basename)
     message = _(
         "Please check that the file you are trying to open is a subtitle file of a format supported by Gaupol."
     )
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #52
0
 def _show_parse_error_dialog(self, basename, format):
     """Show an error dialog after failing to parse file."""
     title = _('Failed to parse file "{}"').format(basename)
     message = _(
         "Please check that the file you are trying to open is a valid {} file."
     ).format(format.label)
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #53
0
 def __init__(self, parent):
     """Initialize an :class:`AddFramerateDialog` instance."""
     directory = os.path.abspath(os.path.dirname(__file__))
     ui_file_path = os.path.join(directory, "add-framerate-dialog.ui")
     gaupol.BuilderDialog.__init__(self, ui_file_path)
     self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
     self.add_button(_("_Add"), Gtk.ResponseType.OK)
     self.set_default_response(Gtk.ResponseType.OK)
     self.set_transient_for(parent)
     self.set_modal(True)
Пример #54
0
 def _show_encoding_error_dialog(self, basename):
     """Show an error dialog after failing to decode file."""
     title = _('Failed to decode file "{}" with all attempted codecs'
               ).format(basename)
     message = _(
         "Please try to open the file with a different character encoding.")
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Пример #55
0
 def _show_encoding_error_dialog(self):
     """Show an error dialog after failing to encode file."""
     title = _('Failed to encode subtitle file to temporary directory "{}"'
               ).format(tempfile.gettempdir())
     message = _(
         "Subtitle data could not be encoded to a temporary file for preview with the current character encoding. Please first save the subtitle file with a different character encoding."
     )
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)