-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathecmcTrend.py
199 lines (169 loc) · 7.66 KB
/
ecmcTrend.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#*************************************************************************
# 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.
#
# ecmcTrend.py
#
# Created on: July 6, 2020
# Author: Anders Sandström
#
# Heavily inspired by: https://exceptionshub.com/real-time-plotting-in-while-loop-with-matplotlib.html
#
#*************************************************************************
import sys
import os
import ecmcRTCanvas
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import functools
import numpy as np
import random as rd
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 time
import threading
class ecmcTrend(QtWidgets.QDialog):
def __init__(self):
super(ecmcTrend, self).__init__()
# Define the geometry of the main window
self.setGeometry(300, 300, 900, 700)
self.setWindowTitle("ecmc plot")
self.main_frame= QtWidgets.QFrame(self)
self.main_layout = QtWidgets.QHBoxLayout()
self.left_frame = QFrame(self)
self.left_layout = QVBoxLayout()
self.right_frame = QFrame(self)
self.right_layout = QVBoxLayout()
# Manual zoom High
self.zoomHigh_frame = QFrame(self)
self.zoomHigh_layout = QGridLayout()
self.lblYMax= QLabel(text = "y-max:")
self.lineEditZoomHigh = QLineEdit(text = '100')
self.lineEditZoomHigh.setFixedSize(100, 50)
self.zoomHighBtn = QPushButton(text = '>')
self.zoomHighBtn.setFixedSize(10, 50)
self.zoomHighBtn.clicked.connect(self.zoomHighBtnAction)
self.zoomHigh_layout.addWidget(self.lblYMax,0,0,alignment = Qt.AlignRight | Qt.AlignBottom)
self.zoomHigh_layout.addWidget(self.lineEditZoomHigh,1,0,alignment = Qt.AlignRight | Qt.AlignTop)
self.zoomHigh_layout.addWidget(self.zoomHighBtn,1,1,alignment = Qt.AlignLeft | Qt.AlignTop)
self.zoomHigh_frame.setLayout(self.zoomHigh_layout)
# Auto zoom
self.zoomBtn = QPushButton(text = 'zoom auto')
self.zoomBtn.setFixedSize(100, 50)
self.zoomBtn.clicked.connect(self.zoomBtnAction)
# Pause
self.pauseBtn = QPushButton(text = 'pause')
self.pauseBtn.setFixedSize(100, 50)
self.pauseBtn.clicked.connect(self.pauseBtnAction)
# Manual zoom Low
self.zoomLow_frame = QFrame(self)
self.zoomLow_layout = QGridLayout()
self.lblYMin= QLabel(text = "y-min:")
self.lineEditZoomLow = QLineEdit(text = '-100')
self.lineEditZoomLow.setFixedSize(100, 50)
self.zoomLowBtn = QPushButton(text = '>')
self.zoomLowBtn.setFixedSize(10, 50)
self.zoomLowBtn.clicked.connect(self.zoomLowBtnAction)
self.zoomLow_layout.addWidget(self.lblYMin,0,0,alignment = Qt.AlignRight | Qt.AlignBottom)
self.zoomLow_layout.addWidget(self.lineEditZoomLow,1,0,alignment = Qt.AlignRight | Qt.AlignTop)
self.zoomLow_layout.addWidget(self.zoomLowBtn,1,1,alignment = Qt.AlignLeft | Qt.AlignTop)
self.zoomLow_frame.setLayout(self.zoomLow_layout)
# Write PV
self.pvPut_frame = QFrame(self)
self.pvPut_layout = QGridLayout()
self.lblYMin= QLabel(text = "Write PV:")
self.lineEditpvPut = QLineEdit(text = '0')
self.lineEditpvPut.setFixedSize(100, 50)
self.pvPutBtn = QPushButton(text = '>')
self.pvPutBtn.setFixedSize(10, 50)
self.pvPutBtn.clicked.connect(self.pvPutBtnAction)
self.pvPut_layout.addWidget(self.lblYMin,0,0,alignment = Qt.AlignRight | Qt.AlignBottom)
self.pvPut_layout.addWidget(self.lineEditpvPut,1,0,alignment = Qt.AlignRight | Qt.AlignTop)
self.pvPut_layout.addWidget(self.pvPutBtn,1,1,alignment = Qt.AlignLeft | Qt.AlignTop)
self.pvPut_frame.setLayout(self.pvPut_layout)
# Buffer size
self.bufferSize_frame = QFrame(self)
self.bufferSize_layout = QGridLayout()
self.lblBufferSize= QLabel(text = "Buffer size []")
self.lineBufferSize = QLineEdit(text = '1000')
self.lineBufferSize.setFixedSize(100, 50)
self.setBufferSizeBtn = QPushButton(text = '>')
self.setBufferSizeBtn.setFixedSize(10, 50)
self.setBufferSizeBtn.clicked.connect(self.setBufferSizeBtnAction)
self.bufferSize_layout.addWidget(self.lblBufferSize,0,0,alignment = Qt.AlignRight | Qt.AlignBottom) # row, col
self.bufferSize_layout.addWidget(self.lineBufferSize, 1,0,alignment = Qt.AlignRight | Qt.AlignTop)
self.bufferSize_layout.addWidget(self.setBufferSizeBtn, 1,1,alignment = Qt.AlignLeft | Qt.AlignTop)
self.bufferSize_frame.setLayout(self.bufferSize_layout)
self.spacerTop = QSpacerItem(100,50)
self.spacerZoomUpper = QSpacerItem(100,10)
self.spacerZoomLower = QSpacerItem(100,10)
self.left_layout.addWidget(self.zoomHigh_frame)
self.left_layout.addWidget(self.zoomBtn)
self.left_layout.addWidget(self.pauseBtn)
self.left_layout.addWidget(self.zoomLow_frame)
self.left_layout.addWidget(self.pvPut_frame)
# Place the matplotlib figure
self.myFig = ecmcRTCanvas.ecmcRTCanvas("ecmc plot")
self.myFig.setFixedSize(700,500 )
self.toolbar = NavigationToolbar(self.myFig, self)
self.right_layout.addWidget(self.toolbar)
self.right_layout.addWidget(self.myFig)
self.right_layout.addWidget(self.bufferSize_frame)
self.lineEditZoomLow.setText(str(self.myFig.getYLims()[0]))
self.lineEditZoomHigh.setText(str(self.myFig.getYLims()[1]))
self.left_frame.setLayout(self.left_layout)
self.right_frame.setLayout(self.right_layout)
self.main_layout.addWidget(self.left_frame)
self.main_layout.addWidget(self.right_frame)
self.main_frame.setLayout(self.main_layout)
return
def setBufferSizeBtnAction(self):
value = float(self.lineBufferSize.text())
self.myFig.setBufferSize(value)
def zoomBtnAction(self):
self.myFig.zoomAuto()
return
def zoomHighBtnAction(self):
value = float(self.lineEditZoomHigh.text())
self.myFig.zoomHigh(value)
return
def zoomLowBtnAction(self):
value = float(self.lineEditZoomLow.text())
self.myFig.zoomLow(value)
return
def pvPutBtnAction(self):
value = float(self.lineEditpvPut.text())
self.writePV(value)
return
def pauseBtnAction(self):
self.myFig.pauseUpdate()
return
def lineEditHighAction(self):
value = float(self.lineEditZoomHigh.text())
self.myFig.zoomHigh(value)
return
def lineEditLowAction(self):
value = float(self.lineEditZoomLow.text())
self.myFig.zoomLow(value)
return
def addData_callbackFunc(self, value):
self.myFig.addData(value)
return
def setYLabel(self,label):
self.myFig.setYLabel(label)
def setTitle(self,label):
self.myFig.setTitle(label)
self.setWindowTitle("ecmc plot: " + label)
def enablePut(self,enable):
self.pvPut_frame.setEnabled(enable)
self.pvPutBtn.setEnabled(enable)
self.lineEditpvPut.setEnabled(enable)
QCoreApplication.processEvents()