2
0
forked from awendt/pyrelacs
minipyrelacs/pyrelacs/ui/plots/continously.py

41 lines
1.3 KiB
Python

import pyqtgraph as pg
from PyQt6.QtCore import QTimer
from pyrelacs.dataio.circbuffer import CircBuffer
from pyrelacs.util.logging import config_logging
log = config_logging()
class Continously:
def __init__(self, figure: pg.GraphicsLayoutWidget, buffer: CircBuffer):
self.figure = figure
self.buffer = buffer
def plot_daq(self, *args, **kwargs):
self.figure.setBackground("w")
self.daq_plot = self.figure.addPlot(row=0, col=0)
self.time = list(range(10))
pen = pg.mkPen("red")
self.data = list(range(10))
self.line = self.daq_plot.plot(self.time, self.data, pen=pen)
self.item = 0
self.timer = QTimer()
self.timer.setInterval(1)
self.timer.timeout.connect(self.update_plot)
self.timer.start()
def update_plot(self):
if self.buffer.totalcount() > 100:
if self.buffer.write_index() > self.item:
self.time = self.time[1:]
self.time.append(self.time[-1] + 1)
self.data = self.data[1:]
item = self.buffer.get(self.item)
self.data.append(item)
self.line.setData(self.time, self.data)
self.item += 1
else:
pass