Added new examples

This commit is contained in:
Luke Campagnola 2012-05-31 16:05:19 -04:00
parent ce5fef9675
commit 5644a17045
7 changed files with 270 additions and 8 deletions

30
examples/ColorButton.py Normal file
View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
import initExample ## Add path to library (just for examples; you do not need this)
"""
Simple example demonstrating a button which displays a colored rectangle
and allows the user to select a new color by clicking on the button.
"""
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
app = QtGui.QApplication([])
win = QtGui.QMainWindow()
btn = pg.ColorButton()
win.setCentralWidget(btn)
win.show()
def change(btn):
print("change", btn.color())
def done(btn):
print("done", btn.color())
btn.sigColorChanging.connect(change)
btn.sigColorChanged.connect(done)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
"""
Simple use of DataTreeWidget to display a structure of nested dicts, lists, and arrays
"""
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
app = QtGui.QApplication([])
d = {
'list1': [1,2,3,4,5,6, {'nested1': 'aaaaa', 'nested2': 'bbbbb'}, "seven"],
'dict1': {
'x': 1,
'y': 2,
'z': 'three'
},
'array1 (20x20)': np.ones((10,10))
}
tree = pg.DataTreeWidget(data=d)
tree.show()
tree.resize(600,600)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -62,12 +62,17 @@ update(rois[-1])
text = """Extraction of traces from image data""" text = """User-Modifiable ROIs<br>
Click on a line segment to add a new handle.
Right click on a handle to remove.
"""
w2 = w.addLayout(row=0, col=1) w2 = w.addLayout(row=0, col=1)
label2 = w2.addLabel(text, row=0, col=0) label2 = w2.addLabel(text, row=0, col=0)
v2a = w2.addViewBox(row=1, col=0, lockAspect=True) v2a = w2.addViewBox(row=1, col=0, lockAspect=True)
v2b = w2.addPlot(row=2, col=0) r2a = pg.PolyLineROI([[0,0], [10,10], [10,30], [30,10]], closed=True)
v2a.addItem(r2a)
r2b = pg.PolyLineROI([[0,-20], [10,-10], [10,-30]], closed=False)
v2a.addItem(r2b)
text = """Building custom ROI types<Br> text = """Building custom ROI types<Br>
ROIs can be built with a variety of different handle types<br> ROIs can be built with a variety of different handle types<br>

View File

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ScatterPlotSpeedTestTemplate.ui'
#
# Created: Tue May 8 23:09:16 2012
# by: PyQt4 UI code generator 4.8.5
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 300)
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.gridLayout = QtGui.QGridLayout(Form)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.plot = PlotWidget(Form)
self.plot.setObjectName(_fromUtf8("plot"))
self.gridLayout.addWidget(self.plot, 0, 0, 1, 2)
self.identicalCheck = QtGui.QCheckBox(Form)
self.identicalCheck.setText(QtGui.QApplication.translate("Form", "Identical", None, QtGui.QApplication.UnicodeUTF8))
self.identicalCheck.setObjectName(_fromUtf8("identicalCheck"))
self.gridLayout.addWidget(self.identicalCheck, 1, 0, 1, 1)
self.pixelModeCheck = QtGui.QCheckBox(Form)
self.pixelModeCheck.setText(QtGui.QApplication.translate("Form", "pixel mode", None, QtGui.QApplication.UnicodeUTF8))
self.pixelModeCheck.setObjectName(_fromUtf8("pixelModeCheck"))
self.gridLayout.addWidget(self.pixelModeCheck, 1, 1, 1, 1)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
pass
from pyqtgraph import PlotWidget

105
examples/SpinBox.py Normal file
View File

