from PyQt4 import QtCore,QtGui,uic
from PyQt4.QtCore import QTime, QTimer
import sys
import time
from pyqtgraph import ViewBox, PlotWidget, PlotItem
#import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
from collections import deque
from customthread import customthread
class TimeAxisItem(pg.AxisItem):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def tickStrings(self, values, scale, spacing):
a = 'a'
# PySide's QTime() initialiser fails miserably and dismisses args/kwargs
return [QTime().addMSecs(value).toString('mm:ss') for value in values]
qtCreatorFile = "mejaGetar2.ui"
Ui_MainWindow,QtBaseClass = uic.loadUiType(qtCreatorFile)
class MyApp(QtGui.QTabWidget,Ui_MainWindow):
akselerasi = 0
#threads = []
#threads2 = []
curve = None
curve2 = None
dataGraph = deque(maxlen=20)
x1 = []
y1 = []
aa = False
aa2 = 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.valueChanged.connect(self.valueAkselerasi)
self.akselerasi.sliderReleased.connect(self.getThread)
self.threadDinamis = customthread ()
self.threadDinamis.dataThread.connect(self.runningDynamic)
MyApp.curve = self.graph1.plot(pen=(255,0,0))
self.graph1.setRange(xRange=None, yRange=[-1, 1 ])
self.graph1.setLabel('bottom', 'time', 's')
self.graph1.PlotWidget(axisItems={'bottom': TimeAxisItem(orientation='bottom')})
self.graph1.showGrid(x=True, y=True)
self.graph1.setMouseEnabled(x=False, y=False)
self.l1.setText(str(self.akselerasi.value()))
def getThread(self):
if self.sender() == self.akselerasi:
MyApp.akselerasii = int(self.akselerasi.value())
if MyApp.akselerasii > 0:
if MyApp.aa == True:
print("second")
minRange = int(self.akselerasi.value()) * -1
self.graph1.setRange(xRange=None, yRange=[minRange, int(self.akselerasi.value()) ])
self.threadDinamis.trigrer(MyApp.akselerasii)
else:
minRange = int(self.akselerasi.value()) * -1
self.graph1.setRange(xRange=None, yRange=[minRange, int(self.akselerasi.value()) ])
MyApp.aa = True
print("first")
self.threadDinamis.trigrer(MyApp.akselerasii)
self.threadDinamis.start()
else:
self.threadDinamis.stop()
#self.graph1.clear()
MyApp.aa = False
MyApp.dataGraph.clear()
#MyApp.dataGraph = deque(maxlen=20)
MyApp.x1 = []
MyApp.y1 = []
def runningDynamic(self,generateData):
#print(generateData['x'])
MyApp.dataGraph.append({'x': generateData['x'], 'y': generateData['y']})
MyApp.x1 = [item['x'] for item in MyApp.dataGraph]
MyApp.y1 = [item['y'] for item in MyApp.dataGraph]
MyApp.curve.setData(x=MyApp.x1, y=MyApp.y1)
def valueAkselerasi(self):
value = self.akselerasi.value()
self.l1.setText(str(value))
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())