forked from smileboywtu/DrawZigBeeTopology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
topology_view.py
52 lines (44 loc) · 1.26 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
# show the topology use graphviz
# python 3.4
import base64
import threading
import tkinter as tk
from graphviz import Digraph
share_queue = Queue()
def update_label(label):
"use the timer to update the label image"
while not share_queue.empty():
image = share_queue.get()
label.configure(image=image)
label.image = image
share_queue.task_done()
def init_graph():
"init the graph and image panel"
dot = Digraph()
dot.name = "topology"
dot.format = "gif"
dot.filename = "zigbee_topology"
return dot
def init_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(100, update_label, (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")
share_queue.put(tk.PhotoImage(base64.b64encode(asc_image)))