Exemple #1
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)
Exemple #2
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(Gtk.STOCK_OK, Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Exemple #3
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)
Exemple #4
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)
Exemple #5
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)
Exemple #6
0
 def _on_bus_message_error(self, bus, message):
     """Handle error message from the bus."""
     title, message = message.parse_error()
     dialog = gaupol.ErrorDialog(None, title, message)
     dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
     dialog.set_default_response(Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Exemple #7
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)
Exemple #8
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)
Exemple #9
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(Gtk.STOCK_OK, Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Exemple #10
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)
Exemple #11
0
 def _show_mpsub_error_dialog(self):
     """Show an error dialog for invalid MPsub header."""
     title = _("Invalid header")
     msg = _('MPsub header must contain a line of form "FORMAT=VALUE", '
             'where VALUE is any of "TIME", "23.98", "25.00" or "29.97".')
     dialog = gaupol.ErrorDialog(self._dialog, title, msg)
     dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Exemple #12
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(Gtk.STOCK_OK, Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Exemple #13
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)
Exemple #14
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(Gtk.STOCK_OK, Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Exemple #15
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)
Exemple #16
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(Gtk.STOCK_OK, Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Exemple #17
0
 def _show_error_dialog(self, message):
     """Show an error dialog after failing to load dictionary."""
     try:
         name = aeidon.locales.code_to_name(self._language)
     except LookupError:
         name = self._language
     title = _('Failed to load dictionary for language "{}"').format(name)
     dialog = gaupol.ErrorDialog(self._dialog, title, message)
     dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Exemple #18
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)
Exemple #19
0
 def _on_check_spelling_activate(self, *args):
     """Check for incorrect spelling."""
     gaupol.util.set_cursor_busy(self.window)
     try:
         dialog = gaupol.SpellCheckDialog(self.window, self)
     except Exception as error:
         gaupol.util.set_cursor_normal(self.window)
         title = _('Failed to load dictionary for language "{}"')
         title = title.format(gaupol.conf.spell_check.language)
         dialog = gaupol.ErrorDialog(self.window, title, str(error))
         dialog.add_button(_("_OK"), Gtk.ResponseType.OK)
         dialog.set_default_response(Gtk.ResponseType.OK)
         return gaupol.util.flash_dialog(dialog)
     gaupol.util.set_cursor_normal(self.window)
     gaupol.util.flash_dialog(dialog)
Exemple #20
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)
         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)
Exemple #21
0
 def _on_tree_view_cell_toggled(self, renderer, path):
     """Activate or deactivate toggled extension."""
     store = self._tree_view.get_model()
     module = store[path][0]
     active = store[path][1]
     if active:
         try:
             self.manager.teardown_extension(module)
             gaupol.conf.extensions.active.remove(module)
         except gaupol.DependencyError:
             title = _("Cannot deactivate extension")
             message = _('Extension "{}" is required by other extensions.')
             message = message.format(store[path][2])
             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)
     else:  # Activating extension.
         self.manager.setup_extension(module)
         gaupol.conf.extensions.active.append(module)
     for row in store:
         row[1] = self.manager.is_active(row[0])
     selection = self._tree_view.get_selection()
     selection.emit("changed")
Exemple #22
0
 def setup_method(self, method):
     self.dialog = gaupol.ErrorDialog(Gtk.Window(), "test", "test")
     self.dialog.add_button("_OK", Gtk.ResponseType.OK)
     self.dialog.set_default_response(Gtk.ResponseType.OK)
     self.dialog.show()
Exemple #23
0
 def _show_io_error_dialog(self, basename, message):
     """Show an error dialog after failing to read file."""
     title = _('Failed to open file "{}"').format(basename)
     dialog = gaupol.ErrorDialog(self.window, title, message)
     dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)
Exemple #24
0
 def setup_method(self, method):
     self.dialog = gaupol.ErrorDialog(Gtk.Window(), "test", "test")
     self.dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
     self.dialog.show()
 def _show_bus_message_error_dialog(self, message):
     """Show an error dialog after failing to decode file."""
     title = _("Something went wrong")
     dialog = gaupol.ErrorDialog(self, title, message)
     dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
     gaupol.util.flash_dialog(dialog)