GraceEditor now clears previously read graphs when calling; fixes T257

This commit is contained in:
Dominik Demuth 2023-01-23 18:45:42 +01:00
parent bc14b26a5f
commit af313c7a58
2 changed files with 10 additions and 6 deletions

View File

@ -45,7 +45,6 @@ class QGraceReader(QtWidgets.QDialog, Ui_Dialog):
def read(self, fname): def read(self, fname):
self._reader.parse(fname) self._reader.parse(fname)
print('halio', len(self._reader.graphs))
for graphs in self._reader.graphs: for graphs in self._reader.graphs:
item = QtWidgets.QTreeWidgetItem([f'Graph {graphs.idx} (Title "{graphs.get_property("title")}")']) item = QtWidgets.QTreeWidgetItem([f'Graph {graphs.idx} (Title "{graphs.get_property("title")}")'])

View File

@ -10,6 +10,7 @@ import numpy as np
from numpy import log10 from numpy import log10
from ..configs import config_paths from ..configs import config_paths
from ..lib.logger import logger
class GraceEditor: class GraceEditor:
@ -65,6 +66,7 @@ class GraceEditor:
self.regions = [] self.regions = []
self.graphs = [] self.graphs = []
self.sets = [] self.sets = []
self.graphs = []
def new_graph(self): def new_graph(self):
if self.file is None: if self.file is None:
@ -129,7 +131,7 @@ class GraceEditor:
self.drawing_objects.append(GraceDrawing()) self.drawing_objects.append(GraceDrawing())
self.drawing_objects[-1].append(line) self.drawing_objects[-1].append(line)
else: else:
print('What happened with this line?', line.rstrip()) logger.warn('What happened with this line?', line.rstrip())
elif current_pos == 'drawing': elif current_pos == 'drawing':
if self._RE_REGION_START.match(line): if self._RE_REGION_START.match(line):
@ -194,8 +196,11 @@ class GraceEditor:
def _make_graph(self, line: str): def _make_graph(self, line: str):
m = self._RE_GRAPH_START.match(line) m = self._RE_GRAPH_START.match(line)
g_idx = int(m.group(1)) g_idx = int(m.group(1))
while g_idx != len(self.graphs): if g_idx < len(self.graphs):
self.graphs.append(GraceGraph(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)) self.graphs.append(GraceGraph(g_idx))
return 'graph' return 'graph'
@ -229,7 +234,7 @@ class GraceEditor:
pos = 'in_colors' pos = 'in_colors'
cnt += 1 cnt += 1
if (int(m['red']), int(m['green']), int(m['blue'])) == rgb: 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'] return m['id']
elif m['id'] == idx: elif m['id'] == idx:
self.header[i] = f'@map color {idx} to {rgb}, "{name}"\n' 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 # landing here for first mismatch after all colors
if idx is None: if idx is None:
if cnt >= 64: 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') self.header.insert(i, f'@map color {cnt} to {rgb}, "{name}"\n')
return cnt return cnt
else: else: