-
Notifications
You must be signed in to change notification settings - Fork 1
/
topology_view.py
56 lines (48 loc) · 1.46 KB
/
topology_view.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
# show the topology use graphviz
# python 3.4
import base64
import threading
import tkinter as tk
from datetime import time
from graphviz import Digraph
share_queue = Queue()
def update_label(root, label):
"use the timer to update the label image"
if not share_queue.empty():
image = share_queue.get()
label.configure(image=image)
label.image = image
share_queue.task_done()
print(time.hour(), ":", time.minute(), ":", time.second(), " update the topology.")
root.after(200, update_label, root, label)
def init_graph():
"init the graph and image panel"
dot = Digraph()
dot.name = "topology"
dot.format = "gif"
dot.filename = "zigbee_topology"
return dot
def start_view():
"init a window"
root = tk.Tk()
root.title("ZigBee Network Topology")
text_lable = tk.Label(root, text="""
zigbee network topology
and now the network is running,
new added node will update the
topology image.""")
image_lable = tk.Label(root)
text_lable.pack(side="left")
image_lable.pack(side="right")
root.after(200, update_label, root, image_lable)
root.mainloop()
def add_new_edge(dot, a, b):
"add new edge to the graph"
if a == b:
dot.node(a, "Coord")
else:
dot.edge(a, b)
# add new image content
asc_image = dot.pipe(format="gif")
image_data = tk.PhotoImage(data=base64.b64encode(asc_image))
share_queue.put(image_data)