コード例 #1
0
 def __init__(self):
     self.textEdit = TETextEdit(
         language_name=TLPreferences['DFT_WRITING_LANGUAGE'])
     self.metadata = DPMetaData()
     self.filepath = None
     self.lastFiles = CLLastFiles()
     self.config_spelling = CLSpelling()
     self.config_autocor = CLAutoCorrection()
コード例 #2
0
    def CMD_FileOpen_version_1(self, filepath):
        """
		In order to open old Athw files that were not a zip file.
		"""
        # Get the text:
        local_dir, tmp = os.path.split(self.filepath)
        text = FMTextFileManagement.open(filepath)

        meta_filepath, tmp = os.path.splitext(self.filepath)
        meta_filepath += '.athw_meta'
        if os.path.exists(meta_filepath):
            metadata = DPMetaData.init_from_xml_string(
                FMTextFileManagement.open(meta_filepath))
        else:
            metadata = DPMetaData()
        return text, metadata
コード例 #3
0
    def SLOT_actionFileNew(self):
        """
		Slot used when creating a new file.
		"""
        res = self.doSaveDialog()
        if (res != QtWidgets.QMessageBox.Yes) and (res !=
                                                   QtWidgets.QMessageBox.No):
            return False
        self.clean_tmp_files()  # we remove the previous tmp files
        self.textEdit.setText("")
        self.filepath = None
        self.metadata = DPMetaData()
        self.setWindowTitle("AthenaWriter : NewFile")
        self.changeMessageStatusBar("Created a new file")

        return True
コード例 #4
0
    def CMD_FileOpen(self, filepath):
        if filepath == None:
            if self.filepath == None:
                raise self.Error('Please specify the filepath')
            filepath = self.filepath
        else:
            self.filepath = filepath

        try:
            text = FMZipFileManagement.open(self.filepath, 'main.txt')
            if 'meta.xml' in FMZipFileManagement.listFiles(self.filepath):
                metadata = DPMetaData.init_from_xml_string(
                    FMZipFileManagement.open(self.filepath, 'meta.xml'))
            else:
                metadata = DPMetaData()
            self.config_spelling.changeFile(filepath)
            self.config_autocor.changeFile(filepath)

        except zipfile.BadZipFile:
            text, metadata = self.CMD_FileOpen_version_1(filepath)
        except KeyError as e:
            raise IOError('Not a correct ATHW file' + str(e))

        self.metadata = metadata
        language = self.metadata['language']
        lastpos = self.metadata['lastpos']
        profile = self.metadata['profile']
        if profile == None:
            profile = TLPreferences['DFT_TYPO_PROFILE']

        self.textEdit.setText(text,
                              type='xml',
                              new_language=language,
                              profile=profile)
        if lastpos != None:
            if lastpos == -1:
                lastpos = self.textEdit.document().characterCount()
            cur = self.textEdit.textCursor()
            cur.setPosition(lastpos)
            self.textEdit.setTextCursor(cur)

        return True