Esempio n. 1
0
    def _saveCurves(self, filename, nameFilter):
        """Save all curves from the plot.

        :param str filename: The name of the file to write
        :param str nameFilter: The selected name filter
        :return: False if format is not supported or save failed,
                 True otherwise.
        """
        if nameFilter not in self.ALL_CURVES_FILTERS:
            return False

        curves = self.plot.getAllCurves()
        if not curves:
            self._errorMessage("No curves to be saved")
            return False

        curve = curves[0]
        scanno = 1
        try:
            xlabel = curve.getXLabel() or self.plot.getGraphXLabel()
            ylabel = curve.getYLabel() or self.plot.getGraphYLabel(
                curve.getYAxis())
            specfile = savespec(filename,
                                curve.getXData(copy=False),
                                curve.getYData(copy=False),
                                xlabel,
                                ylabel,
                                fmt="%.7g",
                                scan_number=1,
                                mode="w",
                                write_file_header=True,
                                close_file=False)
        except IOError:
            self._errorMessage('Save failed\n')
            return False

        for curve in curves[1:]:
            try:
                scanno += 1
                xlabel = curve.getXLabel() or self.plot.getGraphXLabel()
                ylabel = curve.getYLabel() or self.plot.getGraphYLabel(
                    curve.getYAxis())
                specfile = savespec(specfile,
                                    curve.getXData(copy=False),
                                    curve.getYData(copy=False),
                                    xlabel,
                                    ylabel,
                                    fmt="%.7g",
                                    scan_number=scanno,
                                    write_file_header=False,
                                    close_file=False)
            except IOError:
                self._errorMessage('Save failed\n')
                return False
        specfile.close()

        return True
Esempio n. 2
0
    def _saveCurves(self, filename, nameFilter):
        """Save all curves from the plot.

        :param str filename: The name of the file to write
        :param str nameFilter: The selected name filter
        :return: False if format is not supported or save failed,
                 True otherwise.
        """
        if nameFilter not in self.ALL_CURVES_FILTERS:
            return False

        curves = self.plot.getAllCurves()
        if not curves:
            self._errorMessage("No curves to be saved")
            return False

        curve = curves[0]
        scanno = 1
        try:
            specfile = savespec(
                filename,
                curve[0],
                curve[1],
                curve[4]["xlabel"],
                curve[4]["ylabel"],
                fmt="%.7g",
                scan_number=1,
                mode="w",
                write_file_header=True,
                close_file=False,
            )
        except IOError:
            self._errorMessage("Save failed\n")
            return False

        for curve in curves[1:]:
            try:
                scanno += 1
                specfile = savespec(
                    specfile,
                    curve[0],
                    curve[1],
                    curve[4]["xlabel"],
                    curve[4]["ylabel"],
                    fmt="%.7g",
                    scan_number=scanno,
                    mode="w",
                    write_file_header=False,
                    close_file=False,
                )
            except IOError:
                self._errorMessage("Save failed\n")
                return False
        specfile.close()

        return True
Esempio n. 3
0
    def _saveCurves(self, plot, filename, nameFilter):
        """Save all curves from the plot.

        :param str filename: The name of the file to write
        :param str nameFilter: The selected name filter
        :return: False if format is not supported or save failed,
                 True otherwise.
        """
        if nameFilter not in self.DEFAULT_ALL_CURVES_FILTERS:
            return False

        curves = plot.getAllCurves()
        if not curves:
            self._errorMessage("No curves to be saved", parent=self.plot)
            return False

        curve = curves[0]
        scanno = 1
        try:
            xdata, data, xlabel, labels = self._get1dData(curve)

            specfile = savespec(filename,
                                xdata,
                                data,
                                xlabel,
                                labels,
                                fmt="%.7g",
                                scan_number=1,
                                mode="w",
                                write_file_header=True,
                                close_file=False)
        except IOError:
            self._errorMessage('Save failed\n', parent=self.plot)
            return False

        for curve in curves[1:]:
            try:
                scanno += 1
                xdata, data, xlabel, labels = self._get1dData(curve)
                specfile = savespec(specfile,
                                    xdata,
                                    data,
                                    xlabel,
                                    labels,
                                    fmt="%.7g",
                                    scan_number=scanno,
                                    write_file_header=False,
                                    close_file=False)
            except IOError:
                self._errorMessage('Save failed\n', parent=self.plot)
                return False
        specfile.close()

        return True
Esempio n. 4
0
File: io.py Progetto: vasole/silx
    def _saveCurves(self, plot, filename, nameFilter):
        """Save all curves from the plot.

        :param str filename: The name of the file to write
        :param str nameFilter: The selected name filter
        :return: False if format is not supported or save failed,
                 True otherwise.
        """
        if nameFilter not in self.DEFAULT_ALL_CURVES_FILTERS:
            return False

        curves = plot.getAllCurves()
        if not curves:
            self._errorMessage("No curves to be saved")
            return False

        curve = curves[0]
        scanno = 1
        try:
            xlabel = curve.getXLabel() or plot.getGraphXLabel()
            ylabel = curve.getYLabel() or plot.getGraphYLabel(curve.getYAxis())
            specfile = savespec(filename,
                                curve.getXData(copy=False),
                                curve.getYData(copy=False),
                                xlabel,
                                ylabel,
                                fmt="%.7g", scan_number=1, mode="w",
                                write_file_header=True,
                                close_file=False)
        except IOError:
            self._errorMessage('Save failed\n')
            return False

        for curve in curves[1:]:
            try:
                scanno += 1
                xlabel = curve.getXLabel() or plot.getGraphXLabel()
                ylabel = curve.getYLabel() or plot.getGraphYLabel(curve.getYAxis())
                specfile = savespec(specfile,
                                    curve.getXData(copy=False),
                                    curve.getYData(copy=False),
                                    xlabel,
                                    ylabel,
                                    fmt="%.7g", scan_number=scanno,
                                    write_file_header=False,
                                    close_file=False)
            except IOError:
                self._errorMessage('Save failed\n')
                return False
        specfile.close()

        return True