2020-04-03 05:55:33 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-06-09 19:16:22 +00:00
|
|
|
import numpy as np
|
2020-04-03 05:55:33 +00:00
|
|
|
import pyqtgraph as pg
|
2021-06-09 19:16:22 +00:00
|
|
|
from pyqtgraph.Qt import QtGui
|
2020-04-03 05:55:33 +00:00
|
|
|
from pyqtgraph.exporters import ImageExporter
|
2021-06-09 19:16:22 +00:00
|
|
|
import pyqtgraph.functions as fn
|
2020-04-03 05:55:33 +00:00
|
|
|
|
|
|
|
app = pg.mkQApp()
|
|
|
|
|
|
|
|
|
|
|
|
def test_ImageExporter_filename_dialog():
|
|
|
|
"""Tests ImageExporter code path that opens a file dialog. Regression test
|
|
|
|
for pull request 1133."""
|
|
|
|
p = pg.plot()
|
|
|
|
exp = ImageExporter(p.getPlotItem())
|
|
|
|
exp.export()
|
2021-06-09 19:16:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_ImageExporter_toBytes():
|
|
|
|
p = pg.plot()
|
|
|
|
p.hideAxis('bottom')
|
|
|
|
p.hideAxis('left')
|
|
|
|
exp = ImageExporter(p.getPlotItem())
|
|
|
|
qimg = exp.export(toBytes=True)
|
|
|
|
qimg = qimg.convertToFormat(QtGui.QImage.Format.Format_RGBA8888)
|
|
|
|
data = fn.qimage_to_ndarray(qimg)
|
|
|
|
black = (0, 0, 0, 255)
|
|
|
|
assert np.all(data == black), "Exported image should be entirely black."
|