From 091677991be4b4dd05ac1f7df9dd5be1403c0bd1 Mon Sep 17 00:00:00 2001 From: dominik Date: Tue, 8 Nov 2022 20:07:16 +0100 Subject: [PATCH] save fit parameter does not confirm overwrite; export graphics with try-catch around get_data_opts; --- bin/evaluate.py | 2 +- src/gui_qt/graphs/graphwindow.py | 12 +++++++++--- src/gui_qt/lib/pg_objects.py | 7 ++++--- src/gui_qt/main/mainwindow.py | 4 +++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/bin/evaluate.py b/bin/evaluate.py index a8a919e..9ccfedc 100755 --- a/bin/evaluate.py +++ b/bin/evaluate.py @@ -2,7 +2,7 @@ import sys import pathlib -sys.path.append(str(pathlib.Path(__file__).parent.parent / 'src')) +sys.path.append(str(pathlib.Path(__file__).absolute().parent.parent / 'src')) from nmreval.configs import check_for_config diff --git a/src/gui_qt/graphs/graphwindow.py b/src/gui_qt/graphs/graphwindow.py index 8ae796e..0c2ddd1 100644 --- a/src/gui_qt/graphs/graphwindow.py +++ b/src/gui_qt/graphs/graphwindow.py @@ -596,7 +596,12 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow): legend_shown = True break in_legend.append(legend_shown) - item_dic = plot_item.get_data_opts() + try: + item_dic = plot_item.get_data_opts() + except Exception as e: + print(f'{item} could not exported because {e.args}') + continue + if len(item) == 2: # plot can show errorbars item_dic['yerr'] = item[1].opts['topData'] @@ -607,9 +612,10 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow): for item in self._external_items: try: dic['items'].append(item.get_data_opts()) - except AttributeError: - print(f'{item} is missing "get_data_opts()"') + except Exception as e: + print(f'{item} could not be exported because {e.args}') continue + in_legend.append(False) dic['in_legend'] = in_legend diff --git a/src/gui_qt/lib/pg_objects.py b/src/gui_qt/lib/pg_objects.py index 0b4cf0b..5412aca 100644 --- a/src/gui_qt/lib/pg_objects.py +++ b/src/gui_qt/lib/pg_objects.py @@ -22,9 +22,10 @@ pyqtgraph looks for function "setLogMode" for logarithmic axes, so needs to be i class LogInfiniteLine(InfiniteLine): def __init__(self, **kwargs): - super().__init__(**kwargs) self.logmode = [False, False] + super().__init__(**kwargs) + def setLogMode(self, xmode, ymode): """ Does only work for vertical and horizontal lines @@ -33,13 +34,13 @@ class LogInfiniteLine(InfiniteLine): return new_p = list(self.p[:]) - if (self.angle == 90) and (self.logmode[0] != xmode): + if self.logmode[0] != xmode: if xmode: new_p[0] = np.log10(new_p[0]+np.finfo(float).eps) else: new_p[0] = 10**new_p[0] - if (self.angle == 0) and (self.logmode[1] != ymode): + if self.logmode[1] != ymode: if ymode: new_p[1] = np.log10(new_p[1]+np.finfo(float).eps) else: diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index 4b7717b..425d90c 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -111,6 +111,7 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.datawidget.management = self.management self.integralwidget.management = self.management + # self.drawingswidget.graphs = self.management.graphs self.ac_group = QtWidgets.QActionGroup(self) self.ac_group.addAction(self.action_lm_fit) @@ -276,7 +277,8 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): @QtCore.pyqtSlot(list) def save_fit_parameter(self, fit_sets: list[str] = None): fname, _ = QtWidgets.QFileDialog.getSaveFileName(self, 'Save fit parameter', directory=str(self.path), - filter='All files(*, *);;Text files(*.dat *.txt)') + filter='All files(*, *);;Text files(*.dat *.txt)', + options=QtWidgets.QFileDialog.DontConfirmOverwrite) if fname: self.management.save_fit_parameter(fname, fit_sets=fit_sets)