Пример #1
0
 def _detect_subtitle_encoding(self):
     """Try to detect the encoding of the subtitle file if it's not
     set in the submod-script.
     
     This is done in the Gtk-thread because a dialog may be shown to
     select the proper encoding if it can not be detected
     automatically.
     
     Then continue with the next step (load subtitle and run Submod-
     script).
     """
     self._show_step_icons(self.STEP_LOADING_SUBTITLE)
     # Generate path for subtitle based on script-directory and
     # subtitle filename from the script.
     subtitle_filename = self._submod.script['subtitle']['filename']
     dir_, script_filename = path.split(self._script_file)
     subtitle_file = path.join(dir_, subtitle_filename)
     if not path.isfile(subtitle_file):
         self._error(self.STEP_LOADING_SUBTITLE,
              _('Could not find subtitle file "{}"!').format(subtitle_file))
         return
     encoding = None
     if 'encoding' in self._submod.script['subtitle']:
         encoding = self._submod.script['subtitle']['encoding']
     if encoding is None:
         encoding = EncodingDialog.detect_textfile_encoding(self._dialog,
                                                            subtitle_file)
     if encoding is None:
         self._error(self.STEP_LOADING_SUBTITLE,
                        _('Could not determine encoding of subtitle file!'))
         return
     self._load_subtitle_run_script(subtitle_file, encoding)
Пример #2
0
 def _on_dialog_show(self, widget):
     encoding = EncodingDialog.detect_textfile_encoding(self._dialog,
                                                        self._script_file)
     if encoding is None:
         self._error(self.STEP_LOADING_SUBMOD,
                     _('Could not determine encoding of Submod-script!'))
         return
     self._submod = Submod()
     self._load_script(encoding)
Пример #3
0
 def _open_cutlist(self):
     self._show_step_icons(self.STEP_LOADING_CUTLIST)
     if self._submod.script['timings-for'] == 'uncut':
         dialog = Gtk.MessageDialog(self._dialog, 0, 
                     Gtk.MessageType.QUESTION,
                     Gtk.ButtonsType.YES_NO,
                     _('Do you want to synchronize the subtitles for a cutli'
                       'st file?'))
         res = dialog.run()
         dialog.destroy()
         if res == Gtk.ResponseType.YES:
             filechooser = ExtFileChooserDialog(
                       self._dialog, _('Please choose a cutlist file'), True)
             folder = Settings().get(self, 'cuts_folder')
             if folder is not None:
                 filechooser.set_current_folder(folder)
             filter_subtitle = Gtk.FileFilter()
             filter_subtitle.set_name(_('Cutlist files')+' (*.cutlist)')
             filter_subtitle.add_pattern('*.cutlist')
             filechooser.add_filter(filter_subtitle)
             res = filechooser.run()
             file_ = filechooser.get_filename()
             filechooser.destroy_dialog()
             if res == Gtk.ResponseType.OK and path.isfile(file_):
                 dir_, filename = path.split(file_)
                 Settings().set(self, 'cuts_folder', dir_)
                 encoding = filechooser.encoding
                 if encoding is None:
                     encoding = EncodingDialog.detect_textfile_encoding(
                                                         self._dialog, file_)
                 if encoding is None:
                     self._error(self.STEP_LOADING_CUTLIST,
                                _('Cutlist encoding could not be detected!'))
                     return
                 self._load_cutlist(file_, encoding)
                 # Since _load_cutlist will continue to the next step
                 # (detect subtitle encoding) we return here, s.b..
                 return
             else:
                 self._error(self.STEP_LOADING_CUTLIST,
                                        _('No cutlist selected! Cancelled!'))
                 return
     self._detect_subtitle_encoding()