aboutsummaryrefslogtreecommitdiff
path: root/eitControl.py
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-15 15:31:16 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-15 18:21:02 -0400
commit41974c67feae386a0114e6f5de8d5496089faa4f (patch)
tree6eca06ba16ccad4aee957833bacdb0031a22ec5f /eitControl.py
parent8b1aeef3c0a7af167861c848de1ebc73d6d7eaee (diff)
downloadpyExpControl-41974c67feae386a0114e6f5de8d5496089faa4f.tar.gz
pyExpControl-41974c67feae386a0114e6f5de8d5496089faa4f.zip
work around image exporting bug
Diffstat (limited to 'eitControl.py')
-rw-r--r--eitControl.py26
1 files changed, 18 insertions, 8 deletions
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()