2014-03-24 16:48:30 +00:00
|
|
|
"""
|
|
|
|
SVG export test
|
|
|
|
"""
|
2015-07-17 17:31:14 +00:00
|
|
|
from __future__ import division, print_function, absolute_import
|
2014-03-24 16:48:30 +00:00
|
|
|
import pyqtgraph as pg
|
2015-07-13 18:14:46 +00:00
|
|
|
import tempfile
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
2014-03-24 16:48:30 +00:00
|
|
|
app = pg.mkQApp()
|
|
|
|
|
2015-07-13 18:14:46 +00:00
|
|
|
|
2014-03-24 16:48:30 +00:00
|
|
|
def test_plotscene():
|
2015-07-17 17:31:14 +00:00
|
|
|
tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name
|
|
|
|
print("using %s as a temporary file" % tempfilename)
|
2014-03-24 16:48:30 +00:00
|
|
|
pg.setConfigOption('foreground', (0,0,0))
|
|
|
|
w = pg.GraphicsWindow()
|
|
|
|
w.show()
|
|
|
|
p1 = w.addPlot()
|
|
|
|
p2 = w.addPlot()
|
|
|
|
p1.plot([1,3,2,3,1,6,9,8,4,2,3,5,3], pen={'color':'k'})
|
|
|
|
p1.setXRange(0,5)
|
|
|
|
p2.plot([1,5,2,3,4,6,1,2,4,2,3,5,3], pen={'color':'k', 'cosmetic':False, 'width': 0.3})
|
|
|
|
app.processEvents()
|
|
|
|
app.processEvents()
|
|
|
|
|
|
|
|
ex = pg.exporters.SVGExporter(w.scene())
|
2015-07-17 17:31:14 +00:00
|
|
|
ex.export(fileName=tempfilename)
|
2015-07-13 18:14:46 +00:00
|
|
|
# clean up after the test is done
|
2015-07-17 17:31:14 +00:00
|
|
|
os.unlink(tempfilename)
|
2019-09-27 20:37:40 +00:00
|
|
|
w.close()
|
2014-03-24 16:48:30 +00:00
|
|
|
|
|
|
|
def test_simple():
|
2015-07-17 17:31:14 +00:00
|
|
|
tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name
|
|
|
|
print("using %s as a temporary file" % tempfilename)
|
2014-03-24 16:48:30 +00:00
|
|
|
|
2020-10-28 04:27:31 +00:00
|
|
|
view = pg.GraphicsView()
|
|
|
|
view.show()
|
|
|
|
|
|
|
|
scene = view.sceneObj
|
|
|
|
|
|
|
|
rect = pg.QtGui.QGraphicsRectItem(0, 0, 100, 100)
|
|
|
|
scene.addItem(rect)
|
|
|
|
rect.setPos(20,20)
|
2021-01-31 15:13:54 +00:00
|
|
|
tr = pg.QtGui.QTransform()
|
|
|
|
rect.setTransform(tr.translate(50, 50).rotate(30).scale(0.5, 0.5))
|
2020-10-28 04:27:31 +00:00
|
|
|
|
|
|
|
rect1 = pg.QtGui.QGraphicsRectItem(0, 0, 100, 100)
|
|
|
|
rect1.setParentItem(rect)
|
|
|
|
rect1.setFlag(rect1.ItemIgnoresTransformations)
|
|
|
|
rect1.setPos(20, 20)
|
2021-01-31 15:13:54 +00:00
|
|
|
rect1.setScale(2)
|
2014-03-24 16:48:30 +00:00
|
|
|
|
2020-10-28 04:27:31 +00:00
|
|
|
el1 = pg.QtGui.QGraphicsEllipseItem(0, 0, 100, 100)
|
|
|
|
el1.setParentItem(rect1)
|
|
|
|
grp = pg.ItemGroup()
|
|
|
|
grp.setParentItem(rect)
|
2021-01-31 15:13:54 +00:00
|
|
|
tr = pg.QtGui.QTransform()
|
|
|
|
grp.setTransform(tr.translate(200, 0).rotate(30))
|
2014-03-24 16:48:30 +00:00
|
|
|
|
2020-10-28 04:27:31 +00:00
|
|
|
rect2 = pg.QtGui.QGraphicsRectItem(0, 0, 100, 25)
|
|
|
|
rect2.setFlag(rect2.ItemClipsChildrenToShape)
|
|
|
|
rect2.setParentItem(grp)
|
|
|
|
rect2.setPos(0,25)
|
2021-01-31 15:13:54 +00:00
|
|
|
rect2.setRotation(30)
|
2020-10-28 04:27:31 +00:00
|
|
|
el = pg.QtGui.QGraphicsEllipseItem(0, 0, 100, 50)
|
2021-01-31 15:13:54 +00:00
|
|
|
tr = pg.QtGui.QTransform()
|
|
|
|
el.setTransform(tr.translate(10, -5).scale(0.5, 2))
|
2015-07-13 18:14:46 +00:00
|
|
|
|
2020-10-28 04:27:31 +00:00
|
|
|
el.setParentItem(rect2)
|
2015-07-13 18:14:46 +00:00
|
|
|
|
2014-03-24 16:48:30 +00:00
|
|
|
grp2 = pg.ItemGroup()
|
|
|
|
scene.addItem(grp2)
|
2021-01-31 15:13:54 +00:00
|
|
|
grp2.setScale(100)
|
2015-07-13 18:14:46 +00:00
|
|
|
|
2014-03-24 16:48:30 +00:00
|
|
|
rect3 = pg.QtGui.QGraphicsRectItem(0,0,2,2)
|
|
|
|
rect3.setPen(pg.mkPen(width=1, cosmetic=False))
|
|
|
|
grp2.addItem(rect3)
|
|
|
|
|
2015-07-13 18:14:46 +00:00
|
|
|
ex = pg.exporters.SVGExporter(scene)
|
2015-07-17 17:31:14 +00:00
|
|
|
ex.export(fileName=tempfilename)
|
|
|
|
os.unlink(tempfilename)
|