-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
show_path.py
77 lines (65 loc) · 2.67 KB
/
show_path.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_ShowPath(QtWidgets.QDialog):
def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
try:
self.graph.ShowSpfPath(
self.source_node, self.target_node, set_highlight=False
)
self.graph.reset_highlight()
except:
pass
return super().closeEvent(a0)
def __init__(self, parent=None):
super(Ui_ShowPath, self).__init__(parent=parent)
def setupUi(self, ShowPath, target_node, source_node, graph):
self.target_node = target_node
self.source_node = source_node
self.graph = graph
self.graph.reset_highlight()
ShowPath.setObjectName("ShowPath")
# ShowPath.resize(465, 243)
self.showPath = QtWidgets.QTreeWidget(ShowPath)
self.showPath.setSizeAdjustPolicy(
QtWidgets.QAbstractScrollArea.AdjustToContents
)
self.showPath.setWordWrap(False)
self.showPath.expandAll()
self.showPath.setGeometry(QtCore.QRect(30, 20, 550, 200))
self.showPath.setObjectName("showPath")
try:
n1, n2, n3 = graph.ShowSpfPath(source_node, target_node, set_highlight=True)
except:
QtWidgets.QMessageBox.critical(
self.showPath,
"Error!",
"No path between the nodes !",
)
return
items = [f"{source_node.label}", f"{target_node.label}", f"{n1}", f"{n2}"]
l1 = QtWidgets.QTreeWidgetItem(items)
for path in n3:
string_output = []
string_output.append(f"{path[0]}")
string_output.append(f"{path[1]}")
string_output.append(f"{path[2]}")
string_output.append(f"{path[3]}")
l1_1 = QtWidgets.QTreeWidgetItem(string_output)
l1.addChild(l1_1)
self.showPath.addTopLevelItem(l1)
self.retranslateUi(ShowPath)
QtCore.QMetaObject.connectSlotsByName(ShowPath)
def retranslateUi(self, ShowPath):
_translate = QtCore.QCoreApplication.translate
ShowPath.setWindowTitle(_translate("ShowPath", "ShowPath"))
self.showPath.headerItem().setText(0, _translate("ShowPath", "source"))
self.showPath.headerItem().setText(1, _translate("ShowPath", "target"))
self.showPath.headerItem().setText(2, _translate("ShowPath", "metric"))
self.showPath.headerItem().setText(3, _translate("ShowPath", "latency"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
ShowPath = QtWidgets.QShowPath()
ui = Ui_ShowPath()
ui.setupUi(ShowPath)
ShowPath.show()
sys.exit(app.exec_())