From edf858da29db371b16798f89c37208201217f4f8 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Thu, 11 May 2023 20:12:32 +0200 Subject: [PATCH] hacky solution to have correct tuda colors in agr file; closes #63 --- src/gui_qt/io/exporters.py | 6 +++--- src/gui_qt/lib/delegates.py | 8 ++++---- src/nmreval/io/graceeditor.py | 21 ++++++++++++++++++--- src/nmreval/lib/colors.py | 1 + src/resources/Default.agr | 8 ++++---- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/gui_qt/io/exporters.py b/src/gui_qt/io/exporters.py index e089991..75b4a55 100644 --- a/src/gui_qt/io/exporters.py +++ b/src/gui_qt/io/exporters.py @@ -55,9 +55,9 @@ class GraceExporter: break if c_num == -1: - c_num = max(colors.keys()) - colors[c_num + 1] = (f'color{c_num + 1}', sc) - new_colors.append((c_num + 1, f'color{c_num + 1}', sc)) + c_num = max(colors.keys())+1 + colors[c_num] = (f'color{c_num}', sc) + new_colors.append((c_num, f'color{c_num}', sc)) new_s.set_symbol(**{'symbol': item['symbol'].value, 'size': item['symbolsize'] / 10., 'color': c_num, 'fill color': c_num, 'fill pattern': 1}) diff --git a/src/gui_qt/lib/delegates.py b/src/gui_qt/lib/delegates.py index d6f0c9a..2ef865c 100644 --- a/src/gui_qt/lib/delegates.py +++ b/src/gui_qt/lib/delegates.py @@ -30,7 +30,7 @@ class PropertyDelegate(QtWidgets.QStyledItemDelegate): rect = options.rect rect.adjust(5, 0, -5, 0) - mid = (rect.bottom()+rect.top()) / 2 + mid = int((rect.bottom()+rect.top()) / 2) painter.drawLine(rect.left(), mid, rect.right(), mid) painter.restore() @@ -42,7 +42,7 @@ class PropertyDelegate(QtWidgets.QStyledItemDelegate): painter.setPen(pen) pm = make_symbol_pixmap(r) - painter.drawPixmap(options.rect.topLeft()+QtCore.QPoint(3, (options.rect.height()-pm.height())/2), pm) + painter.drawPixmap(options.rect.topLeft()+QtCore.QPoint(3, int((options.rect.height()-pm.height())/2)), pm) style = QtWidgets.QApplication.style() text_rect = style.subElementRect(QtWidgets.QStyle.SE_ItemViewItemText, options, None) @@ -171,7 +171,7 @@ class LineStyleEditor(QtWidgets.QComboBox): rect = painter.style().subControlRect(QtWidgets.QStyle.CC_ComboBox, opt, QtWidgets.QStyle.SC_ComboBoxEditField, None) rect.adjust(+10, 0, -10, 0) - mid = (rect.bottom() + rect.top()) / 2 + mid = int((rect.bottom() + rect.top()) / 2) painter.drawLine(rect.left(), mid, rect.right(), mid) painter.end() else: @@ -193,7 +193,7 @@ class LineStyleDelegate(QtWidgets.QStyledItemDelegate): rect = option.rect rect.adjust(+10, 0, -10, 0) - mid = (rect.bottom()+rect.top()) / 2 + mid = int((rect.bottom()+rect.top()) / 2) painter.drawLine(rect.left(), mid, rect.right(), mid) else: QtWidgets.QStyledItemDelegate.paint(self, painter, option, index) diff --git a/src/nmreval/io/graceeditor.py b/src/nmreval/io/graceeditor.py index 58a114e..f657f68 100644 --- a/src/nmreval/io/graceeditor.py +++ b/src/nmreval/io/graceeditor.py @@ -1,9 +1,7 @@ from __future__ import annotations -import codecs import pathlib import re -import warnings from io import StringIO from typing import Optional, Tuple @@ -46,6 +44,22 @@ class GraceEditor: if filename is not None: self.parse(filename) + def _fix_tuda_colors(self): + # 2023-05-11: Default.agr had wrong TUDa colors (4a, 7b, 9b, 9d), so set the values given in colors.py + color_mapping = [ + ('tuda4a', (175, 204, 80)), + ('tuda7b', (245, 163, 0)), + ('tuda9b', (230, 0, 26)), + ('tuda9d', (156, 28, 38)), + ] + + for i, line in enumerate(self.header): + m = self._RE_COLOR.match(line) + if m: + for name, right_color in color_mapping: + if m['disp'].lower() == name: + self.header[i] = f'@map color {m["id"]} to {right_color}, "{m["disp"]}"\n' + def __call__(self, filename: str): self.clear() self.parse(filename) @@ -193,6 +207,8 @@ class GraceEditor: self.graphs[-1].append(line) + self._fix_tuda_colors() + def _make_graph(self, line: str): m = self._RE_GRAPH_START.match(line) g_idx = int(m.group(1)) @@ -212,7 +228,6 @@ class GraceEditor: m = self._RE_COLOR.match(line) if m: _colors[int(m['id'])] = (m['disp'], (int(m['red']), int(m['green']), int(m['blue']))) - return _colors def get_color(self, color_num): diff --git a/src/nmreval/lib/colors.py b/src/nmreval/lib/colors.py index 90765a6..d3aba66 100644 --- a/src/nmreval/lib/colors.py +++ b/src/nmreval/lib/colors.py @@ -247,6 +247,7 @@ class Tab10(BaseColor): TabChartreuse = TUColorsC.TUDa5c.value TabTurquoise = TUColorsA.TUDa2a.value + class Tab20(BaseColor): TabBlue = (31, 119, 180) TabBlue2 = (174, 199, 232) diff --git a/src/resources/Default.agr b/src/resources/Default.agr index 8d08a08..10e7a0c 100644 --- a/src/resources/Default.agr +++ b/src/resources/Default.agr @@ -64,7 +64,7 @@ @map color 2 to (93, 133, 195), "TUDa1a" @map color 3 to (0, 156, 218), "TUDa2a" @map color 4 to (80, 182, 149), "TUDa3a" -@map color 5 to (176, 204, 80), "TUDa4a" +@map color 5 to (175, 204, 80), "TUDa4a" @map color 6 to (221, 223, 72), "TUDa5a" @map color 7 to (255, 224, 92), "TUDa6a" @map color 8 to (248, 186, 60), "TUDa7a" @@ -78,9 +78,9 @@ @map color 16 to (153, 192, 0), "TUDa4b" @map color 17 to (201, 212, 0), "TUDa5b" @map color 18 to (253, 202, 0), "TUDa6b" -@map color 19 to (248, 163, 0), "TUDa7b" +@map color 19 to (245, 163, 0), "TUDa7b" @map color 20 to (236, 101, 0), "TUDa8b" -@map color 21 to (239, 0, 26), "TUDa9b" +@map color 21 to (230, 0, 26), "TUDa9b" @map color 22 to (166, 0, 132), "TUDa10b" @map color 23 to (114, 16, 133), "TUDa11b" @map color 24 to (0, 78, 138), "TUDa1c" @@ -102,7 +102,7 @@ @map color 40 to (174, 142, 0), "TUDa6d" @map color 41 to (190, 111, 0), "TUDa7d" @map color 42 to (169, 73, 19), "TUDa8d" -@map color 43 to (188, 28, 38), "TUDa9d" +@map color 43 to (156, 28, 38), "TUDa9d" @map color 44 to (115, 32, 84), "TUDa10d" @map color 45 to (76, 34, 106), "TUDa11d" @map color 46 to (220, 220, 220), "TUDa0a"