so, can I using this: https://groups.google.com/forum/#!topic/pyqtgraph/haiJsGhxTaQ as a example for my code if I didn't want using qTimer?
Pada Selasa, 15 Mei 2018 23.17.41 UTC+7, Luke Campagnola menulis: > > My first thought is that the example is attempting to perform GUI > operations from a thread. Qt does not support this behavior, so that > probably explains the freezing. If you search a little, there are many > articles and examples that discuss how to properly use threads with Qt. > > On Tue, May 15, 2018, 08:55 Jan Sebastian <[email protected] > <javascript:>> wrote: > >> I write an application that displays random number in real time graph, it >> run perfectly on windows but when I try it on raspberry pi it alwarys stop >> updating the graph, but the proses in the python shell is still running >> generate a rundom number and the program didn't. >> >> Any idea, how to fix it? >> >> the example of my code: >> >> >> from PyQt4 import QtCore,QtGui,uic >> from PyQt4.QtCore import QTime, QTimer >> import sys >> import time >> import threading >> from pyqtgraph import ViewBox, PlotWidget >> #import pyqtgraph as pg >> from pyqtgraph.Qt import QtCore, QtGui >> import numpy as np >> from blupblupshub import BlumBlumShub >> from TimeAxisItem import TimeAxisItem >> from collections import deque >> import random >> >> >> qtCreatorFile = "mejaGetar2.ui" >> >> >> Ui_MainWindow,QtBaseClass = uic.loadUiType(qtCreatorFile) >> >> class MyApp(QtGui.QTabWidget,Ui_MainWindow): >> akselerasi = 0 >> threads = [] >> threads2 = [] >> varGraph1 = object >> aa = False >> def __init__(self): >> >> QtGui.QTabWidget.__init__(self) >> Ui_MainWindow.__init__(self) >> self.setupUi(self) >> self.akselerasi.setMinimum(0) >> self.akselerasi.setMaximum(30) >> self.akselerasi.setValue(0) >> >> self.akselerasi.sliderReleased.connect(self.getThread) >> self.graph1.setRange(xRange=None, yRange=[-1, 1 ]) >> self.graph1.setLabel('bottom', 'time', 's') >> self.graph1.showGrid(x=True, y=True) >> #self.graph1.setLab('bottom',TimeAxisItem(orientation='bottom')) >> self.graph1.setMouseEnabled(x=False, y=False) >> MyApp.varGraph1 = self.graph1 >> >> self.l1.setText(str(self.akselerasi.value())) >> #self.currentChanged.connect(self.forceCloseThread) >> >> >> def getThread(self): >> >> if self.sender() == self.akselerasi: >> MyApp.akselerasii = int(self.akselerasi.value()) >> >> if MyApp.akselerasii > 0: >> >> thread1 = DynamicThread("akselerasi") >> >> if MyApp.aa == True: >> print("second") >> minRange = int(self.akselerasi.value()) * -1 >> self.graph1.setRange(xRange=None, yRange=[minRange, >> int(self.akselerasi.value()) ]) >> thread1.trigrer(MyApp.akselerasii) >> >> else: >> thread1.trigrer(MyApp.akselerasii) >> MyApp.threads2.append(thread1) >> minRange = int(self.akselerasi.value()) * -1 >> self.graph1.setRange(xRange=None, yRange=[minRange, >> int(self.akselerasi.value()) ]) >> MyApp.aa = True >> >> print("first") >> thread1.start() >> else: >> for t in MyApp.threads2: >> MyApp.aa = False >> t.stop() >> self.graph1.clear() >> >> >> class DynamicThread(threading.Thread,MyApp): >> intAkselerasi = 0 >> ruuun = False >> >> def __init__(self,sub): >> threading.Thread.__init__(self) >> >> self.subject = sub >> >> def trigrer(self,num): >> DynamicThread.intAkselerasi = num >> >> def run(self): >> listData = [] >> a = 0 >> count = 0 >> test = 0 >> t = QTime() >> t.start() >> dataGraph = deque(maxlen=20) >> x1 = [] >> y1 = [] >> >> print("starting " + self.subject) >> dynamicGenerator = BlumBlumShub() >> curve = MyApp.varGraph1.plot(pen=(255,0,0)) >> while DynamicThread.ruuun == True: >> if DynamicThread.intAkselerasi > 0: >> minus = DynamicThread.intAkselerasi *-1 >> data = random.randint(minus,DynamicThread.intAkselerasi) >> >> dataGraph.append({'x': t.elapsed(), 'y': data}) >> x1 = [item['x'] for item in dataGraph] >> y1 = [item['y'] for item in dataGraph] >> curve.setData(x=x1, y=y1) >> print("test: ",data) >> print("\n") >> a = a + 1 >> >> time.sleep(0.5) >> >> else: >> DynamicThread.ruuun = False >> print("stop") >> break >> print("stoping " + self.subject) >> dataGraph = [] >> x1 = [] >> y1 = [] >> >> def start(self): >> DynamicThread.ruuun = True >> super(DynamicThread,self).start() >> >> def stop(self): >> DynamicThread.ruuun = False >> >> if __name__ == "__main__": >> app = QtGui.QApplication(sys.argv) >> window = MyApp() >> window.show() >> sys.exit(app.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] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/pyqtgraph/292d1a51-6aae-4d2c-b7c9-6228dccf178b%40googlegroups.com >> >> <https://groups.google.com/d/msgid/pyqtgraph/292d1a51-6aae-4d2c-b7c9-6228dccf178b%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/3ea7cd1c-07f7-4b5a-ba60-0ebc02607a9c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
