2020-04-02 22:55:33 -07:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-06-10 03:16:22 +08:00
|
|
|
import numpy as np
|
2020-04-02 22:55:33 -07:00
|
|
|
import pyqtgraph as pg
|
2021-06-10 03:16:22 +08:00
|
|
|
from pyqtgraph.Qt import QtGui
|
2020-04-02 22:55:33 -07:00
|
|
|
from pyqtgraph.exporters import ImageExporter
|
2021-06-10 03:16:22 +08:00
|
|
|
import pyqtgraph.functions as fn
|
2020-04-02 22:55:33 -07: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-10 03:16:22 +08: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)
|
2021-07-31 21:10:34 +08:00
|
|
|
data = fn.ndarray_from_qimage(qimg)
|
2021-06-10 03:16:22 +08:00
|
|
|
black = (0, 0, 0, 255)
|
|
|
|
assert np.all(data == black), "Exported image should be entirely black."
|