From e10b85b9043062db310149cb074993fee75fab53 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Thu, 11 May 2023 18:28:03 +0200 Subject: [PATCH] more correct lines preview in asciireader --- src/gui_qt/io/asciireader.py | 8 ++++++-- src/nmreval/io/asciireader.py | 15 ++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/gui_qt/io/asciireader.py b/src/gui_qt/io/asciireader.py index 4a41bc0..10581a3 100644 --- a/src/gui_qt/io/asciireader.py +++ b/src/gui_qt/io/asciireader.py @@ -98,15 +98,19 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): @QtCore.pyqtSlot(int, name='on_preview_spinBox_valueChanged') def show_preview(self, line_no: int): - preview, width = self.reader.make_preview(line_no) + preview, width, comments = self.reader.make_preview(line_no) self.ascii_table.setRowCount(min(line_no, len(preview))) - self.ascii_table.setColumnCount(width) + self.ascii_table.setColumnCount(width + 1) for i, line in enumerate(preview): + comment_line = comments[i] for j, field in enumerate(line): it = QtWidgets.QTableWidgetItem(field) self.ascii_table.setItem(i, j, it) + it = QtWidgets.QTableWidgetItem(comment_line) + self.ascii_table.setItem(i, len(line), it) + self.ascii_table.resizeColumnsToContents() @QtCore.pyqtSlot(int, name='on_column_checkBox_stateChanged') diff --git a/src/nmreval/io/asciireader.py b/src/nmreval/io/asciireader.py index e2c0464..e8a19ea 100644 --- a/src/nmreval/io/asciireader.py +++ b/src/nmreval/io/asciireader.py @@ -19,10 +19,8 @@ class AsciiReader: self.fname = None self.header = [] self.lines = [] - self.num_data = [] self.delays = None self.width = [] - self.num_width = [] self.line_comment = [] self._last_read_pos = 0 @@ -61,13 +59,12 @@ class AsciiReader: is_empty = len(line) == 0 if not is_empty: - self.width.append(len(line)) self.lines.append(line) - if not line[0].startswith('#'): - self.num_data.append(line) - self.num_width.append(len(line)) + self.width.append(len(line)) + else: + self.lines.append('') - return self.lines, max(self.width) + return self.lines, max(self.width), self.line_comment def look_for_delay(self, fname=None): if fname is None: @@ -105,7 +102,7 @@ class AsciiReader: raise ValueError(f'x is {type(x)} not int') if y is None: - y = list(range(1, max(self.num_width))) + y = list(range(1, max(self.width))) cols = x + y + yerr with self.fname.open('rb') as fh: @@ -115,7 +112,7 @@ class AsciiReader: if raw_data.ndim == 1: # only one row or column - if len(self.num_data) == 1: + if len(self.lines) == 1: # one row raw_data = raw_data.reshape(1, -1) else: