-
Notifications
You must be signed in to change notification settings - Fork 8
/
Plotting.py
77 lines (58 loc) · 2.18 KB
/
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
73
74
75
76
77
"""
This file is part of HDCS.
HDCS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
HDCS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with HDCS. If not, see <http://www.gnu.org/licenses/>.
"""
# Loosely based on https://gist.github.com/Overdrivr/efea3d363556c0dcf4b6
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
from multiprocessing import Process,Pipe
import random
from GUI_colors import *
def Plot(link,N):
colors = [active_blue_solid,active_blue,active_green,white,warning,
critical, warning_solid]
color = colors[random.randint(0,len(colors)-1)] # unified color per plot
pg.setConfigOption('background','#041a25')
win = pg.GraphicsWindow()
win.resize(600,400)
win.setWindowTitle('Plot '+str(N))
plots = {}
data = {}
def add(name):
plt_zone = win.addPlot(title = name)
plt = plt_zone.plot(pen = color)
plots[name] = plt
data[name] = []
def update(link):
communicate(link)
if data:
for name,plot in plots.items():
plot.setData(data[name])
def communicate(link):
link.send('Rdy')
try:
received = link.recv()
except EOFError as e:
print('Plot.communicate exception >>',e)
pass
if 'new' in received:
name = received.split(':')[1]
add(name)
elif type(received)==dict:
for name,new_data in received.items():
data[name].append(new_data)
while len(data[name])>1000:
data[name].pop(0)
timer = QtCore.QTimer()
timer.timeout.connect(lambda: update(link))
timer.start(1)
QtGui.QApplication.instance().exec_()