Skip to content
Snippets Groups Projects
Commit 92d3b3fb authored by Luke Campagnola's avatar Luke Campagnola
Browse files

cleanups

parent 96296749
No related branches found
No related tags found
No related merge requests found
import initExample ## Add path to library (just for examples; you do not need this) import initExample ## Add path to library (just for examples; you do not need this)
from os.path import *
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg import pyqtgraph as pg
import numpy as np import numpy as np
plt = pg.plot(np.random.normal(size=100), title="Simplest possible plotting example") 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(join(dirname(__file__), 'test.svg'))
if __name__ == '__main__': if __name__ == '__main__':
import sys 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_() pg.QtGui.QApplication.exec_()
...@@ -16,12 +16,14 @@ class ArrowItem(QtGui.QGraphicsPathItem): ...@@ -16,12 +16,14 @@ class ArrowItem(QtGui.QGraphicsPathItem):
Arrows can be initialized with any keyword arguments accepted by Arrows can be initialized with any keyword arguments accepted by
the setStyle() method. the setStyle() method.
""" """
self.opts = {}
QtGui.QGraphicsPathItem.__init__(self, opts.get('parent', None)) QtGui.QGraphicsPathItem.__init__(self, opts.get('parent', None))
if 'size' in opts: if 'size' in opts:
opts['headLen'] = opts['size'] opts['headLen'] = opts['size']
if 'width' in opts: if 'width' in opts:
opts['headWidth'] = opts['width'] opts['headWidth'] = opts['width']
defOpts = { defaultOpts = {
'pxMode': True, 'pxMode': True,
'angle': -150, ## If the angle is 0, the arrow points left 'angle': -150, ## If the angle is 0, the arrow points left
'pos': (0,0), 'pos': (0,0),
...@@ -33,12 +35,9 @@ class ArrowItem(QtGui.QGraphicsPathItem): ...@@ -33,12 +35,9 @@ class ArrowItem(QtGui.QGraphicsPathItem):
'pen': (200,200,200), 'pen': (200,200,200),
'brush': (50,50,200), 'brush': (50,50,200),
} }
defOpts.update(opts) defaultOpts.update(opts)
self.setStyle(**defOpts)
self.setPen(fn.mkPen(defOpts['pen'])) self.setStyle(**defaultOpts)
self.setBrush(fn.mkBrush(defOpts['brush']))
self.rotate(self.opts['angle']) self.rotate(self.opts['angle'])
self.moveBy(*self.opts['pos']) self.moveBy(*self.opts['pos'])
...@@ -60,9 +59,9 @@ class ArrowItem(QtGui.QGraphicsPathItem): ...@@ -60,9 +59,9 @@ class ArrowItem(QtGui.QGraphicsPathItem):
specified, ot overrides headWidth. default=25 specified, ot overrides headWidth. default=25
baseAngle Angle of the base of the arrow head. Default is baseAngle Angle of the base of the arrow head. Default is
0, which means that the base of the arrow head 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 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. this value is None, no tail will be drawn.
default=None default=None
tailWidth Width of the tail. default=3 tailWidth Width of the tail. default=3
...@@ -70,15 +69,15 @@ class ArrowItem(QtGui.QGraphicsPathItem): ...@@ -70,15 +69,15 @@ class ArrowItem(QtGui.QGraphicsPathItem):
brush The brush used to fill the arrow. brush The brush used to fill the arrow.
================= ================================================= ================= =================================================
""" """
try: self.opts.update(opts)
self.opts.update(opts)
except AttributeError:
self.opts = opts
opt = dict([(k,self.opts[k]) for k in ['headLen', 'tipAngle', 'baseAngle', 'tailLen', 'tailWidth']]) opt = dict([(k,self.opts[k]) for k in ['headLen', 'tipAngle', 'baseAngle', 'tailLen', 'tailWidth']])
self.path = fn.makeArrowPath(**opt) self.path = fn.makeArrowPath(**opt)
self.setPath(self.path) self.setPath(self.path)
self.setPen(fn.mkPen(self.opts['pen']))
self.setBrush(fn.mkBrush(self.opts['brush']))
if self.opts['pxMode']: if self.opts['pxMode']:
self.setFlags(self.flags() | self.ItemIgnoresTransformations) self.setFlags(self.flags() | self.ItemIgnoresTransformations)
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment