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!")
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!")
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!")
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!")