示例#1
0
    def saveFile(self):
        """save the current file that is being worked on to XML format"""
        # creates a graphical dialog that returns a path to where the user wants to save
        saveF = QtGui.QFileDialog.getSaveFileName(self, "Save File", "untitled.xml", "XML (*.xml)")
        
        #get the data for the links and nodes
        nodes = self.networkBuild.graph.nodes(data = True)
        links = self.networkBuild.graph.edges(data = True)

        try:
            # calls the XMLFunctions to create an xml file at the given path
            xml.create(saveF)

            for item in nodes: # add each node to the xml file
                node = item[1]['obj']
                name = node.getName()
                storage = node.getStorage()
                xml.addNode(saveF, name, storage)

            for item in links: # add each link to the xml file
                link = item[2]['obj']
                name = link.getName()
                protocol = link.getProtocol()
                (n1, n2) = link.getNodes()
                node1 = n1.getName()
                node2 = n2.getName()
                risk = link.getRisk()
                xml.addLink(saveF, name, protocol, node1, node2, risk)

        except IOError: # displays a warning if an incorrect file is chosen
            dialog = QtGui.QMessageBox.warning(self, "Incorrect File Selection", "You selected no file or an incorrect file type!")
示例#2
0
    def saveFile(self):
        """save the current file that is being worked on to XML format"""
        # creates a graphical dialog that returns a path to where the user wants to save
        saveF = QtGui.QFileDialog.getSaveFileName(self, "Save File",
                                                  "untitled.xml",
                                                  "XML (*.xml)")

        #get the data for the links and nodes
        nodes = self.networkBuild.graph.nodes(data=True)
        links = self.networkBuild.graph.edges(data=True)

        try:
            # calls the XMLFunctions to create an xml file at the given path
            xml.create(saveF)

            for item in nodes:  # add each node to the xml file
                node = item[1]['obj']
                name = node.getName()
                storage = node.getStorage()
                xml.addNode(saveF, name, storage)

            for item in links:  # add each link to the xml file
                link = item[2]['obj']
                name = link.getName()
                protocol = link.getProtocol()
                (n1, n2) = link.getNodes()
                node1 = n1.getName()
                node2 = n2.getName()
                risk = link.getRisk()
                xml.addLink(saveF, name, protocol, node1, node2, risk)

        except IOError:  # displays a warning if an incorrect file is chosen
            dialog = QtGui.QMessageBox.warning(
                self, "Incorrect File Selection",
                "You selected no file or an incorrect file type!")