From c6b68f2f9f13682560cd946d82da07bd6ac1025a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=2E=20Armando=20Sol=C3=A9?= Date: Tue, 5 Dec 2023 10:14:37 +0100 Subject: [PATCH 1/3] Add test --- PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py | 2 ++ PyMca5/tests/WidgetsInstantiationTest.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py b/PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py index d11dc1d9a..33be30d09 100644 --- a/PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py +++ b/PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py @@ -490,6 +490,8 @@ def addDataToPlot(self, x, y, legend = None, linestyle = None, marker=None, alias = None,**kw): + x = numpy.array(x, copy=False) + y = numpy.array(y, copy=False) if self.limitsSet is not None: n = self._filterData(x, y) if not len(n): diff --git a/PyMca5/tests/WidgetsInstantiationTest.py b/PyMca5/tests/WidgetsInstantiationTest.py index 0b5148f4f..577db4b3e 100644 --- a/PyMca5/tests/WidgetsInstantiationTest.py +++ b/PyMca5/tests/WidgetsInstantiationTest.py @@ -111,6 +111,21 @@ def testShow(self): widget.show() self.qapp.processEvents() +class TestQPyMcaMatplotlibSave1D(TestCaseQt): + def setUp(self): + super(TestQPyMcaMatplotlibSave1D, self).setUp() + + def testShow(self): + from PyMca5.PyMcaGui.pymca import QPyMcaMatplotlibSave1D + widget = QPyMcaMatplotlibSave1D.QPyMcaMatplotlibSave() + widget.setLimits(0, 3, 0, 9) + widget.addDataToPlot([0, 1, 2, 3], [0, 1, 4, 9], legend="1") + widget.show() + self.qapp.processEvents() + from PyMca5.PyMcaGui.plotting import PyMcaPrintPreview + PyMcaPrintPreview.resetSingletonPrintPreview() + + class TestScanWindow(TestCaseQt): def setUp(self): super(TestScanWindow, self).setUp() @@ -254,6 +269,7 @@ def runTest(self): TestXASNormalizationWindow, TestMaskImageWidget, TestScanWindow, + TestQPyMcaMatplotlibSave1D, TestMcaCalWidget, TestMcaWindow, TestMaterialEditor, From 0c7cc0aefbb3ef49c2ee32b4b30b89fab8761442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=2E=20Armando=20Sol=C3=A9?= Date: Tue, 5 Dec 2023 10:24:14 +0100 Subject: [PATCH 2/3] Make sure the test can reproduce the issue. --- PyMca5/tests/WidgetsInstantiationTest.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/PyMca5/tests/WidgetsInstantiationTest.py b/PyMca5/tests/WidgetsInstantiationTest.py index 577db4b3e..1e5dda4fe 100644 --- a/PyMca5/tests/WidgetsInstantiationTest.py +++ b/PyMca5/tests/WidgetsInstantiationTest.py @@ -117,9 +117,13 @@ def setUp(self): def testShow(self): from PyMca5.PyMcaGui.pymca import QPyMcaMatplotlibSave1D - widget = QPyMcaMatplotlibSave1D.QPyMcaMatplotlibSave() - widget.setLimits(0, 3, 0, 9) - widget.addDataToPlot([0, 1, 2, 3], [0, 1, 4, 9], legend="1") + widget = QPyMcaMatplotlibSave1D.QPyMcaMatplotlibSaveDialog() + w = widget.plot + w.setLimits(0, 3, 0, 9) + w.addDataToPlot([0, 1, 2, 3], [0, 1, 4, 9], legend="1") + widget.setXLabel('Channel') + widget.setYLabel('Counts') + w.plotLegends() widget.show() self.qapp.processEvents() from PyMca5.PyMcaGui.plotting import PyMcaPrintPreview From 6a23ad68e4efe00dd6897801b52dd2b7cccbb5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=2E=20Armando=20Sol=C3=A9?= Date: Tue, 5 Dec 2023 10:26:46 +0100 Subject: [PATCH 3/3] Correct issue. --- PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py b/PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py index 33be30d09..c54be87b8 100644 --- a/PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py +++ b/PyMca5/PyMcaGui/pymca/QPyMcaMatplotlibSave1D.py @@ -1,6 +1,6 @@ #!/usr/bin/env python #/*########################################################################## -# Copyright (C) 2004-2022 European Synchrotron Radiation Facility +# Copyright (C) 2004-2023 European Synchrotron Radiation Facility # # This file is part of the PyMca X-ray Fluorescence Toolkit developed at # the ESRF. @@ -39,16 +39,8 @@ from matplotlib import __version__ as matplotlib_version from matplotlib.font_manager import FontProperties -if qt.BINDING in ["PyQt5", "PySide2"]: - import matplotlib - matplotlib.rcParams['backend']='Qt5Agg' - from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas -elif qt.BINDING in ["PyQt6", "PySide6"]: - import matplotlib - matplotlib.rcParams['backend']='Qt5Agg' - from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas -else: - from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas +import matplotlib +from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure _logger = logging.getLogger(__name__) @@ -223,7 +215,7 @@ def _mySlot(self, ddict): class ComboBoxItem(qt.QComboBox): sigComboBoxItemSignal = qt.pyqtSignal(object) def __init__(self, parent, row, col, options=[1,2,3]): - qt.QCheckBox.__init__(self, parent) + qt.QComboBox.__init__(self, parent) self.__row = row self.__col = col for option in options: