read-fid (#269); closes #268
All checks were successful
Build AppImage / Explore-Gitea-Actions (push) Successful in 2m18s

Co-authored-by: Dominik Demuth <dominik.demuth@physik.tu-darmstadt.de>
Reviewed-on: #269
This commit is contained in:
Dominik Demuth 2024-04-29 16:26:09 +00:00
parent 1162458290
commit 79d0ab1628

View File

@ -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,16 +195,35 @@ 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:
y_err = None
mode = self.buttonGroup.checkedButton().text()
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 = []
@ -221,15 +241,16 @@ 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(),
)
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
@ -284,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]
@ -295,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