-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUIApp.py
152 lines (119 loc) · 4.59 KB
/
GUIApp.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import os
import networkx as nx
import matplotlib.pyplot as plt
import matplotlib as mpl
import wx
from GUI.GUI_WebPanel import WebPanel
from config.config_constants import ALPHA_VALUE, RESULT_PIC_DPI
import sys
def draw_graph(G, node_groups, edge_groups, leaves, node_map, pos):
'''Drawing result graph to the file "result.png".
Args:
G: NetworkX graph.
node_groups: Group ID to node-list map.
edge_groups: Group ID to edge-list map.
leaves: List of leave-nodes in network graph.
node_map: Cluster node map.
pos: Position of nodes in drawing graph.
'''
mpl.rcParams['toolbar'] = 'None'
mpl.rcParams['font.size'] = 11
mpl.rcParams['font.family'] = 'Candara'
max_pos = 0
for v in pos.values():
if v[0] > max_pos:
max_pos = v[0]
if v[1] > max_pos:
max_pos = v[1]
avr_pos = max_pos / 50
# fig = plt.figure(1, figsize=(15, 8), frameon=False)
# fig.canvas.set_window_title("Mininet CE Network Graph")
frame = plt.gca()
frame.axes.get_xaxis().set_visible(False)
frame.axes.get_yaxis().set_visible(False)
frame.patch.set_facecolor((0.0, 0.0, 0.8, 0.1))
label_pos = {k: [v[0],v[1]+ avr_pos] for k, v in pos.items()}
colors = ['b','g','r','c','m','y']
labels = {}
for n in G.nodes():
if n in leaves:
labels[n] = 'h' + str(n)
else:
labels[n] = 's' + str(n)
pl_nodes = []
for group in node_groups.keys():
pl_node = nx.draw_networkx_nodes(G, pos, nodelist=node_groups[group], node_color=colors[group], node_size=50)
pl_nodes.append(pl_node)
for group in edge_groups.keys():
if group != 'no_group':
nx.draw_networkx_edges(G, pos, edgelist=edge_groups[group], edge_color=colors[group], alpha=ALPHA_VALUE, width=3.0)
else:
nx.draw_networkx_edges(G, pos, edgelist=edge_groups[group], edge_color='k', alpha=ALPHA_VALUE, width=3.0)
nx.draw_networkx_labels(G, label_pos, labels, font_size=10, font_family='candara')
leg = plt.legend(pl_nodes, node_map.keys(), prop={'size': 8}, handletextpad=3)
leg.legendPatch.set_alpha(0.77)
plt.savefig('GUI/result.png', dpi=RESULT_PIC_DPI, transparent=True, bbox_inches='tight', pad_inches=0)
class GUI_Editor(wx.Frame):
"""Class of GUI Editor.
TODO
"""
def __init__(self, parent):
'''Cunstructor of GUI Editor.
Args:
parent:
'''
self.parent = parent
style = (wx.DEFAULT_FRAME_STYLE) # wx.STAY_ON_TOP | wx.CLOSE_BOX | wx.FRAME_NO_TASKBAR | wx.SYSTEM_MENU | wx.CAPTION | wx.NO_BORDER | wx.CLIP_CHILDREN
"""Constructor"""
wx.Frame.__init__(self, None, -1, 'NPS Graph Editor', style=style, pos=wx.Point(0, 50))
self.SetSize((self.parent.width,self.parent.height)) # (1075,675)
self.SetBackgroundColour('#CECECE') #CCCCFF
self.SetTransparent(230)
panel = WebPanel(self)
self.Show()
class GUIApp():
'''Class of GUI Application.
TODO
'''
def __init__(self, html_path, width=1075, height=655):
'''Cunstructor of GUI Application.
Args:
html_path:
width:
height:
'''
os.system("cp GUI/res/not_ready.png GUI/result.png")
self.graph_data = {}
self.node_num_map = {}
self.random_flag = False
self.html_path = html_path
self.width, self.height = width, height
def main_loop(self):
app = wx.App(False)
frame = GUI_Editor(self)
app.MainLoop()
def get_networkX_graph(self):
G = nx.Graph()
node_counter = 0
pos = {}
for edge in self.graph_data['edges']:
if edge[0] not in self.node_num_map.keys():
G.add_node(node_counter)
self.node_num_map[edge[0]] = node_counter
pos[node_counter] = [self.graph_data['pos'][edge[0]][0], self.graph_data['pos'][edge[0]][1]]
node_counter += 1
if edge[1] not in self.node_num_map.keys():
G.add_node(node_counter)
self.node_num_map[edge[1]] = node_counter
pos[node_counter] = [self.graph_data['pos'][edge[1]][0], self.graph_data['pos'][edge[1]][1]]
node_counter += 1
G.add_edge(self.node_num_map[edge[0]], self.node_num_map[edge[1]])
return G, pos
def delete_gedit(self):
self.Destroy()
if __name__ == "__main__":
gui = GUIApp()
gui.main_loop()
G = gui.get_networkX_graph()
print G.nodes()
print G.edges()