2010-03-22 06:21:56 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
## Add path to library (just for examples; you do not need this)
|
|
|
|
import sys, os
|
2011-04-05 16:53:05 +00:00
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
2012-03-02 02:55:32 +00:00
|
|
|
import ptime
|
2011-04-05 14:35:50 +00:00
|
|
|
|
2010-03-22 06:21:56 +00:00
|
|
|
from PyQt4 import QtCore, QtGui
|
2011-04-05 14:35:50 +00:00
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
2010-03-22 06:21:56 +00:00
|
|
|
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
|
|
|
|
## Create window with GraphicsView widget
|
|
|
|
win = QtGui.QMainWindow()
|
2011-06-14 23:47:52 +00:00
|
|
|
win.resize(800,800)
|
2011-04-05 14:35:50 +00:00
|
|
|
view = pg.GraphicsView()
|
2010-03-22 06:21:56 +00:00
|
|
|
win.setCentralWidget(view)
|
|
|
|
win.show()
|
|
|
|
|
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.
|
|
|
|
if sys.flags.interactive != 1:
|
|
|
|
app.exec_()
|