@ -0,0 +1,105 @@
# -*- coding: utf-8 -*-
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
app = QtGui.QApplication([])
spins = [
("Floating-point spin box, min=0, no maximum.", pg.SpinBox(value=5.0, bounds=[0, None])),
("Integer spin box, dec stepping<br>(1-9, 10-90, 100-900, etc)", pg.SpinBox(value=10, int=True, dec=True, minStep=1, step=1)),
("Float with SI-prefixed units<br>(n, u, m, k, M, etc)", pg.SpinBox(value=0.9, suffix='V', siPrefix=True)),
("Float with SI-prefixed units,<br>dec step=0.1, minStep=0.1", pg.SpinBox(value=1.0, suffix='V', siPrefix=True, dec=True, step=0.1, minStep=0.1)),
("Float with SI-prefixed units,<br>dec step=0.5, minStep=0.01", pg.SpinBox(value=1.0, suffix='V', siPrefix=True, dec=True, step=0.5, minStep=0.01)),
("Float with SI-prefixed units,<br>dec step=1.0, minStep=0.001", pg.SpinBox(value=1.0, suffix='V', siPrefix=True, dec=True, step=1.0, minStep=0.001)),
]
win = QtGui.QMainWindow()
cw = QtGui.QWidget()
layout = QtGui.QGridLayout()
cw.setLayout(layout)
win.setCentralWidget(cw)
win.show()
#win.resize(300, 600)
changingLabel = QtGui.QLabel() ## updated immediately
changedLabel = QtGui.QLabel() ## updated only when editing is finished or mouse wheel has stopped for 0.3sec
changingLabel.setMinimumWidth(200)
font = changingLabel.font()
font.setBold(True)
font.setPointSize(14)
changingLabel.setFont(font)
changedLabel.setFont(font)
labels = []
def valueChanged(sb):
changedLabel.setText("Final value: %s" % str(sb.value()))
def valueChanging(sb, value):
changingLabel.setText("Value changing: %s" % str(sb.value()))
for text, spin in spins:
label = QtGui.QLabel(text)
labels.append(label)
layout.addWidget(label)
layout.addWidget(spin)
spin.sigValueChanged.connect(valueChanged)
spin.sigValueChanging.connect(valueChanging)
layout.addWidget(changingLabel, 0, 1)
layout.addWidget(changedLabel, 2, 1)
#def mkWin():
#win = QtGui.QMainWindow()
#g = QtGui.QFormLayout()
#w = QtGui.QWidget()
#w.setLayout(g)
#win.setCentralWidget(w)
#s1 = SpinBox(value=5, step=0.1, bounds=[-1.5, None], suffix='units')
#t1 = QtGui.QLineEdit()
#g.addRow(s1, t1)
#s2 = SpinBox(value=10e-6, dec=True, step=0.1, minStep=1e-6, suffix='A', siPrefix=True)
#t2 = QtGui.QLineEdit()
#g.addRow(s2, t2)
#s3 = SpinBox(value=1000, dec=True, step=0.5, minStep=1e-6, bounds=[1, 1e9], suffix='Hz', siPrefix=True)
#t3 = QtGui.QLineEdit()
#g.addRow(s3, t3)
#s4 = SpinBox(int=True, dec=True, step=1, minStep=1, bounds=[-10, 1000])
#t4 = QtGui.QLineEdit()
#g.addRow(s4, t4)
#win.show()
#import sys
#for sb in [s1, s2, s3,s4]:
##QtCore.QObject.connect(sb, QtCore.SIGNAL('valueChanged(double)'), lambda v: sys.stdout.write(str(sb) + " valueChanged\n"))
##QtCore.QObject.connect(sb, QtCore.SIGNAL('editingFinished()'), lambda: sys.stdout.write(str(sb) + " editingFinished\n"))
#sb.sigValueChanged.connect(valueChanged)
#sb.sigValueChanging.connect(valueChanging)
#sb.editingFinished.connect(lambda: sys.stdout.write(str(sb) + " editingFinished\n"))
#return win, w, [s1, s2, s3, s4]
#a = mkWin()
#def test(n=100):
#for i in range(n):
#win, w, sb = mkWin()
#for s in sb:
#w.setParent(None)
#s.setParent(None)
#s.valueChanged.disconnect()
#s.editingFinished.disconnect()
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

45
examples/TreeWidget.py Normal file
View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
import initExample ## Add path to library (just for examples; you do not need this)
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
app = QtGui.QApplication([])
w = pg.TreeWidget()
w.setColumnCount(2)
w.show()
i1 = QtGui.QTreeWidgetItem(["Item 1"])
i11 = QtGui.QTreeWidgetItem(["Item 1.1"])
i12 = QtGui.QTreeWidgetItem(["Item 1.2"])
i2 = QtGui.QTreeWidgetItem(["Item 2"])
i21 = QtGui.QTreeWidgetItem(["Item 2.1"])
i211 = QtGui.QTreeWidgetItem(["Item 2.1.1"])
i212 = QtGui.QTreeWidgetItem(["Item 2.1.2"])
i22 = QtGui.QTreeWidgetItem(["Item 2.2"])
i3 = QtGui.QTreeWidgetItem(["Item 3"])
i4 = QtGui.QTreeWidgetItem(["Item 4"])
i5 = QtGui.QTreeWidgetItem(["Item 5"])
w.addTopLevelItem(i1)
w.addTopLevelItem(i2)
w.addTopLevelItem(i3)
w.addTopLevelItem(i4)
w.addTopLevelItem(i5)
i1.addChild(i11)
i1.addChild(i12)
i2.addChild(i21)
i21.addChild(i211)
i21.addChild(i212)
i2.addChild(i22)
b1 = QtGui.QPushButton("B1")
w.setItemWidget(i1, 1, b1)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -22,7 +22,7 @@ examples = OrderedDict([
('IsocurveItem', 'isocurve.py'), ('IsocurveItem', 'isocurve.py'),
('ImageItem - video', 'ImageItem.py'), ('ImageItem - video', 'ImageItem.py'),
('ImageItem - draw', 'Draw.py'), ('ImageItem - draw', 'Draw.py'),
('Region-of-Interest', 'ROItypes.py'), ('Region-of-Interest', 'ROIExamples.py'),
('GraphicsLayout', 'GraphicsLayout.py'), ('GraphicsLayout', 'GraphicsLayout.py'),
('Text Item', 'text.py'), ('Text Item', 'text.py'),
('Linked Views', 'linkedViews.py'), ('Linked Views', 'linkedViews.py'),
@ -35,12 +35,12 @@ examples = OrderedDict([
])), ])),
('Widgets', OrderedDict([ ('Widgets', OrderedDict([
('PlotWidget', 'PlotWidget.py'), ('PlotWidget', 'PlotWidget.py'),
#('SpinBox', '../widgets/SpinBox.py'), ('SpinBox', 'SpinBox.py'),
('TreeWidget', '../widgets/TreeWidget.py'), ('TreeWidget', 'TreeWidget.py'),
('DataTreeWidget', '../widgets/DataTreeWidget.py'), ('DataTreeWidget', 'DataTreeWidget.py'),
('GradientWidget', 'GradientWidget.py'), ('GradientWidget', 'GradientWidget.py'),
#('TableWidget', '../widgets/TableWidget.py'), #('TableWidget', '../widgets/TableWidget.py'),
('ColorButton', '../widgets/ColorButton.py'), ('ColorButton', 'ColorButton.py'),
#('CheckTable', '../widgets/CheckTable.py'), #('CheckTable', '../widgets/CheckTable.py'),
#('VerticalLabel', '../widgets/VerticalLabel.py'), #('VerticalLabel', '../widgets/VerticalLabel.py'),
('JoystickButton', 'JoystickButton.py'), ('JoystickButton', 'JoystickButton.py'),