Skip to content

Instantly share code, notes, and snippets.

@raininja
Created September 16, 2013 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raininja/6587733 to your computer and use it in GitHub Desktop.
Save raininja/6587733 to your computer and use it in GitHub Desktop.
pyqtgraph update issues
class MainWindow(QtGui.QMainWindow):
""" init Qt and draw stuff """
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.resize(1000,600)
self.setWindowTitle('pyqtnia-alpha')
area = DockArea()
self.setCentralWidget(area)
dock1 = Dock("one", size=(150,550), hideTitle=True)
dock2 = Dock("", size=(700,550), hideTitle=True)
dock3 = Dock("", size=(150,550), hideTitle=True)
dock4 = Dock("", size=(1000,20), hideTitle=True)
area.addDock(dock1, 'top')
area.addDock(dock2, 'right')
area.addDock(dock3, 'right')
area.addDock(dock4, 'bottom')
#self.app = QtGui.QApplication([])
#self.app.setGraphicsSystem('opengl')
g = gl.GLGridItem()
g.scale(2,2,1)
g.setDepthValue(10) # draw grid after surfaces since they may be translucent
w1 = gl.GLViewWidget()
w1.setCameraPosition(distance=50)
"""
in the next sequence there needs to be an update thread created
so that the plot will display the new values from the NIA
"""
milliseconds = 50
nd = NiaData(milliseconds)
fourier = nd.fourier()
#qoutput = fourier(qoutput)
#self.fingers = self.fourier(getattr(fingers))
Fourier_Data = nd.Fourier_Data
print(Fourier_Data)
#print(qoutput)
#test_text = self.nd(self, getattr(self.nd.Fourier_Data))
#w1.addItem(QtGui.QGraphicsTextItem.mapFromItem(Fourier_Data))
text_area = QtCore.QTextStream()
#text_holder = gl.GLViewWidget.renderText(x=1.0, y=1.0, z=0.0, qoutput)
#convert = (QtGui.QGraphicsTextItem.mapFromItem(qoutput))
phase = 0.
pos3 = np.zeros((100,100,3))
pos3[:,:,:2] = np.mgrid[:100, :100].transpose(1,2,0) * [-0.1,0.1]
pos3 = pos3.reshape(10000,3)
#pos3 = Fourier_Data
d3 = (pos3**2).sum(axis=1)**0.5
sp3 = gl.GLScatterPlotItem(pos=pos3, color=(1,1,1,.3), size=0.1, pxMode=False)
w1.addItem(g)
w1.addItem(sp3)
dock2.addWidget(w1)
def updater():
## update surface positions and colors
global sp3, d3, pos3, phase
phase = -0.1
z = -np.cos(d3*2+phase)
pos3[:,2] = z
color = np.empty((len(d3),4), dtype=np.float32)
color[:,3] = 0.3
color[:,0] = np.clip(z * 3.0, 0, 1)
color[:,1] = np.clip(z * 1.0, 0, 1)
color[:,2] = np.clip(z ** 3, 0, 1)
sp3.setData(pos=pos3, color=color)
def dataCollector(self):
"""
this function will send data to a database
"""
pass
def begin():
milliseconds = 50
nia = NIA()
nia_data = NiaData(milliseconds)
data_thread = threading.Thread(target=nia_data.get_data)
data_thread.start()
t = QtCore.QTimer()
t.timeout.connect(MainWindow.updater())
t.start(milliseconds)
if __name__ == '__main__':
import sys
# open the NIA, or exit with a failure code
nia = NIA()
if not nia.open():
sys.exit(1)
begin()
# milliseconds = 50
# nia_data = NiaData(milliseconds)
# start data collection thread
# kick-off processing data from the NIA
#plot1_data()
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
app.quitOnLastWindowClosed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment