-
Notifications
You must be signed in to change notification settings - Fork 0
/
RealTime-Window-Plot.py
96 lines (68 loc) · 2.72 KB
/
RealTime-Window-Plot.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
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import random
import numpy as np
import sys
import Tkinter as tk
import time
import API.winWlanApi as wlanAPI
import API.PhysicalAccessPoint as PhyAP
import AP_WalkMeasure_Relative_Plot as APRelPlotLib
def realTimePlot(fig, ax):
PhysicalAPs = PhyAP.PhysicalAccessPoint()
PhysicalAPs = wlanAPI.scan_AP_Fisicos()
if not hasattr(fig,'realTimeData'):
fig.realTimeData = {}
i=-10
APFisicoPerPiso = PhysicalAPs.getAPFisicoPerPiso('0')
if APFisicoPerPiso!="cenas":
#for bssi in APFisicoPerPiso:
for bssi in PhysicalAPs.physicalAPs:
i+=2
tempRSSI = PhysicalAPs.getAverage(bssi,(0,0))
if fig.realTimeData.has_key(bssi):
fig.realTimeData[bssi]['line'][0].set_ydata(tempRSSI)
fig.realTimeData[bssi]['annote'].xytext =(-11,tempRSSI+0.5)
ax.lines.remove(fig.realTimeData[bssi]['line'][0])
fig.realTimeData[bssi]['annote'].remove()
fig.realTimeData.pop(bssi)
else:
fig.realTimeData[bssi] = {}
fig.realTimeData[bssi]['line'] = ax.plot([-10, 10], [tempRSSI,tempRSSI],'b-')
fig.realTimeData[bssi]['annote'] = ax.annotate(str(tempRSSI),fontsize='xx-small', xy=(-11, tempRSSI), xytext=(-11, tempRSSI+0.5) )
else:
print "Nao h? APs no piso."
return fig
class App():
def key(self, event):
print "cenas"
print("Clicked at: ", repr(event.char))
def __init__(self):
self.root = tk.Tk()
self.root.wm_title("Embedding in TK")
self.frame = tk.Frame(self.root, width=100, height=100)
self.fig,self.ax,self.ax2 = APRelPlotLib.renderedRelativePlot()
self.fig.delaxes(self.ax2)
self.canvas = FigureCanvasTkAgg(self.fig, master=self.root)
self.toolbar = NavigationToolbar2TkAgg( self.canvas, self.root )
self.toolbar.update()
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
self.label = tk.Label(text="")
self.frame.bind("<Key>", self.key)
self.frame.bind("<1>", lambda event: self.frame.focus_set())
self.frame.pack()
self.label.pack()
self.update_clock()
self.root.mainloop()
def update_clock(self):
self.fig = realTimePlot(self.fig,self.ax)
self.canvas.show()
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
now = time.strftime("%H:%M:%S")
self.label.configure(text=now)
self.root.after(200, self.update_clock)
app=App()