コード例 #1
0
 def __init__(self, newFile=False, parent=None):
     """Initialize a TreeModel.
     
     Arguments:
         newFile -- if true, adds default root node and formats
         parent -- optional QObject parent for the model
     """
     super().__init__(parent)
     self.root = None
     self.configDialogFormats = None
     self.undoList = None
     self.redoList = None
     self.nodeIdDict = {}
     self.linkRefCollect = linkref.LinkRefCollection()
     self.mathZeroBlanks = True
     if newFile:
         self.formats = treeformats.TreeFormats(True)
         self.root = treenode.TreeNode(None, treeformats.defaultTypeName,
                                       self)
         self.root.setTitle(defaultRootName)
     else:
         self.formats = treeformats.TreeFormats()
     self.fileInfoNode = treenode.TreeNode(None,
                                           self.formats.fileInfoFormat.name,
                                           self)
コード例 #2
0
    def __init__(self, fileData=None, topNodes=None, addDefaults=False,
                 addSpots=True):
        """Create and store a tree structure from file data.

        If no file data is given, create an empty or a default new structure.
        Arguments:
            fileData -- a dict in JSON file format of a structure
            topNodes -- existing top-level nodes to add to a structure
            addDefaults -- if True, adds default new structure
            addSpots -- if True, adds parent spot references
        """
        super().__init__(None)  # init TreeNode, with no formatRef
        self.nodeDict = {}
        self.undoList = None
        self.redoList = None
        self.configDialogFormats = None
        self.mathZeroBlanks = True
        self.childRefErrorNodes = []
        if fileData:
            self.treeFormats = treeformats.TreeFormats(fileData['formats'])
            self.treeFormats.loadGlobalSavedConditions(fileData['properties'])
            for nodeInfo in fileData['nodes']:
                formatRef = self.treeFormats[nodeInfo['format']]
                node = treenode.TreeNode(formatRef, nodeInfo)
                self.nodeDict[node.uId] = node
            for node in self.nodeDict.values():
                node.assignRefs(self.nodeDict)
                if node.tmpChildRefs:
                    self.childRefErrorNodes.append(node)
                    node.tmpChildRefs = []
            for uId in fileData['properties']['topnodes']:
                node = self.nodeDict[uId]
                self.childList.append(node)
            if 'zeroblanks' in fileData['properties']:
                self.mathZeroBlanks = fileData['properties']['zeroblanks']
            if addSpots:
                self.generateSpots(None)
        elif topNodes:
            self.childList = topNodes
            self.treeFormats = treeformats.TreeFormats()
            for topNode in topNodes:
                for node in topNode.descendantGen():
                    self.nodeDict[node.uId] = node
                    self.treeFormats.addTypeIfMissing(node.formatRef)
            if addSpots:
                self.generateSpots(None)
        elif addDefaults:
            self.treeFormats = treeformats.TreeFormats(setDefault=True)
            node = treenode.TreeNode(self.treeFormats[treeformats.
                                                      defaultTypeName])
            node.setTitle(defaultRootTitle)
            self.nodeDict[node.uId] = node
            self.childList.append(node)
            if addSpots:
                self.generateSpots(None)
        else:
            self.treeFormats = treeformats.TreeFormats()
        self.fileInfoNode = treenode.TreeNode(self.treeFormats.fileInfoFormat)
コード例 #3
0
ファイル: conditional.py プロジェクト: isoftpk/gmedit
 def retrieveRules(self):
     """Show a menu to retrieve stored rules.
     """
     modelRef = globalref.mainControl.activeControl.model
     nodeFormats = modelRef.formats
     savedRules = nodeFormats.savedConditions()
     ruleNames = sorted(list(savedRules.keys()))
     dlg = RuleRetrieveDialog(ruleNames, self)
     if dlg.exec_() == QtGui.QDialog.Accepted:
         if dlg.selectedRule:
             conditional = savedRules[dlg.selectedRule]
             self.setCondition(conditional, conditional.origNodeFormatName)
         if dlg.removedRules:
             undo.FormatUndo(modelRef.undoList, nodeFormats,
                             treeformats.TreeFormats())
             for ruleName in dlg.removedRules:
                 conditional = savedRules[ruleName]
                 if conditional.origNodeFormatName:
                     typeFormat = nodeFormats[
                         conditional.origNodeFormatName]
                     del typeFormat.savedConditionText[ruleName]
                 else:
                     del nodeFormats.savedConditionText[ruleName]
             self.retrieveButton.setEnabled(
                 len(nodeFormats.savedConditions()) > 0)
             globalref.mainControl.activeControl.setModified()
