read-fid (#269); closes #268
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build AppImage / Explore-Gitea-Actions (push) Successful in 2m18s
				
			
		
		
	
	
				
					
				
			
		
			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:
		@@ -186,6 +186,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
 | 
				
			|||||||
    def apply(self):
 | 
					    def apply(self):
 | 
				
			||||||
        # default row for x is the first row, it will be superseded if an integer number is given.
 | 
					        # default row for x is the first row, it will be superseded if an integer number is given.
 | 
				
			||||||
        x = self.x_lineedit.text()
 | 
					        x = self.x_lineedit.text()
 | 
				
			||||||
 | 
					        is_valid = True
 | 
				
			||||||
        if x:
 | 
					        if x:
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                x = int(x)-1
 | 
					                x = int(x)-1
 | 
				
			||||||
@@ -194,16 +195,35 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
 | 
				
			|||||||
        else:
 | 
					        else:
 | 
				
			||||||
            x = None
 | 
					            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:
 | 
					        try:
 | 
				
			||||||
            y = [int(t)-1 for t in self.y_lineedit.text().split(' ')]
 | 
					            y = [int(t)-1 for t in self.y_lineedit.text().split(' ')]
 | 
				
			||||||
        except ValueError:
 | 
					        except ValueError:
 | 
				
			||||||
            y = None
 | 
					            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:
 | 
					        try:
 | 
				
			||||||
            y_err = [int(t)-1 for t in self.deltay_lineEdit.text().split(' ')]
 | 
					            y_err = [int(t)-1 for t in self.deltay_lineEdit.text().split(' ')]
 | 
				
			||||||
        except ValueError:
 | 
					        except ValueError:
 | 
				
			||||||
            y_err = None
 | 
					            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
 | 
					        col_header = None
 | 
				
			||||||
        if self.column_checkBox.isChecked():
 | 
					        if self.column_checkBox.isChecked():
 | 
				
			||||||
            col_header = []
 | 
					            col_header = []
 | 
				
			||||||
@@ -221,15 +241,16 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
 | 
				
			|||||||
                x=x,
 | 
					                x=x,
 | 
				
			||||||
                y=y,
 | 
					                y=y,
 | 
				
			||||||
                yerr=y_err,
 | 
					                yerr=y_err,
 | 
				
			||||||
                mode=self.buttonGroup.checkedButton().text(),
 | 
					                mode=mode,
 | 
				
			||||||
                col_names=col_header,
 | 
					                col_names=col_header,
 | 
				
			||||||
                num_value=self.get_numerical_value(),
 | 
					                num_value=self.get_numerical_value(),
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            self.data_read.emit(ret_dic)
 | 
					            self.data_read.emit(ret_dic)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        except ImportError as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            _ = QtWidgets.QMessageBox.information(self, 'Reading failed',
 | 
					            _ = 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
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -284,7 +305,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
 | 
				
			|||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.label_8.setText(fname)
 | 
					            self.label_8.setText(fname)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_numerical_value(self):
 | 
					    def get_numerical_value(self) -> float:
 | 
				
			||||||
        val = 0
 | 
					        val = 0
 | 
				
			||||||
        if self.re_button.isChecked() and self._matches:
 | 
					        if self.re_button.isChecked() and self._matches:
 | 
				
			||||||
            m = self._matches[self.re_match_index.value()-1]
 | 
					            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())
 | 
					            val = float(self.custom_input.text())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return val
 | 
					        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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user