From 11897061d1d92dc7e47a9211df55d6c9de087413 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Mon, 22 Mar 2010 02:21:56 -0400 Subject: [PATCH] Removed some debugging code, moved examples --- GraphicsView.py | 10 ++-- MultiPlotItem.py | 2 +- examples/test_ImageItem.py | 49 +++++++++++++++++ .../test_ImageView.py | 15 ++++-- .../test_MultiPlotWidget.py | 15 ++++-- .../test_PlotWidget.py | 9 ++-- test_ROItypes.py => examples/test_ROItypes.py | 17 +++--- test_viewBox.py => examples/test_viewBox.py | 52 ++++--------------- widgets.py | 4 +- 9 files changed, 109 insertions(+), 64 deletions(-) create mode 100644 examples/test_ImageItem.py rename test_ImageView.py => examples/test_ImageView.py (58%) rename test_MultiPlotWidget.py => examples/test_MultiPlotWidget.py (54%) rename test_PlotWidget.py => examples/test_PlotWidget.py (87%) rename test_ROItypes.py => examples/test_ROItypes.py (85%) rename test_viewBox.py => examples/test_viewBox.py (51%) diff --git a/GraphicsView.py b/GraphicsView.py index 46514ee1..3367ef54 100644 --- a/GraphicsView.py +++ b/GraphicsView.py @@ -234,11 +234,11 @@ class GraphicsView(QtGui.QGraphicsView): def mousePressEvent(self, ev): QtGui.QGraphicsView.mousePressEvent(self, ev) - print "Press over:" - for i in self.items(ev.pos()): - print i.zValue(), int(i.acceptedMouseButtons()), i, i.scenePos() - print "Event accepted:", ev.isAccepted() - print "Grabber:", self.scene().mouseGrabberItem() + #print "Press over:" + #for i in self.items(ev.pos()): + #print i.zValue(), int(i.acceptedMouseButtons()), i, i.scenePos() + #print "Event accepted:", ev.isAccepted() + #print "Grabber:", self.scene().mouseGrabberItem() if not self.mouseEnabled: return self.lastMousePos = Point(ev.pos()) diff --git a/MultiPlotItem.py b/MultiPlotItem.py index 137813db..83f08505 100644 --- a/MultiPlotItem.py +++ b/MultiPlotItem.py @@ -13,7 +13,7 @@ try: from metaarray import * HAVE_METAARRAY = True except: - raise + #raise HAVE_METAARRAY = False diff --git a/examples/test_ImageItem.py b/examples/test_ImageItem.py new file mode 100644 index 00000000..3d46fb8d --- /dev/null +++ b/examples/test_ImageItem.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +## Add path to library (just for examples; you do not need this) +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) + +from pyqtgraph.GraphicsView import * +from pyqtgraph.graphicsItems import * +from numpy import random +from PyQt4 import QtCore, QtGui +from scipy.ndimage import * + +app = QtGui.QApplication([]) + +## Create window with GraphicsView widget +win = QtGui.QMainWindow() +view = GraphicsView() +win.setCentralWidget(view) +win.show() + +## Allow mouse scale/pan +view.enableMouse() + +## ..But lock the aspect ratio +view.setAspectLocked(True) + +## Create image item +img = ImageItem() +view.scene().addItem(img) + +## Set initial view bounds +view.setRange(QtCore.QRectF(0, 0, 200, 200)) + +def updateData(): + global img + ## Create random image + data = random.random((200, 200)) + + ## Display the data + img.updateImage(data) + + +# update image data every 20ms (or so) +t = QtCore.QTimer() +QtCore.QObject.connect(t, QtCore.SIGNAL('timeout()'), updateData) +t.start(20) + + + +app.exec_() diff --git a/test_ImageView.py b/examples/test_ImageView.py similarity index 58% rename from test_ImageView.py rename to examples/test_ImageView.py index ea197f95..9387c1b0 100644 --- a/test_ImageView.py +++ b/examples/test_ImageView.py @@ -1,21 +1,30 @@ # -*- coding: utf-8 -*- +## Add path to library (just for examples; you do not need this) +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) -from ImageView import * +from pyqtgraph.ImageView import * from numpy import random from PyQt4 import QtCore, QtGui from scipy.ndimage import * app = QtGui.QApplication([]) + +## Create window with ImageView widget win = QtGui.QMainWindow() imv = ImageView() win.setCentralWidget(imv) win.show() +## Create random 3D data set img = gaussian_filter(random.random((200, 200)), (5, 5)) * 5 data = random.random((100, 200, 200)) data += img - for i in range(data.shape[0]): data[i] += exp(-(2.*i)/data.shape[0]) data += 10 -imv.setImage(data) \ No newline at end of file + +## Display the data +imv.setImage(data) + +app.exec_() diff --git a/test_MultiPlotWidget.py b/examples/test_MultiPlotWidget.py similarity index 54% rename from test_MultiPlotWidget.py rename to examples/test_MultiPlotWidget.py index ab29f115..c24053ea 100755 --- a/test_MultiPlotWidget.py +++ b/examples/test_MultiPlotWidget.py @@ -1,12 +1,19 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +## Add path to library (just for examples; you do not need this) +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) from scipy import random from numpy import linspace from PyQt4 import QtGui, QtCore -from MultiPlotWidget import * -from metaarray import * - +from pyqtgraph.MultiPlotWidget import * +try: + from metaarray import * +except: + print "MultiPlot is only used with MetaArray for now (and you do not have the metaarray module)" + exit() + app = QtGui.QApplication([]) mw = QtGui.QMainWindow() pw = MultiPlotWidget() @@ -15,3 +22,5 @@ mw.show() ma = MetaArray(random.random((3, 1000)), info=[{'name': 'Signal', 'cols': [{'name': 'Col1'}, {'name': 'Col2'}, {'name': 'Col3'}]}, {'name': 'Time', 'vals': linspace(0., 1., 1000)}]) pw.plot(ma) + +app.exec_() \ No newline at end of file diff --git a/test_PlotWidget.py b/examples/test_PlotWidget.py similarity index 87% rename from test_PlotWidget.py rename to examples/test_PlotWidget.py index d022c716..e40c1390 100755 --- a/test_PlotWidget.py +++ b/examples/test_PlotWidget.py @@ -1,10 +1,13 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +## Add path to library (just for examples; you do not need this) +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) from scipy import random from PyQt4 import QtGui, QtCore -from PlotWidget import * -from graphicsItems import * +from pyqtgraph.PlotWidget import * +from pyqtgraph.graphicsItems import * app = QtGui.QApplication([]) @@ -77,4 +80,4 @@ for i in range(0, 5): yd, xd = rand(10000) pw2.plot(yd*(j+1), xd, params={'iter': i, 'val': j}) -#app.exec_() \ No newline at end of file +app.exec_() \ No newline at end of file diff --git a/test_ROItypes.py b/examples/test_ROItypes.py similarity index 85% rename from test_ROItypes.py rename to examples/test_ROItypes.py index 1d50f7fb..4bca45f8 100755 --- a/test_ROItypes.py +++ b/examples/test_ROItypes.py @@ -1,13 +1,17 @@ #!/usr/bin/python -i # -*- coding: utf-8 -*- +## Add path to library (just for examples; you do not need this) +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) + from scipy import zeros -from graphicsWindows import * -from graphicsItems import * -from widgets import * -from PlotWidget import * +from pyqtgraph.graphicsWindows import * +from pyqtgraph.graphicsItems import * +from pyqtgraph.widgets import * +from pyqtgraph.PlotWidget import * from PyQt4 import QtCore, QtGui -qapp = QtGui.QApplication([]) +app = QtGui.QApplication([]) #i = PlotWindow(array([0,1,2,1,2]), parent=None, title='') @@ -85,4 +89,5 @@ mlroi.connect(QtCore.SIGNAL('regionChanged'), lambda: updateImg(mlroi)) v.setRange(QtCore.QRect(-2, -2, 220, 220)) -w.show() \ No newline at end of file +w.show() +app.exec_() diff --git a/test_viewBox.py b/examples/test_viewBox.py similarity index 51% rename from test_viewBox.py rename to examples/test_viewBox.py index 0c51963b..3917dc58 100755 --- a/test_viewBox.py +++ b/examples/test_viewBox.py @@ -1,11 +1,13 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +## Add path to library (just for examples; you do not need this) +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) from scipy import random from PyQt4 import QtGui, QtCore -from GraphicsView import * -from graphicsItems import * - +from pyqtgraph.GraphicsView import * +from pyqtgraph.graphicsItems import * app = QtGui.QApplication([]) mw = QtGui.QMainWindow() @@ -19,7 +21,6 @@ mw.resize(800, 600) gv = GraphicsView(cw) gv.enableMouse(False) -#w1 = QtGui.QGraphicsWidget() l = QtGui.QGraphicsGridLayout() l.setHorizontalSpacing(0) l.setVerticalSpacing(0) @@ -27,46 +28,23 @@ l.setVerticalSpacing(0) vb = ViewBox() p1 = PlotCurveItem() -#gv.scene().addItem(vb) vb.addItem(p1) vl.addWidget(gv) rect = QtGui.QGraphicsRectItem(QtCore.QRectF(0, 0, 1, 1)) rect.setPen(QtGui.QPen(QtGui.QColor(100, 200, 100))) vb.addItem(rect) -l.addItem(vb, 0, 2) +l.addItem(vb, 0, 1) gv.centralWidget.setLayout(l) xScale = ScaleItem(orientation='bottom', linkView=vb) -l.addItem(xScale, 1, 2) +l.addItem(xScale, 1, 1) yScale = ScaleItem(orientation='left', linkView=vb) -l.addItem(yScale, 0, 1) +l.addItem(yScale, 0, 0) -xLabel = LabelItem(u"X Axis (μV)", html=True, color='CCC') -l.setRowFixedHeight(2, 20) -l.setRowFixedHeight(1, 40) -l.addItem(xLabel, 2, 2) -yLabel = LabelItem("Y Axis", color=QtGui.QColor(200, 200, 200)) -yLabel.setAngle(90) -l.setColumnFixedWidth(0, 20) -l.setColumnFixedWidth(1, 60) -l.addItem(yLabel, 0, 0) - - -#grid = GridItem(gv) -#vb.addItem(grid) - -#gv.scene().addItem(w1) -#w1.setGeometry(0, 0, 1, 1) - - -#c1 = Qwt.QwtPlotCurve() -#c1.setData(range(len(data)), data) -#c1.attach(p1) -#c2 = PlotCurve() -#c2.setData([1,2,3,4,5,6,7,8], [1,2,10,4,3,2,4,1]) -#c2.attach(p2) +xScale.setLabel(text=u"X Axis", units="s") +yScale.setLabel('Y Axis', units='V') def rand(n): data = random.random(n) @@ -74,23 +52,14 @@ def rand(n): data[int(n*0.18)] += 2 data[int(n*0.1):int(n*0.13)] *= 5 data[int(n*0.18)] *= 20 - #c1.setData(range(len(data)), data) return data, arange(n, n+len(data)) / float(n) def updateData(): yd, xd = rand(10000) p1.updateData(yd, x=xd) - - #vb.setRange(p1.boundingRect()) - #p1.plot(yd, x=xd, clear=True) yd, xd = rand(10000) -#p2.plot(yd * 1000, x=xd) -#for i in [1,2]: - #for j in range(3): - #yd, xd = rand(1000) - #p3.plot(yd * 100000 * i, x=xd, params={'repetitions': j, 'scale': i}) updateData() vb.autoRange() @@ -98,3 +67,4 @@ t = QtCore.QTimer() QtCore.QObject.connect(t, QtCore.SIGNAL('timeout()'), updateData) t.start(50) +app.exec_() \ No newline at end of file diff --git a/widgets.py b/widgets.py index 8939c4ee..7ee8b2c2 100644 --- a/widgets.py +++ b/widgets.py @@ -631,14 +631,14 @@ class Handle(QtGui.QGraphicsItem): return self.bounds def mousePressEvent(self, ev): - print "handle press" + #print "handle press" if ev.button() != QtCore.Qt.LeftButton: ev.ignore() return self.cursorOffset = self.scenePos() - ev.scenePos() for r in self.roi: r[0].pointPressEvent(r[1], ev) - print " accepted." + #print " accepted." ev.accept() def mouseReleaseEvent(self, ev):