def edit_node(node): nodeID = node.getID() dlg = QDialog() dlg.setWindowTitle('Edit Node') dlg.setWindowFlags( QtCore.Qt.Window | QtCore.Qt.WindowTitleHint | QtCore.Qt.CustomizeWindowHint) # remove close button dlg.ok = False dlg.OK = True dlg.node_name = "" dlg.node_time = "" dlg.node_desc = "" dlg.node_img = "" dlg.node_team = "" # Layouts main_layout = QVBoxLayout() l = QFormLayout() buttons_layout = QHBoxLayout() main_layout.addLayout(l) main_layout.addLayout(buttons_layout) dlg.setLayout(main_layout) if (nodeDic[nodeID]["name"]): leNodeName = QLineEdit(nodeDic[nodeID]["name"]) else: leNodeName = QLineEdit() if (nodeDic[nodeID]["time"]): leNodeTime = QLineEdit(nodeDic[nodeID]["time"]) else: leNodeTime = QLineEdit() if (nodeDic[nodeID]["description"]): leNodeDesc = QLineEdit(nodeDic[nodeID]["description"]) else: leNodeDesc = QLineEdit() cbxNodeType = QComboBox() icon = node.getIcon() # If there is a custom icon directory set, show it, else leave blank for default icon if (icon != redTeamIcon and icon != blueTeamIcon and icon != whiteTeamIcon): leImagePath = QLineEdit(icon) else: leImagePath = QLineEdit() pbOK = QPushButton() pbCancel = QPushButton() # Place current node's team as the first selection in the comboBox if (nodeDic[nodeID]["team"] == "blue"): cbxNodeType.addItems(["blue", "red", "white"]) elif (nodeDic[nodeID]["team"] == "white"): cbxNodeType.addItems(["white", "blue", "red"]) else: cbxNodeType.addItems(["red", "blue", "white"]) pbOK.setText("&OK") pbCancel.setText("&Cancel") l.setWidget(0, QFormLayout.LabelRole, QLabel("Node ID")) l.setWidget(0, QFormLayout.FieldRole, QLabel(nodeID)) l.setWidget(1, QFormLayout.LabelRole, QLabel("Node Name")) l.setWidget(1, QFormLayout.FieldRole, leNodeName) l.setWidget(2, QFormLayout.LabelRole, QLabel("Node Time-Stamp")) l.setWidget(2, QFormLayout.FieldRole, leNodeTime) l.setWidget(3, QFormLayout.LabelRole, QLabel("Node Description")) l.setWidget(3, QFormLayout.FieldRole, leNodeDesc) l.setWidget(4, QFormLayout.LabelRole, QLabel("Node Team")) l.setWidget(4, QFormLayout.FieldRole, cbxNodeType) l.setWidget(5, QFormLayout.LabelRole, QLabel("Icon Image")) l.setWidget(5, QFormLayout.FieldRole, leImagePath) def ok(): dlg.OK = True dlg.node_name = leNodeName.text() dlg.node_time = leNodeTime.text() dlg.node_desc = leNodeDesc.text() dlg.node_img = "" if (leImagePath.text()): dlg.node_img = leImagePath.text() dlg.node_team = cbxNodeType.currentText() dlg.close() def cancel(): dlg.OK = False dlg.close() pbOK.clicked.connect(ok) pbCancel.clicked.connect(cancel) buttons_layout.addWidget(pbOK) buttons_layout.addWidget(pbCancel) dlg.exec_() # Adds changes to node Dictionary and graph if OK is selected if dlg.OK: # Edit node in Dictionary nodeDic[nodeID] = { "name": dlg.node_name, "team": dlg.node_team, "time": dlg.node_time, "description": dlg.node_desc } # Edit node in graph nodeText = "" if (showNodeID): nodeText += newNodeID if (showNodeName and dlg.node_name != ""): nodeText += "\n" + dlg.node_name if (showNodeTime and dlg.node_time != ""): nodeText += "\n" + dlg.node_time if (showNodeDesc and dlg.node_desc != ""): nodeText += "\n" + dlg.node_desc if (dlg.node_img != ""): team = dlg.node_img elif (dlg.node_team == "red"): team = redTeamIcon elif (dlg.node_team == "blue"): team = blueTeamIcon else: team = whiteTeamIcon node.setText(nodeText) node.setIcon(team) print("Edited node with NodeID: " + nodeID) qgv.build()
def add_node(): newNodeID = getNextNodeID() dlg = QDialog() dlg.setWindowTitle('Add New Node') dlg.setWindowFlags( QtCore.Qt.Window | QtCore.Qt.WindowTitleHint | QtCore.Qt.CustomizeWindowHint) #remove close button dlg.ok = False dlg.OK = True dlg.node_name = "" dlg.node_time = "" dlg.node_desc = "" dlg.node_img = "" dlg.node_team = "" # Layouts main_layout = QVBoxLayout() l = QFormLayout() buttons_layout = QHBoxLayout() main_layout.addLayout(l) main_layout.addLayout(buttons_layout) dlg.setLayout(main_layout) leNodeName = QLineEdit() leNodeTime = QLineEdit() leNodeDesc = QLineEdit() cbxNodeType = QComboBox() leImagePath = QLineEdit() pbOK = QPushButton() pbCancel = QPushButton() cbxNodeType.addItems(["red", "blue", "white"]) pbOK.setText("&OK") pbCancel.setText("&Cancel") l.setWidget(0, QFormLayout.LabelRole, QLabel("Node ID")) l.setWidget(0, QFormLayout.FieldRole, QLabel(newNodeID)) l.setWidget(1, QFormLayout.LabelRole, QLabel("Node Name")) l.setWidget(1, QFormLayout.FieldRole, leNodeName) l.setWidget(2, QFormLayout.LabelRole, QLabel("Node Time-Stamp")) l.setWidget(2, QFormLayout.FieldRole, leNodeTime) l.setWidget(3, QFormLayout.LabelRole, QLabel("Node Description")) l.setWidget(3, QFormLayout.FieldRole, leNodeDesc) l.setWidget(4, QFormLayout.LabelRole, QLabel("Node Team")) l.setWidget(4, QFormLayout.FieldRole, cbxNodeType) l.setWidget(5, QFormLayout.LabelRole, QLabel("Icon Image")) l.setWidget(5, QFormLayout.FieldRole, leImagePath) def ok(): dlg.OK = True dlg.node_name = leNodeName.text() dlg.node_time = leNodeTime.text() dlg.node_desc = leNodeDesc.text() dlg.node_img = "" if (leImagePath.text()): dlg.node_img = leImagePath.text() dlg.node_team = cbxNodeType.currentText() dlg.close() def cancel(): dlg.OK = False dlg.close() pbOK.clicked.connect(ok) pbCancel.clicked.connect(cancel) buttons_layout.addWidget(pbOK) buttons_layout.addWidget(pbCancel) dlg.exec_() # Adds new node to node Dictionary and graph if OK is selected if dlg.OK: # Add node to Dictionary nodeDic[newNodeID] = { "name": dlg.node_name, "team": dlg.node_team, "time": dlg.node_time, "description": dlg.node_desc } # Add node to graph nodeText = "" if (showNodeID): nodeText += newNodeID if (showNodeName and nodeDic[newNodeID]["name"] != ""): nodeText += "\n" + nodeDic[newNodeID]["name"] if (showNodeTime and nodeDic[newNodeID]["time"] != ""): nodeText += "\n" + nodeDic[newNodeID]["time"] if (showNodeDesc and nodeDic[newNodeID]["description"] != ""): nodeText += "\n" + nodeDic[newNodeID]["description"] if (dlg.node_img != ""): team = dlg.node_img elif (dlg.node_team == "red"): team = redTeamIcon elif (dlg.node_team == "blue"): team = blueTeamIcon else: team = whiteTeamIcon nodeDic[newNodeID]["node"] = qgv.addNode(qgv.engine.graph, newNodeID, label=" ", text=nodeText, shape=team) print("Added new node with NodeID: " + newNodeID) qgv.build()