From 141e9f810afcbe4da615213d867005fad72110d1 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Sat, 29 Jul 2023 18:47:57 +0200 Subject: [PATCH] convert removes agr controls --- src/gui_qt/io/gracereader.py | 4 +++- src/nmreval/utils/text.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui_qt/io/gracereader.py b/src/gui_qt/io/gracereader.py index be3d62a..ca1e414 100644 --- a/src/gui_qt/io/gracereader.py +++ b/src/gui_qt/io/gracereader.py @@ -4,6 +4,7 @@ from nmreval.lib.lines import LineStyle from nmreval.lib.symbols import SymbolStyle from nmreval.data.points import Points from nmreval.io.graceeditor import GraceEditor +from nmreval.utils.text import convert from ..Qt import QtCore, QtWidgets, QtGui from .._py.gracereader import Ui_Dialog @@ -55,7 +56,7 @@ class QGraceReader(QtWidgets.QDialog, Ui_Dialog): if ds is None: continue - item_2 = QtWidgets.QTreeWidgetItem([f'Set {gset.idx} (Label: {gset.get_property("legend")}, ' + item_2 = QtWidgets.QTreeWidgetItem([f'Set {gset.idx} (Label: {convert(gset.get_property("legend"), old="agr", new="str")}, ' f'shape: {ds.shape})']) item_2.setCheckState(0, QtCore.Qt.Checked) item_2.setData(0, QtCore.Qt.UserRole, (graphs.idx, gset.idx)) @@ -94,6 +95,7 @@ class QGraceReader(QtWidgets.QDialog, Ui_Dialog): label = '' else: label = label.replace('"', '') + label = convert(label, old='agr', new='str') sd = s.data sd = np.atleast_2d(sd) if s.type == 'xydy': diff --git a/src/nmreval/utils/text.py b/src/nmreval/utils/text.py index 57ff30a..7a8e8ba 100644 --- a/src/nmreval/utils/text.py +++ b/src/nmreval/utils/text.py @@ -80,6 +80,10 @@ def _replace_delims(text, src, dest): return text +def _replace_agr_controls(text: str): + return re.sub(r'\\[hvzfx]\{(\d*.?\d+.?)?\}', '', text) + + def convert(text: str, old: str = 'tex', new: str = 'html', brackets: bool = True): t = {'latex': 0, 'tex': 0, 'html': 1, 'agr': 2, 'plain': 3, 'str': 3} @@ -101,5 +105,8 @@ def convert(text: str, old: str = 'tex', new: str = 'html', brackets: bool = Tru if idx_out == 3 and not brackets: text = text.replace('{', '').replace('}', '') + if idx_in == 2: + text = _replace_agr_controls(text) + return text