尝试在PyQt5中打开PyQtGraph窗口

问题描述 投票:0回答:1

我的OptionsViz类正在单独工作。但是,当我抛出异步内容时,它什么也没显示。为了简洁起见,我需要删除该代码,因此请不要将其丢弃。

from PyQt5.QtWidgets import QApplication, QMainWindow, QDockWidget
from PyQt5 import QtGui, QtCore
# from quamash import QEventLoop, QThreadExecutor
import pyqtgraph as pg
import numpy as np

class OptionViz():

  def __init__(self, app):
    self.app = app

    p = pg.plot()
    p.setWindowTitle('pyqtgraph example: PlotSpeedTest')
    p.setRange(QtCore.QRectF(0, -10, 5000, 20))
    p.setLabel('bottom', 'Index', units='B')
    self.curve = p.plot()
    self.data = np.random.normal(size=(50, 5000))

    timer = QtCore.QTimer()
    timer.timeout.connect(self.update)
    timer.start(0)

  def update(self):
    self.curve.setData(self.data[self.ptr % 10])
    self.app.processEvents()  ## force complete redraw for every plot


async def main():
  app = QApplication([])
  OptionViz(app)


loop = asyncio.get_event_loop()
loop.create_task(main())
loop.run_forever()
python pyqt pyqtgraph
1个回答
0
投票
import sys import asyncio from qasync import QEventLoop from PyQt5 import QtCore, QtWidgets import pyqtgraph as pg import numpy as np class OptionViz: def __init__(self, app): self.app = app p = pg.plot() p.setWindowTitle("pyqtgraph example: PlotSpeedTest") p.setRange(QtCore.QRectF(0, -10, 5000, 20)) p.setLabel("bottom", "Index", units="B") self.curve = p.plot() async def main(viz): data = np.random.normal(size=(50, 5000)) ptr = 0 while True: viz.curve.setData(data[ptr % 10]) await asyncio.sleep(0.1) ptr += 1 if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) loop = QEventLoop(app) asyncio.set_event_loop(loop) viz = OptionViz(app) loop.create_task(main(viz)) loop.run_forever()
© www.soinside.com 2019 - 2024. All rights reserved.