Example #1
0
 def __init__(self, parent):
     self.subtitles = SubtitlesLoader()
     self.currentSequenceId = 0
     self.sequenceList = []
     self.parent = parent
     self.videoExportPath = None
     self.exerciseExportPath = None
     self.translationExportPath = None
Example #2
0
 def __init__(self):
     self.subtitles = SubtitlesLoader()
     self.repeatCount = 0
     self.currentSubExerciseId = 0
     self.subExercisesList = []
     self.currentSubExercise = None
     self.repeatAfterCompleted = True
     self.maxSequenceLength = 60.0
     self.timeBetweenSequence = 0.0
     self.outputSavePath = None
     self.template = False
     self.name = None
     self.mediaChangeCallback = None
     self.language = None
     self.randomOrder = False
     self.playMarginAfter = 500
     self.playMarginBefore = 1000
     self.use_dynamic_correction = True
     self.repeat_count_limit_by_sequence = 0
     self.lock_help = False
     self.lock_properties = False
     self.lock_correction = False
     self.lock_properties_password = None
     self.lock_correction_password = None
     self.lock_properties_salt = None
     self.lock_correction_salt = None
Example #3
0
class SubExercise(object):

    def __init__(self, parent):
        self.subtitles = SubtitlesLoader()
        self.currentSequenceId = 0
        self.sequenceList = []
        self.parent = parent
        self.videoExportPath = None
        self.exerciseExportPath = None
        self.translationExportPath = None

    def load_subtitles(self):

        self.subList = self.subtitles.get_subtitle_list(self.exercisePath)
        self.subList = self.subtitles.compact_subtitles_list(self.subList, self.parent.timeBetweenSequence, self.parent.maxSequenceLength)

        self.translationList = None
        if self.translationPath != "":
            self.translationList = self.subtitles.get_subtitle_list(self.translationPath)

        oldSequenceList = self.sequenceList

        self.sequenceList = []

        for sub in self.subList:
            if self.parent.is_use_dynamic_correction():
                sequence = SequenceDynamicCorrection(self.parent.language)
            else:
                sequence = SequenceSimple(self.parent.language)
            sequence.load(sub.get_text())
            if len(sequence.get_words()) == 0:
                # Empty sequence
                continue
            sequence.set_time_begin(sub.get_time_begin())
            sequence.set_time_end(sub.get_time_end())
            self.sequenceList.append(sequence)

        # Restore found words.
        # This is useful only this the subtitle file path has change : the found words are restored

        if len(oldSequenceList) > 0: # Empty is this is a new or loaded from file exercise

            for old_sequence, new_sequence in zip(oldSequenceList, self.sequenceList): # For each sequences
                for old_word, new_word in zip(old_sequence.get_words(), new_sequence.get_words()): # and for each words
                    new_word.set_text(old_word.get_text()) # copy the value set by the user



    def extract_word_list(self):
        wordList = []

        for sequence in self.sequenceList:
            for word in sequence.get_words():
                wordList.append(word.get_valid())

        return wordList

    def goto_sequence(self, id):
        self.currentSequenceId = id
        self.update_current_infos()

    def goto_next_sequence(self):
        if self.currentSequenceId < len(self.sequenceList) - 1:
            self.currentSequenceId += 1
            self.update_current_infos()
            return True
        else:
            return False

    def goto_previous_sequence(self):
        if self.currentSequenceId > 0:
            self.currentSequenceId -= 1
            self.update_current_infos()
            return True
        else:
            return False

    def update_current_infos(self):
        self.currentSequence = self.sequenceList[self.currentSequenceId]
        self.currentSequenceValid = self.currentSequence.is_valid()

    def is_paths_valid(self):
        error = False
        errorList = []
        if not os.path.exists(self.videoPath):
            error = True;
            errorList.append(self.videoPath)

        if not os.path.exists(self.exercisePath):
            error = True;
            errorList.append(self.exercisePath)

        if self.translationPath != "" and not os.path.exists(self.translationPath):
            error = True;
            errorList.append(self.translationPath)

        return (not error), errorList

    def increment_repeat_count(self):
        self.repeatCount += 1

    def set_video_path(self, videoPath):
        self.videoPath = videoPath

    def set_exercise_path(self, exercisePath):
        self.exercisePath = exercisePath

    def set_translation_path(self, translationPath):
        self.translationPath = translationPath

    #Define path to use when the parent file is exported
    def set_video_export_path(self, videoPath):
        self.videoExportPath = videoPath

    #Define path to use when the parent file is exported
    def set_exercise_export_path(self, exercisePath):
        self.exerciseExportPath = exercisePath

    #Define path to use when the parent file is exported
    def set_translation_export_path(self, translationPath):
        self.translationExportPath = translationPath

    def set_current_sequence(self, id):
        if id >= len(self.sequenceList):
            self.currentSequenceId = len(self.sequenceList) - 1
        else:
            self.currentSequenceId = id

    def get_sequence_list(self):
        return self.sequenceList

    def get_current_sequence(self):
        return self.sequenceList[self.currentSequenceId]

    def get_current_sequence_id(self):
        return self.currentSequenceId

    def get_sequence_count(self):
        return len(self.sequenceList)

    def get_video_path(self):
        return self.videoPath

    def get_exercise_path(self):
        return self.exercisePath

    def get_translation_path(self):
        return self.translationPath

    #get path to use when the parent file is exported. If no specila
    #path is set, the absolute path is used
    def get_video_export_path(self):
        if self.videoExportPath:
            return self.videoExportPath
        else:
            return self.videoPath

    #get path to use when the parent file is exported. If no specila
    #path is set, the absolute path is used
    def get_exercise_export_path(self):
        if self.exerciseExportPath:
            return self.exerciseExportPath
        else:
            return self.exercisePath

    #get path to use when the parent file is exported. If no specila
    #path is set, the absolute path is used
    def get_translation_export_path(self):
        if self.translationExportPath:
            return self.translationExportPath
        else:
            return self.translationPath

    def get_translation_list(self):
        return self.translationList