From 2499aac7a12dd09f1a464088245c7b5037387867 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Mon, 12 Jun 2023 17:52:25 +0200 Subject: [PATCH] check for value changes while tabbing in edit mode, avoid signal; closes #79 --- src/gui_qt/_py/valueeditor.py | 4 ++-- src/gui_qt/data/valueeditwidget.py | 17 +++++++++++++---- src/gui_qt/main/mainwindow.py | 1 - 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/gui_qt/_py/valueeditor.py b/src/gui_qt/_py/valueeditor.py index f2e2aeb..cac1bcf 100644 --- a/src/gui_qt/_py/valueeditor.py +++ b/src/gui_qt/_py/valueeditor.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'resources/_ui/valueeditor.ui' +# Form implementation generated from reading ui file 'src/resources/_ui/valueeditor.ui' # -# Created by: PyQt5 UI code generator 5.15.4 +# Created by: PyQt5 UI code generator 5.15.9 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. diff --git a/src/gui_qt/data/valueeditwidget.py b/src/gui_qt/data/valueeditwidget.py index bb94965..540c268 100644 --- a/src/gui_qt/data/valueeditwidget.py +++ b/src/gui_qt/data/valueeditwidget.py @@ -259,10 +259,7 @@ class ValueModel(QtCore.QAbstractTableModel): row = idx.row() if role in [QtCore.Qt.DisplayRole, QtCore.Qt.EditRole]: val = self._data[row][idx.column()] - if isinstance(val, complex): - return f'{val.real:.8g}{val.imag:+.8g}j' - else: - return f'{val:.8g}' + return self.as_string(val) elif role == QtCore.Qt.BackgroundRole: pal = QtGui.QGuiApplication.palette() @@ -295,11 +292,16 @@ class ValueModel(QtCore.QAbstractTableModel): if value: if role == QtCore.Qt.EditRole: + if value == self.as_string(self._data[row][col]): + return True + try: value = complex(value) except ValueError: # not a number return False + + value = value.real if value.imag == 0 else value self._data[row][col] = value.real if value.imag == 0 else value self.itemChanged.emit(col, row, str(value)) self.dataChanged.emit(self.index(0, 0), self.index(0, 1), [role]) @@ -368,3 +370,10 @@ class ValueModel(QtCore.QAbstractTableModel): def unmask(self): self.mask = [True] * self.total_rows self.dataChanged.emit(self.index(0, 0), self.index(0, 1), [ValueModel.maskRole]) + + @staticmethod + def as_string(value) -> str: + if isinstance(value, complex): + return f'{value.real:.8g}{value.imag:+.8g}j' + else: + return f'{value:.8g}' diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index d6bac83..c09433b 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -1115,7 +1115,6 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): else: pass - @QtCore.pyqtSlot(name='on_actionCreate_starter_triggered') def create_starter(self): make_starter(os.getenv('APPIMAGE'))