示例#1
0
    def openFile(self):
        """opens an xml file into a network"""
        # creates a graphical dialog allowing the user to choose a file
        openF = QtGui.QFileDialog.getOpenFileName(self, "Open File", "", "XML (*.xml)")
        try:

            links = xml.returnLinks(openF) # get all the links from xml
            nodes = xml.returnNodes(openF) # get all the nodes from xml

            #clear the current graph
            self.makeNew() # create a blank graph

            for item in nodes: # add each node to the graph
                if item != None:
                    name = item[0]
                    storage = item[1]
                    node = Node(name, storage)
                    self.networkBuild.addNode(node)

            nodes = self.networkBuild.graph.nodes(data = True)

            for item in links: # add each link to the graph
                if item != None:
                    name = item[0]
                    risk = item[1]
                    protocol = item[2]
                    nodeName1 = item[3]
                    nodeName2 = item[4]
                    node1 = self.networkBuild.findNode(nodeName1)[1]['info']
                    node2 = self.networkBuild.findNode(nodeName2)[1]['info']
                    link = Link(node1, node2, name, protocol, risk)
                    self.networkBuild.addEdge(link)

        except IOError: # show an error dialog when a wrong file is selected
            dialog = QtGui.QMessageBox.warning(self, "Incorrect File Selection", "You selected no file or an incorrect file type!")
示例#2
0
    def openFile(self):
        """opens an xml file into a network"""
        # creates a graphical dialog allowing the user to choose a file
        openF = QtGui.QFileDialog.getOpenFileName(self, "Open File", "",
                                                  "XML (*.xml)")
        try:

            links = xml.returnLinks(openF)  # get all the links from xml
            nodes = xml.returnNodes(openF)  # get all the nodes from xml

            #clear the current graph
            self.makeNew()  # create a blank graph

            for item in nodes:  # add each node to the graph
                if item != None:
                    name = item[0]
                    storage = item[1]
                    node = Node(name, storage)
                    self.networkBuild.addNode(node)

            nodes = self.networkBuild.graph.nodes(data=True)

            for item in links:  # add each link to the graph
                if item != None:
                    name = item[0]
                    risk = item[1]
                    protocol = item[2]
                    nodeName1 = item[3]
                    nodeName2 = item[4]
                    node1 = self.networkBuild.findNode(nodeName1)[1]['info']
                    node2 = self.networkBuild.findNode(nodeName2)[1]['info']
                    link = Link(node1, node2, name, protocol, risk)
                    self.networkBuild.addEdge(link)

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