From b25db92cf119e4c7013ef3ac31474fd260690660 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Tue, 2 Apr 2024 15:34:42 +0000 Subject: [PATCH] stop autoamtic ascii reading if first is cancelled (#260); close #251 Co-authored-by: Dominik Demuth Reviewed-on: https://gitea.pkm.physik.tu-darmstadt.de/IPKM/nmreval/pulls/260 --- src/gui_qt/io/asciireader.py | 2 +- src/gui_qt/io/filereaders.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/gui_qt/io/asciireader.py b/src/gui_qt/io/asciireader.py index 2520844..489c33d 100644 --- a/src/gui_qt/io/asciireader.py +++ b/src/gui_qt/io/asciireader.py @@ -178,7 +178,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): @QtCore.pyqtSlot() def accept(self): if self.apply(): - self.close() + super().accept() def apply(self): # default row for x is the first row, it will be superseded if an integer number is given. diff --git a/src/gui_qt/io/filereaders.py b/src/gui_qt/io/filereaders.py index 11d28c2..808d96f 100755 --- a/src/gui_qt/io/filereaders.py +++ b/src/gui_qt/io/filereaders.py @@ -3,7 +3,7 @@ from __future__ import annotations from pathlib import Path import struct -from ..Qt import QtCore +from ..Qt import QtCore, QtWidgets from .asciireader import QAsciiReader from .hdfreader import QHdfViewer from .bdsreader import QBDSReader @@ -26,8 +26,12 @@ class QFileReader(QtCore.QObject): self.reader = {} for ext, reader in [ - ('txt', QAsciiReader), ('dsc', QDSCReader), ('agr', QGraceReader), - ('bds', QBDSReader), ('hdf', QHdfViewer), ('nmr', QNMRReader) + ('txt', QAsciiReader), + ('dsc', QDSCReader), + ('agr', QGraceReader), + ('bds', QBDSReader), + ('hdf', QHdfViewer), + ('nmr', QNMRReader), ]: self.register(ext, reader) @@ -57,7 +61,10 @@ class QFileReader(QtCore.QObject): try: # If QAsciiReader.skip = True it accepts automatically and returns None - r(f).exec() + status = r(f).exec() + if status == QtWidgets.QDialog.Rejected and isinstance(r, QAsciiReader): + break + except AttributeError: pass