-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_plotting.py
76 lines (45 loc) · 1.58 KB
/
test_plotting.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
from hw_interface.definitions import MessageMovementCommandReply
from gui.plotting import GraphPlotter
import PySimpleGUI as sg
from random import random, randint
import threading, time
layout = [
[sg.Canvas(size=(400,400), k="canvas")],
]
def get_data():
print("get_data")
data = []
for i in range(randint(250,500)):
data.append(
MessageMovementCommandReply(
current = random() *200+100,
position=1000.5 +i,
tics = 50000 + 1031.111*i,
millis = 2891283,
)
)
sorted_ = sorted(data)
return [i.tics for i in sorted_],[i.current for i in sorted_]
def update_graph_thread(window:sg.Window):
while True:
time.sleep(2)
x, y = get_data()
window.write_event_value("UPDATE", dict(x=x, y=y))
def update_graph(event, values):
d = values[event]
x, y = d.get('x'), d.get('y')
print("update graph", "x = ", len(x))
graph_plotter.plot_data(x, y)
if __name__ == "__main__":
window = sg.Window("Testing Stuff.", layout, size=(800,800), finalize=True)
x_data, y_data = get_data()
graph_plotter = GraphPlotter(window["canvas"])
graph_plotter.plot_data(x_data, y_data)
threading.Thread(target=update_graph_thread, args=(window,), daemon=True).start()
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'):
break
if event == "UPDATE":
update_graph(event, values)
window.close()