I already sent this code once, so this is my way to use threads.

*# 'calculate' function is an inside-class thread and main thread use
calculated self.y array*








*import numpy as npimport pyqtgraph as pgimport threadingclass
FuncThread(threading.Thread):    def __init__(self,t,*a):
self._t=t        self._a=a        threading.Thread.__init__(*























*self)    def run(self):        self._t(*self._a)class MyApp():    def
__init__(self):        self.number_of_data_steps = 100000        self.qapp
= pg.mkQApp()        self.win = pg.GraphicsWindow()        plot1 =
self.win.addPlot()        curve = plot1.plot()        curve.setPen('r')
            x = np.linspace(0, self.number_of_data_steps,
self.number_of_data_steps)        self.y = np.linspace(-5, 5,
self.number_of_data_steps)                calculating_thread =
FuncThread(self.calculate)        calculating_thread.start()
    while self.win.isVisible():               curve.setData(x,self.y)
        self.qapp.processEvents()    def calculate(self):        while
self.win.isVisible():               self.y += np.random.random(self.number_*


*of_data_steps) - 0.5                    if __name__=='__main__':      m =
MyApp()*

On Thu, Jun 1, 2017 at 12:34 PM, Quinty van Dijk <[email protected]>
wrote:

> Hi,
>
> I'm trying to plot data from a drone in an updating scrolling plot. For
> the plotting I use the example code number 3 from this file:
> https://github.com/pyqtgraph/pyqtgraph/blob/develop/
> examples/scrollingPlots.py
>
> Now i want to be able to send commands to the drone while the plots keep
> updating, because that's the data that I want to see.
> Now I figured I need to multi thread using Qt, and got my code form here:
> https://groups.google.com/forum/#!topic/pyqtgraph/haiJsGhxTaQ
>
> But when I start the thread the main thread sleeps. I'm new to this and
> have no idea what's happening, can someone help me?
> Without the the threading the plots work just fine.
>
> This is my code:
>
> import pyqtgraph as pg
> import time
> from pyqtgraph.Qt import QtCore, QtGui
> import numpy as np
> from pyardrone import ARDrone, at
> import thread1
>
> ## Code for plot, copied form example.
> --
>
>
> ## Threading and updating part
>
> def update():
>     print("update")
>     update_plot_vx()
>     update_plot_vy()
>     update_plot_vz()
>
>
> class Thread(pg.QtCore.QThread):
>     newData = pg.QtCore.Signal(object)
>     def run(self):
>             thread1
>
> timer = pg.QtCore.QTimer()
> timer.timeout.connect(update)
> timer.start(50)
>
> thread = Thread()
> thread.newData.connect(update)  #It might be something with row, but
> removing it doesn't change anything
> thread.start()
>
> # Start Qt event loop unless running in interactive mode or using pyside.
> if __name__ == '__main__':
>     import sys
>     if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
>         QtGui.QApplication.instance().exec_()
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyqtgraph" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/pyqtgraph/f9941f7c-0449-42e9-98c9-bea183da47d1%40googlegroups.com
> <https://groups.google.com/d/msgid/pyqtgraph/f9941f7c-0449-42e9-98c9-bea183da47d1%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/CAD_qyJqW1KjouobESbKJ4frhRpaw51CS9aqHCQLc7sWEJDb53Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to