def addLink(self, link): """adds a link to the graph""" (node1, node2) = link.getNodes() linkName = link.getName() # adds the link into the graph self.add_edge(node1.getName(), node2.getName(), key=linkName, obj=link) self.createLinkLabels() # creates new labels for links
def addLink(self, link): """adds a link to the graph""" (node1, node2) = link.getNodes() linkName = link.getName() # adds the link into the graph self.add_edge(node1.getName(), node2.getName(), key = linkName, obj = link) self.createLinkLabels() # creates new labels for links
def removeLink(self, linkName): """removes a link from the graph""" for linkData in self.edges(data=True): link = linkData[2]['obj'] if link.getName() == linkName: # finds the correct link (node1, node2) = link.getNodes() # removes the link from the graph self.remove_edge(node1.getName(), node2.getName()) self.createLinkLabels() # creates the new link labels return
def removeLink(self, linkName): """removes a link from the graph""" for linkData in self.edges(data = True): link = linkData[2]['obj'] if link.getName() == linkName: # finds the correct link (node1, node2) = link.getNodes() # removes the link from the graph self.remove_edge(node1.getName(), node2.getName()) self.createLinkLabels() # creates the new link labels return
def createLinkLabels(self): """creates the labels for all links in the graph""" links = self.edges(data=True) # get all links self._linkLabels = {} # clear the link lables for linkData in links: # get all data for the link link = linkData[2]['obj'] linkName = link.getName() (node1, node2) = link.getNodes() node1Name = node1.getName() node2Name = node2.getName() # creates the link labels ensuring that multiple can be listed # to account for multiple links between a single node if (node1Name, node2Name) in self._linkLabels.keys(): self._linkLabels[(node1Name, node2Name)] += ",\n" + linkName elif (node2Name, node1Name) in self._linkLabels.keys(): self._linkLabels[(node2Name, node1Name)] += ",\n" + linkName else: self._linkLabels[(node1Name, node2Name)] = linkName
def createLinkLabels(self): """creates the labels for all links in the graph""" links = self.edges(data = True) # get all links self._linkLabels = {} # clear the link lables for linkData in links: # get all data for the link link = linkData[2]['obj'] linkName = link.getName() (node1, node2) = link.getNodes() node1Name = node1.getName() node2Name = node2.getName() # creates the link labels ensuring that multiple can be listed # to account for multiple links between a single node if (node1Name, node2Name) in self._linkLabels.keys(): self._linkLabels[(node1Name, node2Name)] += ",\n" + linkName elif (node2Name, node1Name) in self._linkLabels.keys(): self._linkLabels[(node2Name, node1Name)] += ",\n" + linkName else: self._linkLabels[(node1Name, node2Name)] = linkName
def displayLink(self): """creates a graphical dialog to select an edge and display its information""" currEdges = self.graph.edges(data = True) link, ok = dialogs.DisplayLink.getDataDialog(currEdges) if ok: # gets the user selected edge (node1, node2) = link.getNodes() nodeName1 = node1.getName() nodeName2 = node2.getName() protocol = link.getProtocol() risk = link.getRisk() # display the data for the edge in a message box message = QtGui.QMessageBox.information(self, "View Edge", "Name: {0}\nNode 1: {1}\nNode 2: {2}\nProtocol: {3}\nRisk: {4}".format(link.getName(), nodeName1, nodeName2, protocol, risk))
def getLink(self, linkName): """gets a link from the graph""" for linkData in self.edges(data=True): link = linkData[2]['obj'] if link.getName() == linkName: return link
def getLink(self, linkName): """gets a link from the graph""" for linkData in self.edges(data = True): link = linkData[2]['obj'] if link.getName() == linkName: return link