コード例 #4
0
ファイル: conditional.py プロジェクト: fanzalika/TreeLine
 def deleteRule(self):
     """Remove the current saved rule.
     """
     treeStructure = globalref.mainControl.activeControl.structure
     nodeFormats = treeStructure.treeFormats
     undo.FormatUndo(treeStructure.undoList, nodeFormats,
                     treeformats.TreeFormats())
     savedRules = nodeFormats.savedConditions()
     ruleName = self.saveListBox.currentItem().text()
     conditional = savedRules[ruleName]
     if conditional.origNodeFormatName:
         typeFormat = nodeFormats[conditional.origNodeFormatName]
         del typeFormat.savedConditionText[ruleName]
     else:
         del nodeFormats.savedConditionText[ruleName]
     self.loadSavedNames(True)
     globalref.mainControl.activeControl.setModified()
コード例 #5
0
ファイル: conditional.py プロジェクト: fanzalika/TreeLine
 def saveRule(self):
     """Save the current rule settings.
     """
     name = self.saveNameEdit.text()
     self.saveNameEdit.setText('')
     treeStructure = globalref.mainControl.activeControl.structure
     undo.FormatUndo(treeStructure.undoList, treeStructure.treeFormats,
                     treeformats.TreeFormats())
     typeName = self.typeCombo.currentText()
     if typeName == _allTypeEntry:
         nodeFormat = treeStructure.treeFormats
     else:
         nodeFormat = treeStructure.treeFormats[typeName]
     nodeFormat.savedConditionText[name] = (
         self.conditional().conditionStr())
     self.loadSavedNames(True)
     self.saveListBox.setCurrentItem(
         self.saveListBox.findItems(name, Qt.MatchExactly)[0])
     globalref.mainControl.activeControl.setModified()
コード例 #6
0
ファイル: conditional.py プロジェクト: isoftpk/gmedit
 def saveRules(self):
     """Prompt for a name for storing these rules.
     """
     modelRef = globalref.mainControl.activeControl.model
     nodeFormats = modelRef.formats
     usedNames = set(nodeFormats.savedConditions().keys())
     dlg = configdialog.NameEntryDialog(_('Save Rules'),
                                        _('Enter a descriptive name'), '',
                                        '', usedNames, self)
     if dlg.exec_() == QtGui.QDialog.Accepted:
         undo.FormatUndo(modelRef.undoList, nodeFormats,
                         treeformats.TreeFormats())
         typeName = self.typeCombo.currentText()
         if typeName == _allTypeEntry:
             nodeFormat = nodeFormats
         else:
             nodeFormat = nodeFormats[typeName]
         nodeFormat.savedConditionText[dlg.text] = (
             self.conditional().conditionStr())
         self.retrieveButton.setEnabled(True)
         globalref.mainControl.activeControl.setModified()
コード例 #7
0
ファイル: imports.py プロジェクト: isoftpk/gmedit
 def createBookmarkFormat(self):
     """Return a set of node formats for bookmark imports.
     """
     treeFormats = treeformats.TreeFormats()
     folderFormat = nodeformat.NodeFormat(bookmarkFolderTypeName,
                                          treeFormats,
                                          addDefaultField=True)
     folderFormat.iconName = 'folder_3'
     treeFormats[folderFormat.name] = folderFormat
     linkFormat = nodeformat.NodeFormat(bookmarkLinkTypeName,
                                        treeFormats,
                                        addDefaultField=True)
     linkFormat.addField(bookmarkLinkFieldName, {'type': 'ExternalLink'})
     linkFormat.addOutputLine('{{*{0}*}}'.format(bookmarkLinkFieldName))
     linkFormat.iconName = 'bookmark'
     treeFormats[linkFormat.name] = linkFormat
     sepFormat = nodeformat.NodeFormat(bookmarkSeparatorTypeName,
                                       treeFormats, {'formathtml': 'y'},
                                       True)
     sepFormat.changeTitleLine('------------------')
     sepFormat.changeOutputLines(['<hr>'])
     treeFormats[sepFormat.name] = sepFormat
     return treeFormats