Exemplo n.º 1
0
    def open(self):
        '''
        Permet d'ouvrir un fichier .thc ou .txt pour le lire et le modifier
        :return: (translate) Class translate contenant le texte
        '''
        translate = Translate()

        self.OpenFileDialog()
        if self.file.lower().endswith(".txt"):
            doc = open(self.file, "r", encoding='utf8')
            text = doc.read()
            translate.toBin(text)

            return translate
        binary = Binary()

        if self.file == "":
            return None

        doc = open(self.file, "rb")
        data = self.bytes2binstr(doc.read())
        doc.close()

        dic = ""
        text = ""
        isDic = True
        countLenDic = 0
        for i in range(len(data) // 7 + ceil((len(data) % 7) / 7)):
            value = ""
            for y in range(7):
                b = ""
                if isDic:
                    b = "0"
                if len(data) >= i * 7 + y + 1:
                    b = data[i * 7 + y]
                value += b
            if value == cbch["[SUPERSEP¤]"]:
                isDic = False
            elif isDic:
                countLenDic += 7
            if isDic:
                dic += value
            else:
                if value != cbch["[SUPERSEP¤]"]:
                    text += value

        translate.toText(text[(len(text) % 8):], binary.SaveToDict(dic))
        return translate