diff --git a/CHANGELOG b/CHANGELOG index dd076d9d..dcc21eb5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ pyqtgraph-0.9.9 [unreleased] - Speed improvements in functions.makeARGB - ImageItem is faster by avoiding makeQImage(transpose=True) - ComboBox will raise error when adding multiple items of the same name + - ArrowItem.setStyle now updates style options rather than replacing them New Features: - New HDF5 example for working with very large datasets diff --git a/examples/Arrow.py b/examples/Arrow.py index 2cbff113..d5ea2a74 100644 --- a/examples/Arrow.py +++ b/examples/Arrow.py @@ -2,7 +2,7 @@ """ Display an animated arrowhead following a curve. This example uses the CurveArrow class, which is a combination -of ArrowItem and CurvePoint. +of ArrowItem and CurvePoint. To place a static arrow anywhere in a scene, use ArrowItem. To attach other types of item to a curve, use CurvePoint. @@ -45,6 +45,7 @@ p.setRange(QtCore.QRectF(-20, -10, 60, 20)) ## Animated arrow following curve c = p2.plot(x=np.sin(np.linspace(0, 2*np.pi, 1000)), y=np.cos(np.linspace(0, 6*np.pi, 1000))) a = pg.CurveArrow(c) +a.setStyle(headLen=40) p2.addItem(a) anim = a.makeAnimation(loop=-1) anim.start() diff --git a/examples/SimplePlot.py b/examples/SimplePlot.py index f572743a..92106661 100644 --- a/examples/SimplePlot.py +++ b/examples/SimplePlot.py @@ -1,15 +1,10 @@ import initExample ## Add path to library (just for examples; you do not need this) -from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg import numpy as np plt = pg.plot(np.random.normal(size=100), title="Simplest possible plotting example") -plt.getAxis('bottom').setTicks([[(x*20, str(x*20)) for x in range(6)]]) -## Start Qt event loop unless running in interactive mode or using pyside. -ex = pg.exporters.SVGExporter.SVGExporter(plt.plotItem.scene()) -ex.export('/home/luke/tmp/test.svg') if __name__ == '__main__': import sys - if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'): + if sys.flags.interactive != 1 or not hasattr(pg.QtCore, 'PYQT_VERSION'): pg.QtGui.QApplication.exec_() diff --git a/pyqtgraph/graphicsItems/ArrowItem.py b/pyqtgraph/graphicsItems/ArrowItem.py index b15fc664..c98ba127 100644 --- a/pyqtgraph/graphicsItems/ArrowItem.py +++ b/pyqtgraph/graphicsItems/ArrowItem.py @@ -16,12 +16,14 @@ class ArrowItem(QtGui.QGraphicsPathItem): Arrows can be initialized with any keyword arguments accepted by the setStyle() method. """ + self.opts = {} QtGui.QGraphicsPathItem.__init__(self, opts.get('parent', None)) + if 'size' in opts: opts['headLen'] = opts['size'] if 'width' in opts: opts['headWidth'] = opts['width'] - defOpts = { + defaultOpts = { 'pxMode': True, 'angle': -150, ## If the angle is 0, the arrow points left 'pos': (0,0), @@ -33,12 +35,9 @@ class ArrowItem(QtGui.QGraphicsPathItem): 'pen': (200,200,200), 'brush': (50,50,200), } - defOpts.update(opts) + defaultOpts.update(opts) - self.setStyle(**defOpts) - - self.setPen(fn.mkPen(defOpts['pen'])) - self.setBrush(fn.mkBrush(defOpts['brush'])) + self.setStyle(**defaultOpts) self.rotate(self.opts['angle']) self.moveBy(*self.opts['pos']) @@ -60,9 +59,9 @@ class ArrowItem(QtGui.QGraphicsPathItem): specified, ot overrides headWidth. default=25 baseAngle Angle of the base of the arrow head. Default is 0, which means that the base of the arrow head - is perpendicular to the arrow shaft. + is perpendicular to the arrow tail. tailLen Length of the arrow tail, measured from the base - of the arrow head to the tip of the tail. If + of the arrow head to the end of the tail. If this value is None, no tail will be drawn. default=None tailWidth Width of the tail. default=3 @@ -70,13 +69,16 @@ class ArrowItem(QtGui.QGraphicsPathItem): brush The brush used to fill the arrow. ================= ================================================= """ - self.opts = opts + self.opts.update(opts) opt = dict([(k,self.opts[k]) for k in ['headLen', 'tipAngle', 'baseAngle', 'tailLen', 'tailWidth']]) self.path = fn.makeArrowPath(**opt) self.setPath(self.path) - if opts['pxMode']: + self.setPen(fn.mkPen(self.opts['pen'])) + self.setBrush(fn.mkBrush(self.opts['brush'])) + + if self.opts['pxMode']: self.setFlags(self.flags() | self.ItemIgnoresTransformations) else: self.setFlags(self.flags() & ~self.ItemIgnoresTransformations) @@ -121,4 +123,4 @@ class ArrowItem(QtGui.QGraphicsPathItem): return pad - \ No newline at end of file + diff --git a/pyqtgraph/graphicsItems/AxisItem.py b/pyqtgraph/graphicsItems/AxisItem.py index b483f0e4..66efeda5 100644 --- a/pyqtgraph/graphicsItems/AxisItem.py +++ b/pyqtgraph/graphicsItems/AxisItem.py @@ -688,7 +688,7 @@ class AxisItem(GraphicsWidget): ## determine mapping between tick values and local coordinates dif = self.range[1] - self.range[0] if dif == 0: - xscale = 1 + xScale = 1 offset = 0 else: if axis == 0: @@ -806,10 +806,10 @@ class AxisItem(GraphicsWidget): ## measure all text, make sure there's enough room if axis == 0: textSize = np.sum([r.height() for r in textRects]) - textSize2 = np.max([r.width() for r in textRects]) + textSize2 = np.max([r.width() for r in textRects]) if textRects else 0 else: textSize = np.sum([r.width() for r in textRects]) - textSize2 = np.max([r.height() for r in textRects]) + textSize2 = np.max([r.height() for r in textRects]) if textRects else 0 ## If the strings are too crowded, stop drawing text now. ## We use three different crowding limits based on the number diff --git a/pyqtgraph/graphicsItems/CurvePoint.py b/pyqtgraph/graphicsItems/CurvePoint.py index f981bdf8..bb6beebc 100644 --- a/pyqtgraph/graphicsItems/CurvePoint.py +++ b/pyqtgraph/graphicsItems/CurvePoint.py @@ -112,6 +112,6 @@ class CurveArrow(CurvePoint): self.arrow = ArrowItem.ArrowItem(**opts) self.arrow.setParentItem(self) - def setStyle(**opts): + def setStyle(self, **opts): return self.arrow.setStyle(**opts)