From bfe28f127d8e48fed7668e2f111ff730c148cf70 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Thu, 5 Jan 2023 17:23:30 +0100 Subject: [PATCH] replaced exception with warning if maximum number of colors is reached; fixes T250 --- src/gui_qt/graphs/graphwindow.py | 6 ++++-- src/nmreval/io/graceeditor.py | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/gui_qt/graphs/graphwindow.py b/src/gui_qt/graphs/graphwindow.py index 8dd2c45..65845bb 100644 --- a/src/gui_qt/graphs/graphwindow.py +++ b/src/gui_qt/graphs/graphwindow.py @@ -520,14 +520,16 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow): elif other_item in self.graphic.items(): self.legend.addItem(other_item, convert(other_item.opts.get('name', ''), old='tex', new='html')) - def export_dialog(self): + def export_dialog(self, path=None): filters = 'All files (*.*);;AGR (*.agr);;SVG (*.svg);;PDF (*.pdf)' for imgformat in QtGui.QImageWriter.supportedImageFormats(): str_format = imgformat.data().decode('utf-8') filters += ';;' + str_format.upper() + ' (*.' + str_format + ')' + if path is None: + path = '' outfile = None - f = FileDialog(caption='Export graphic', filters=filters) + f = FileDialog(caption='Export graphic', directory=str(path), filter=filters) mode = f.exec() if mode == QtWidgets.QDialog.Accepted: outfile = f.save_file() diff --git a/src/nmreval/io/graceeditor.py b/src/nmreval/io/graceeditor.py index 6734362..8427c6a 100644 --- a/src/nmreval/io/graceeditor.py +++ b/src/nmreval/io/graceeditor.py @@ -2,6 +2,7 @@ from __future__ import annotations import pathlib import re +import warnings from io import StringIO from typing import Optional, Tuple @@ -216,9 +217,9 @@ class GraceEditor: elif pos == 'in_colors': # landing here for first mismatch after all colors - if cnt == 64: - raise ValueError('Maximum numbers of color reached, no new color created') - elif idx is None: + if idx is None: + if cnt >= 64: + warnings.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: