From af313c7a589c4b5e32246c5a21346ceede6d0f32 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Mon, 23 Jan 2023 18:45:42 +0100 Subject: [PATCH] GraceEditor now clears previously read graphs when calling; fixes T257 --- src/gui_qt/io/gracereader.py | 1 - src/nmreval/io/graceeditor.py | 15 ++++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/gui_qt/io/gracereader.py b/src/gui_qt/io/gracereader.py index 6de6008..f563239 100644 --- a/src/gui_qt/io/gracereader.py +++ b/src/gui_qt/io/gracereader.py @@ -45,7 +45,6 @@ class QGraceReader(QtWidgets.QDialog, Ui_Dialog): def read(self, fname): self._reader.parse(fname) - print('halio', len(self._reader.graphs)) for graphs in self._reader.graphs: item = QtWidgets.QTreeWidgetItem([f'Graph {graphs.idx} (Title "{graphs.get_property("title")}")']) diff --git a/src/nmreval/io/graceeditor.py b/src/nmreval/io/graceeditor.py index 59c25e9..61c27db 100644 --- a/src/nmreval/io/graceeditor.py +++ b/src/nmreval/io/graceeditor.py @@ -10,6 +10,7 @@ import numpy as np from numpy import log10 from ..configs import config_paths +from ..lib.logger import logger class GraceEditor: @@ -65,6 +66,7 @@ class GraceEditor: self.regions = [] self.graphs = [] self.sets = [] + self.graphs = [] def new_graph(self): if self.file is None: @@ -129,7 +131,7 @@ class GraceEditor: self.drawing_objects.append(GraceDrawing()) self.drawing_objects[-1].append(line) else: - print('What happened with this line?', line.rstrip()) + logger.warn('What happened with this line?', line.rstrip()) elif current_pos == 'drawing': if self._RE_REGION_START.match(line): @@ -194,8 +196,11 @@ class GraceEditor: def _make_graph(self, line: str): m = self._RE_GRAPH_START.match(line) g_idx = int(m.group(1)) - while g_idx != len(self.graphs): - self.graphs.append(GraceGraph(len(self.graphs))) + if g_idx < len(self.graphs): + # this assumes that graphs are ordered in agr file even if missing, e.g. we read gß, g1, g3, ... + while g_idx != len(self.graphs): + self.graphs.append(GraceGraph(len(self.graphs))) + self.graphs.append(GraceGraph(g_idx)) return 'graph' @@ -229,7 +234,7 @@ class GraceEditor: pos = 'in_colors' cnt += 1 if (int(m['red']), int(m['green']), int(m['blue'])) == rgb: - print(f'color already defined as {m["disp"]}') + logger.info(f'color already defined as {m["disp"]}') return m['id'] elif m['id'] == idx: self.header[i] = f'@map color {idx} to {rgb}, "{name}"\n' @@ -238,7 +243,7 @@ class GraceEditor: # landing here for first mismatch after all colors if idx is None: if cnt >= 64: - warnings.warn('Maximum numbers of color reached, color is not used by xmgrace') + logger.warn('Maximum numbers of color reached, color is not used by xmgrace') self.header.insert(i, f'@map color {cnt} to {rgb}, "{name}"\n') return cnt else: