From 7a851191d98f13f24ca573d081912e48c5f65209 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Mon, 29 Apr 2024 17:49:54 +0200 Subject: [PATCH 1/2] read error column only for points --- src/gui_qt/io/asciireader.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gui_qt/io/asciireader.py b/src/gui_qt/io/asciireader.py index ea4c980..fae624d 100644 --- a/src/gui_qt/io/asciireader.py +++ b/src/gui_qt/io/asciireader.py @@ -204,6 +204,10 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): except ValueError: y_err = None + mode = self.buttonGroup.checkedButton().text() + if mode != 'Points': + y_err = None + col_header = None if self.column_checkBox.isChecked(): col_header = [] @@ -221,7 +225,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): x=x, y=y, yerr=y_err, - mode=self.buttonGroup.checkedButton().text(), + mode=mode, col_names=col_header, num_value=self.get_numerical_value(), ) -- 2.39.2 From 2fbae4697c5f290f19676ce852fd26e68b82b03b Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Mon, 29 Apr 2024 18:24:19 +0200 Subject: [PATCH 2/2] check for correct axes input --- src/gui_qt/io/asciireader.py | 38 +++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/gui_qt/io/asciireader.py b/src/gui_qt/io/asciireader.py index fae624d..ea559c2 100644 --- a/src/gui_qt/io/asciireader.py +++ b/src/gui_qt/io/asciireader.py @@ -186,6 +186,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): def apply(self): # default row for x is the first row, it will be superseded if an integer number is given. x = self.x_lineedit.text() + is_valid = True if x: try: x = int(x)-1 @@ -194,11 +195,21 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): else: x = None + if not self.check_column_numbers(x, max(self.reader.width)): + _ = QtWidgets.QMessageBox.information(self, 'Improper input', + f'Input for x axis is invalid') + return False + try: y = [int(t)-1 for t in self.y_lineedit.text().split(' ')] except ValueError: y = None + if not self.check_column_numbers(y, max(self.reader.width)): + _ = QtWidgets.QMessageBox.information(self, 'Improper input', + f'Input for y axis is invalid') + return False + try: y_err = [int(t)-1 for t in self.deltay_lineEdit.text().split(' ')] except ValueError: @@ -208,6 +219,11 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): if mode != 'Points': y_err = None + if not self.check_column_numbers(y, max(self.reader.width)): + _ = QtWidgets.QMessageBox.information(self, 'Improper input', + f'Input for y_err axis is invalid') + return False + col_header = None if self.column_checkBox.isChecked(): col_header = [] @@ -231,9 +247,10 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): ) self.data_read.emit(ret_dic) - except ImportError as e: + except Exception as e: _ = QtWidgets.QMessageBox.information(self, 'Reading failed', - f'Import data failed with {e.args}') + f'Import data failed with\n {e.args[0]}') + return False return True @@ -288,7 +305,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): else: self.label_8.setText(fname) - def get_numerical_value(self): + def get_numerical_value(self) -> float: val = 0 if self.re_button.isChecked() and self._matches: m = self._matches[self.re_match_index.value()-1] @@ -299,3 +316,18 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): val = float(self.custom_input.text()) return val + + def check_column_numbers(self, values: int | list[int] | None, num_column: int) -> bool: + is_valid = False + if values is None: + is_valid = True + elif isinstance(values, int): + is_valid = values < num_column + elif isinstance(values, list): + try: + is_valid = all(v < num_column for v in values) + except TypeError: + is_valid = False + + return is_valid + -- 2.39.2