From 41974c67feae386a0114e6f5de8d5496089faa4f Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Tue, 15 Jun 2021 15:31:16 -0400 Subject: work around image exporting bug --- eitControl.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'eitControl.py') diff --git a/eitControl.py b/eitControl.py index 668b58e..43050a1 100644 --- a/eitControl.py +++ b/eitControl.py @@ -1,7 +1,7 @@ from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg from pyqtgraph.dockarea import * -from pyqtgraph.exporters import ImageExporter +import pyqtgraph.exporters import platform import os @@ -159,13 +159,23 @@ class Experiment: png_file=csv_file.replace(".csv", ".png") print(f"Picture saved to {png_file}") - try: - ex = ImageExporter(self.channelGraph['adc0']) - ex.parameters()['width'] = 800 - ex.parameters()['height'] = 600 - ex.export(png_file) - except ZeroDivisionError: - print("Early version (0.10.0) of PyQtGraph has bug in exporter. The image file is not generated.") + plt = self.dataPlot.getPlotItem() + ex = pg.exporters.ImageExporter(plt) + if pg.__version__ == '0.10.0': + # Workaround for PyQtGraph version <= 0.10.0 + # see https://github.com/pyqtgraph/pyqtgraph/issues/538#issuecomment-361405356 + w= int(plt.width()) + h= int(plt.height()) + # the value in setValue need to be different from default + # otherwise it will not be taken + ex.parameters().param('width').setValue(w+1, blockSignal=ex.widthChanged) + ex.parameters().param('height').setValue(h+1, blockSignal=ex.heightChanged) + # now we set actual value + # ex.parameters()['width'] = w + ex.parameters().param('width').setValue(w, blockSignal=ex.widthChanged) + ex.parameters().param('height').setValue(h, blockSignal=ex.heightChanged) + # beware this is bad workaround!!! plot data is misplaced + ex.export(png_file) def onTic(self,swp=None): start = datetime.now() -- cgit v1.2.3