2010-03-22 06:21:56 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
## Add path to library (just for examples; you do not need this)
|
2012-12-26 22:51:52 +00:00
|
|
|
import initExample
|
2011-04-05 14:35:50 +00:00
|
|
|
|
2012-03-02 03:58:02 +00:00
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
2011-04-05 14:35:50 +00:00
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
2012-03-02 03:58:02 +00:00
|
|
|
import pyqtgraph.ptime as ptime
|
2010-03-22 06:21:56 +00:00
|
|
|
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
|
|
|
|
## Create window with GraphicsView widget
|
2011-04-05 14:35:50 +00:00
|
|
|
view = pg.GraphicsView()
|
2012-03-17 15:47:20 +00:00
|
|
|
view.show() ## show view alone in its own window
|
2010-03-22 06:21:56 +00:00
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
## Allow mouse scale/pan. Normally we use a ViewBox for this, but
|
|
|
|
## for simple examples this is easier.
|
2010-03-22 06:21:56 +00:00
|
|
|
view.enableMouse()
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
## lock the aspect ratio so pixels are always square
|
2010-03-22 06:21:56 +00:00
|
|
|
view.setAspectLocked(True)
|
|
|
|
|
|
|
|
## Create image item
|
2012-03-02 02:55:32 +00:00
|
|
|
img = pg.ImageItem(border='w')
|
2010-03-22 06:21:56 +00:00
|
|
|
view.scene().addItem(img)
|
|
|
|
|
|
|
|
## Set initial view bounds
|
2012-03-02 02:55:32 +00:00
|
|
|
view.setRange(QtCore.QRectF(0, 0, 600, 600))
|
2010-03-22 06:21:56 +00:00
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
## Create random image
|
2012-03-02 02:55:32 +00:00
|
|
|
data = np.random.normal(size=(15, 600, 600), loc=1024, scale=64).astype(np.uint16)
|
2011-04-05 14:35:50 +00:00
|
|
|
i = 0
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
updateTime = ptime.time()
|
|
|
|
fps = 0
|
|
|
|
|
2010-03-22 06:21:56 +00:00
|
|
|
def updateData():
|
2012-03-02 02:55:32 +00:00
|
|
|
global img, data, i, updateTime, fps
|
2010-03-22 06:21:56 +00:00
|
|
|
|
|
|
|
## Display the data
|
2012-03-02 02:55:32 +00:00
|
|
|
img.setImage(data[i])
|
2011-04-05 14:35:50 +00:00
|
|
|
i = (i+1) % data.shape[0]
|
2011-06-14 23:47:52 +00:00
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
QtCore.QTimer.singleShot(1, updateData)
|
|
|
|
now = ptime.time()
|
|
|
|
fps2 = 1.0 / (now-updateTime)
|
|
|
|
updateTime = now
|
|
|
|
fps = fps * 0.9 + fps2 * 0.1
|
|
|
|
|
|
|
|
#print "%0.1f fps" % fps
|
2010-03-22 06:21:56 +00:00
|
|
|
|
|
|
|
|
2011-06-14 23:47:52 +00:00
|
|
|
updateData()
|
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
## Start Qt event loop unless running in interactive mode.
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|