From 067857eda237fe8ed26afc12955c3542e80695e7 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Tue, 19 Sep 2023 12:22:33 +0200 Subject: [PATCH] minor fixes --- src/gui_qt/data/container.py | 5 +- .../data/signaledit/editsignalwidget.py | 3 +- src/gui_qt/fit/fit_parameter.py | 2 +- src/gui_qt/graphs/drawings.py | 2 - src/gui_qt/lib/mdiarea.py | 1 - src/gui_qt/lib/randpok.py | 110 ------------------ src/gui_qt/main/management.py | 1 - src/nmreval/fit/result.py | 26 +++-- 8 files changed, 21 insertions(+), 129 deletions(-) delete mode 100644 src/gui_qt/lib/randpok.py diff --git a/src/gui_qt/data/container.py b/src/gui_qt/data/container.py index 913ad7e..106eee3 100644 --- a/src/gui_qt/data/container.py +++ b/src/gui_qt/data/container.py @@ -8,6 +8,7 @@ from pyqtgraph import mkPen from nmreval.data.points import Points from nmreval.data.signals import Signal +from nmreval.lib.logger import logger from nmreval.utils.text import convert from nmreval.data.bds import BDS from nmreval.data.dsc import DSC @@ -356,7 +357,7 @@ class ExperimentContainer(QtCore.QObject): elif mode in ['imag', 'all'] and self.plot_imag is not None: self.plot_imag.set_symbol(symbol=symbol, size=size, color=color) else: - print('Updating symbol failed for ' + str(self.id)) + logger.warning(f'Updating symbol failed for {self.id}') def setLine(self, *, width=None, style=None, color=None, mode='real'): if mode in ['real', 'all']: @@ -368,7 +369,7 @@ class ExperimentContainer(QtCore.QObject): elif mode in ['imag', 'all'] and self.plot_imag is not None: self.plot_imag.set_line(width=width, style=style, color=color) else: - print('Updating line failed for ' + str(self.id)) + logger.warning(f'Updating line failed for {self.id}') def update_property(self, key1: str, key2: str, value: Any): keykey = key2.split() diff --git a/src/gui_qt/data/signaledit/editsignalwidget.py b/src/gui_qt/data/signaledit/editsignalwidget.py index 980ea19..31c4aff 100644 --- a/src/gui_qt/data/signaledit/editsignalwidget.py +++ b/src/gui_qt/data/signaledit/editsignalwidget.py @@ -1,3 +1,4 @@ +from nmreval.lib.logger import logger from nmreval.math import apodization from nmreval.lib.importer import find_models from nmreval.utils.text import convert @@ -67,7 +68,7 @@ class EditSignalWidget(QtWidgets.QWidget, Ui_Form): self.do_something.emit(sender, (ph0, ph1, pvt)) else: - print('You should never reach this by accident.') + logger.warning(f'You should never reach this by accident, invalid sender {sender!r}') @QtCore.pyqtSlot(int, name='on_apodcombobox_currentIndexChanged') def change_apodization(self, index): diff --git a/src/gui_qt/fit/fit_parameter.py b/src/gui_qt/fit/fit_parameter.py index e6b5a11..30b4b31 100644 --- a/src/gui_qt/fit/fit_parameter.py +++ b/src/gui_qt/fit/fit_parameter.py @@ -175,7 +175,7 @@ class QFitParameterWidget(QtWidgets.QWidget, Ui_FormFit): # disable single parameter if it is set global, enable if global is unset widget = self.sender() idx = self.global_parameter.index(widget) - enable = (widget.global_checkbox.checkState() == QtCore.Qt.Unchecked) and (widget.is_linked is None) + enable = (widget.global_checkbox.checkState() == QtCore.Qt.Unchecked) self.data_parameter[idx].setEnabled(enable) def select_next_preview(self, direction): diff --git a/src/gui_qt/graphs/drawings.py b/src/gui_qt/graphs/drawings.py index cd62db4..e87af0e 100644 --- a/src/gui_qt/graphs/drawings.py +++ b/src/gui_qt/graphs/drawings.py @@ -138,9 +138,7 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form): graph_id = self.graph_comboBox.currentData() current_lines = self.lines[graph_id] - print(remove_rows) for i in reversed(remove_rows): - print(i) self.tableWidget.removeRow(i) self.line_deleted.emit(current_lines[i], graph_id) diff --git a/src/gui_qt/lib/mdiarea.py b/src/gui_qt/lib/mdiarea.py index 37f6c27..3dd6bbf 100644 --- a/src/gui_qt/lib/mdiarea.py +++ b/src/gui_qt/lib/mdiarea.py @@ -27,7 +27,6 @@ class MdiAreaTile(QtWidgets.QMdiArea): pos = QtCore.QPoint(0, 0) for win in window_list: - print(win.minimumSize()) win.setGeometry(rect) win.move(pos) diff --git a/src/gui_qt/lib/randpok.py b/src/gui_qt/lib/randpok.py deleted file mode 100644 index 1cbfcf8..0000000 --- a/src/gui_qt/lib/randpok.py +++ /dev/null @@ -1,110 +0,0 @@ -import os.path -import json -import urllib.request -import webbrowser -import random - -from ..Qt import QtGui, QtCore, QtWidgets -from .._py.pokemon import Ui_Dialog - -random.seed() - - -class QPokemon(QtWidgets.QDialog, Ui_Dialog): - def __init__(self, number=None, parent=None): - super().__init__(parent=parent) - self.setupUi(self) - self._js = json.load(open(os.path.join(path_to_module, 'utils', 'pokemon.json'), 'r'), encoding='UTF-8') - self._id = 0 - - if number is not None and number in range(1, len(self._js)+1): - poke_nr = f'{number:03d}' - self._id = number - else: - poke_nr = f'{random.randint(1, len(self._js)):03d}' - self._id = int(poke_nr) - - self._pokemon = None - self.show_pokemon(poke_nr) - self.label_15.linkActivated.connect(lambda x: webbrowser.open(x)) - - self.buttonBox.clicked.connect(self.randomize) - self.next_button.clicked.connect(self.show_next) - self.prev_button.clicked.connect(self.show_prev) - - def show_pokemon(self, nr): - self._pokemon = self._js[nr] - self.setWindowTitle('Pokémon: ' + self._pokemon['Deutsch']) - - for i in range(self.tabWidget.count(), -1, -1): - print('i', self.tabWidget.count(), i) - try: - self.tabWidget.widget(i).deleteLater() - except AttributeError: - pass - - for n, img in self._pokemon['Bilder']: - w = QtWidgets.QWidget() - vl = QtWidgets.QVBoxLayout() - l = QtWidgets.QLabel(self) - l.setAlignment(QtCore.Qt.AlignHCenter) - pixmap = QtGui.QPixmap() - - try: - pixmap.loadFromData(urllib.request.urlopen(img, timeout=0.5).read()) - except IOError: - l.setText(n) - else: - sc_pixmap = pixmap.scaled(256, 256, QtCore.Qt.KeepAspectRatio) - l.setPixmap(sc_pixmap) - - vl.addWidget(l) - w.setLayout(vl) - self.tabWidget.addTab(w, n) - - if len(self._pokemon['Bilder']) <= 1: - self.tabWidget.tabBar().setVisible(False) - else: - self.tabWidget.tabBar().setVisible(True) - self.tabWidget.adjustSize() - - self.name.clear() - keys = ['National-Dex', 'Kategorie', 'Typ', 'Größe', 'Gewicht', 'Farbe', 'Link'] - label_list = [self.pokedex_nr, self.category, self.poketype, self.weight, self.height, self.color, self.info] - for (k, label) in zip(keys, label_list): - v = self._pokemon[k] - if isinstance(v, list): - v = os.path.join('', *v) - - if k == 'Link': - v = '{}'.format(v, v) - - label.setText(v) - - for k in ['Deutsch', 'Japanisch', 'Englisch', 'Französisch']: - v = self._pokemon[k] - self.name.addItem(k + ': ' + v) - - self.adjustSize() - - def randomize(self, idd): - if idd.text() == 'Retry': - new_number = f'{random.randint(1, len(self._js)):03d}' - self._id = int(new_number) - self.show_pokemon(new_number) - else: - self.close() - - def show_next(self): - new_number = self._id + 1 - if new_number > len(self._js): - new_number = 1 - self._id = new_number - self.show_pokemon(f'{new_number:03d}') - - def show_prev(self): - new_number = self._id - 1 - if new_number == 0: - new_number = len(self._js) - self._id = new_number - self.show_pokemon(f'{new_number:03d}') diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index 8d4c4ee..67e33cd 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -445,7 +445,6 @@ class UpperManagement(QtCore.QObject): models[model_id] = m m_complex = model_p['complex'] - print(model_p) # sets are not in active order but in order they first appeared in fit dialog # iterate over order of set id in active order and access parameter inside loop diff --git a/src/nmreval/fit/result.py b/src/nmreval/fit/result.py index 9cf6d5e..d825e14 100644 --- a/src/nmreval/fit/result.py +++ b/src/nmreval/fit/result.py @@ -2,6 +2,7 @@ from __future__ import annotations import re from collections import OrderedDict +from io import StringIO from pathlib import Path from typing import Any @@ -223,22 +224,25 @@ class FitResult(Points): return self.nobs-self.nvar def pprint(self, statistics=True, correlations=True): - print('Fit result:') - print(' model :', self.name) - print(' #data :', self.nobs) - print(' #var :', self.nvar) - print('\nParameter') - print(self.parameter_string()) + s = StringIO() + s.write('Fit result:\n') + s.write(f' model : {self.name}\n') + s.write(f' #data : {self.nobs}\n') + s.write(f' #var : {self.nvar}\n') + s.write('\nParameter\n') + s.write(self.parameter_string()) if statistics: - print('Statistics') + s.write('Statistics\n') for k, v in self.statistics.items(): - print(f' {k} : {v:.4f}') + s.write(f' {k} : {v:.4f}') if correlations and self.correlation is not None: - print('\nCorrelation (partial corr.)') - print(self._correlation_string()) - print() + s.write('\nCorrelation (partial corr.)\n') + s.write(self._correlation_string()) + s.write('\n') + + print(s.getvalue()) def parameter_string(self): ret_val = ''