Exemplo n.º 1
0
    def __init__(self, setDefault=False):
        """Initialize the format storage.

        Arguments:
            setDefault - if true, initializes with a default format
        """
        super().__init__()
        # new names for types renamed in the config dialog (orig names as keys)
        self.typeRenameDict = {}
        # nested dict for fields renamed, keys are type name then orig field
        self.fieldRenameDict = {}
        # list of format types with unique ID ref field changes
        self.changedIdFieldTypes = set()
        # set of math field names with deleted equations, keys are type names
        self.emptiedMathDict = {}
        self.conditionalTypes = set()
        self.mathFieldRefDict = {}
        # list of math eval levels, each is a dict by type name with lists of
        # equation fields
        self.mathLevelList = []
        # for saving all-type find/filter conditionals
        self.savedConditionText = {}
        self.configModified = False
        self.fileInfoFormat = nodeformat.FileInfoFormat(self)
        if setDefault:
            self[defaultTypeName] = nodeformat.NodeFormat(defaultTypeName,
                                                          self, {}, True)
            self.updateLineParsing()
Exemplo n.º 2
0
 def __init__(self, filePath=None, setNewDefaults=False, importType=None):
     """Open filePath (can also be file ref) if given,
        setNewDefaults uses user defaults for compression & encryption,
        importType gives an import method to read the file"""
     globalref.docRef = self
     self.root = None
     self.treeFormats = TreeFormats()
     self.fileInfoItem = TreeItem(None, nodeformat.FileInfoFormat.name)
     self.fileInfoFormat = None
     TreeDoc.copyFormat = nodeformat.NodeFormat('_DUMMY__ROOT_', {},
                                                TreeFormats.fieldDefault)
     self.undoStore = undo.UndoRedoStore()
     self.redoStore = undo.UndoRedoStore()
     self.sortFields = ['']
     self.fileName = ''
     self.spaceBetween = True
     self.lineBreaks = True
     self.formHtml = True
     self.childFieldSep = TreeDoc.childFieldSepDflt
     self.spellChkLang = ''
     self.xlstLink = ''
     self.xslCssLink = ''
     self.tlVersion = __version__
     self.fileInfoFormat = nodeformat.FileInfoFormat()
     if filePath:
         if importType:
             getattr(self, importType)(filePath)
         else:
             self.readFile(filePath)
     else:
         self.treeFormats = TreeFormats({}, True)
         self.root = TreeItem(None, TreeFormats.rootFormatDefault)
         self.root.setTitle(TreeDoc.rootTitleDefault)
     self.modified = False
     if setNewDefaults or not hasattr(self, 'compressFile'):
         self.compressFile = globalref.options.boolData('CompressNewFiles')
         self.encryptFile = globalref.options.boolData('EncryptNewFiles')
     elif not hasattr(self, 'encryptFile'):
         self.encryptFile = False
     self.selection = treeselection.TreeSelection([self.root])
     self.fileInfoFormat.translateFields()
     self.fileInfoFormat.updateFileInfo()
Exemplo n.º 3
0
    def __init__(self, formatList=None, setDefault=False):
        """Initialize the format storage.

        Arguments:
            formatList -- the list of formats' file info
            setDefault - if true, initializes with a default format
        """
        super().__init__()
        # new names for types renamed in the config dialog (orig names as keys)
        self.typeRenameDict = {}
        # nested dict for fields renamed, keys are type name then orig field
        self.fieldRenameDict = {}
        self.conditionalTypes = set()
        # set of math field names with deleted equations, keys are type names
        self.emptiedMathDict = {}
        self.mathFieldRefDict = {}
        # list of math eval levels, each is a dict by type name with lists of
        # equation fields
        self.mathLevelList = []
        # for saving all-type find/filter conditionals
        self.savedConditionText = {}
        self.fileInfoFormat = nodeformat.FileInfoFormat(self)
        if formatList:
            for formatData in formatList:
                name = formatData['formatname']
                self[name] = nodeformat.NodeFormat(name, self, formatData)
            self.updateDerivedRefs()
            try:
                self.updateMathFieldRefs()
            except matheval.CircularMathError:
                # can see if types with math fields were copied from a 2nd file
                # handle the exception to avoid failure at file open
                print('Warning - Circular math fields detected')
        if nodeformat.FileInfoFormat.typeName in self:
            self.fileInfoFormat.duplicateFileInfo(
                self[nodeformat.FileInfoFormat.typeName])
            del self[nodeformat.FileInfoFormat.typeName]
        if setDefault:
            self[defaultTypeName] = nodeformat.NodeFormat(defaultTypeName,
                                                          self,
                                                          addDefaultField=True)