value tab plots complex selection; graphwindows shows last path for export; filedialog uses call not init
This commit is contained in:
@ -5,11 +5,13 @@ import os
|
||||
import uuid
|
||||
|
||||
from math import isnan
|
||||
from pathlib import Path
|
||||
|
||||
from numpy import errstate, floor, log10
|
||||
from pyqtgraph import GraphicsObject, getConfigOption, mkColor
|
||||
|
||||
from nmreval.utils.text import convert
|
||||
from ..io.filedialog import FileDialog
|
||||
|
||||
from ..lib.pg_objects import LegendItemBlock, RegionItem
|
||||
from ..Qt import QtCore, QtWidgets, QtGui
|
||||
@ -524,64 +526,67 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow):
|
||||
str_format = imgformat.data().decode('utf-8')
|
||||
filters += ';;' + str_format.upper() + ' (*.' + str_format + ')'
|
||||
|
||||
outfile, _ = QtWidgets.QFileDialog.getSaveFileName(self, caption='Export graphic', filter=filters,
|
||||
options=QtWidgets.QFileDialog.DontConfirmOverwrite)
|
||||
outfile = None
|
||||
f = FileDialog(caption='Export graphic', filters=filters)
|
||||
mode = f.exec()
|
||||
if mode == QtWidgets.QDialog.Accepted:
|
||||
outfile = f.save_file()
|
||||
if outfile:
|
||||
self.export(outfile)
|
||||
|
||||
def export(self, outfile: str):
|
||||
_, suffix = os.path.splitext(outfile)
|
||||
if suffix == '':
|
||||
QtWidgets.QMessageBox.warning(self, 'No file extension',
|
||||
'No file extension found, graphic was not saved.')
|
||||
return
|
||||
def export(self, outfile: Path):
|
||||
suffix = outfile.suffix
|
||||
if suffix == '':
|
||||
QtWidgets.QMessageBox.warning(self, 'No file extension',
|
||||
'No file extension found, graphic was not saved.')
|
||||
return
|
||||
|
||||
if suffix == '.agr':
|
||||
res = 0
|
||||
if os.path.exists(outfile):
|
||||
res = GraceMsgBox(outfile, parent=self).exec()
|
||||
if res == -1:
|
||||
return
|
||||
if suffix == '.agr':
|
||||
res = 0
|
||||
if outfile.exists():
|
||||
res = GraceMsgBox(outfile, parent=self).exec()
|
||||
if res == -1:
|
||||
return
|
||||
|
||||
opts = self.export_graphics()
|
||||
opts = self.export_graphics()
|
||||
|
||||
from ..io.exporters import GraceExporter
|
||||
if res == 0:
|
||||
mode = 'w'
|
||||
elif res == 1:
|
||||
mode = 'a'
|
||||
else:
|
||||
mode = res-2
|
||||
from ..io.exporters import GraceExporter
|
||||
if res == 0:
|
||||
mode = 'w'
|
||||
elif res == 1:
|
||||
mode = 'a'
|
||||
else:
|
||||
mode = res-2
|
||||
|
||||
GraceExporter(opts).export(outfile, mode=mode)
|
||||
GraceExporter(opts).export(outfile, mode=mode)
|
||||
|
||||
else:
|
||||
if os.path.exists(outfile):
|
||||
if QtWidgets.QMessageBox.warning(self, 'Export graphic',
|
||||
f'{os.path.split(outfile)[1]} already exists.\n'
|
||||
f'Do you REALLY want to replace it?',
|
||||
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
|
||||
QtWidgets.QMessageBox.No) == QtWidgets.QMessageBox.No:
|
||||
return
|
||||
|
||||
bg_color = self._bgcolor
|
||||
fg_color = self._fgcolor
|
||||
self.set_color(foreground='k', background='w')
|
||||
|
||||
if suffix == '.pdf':
|
||||
from ..io.exporters import PDFPrintExporter
|
||||
PDFPrintExporter(self.graphic).export(outfile)
|
||||
|
||||
elif suffix == '.svg':
|
||||
from pyqtgraph.exporters import SVGExporter
|
||||
SVGExporter(self.scene).export(outfile)
|
||||
|
||||
else:
|
||||
if os.path.exists(outfile):
|
||||
if QtWidgets.QMessageBox.warning(self, 'Export graphic',
|
||||
f'{os.path.split(outfile)[1]} already exists.\n'
|
||||
f'Do you REALLY want to replace it?',
|
||||
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
|
||||
QtWidgets.QMessageBox.No) == QtWidgets.QMessageBox.No:
|
||||
return
|
||||
from pyqtgraph.exporters import ImageExporter
|
||||
|
||||
bg_color = self._bgcolor
|
||||
fg_color = self._fgcolor
|
||||
self.set_color(foreground='k', background='w')
|
||||
ImageExporter(self.scene).export(outfile)
|
||||
|
||||
if suffix == '.pdf':
|
||||
from ..io.exporters import PDFPrintExporter
|
||||
PDFPrintExporter(self.graphic).export(outfile)
|
||||
|
||||
elif suffix == '.svg':
|
||||
from pyqtgraph.exporters import SVGExporter
|
||||
SVGExporter(self.scene).export(outfile)
|
||||
|
||||
else:
|
||||
from pyqtgraph.exporters import ImageExporter
|
||||
|
||||
ImageExporter(self.scene).export(outfile)
|
||||
|
||||
self.set_color(foreground=fg_color, background=bg_color)
|
||||
self.set_color(foreground=fg_color, background=bg_color)
|
||||
|
||||
def export_graphics(self) -> dict:
|
||||
dic = self.get_state()
|
||||
|
Reference in New Issue
Block a user