pyqtgraph/tests/exporters/test_svg.py
Ogi Moore a6971c768d Move and Update test-data repo into pyqtgraph repo
To reduce complexity, and make it easier to add more images and tests,
the images in the `test-data` repository should be merged with the main
repository.  Furthermore, we can remove a lot of the subprocess work in
the image_testing.py file, as we no longer need to have it interact with
git.

The images are not the same.  Images were regenerated with Qt6, and now
have proper big and little endian handling thanks to @pijyoi

Second commit is a slightly modified variant of
2e135ab282d6007b34a3854921be54d0e9efb241 authored by @pijyoi
it is to convert qimages to RGBA8888 for testing.  Image
files were regenerated images for the big/little handling

Fixed issue with bogus test from test_NonUniformImage and generated a
new image
2021-05-31 21:05:00 -07:00

83 lines
2.3 KiB
Python

"""
SVG export test
"""
from __future__ import division, print_function, absolute_import
import pyqtgraph as pg
import tempfile
import os
app = pg.mkQApp()
def test_plotscene():
tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name
print("using %s as a temporary file" % tempfilename)
pg.setConfigOption('foreground', (0,0,0))
w = pg.GraphicsLayoutWidget()
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())
ex.export(fileName=tempfilename)
# clean up after the test is done
os.unlink(tempfilename)
w.close()
def test_simple():
tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name
print("using %s as a temporary file" % tempfilename)
view = pg.GraphicsView()
view.show()
scene = view.sceneObj
rect = pg.QtGui.QGraphicsRectItem(0, 0, 100, 100)
scene.addItem(rect)
rect.setPos(20,20)
tr = pg.QtGui.QTransform()
rect.setTransform(tr.translate(50, 50).rotate(30).scale(0.5, 0.5))
rect1 = pg.QtGui.QGraphicsRectItem(0, 0, 100, 100)
rect1.setParentItem(rect)
rect1.setFlag(rect1.ItemIgnoresTransformations)
rect1.setPos(20, 20)
rect1.setScale(2)
el1 = pg.QtGui.QGraphicsEllipseItem(0, 0, 100, 100)
el1.setParentItem(rect1)
grp = pg.ItemGroup()
grp.setParentItem(rect)
tr = pg.QtGui.QTransform()
grp.setTransform(tr.translate(200, 0).rotate(30))
rect2 = pg.QtGui.QGraphicsRectItem(0, 0, 100, 25)
rect2.setFlag(rect2.ItemClipsChildrenToShape)
rect2.setParentItem(grp)
rect2.setPos(0,25)
rect2.setRotation(30)
el = pg.QtGui.QGraphicsEllipseItem(0, 0, 100, 50)
tr = pg.QtGui.QTransform()
el.setTransform(tr.translate(10, -5).scale(0.5, 2))
el.setParentItem(rect2)
grp2 = pg.ItemGroup()
scene.addItem(grp2)
grp2.setScale(100)
rect3 = pg.QtGui.QGraphicsRectItem(0,0,2,2)
rect3.setPen(pg.mkPen(width=1, cosmetic=False))
grp2.addItem(rect3)
ex = pg.exporters.SVGExporter(scene)
ex.export(fileName=tempfilename)
os.unlink(tempfilename)