-
Notifications
You must be signed in to change notification settings - Fork 1
/
ecmcArrayGui.py
131 lines (113 loc) · 4.35 KB
/
ecmcArrayGui.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#*************************************************************************
# Copyright (c) 2020 European Spallation Source ERIC
# ecmc is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#
# ecmcArrayGui.py
#
# Created on: October 8, 2020
# Author: Anders Sandström
#
# Plots two waveforms (y vs time) updates for each callback on the y-pv
#
#*************************************************************************
import sys
import epics
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import numpy as np
import matplotlib
matplotlib.use("Qt5Agg")
from matplotlib.figure import Figure
from matplotlib.animation import TimedAnimation
from matplotlib.lines import Line2D
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
import threading
class comSignal(QObject):
data_signal = pyqtSignal(object)
class ecmcArrayGui(QtWidgets.QDialog):
def __init__(self,yname=None):
super(ecmcArrayGui, self).__init__()
self.comSignalY = comSignal()
self.comSignalY.data_signal.connect(self.callbackFuncY)
self.pause = 0
self.spectY = None
self.figure = plt.figure()
self.plotted_line = None
self.ax = None
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
self.pauseBtn = QPushButton(text = 'pause')
self.pauseBtn.setFixedSize(100, 50)
self.pauseBtn.clicked.connect(self.pauseBtnAction)
self.pauseBtn.setStyleSheet("background-color: green")
self.pvNameY = yname # "IOC_TEST:Plugin-FFT0-Raw-Data-Act"
self.connectPvs() # Epics
self.setGeometry(300, 300, 900, 700)
self.setWindowTitle("ecmc Array plot: " + self.pvNameY)
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.pauseBtn)
self.setLayout(layout)
return
def connectPvs(self):
if self.pvNameY is None:
raise RuntimeError("pvname y must not be 'None'")
if len(self.pvNameY)==0:
raise RuntimeError("pvname y must not be ''")
self.pvY = epics.PV(self.pvNameY)
#print('self.pvY: ' + self.pvY.info)
self.pvY.add_callback(self.onChangePvY)
QCoreApplication.processEvents()
def onChangePvY(self,pvname=None, value=None, char_value=None,timestamp=None, **kw):
self.comSignalY.data_signal.emit(value)
def pauseBtnAction(self):
self.pause = not self.pause
if self.pause:
self.pauseBtn.setStyleSheet("background-color: red");
else:
self.pauseBtn.setStyleSheet("background-color: green");
self.comSignalY.data_signal.emit(self.spectY)
return
def callbackFuncY(self, value):
if(np.size(value)) > 0:
self.spectY = value
self.plotSpect()
return
def plotSpect(self):
if self.pause:
return
if self.spectY is None:
return
# create an axis
if self.ax is None:
self.ax = self.figure.add_subplot(111)
# plot data
if self.plotted_line is not None:
self.plotted_line.remove()
self.plotted_line, = self.ax.plot(self.spectY, 'b*-')
self.ax.grid(True)
plt.xlabel('Time []')
plt.ylabel(self.pvNameY +' [' + self.pvY.units + ']')
# refresh canvas
self.canvas.draw()
self.ax.autoscale(enable=True)
def printOutHelp():
print("ecmcArrayGui: Plots waveforms data (updates on data callback). ")
print("python ecmcArrayGui.py <y.pv>")
print("example: python ecmcArrayGui.py IOC_TEST:Plugin-FFT0-Raw-Data-Act")
if __name__ == "__main__":
import sys
if len(sys.argv)!=2:
printOutHelp()
sys.exit()
yname=sys.argv[1]
app = QtWidgets.QApplication(sys.argv)
window=ecmcArrayGui(yname=yname)
window.show()
sys.exit(app.exec_())