check for value changes while tabbing in edit mode, avoid signal; closes #79
This commit is contained in:
parent
6e976e1404
commit
2499aac7a1
@ -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.
|
||||
|
@ -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}'
|
||||
|
@ -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'))
|
||||
|
Loading…
Reference in New Issue
Block a user