From c0abe6539f36679daa172476e2a9fb1312e9cf9c Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 8 Oct 2019 15:23:28 +0800 Subject: [PATCH] add real-time plotting program --- plot.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 plot.py diff --git a/plot.py b/plot.py new file mode 100644 index 0000000..ce3b7e9 --- /dev/null +++ b/plot.py @@ -0,0 +1,40 @@ +import asyncio +from PyQt5 import QtCore, QtGui, QtWidgets +import pyqtgraph +import quamash +import atexit + +async def task(mw): + widget = pyqtgraph.PlotWidget() + mw.setCentralWidget(widget) + mw.show() + + process = await asyncio.create_subprocess_shell("cargo run --release", + stdout=asyncio.subprocess.PIPE) + data = [] + while True: + line = await process.stdout.readline() + if not line: + print("input process died") + break + number = int(line.decode().strip()) + data.append(number) + widget.clear() + widget.plot(data) + + + +def main(): + app = QtWidgets.QApplication(["Plot"]) + loop = quamash.QEventLoop(app) + asyncio.set_event_loop(loop) + + mw = QtWidgets.QMainWindow() + mw.showMaximized() + + atexit.register(loop.close) + asyncio.ensure_future(task(mw)) + loop.run_forever() + + +main()