From 42283c065b5b71781bd76164cf2b6f3365fda02b Mon Sep 17 00:00:00 2001 From: Julius Karliczek Date: Mon, 15 Apr 2024 11:09:05 +0200 Subject: [PATCH 1/3] Disable autoDefault for all buttons in the sld-calculator. Change recalculation of SLD upon each keystroke when editing in favor of editingFinished. --- src/sas/qtgui/Calculators/SldPanel.py | 8 ++++---- src/sas/qtgui/Calculators/UI/SldPanel.ui | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/sas/qtgui/Calculators/SldPanel.py b/src/sas/qtgui/Calculators/SldPanel.py index 54fc5c0917..9540ea9efc 100644 --- a/src/sas/qtgui/Calculators/SldPanel.py +++ b/src/sas/qtgui/Calculators/SldPanel.py @@ -147,10 +147,10 @@ def setupModel(self): #self.model.dataChanged.connect(self.dataChanged) - self.ui.editMassDensity.textChanged.connect(self.recalculateSLD) - self.ui.editMolecularFormula.textChanged.connect(self.recalculateSLD) - self.ui.editNeutronWavelength.textChanged.connect(self.recalculateSLD) - self.ui.editXrayWavelength.textChanged.connect(self.recalculateSLD) + self.ui.editMassDensity.editingFinished.connect(self.recalculateSLD) + self.ui.editMolecularFormula.editingFinished.connect(self.recalculateSLD) + self.ui.editNeutronWavelength.editingFinished.connect(self.recalculateSLD) + self.ui.editXrayWavelength.editingFinished.connect(self.recalculateSLD) self.modelReset() diff --git a/src/sas/qtgui/Calculators/UI/SldPanel.ui b/src/sas/qtgui/Calculators/UI/SldPanel.ui index 82838a9617..23d0380348 100644 --- a/src/sas/qtgui/Calculators/UI/SldPanel.ui +++ b/src/sas/qtgui/Calculators/UI/SldPanel.ui @@ -338,6 +338,9 @@ Recalculate + + false + @@ -364,6 +367,9 @@ Close + + false + @@ -377,6 +383,9 @@ Help + + false + From fdd6131041f0b1f9c60140ffcdef3f07fe9fa96e Mon Sep 17 00:00:00 2001 From: Julius Karliczek Date: Mon, 15 Apr 2024 15:59:13 +0200 Subject: [PATCH 2/3] Reinstated the periodictable.formula checker as a checking method for the entered chemical formula --- src/sas/qtgui/Calculators/SldPanel.py | 12 ++---------- src/sas/qtgui/Utilities/GuiUtils.py | 15 +++++++-------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/sas/qtgui/Calculators/SldPanel.py b/src/sas/qtgui/Calculators/SldPanel.py index 9540ea9efc..07da932c82 100644 --- a/src/sas/qtgui/Calculators/SldPanel.py +++ b/src/sas/qtgui/Calculators/SldPanel.py @@ -116,11 +116,8 @@ def setupUi(self): self.ui.setupUi(self) # set validators - # TODO: GuiUtils.FormulaValidator() crashes with Qt5 - fix - #self.ui.editMolecularFormula.setValidator(GuiUtils.FormulaValidator(self.ui.editMolecularFormula)) - - # No need for recalculate - self.ui.recalculateButton.setVisible(False) + # Chemical formula is checked via periodictable.formula module. + self.ui.editMolecularFormula.setValidator(GuiUtils.FormulaValidator(self.ui.editMolecularFormula)) rx = QtCore.QRegularExpression("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") self.ui.editMassDensity.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editMassDensity)) @@ -147,11 +144,6 @@ def setupModel(self): #self.model.dataChanged.connect(self.dataChanged) - self.ui.editMassDensity.editingFinished.connect(self.recalculateSLD) - self.ui.editMolecularFormula.editingFinished.connect(self.recalculateSLD) - self.ui.editNeutronWavelength.editingFinished.connect(self.recalculateSLD) - self.ui.editXrayWavelength.editingFinished.connect(self.recalculateSLD) - self.modelReset() def setupMapper(self): diff --git a/src/sas/qtgui/Utilities/GuiUtils.py b/src/sas/qtgui/Utilities/GuiUtils.py index b04db50d16..6898c11a0a 100644 --- a/src/sas/qtgui/Utilities/GuiUtils.py +++ b/src/sas/qtgui/Utilities/GuiUtils.py @@ -741,16 +741,15 @@ def __init__(self, parent=None): def validate(self, input, pos): self._setStyleSheet("") - return QtGui.QValidator.Acceptable, pos - #try: - # Formula(str(input)) - # self._setStyleSheet("") - # return QtGui.QValidator.Acceptable, pos + try: + Formula(str(input)) + self._setStyleSheet("") + return QtGui.QValidator.Acceptable - #except Exception as e: - # self._setStyleSheet("background-color:pink;") - # return QtGui.QValidator.Intermediate, pos + except Exception as e: + self._setStyleSheet("background-color:pink;") + return QtGui.QValidator.Intermediate def _setStyleSheet(self, value): try: From 13bacb46741381f74a9654804eb57d6c2ba496fd Mon Sep 17 00:00:00 2001 From: Julius Karliczek Date: Tue, 16 Apr 2024 09:17:30 +0200 Subject: [PATCH 3/3] Change button displayed text in ui to calculate instead of recalculate. Also renamed the corresponding logic. Calculate button is now the auto-default and can be triggered via enter keystroke. --- src/sas/qtgui/Calculators/SldPanel.py | 2 +- src/sas/qtgui/Calculators/UI/SldPanel.ui | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sas/qtgui/Calculators/SldPanel.py b/src/sas/qtgui/Calculators/SldPanel.py index 07da932c82..5ddf6ad931 100644 --- a/src/sas/qtgui/Calculators/SldPanel.py +++ b/src/sas/qtgui/Calculators/SldPanel.py @@ -127,7 +127,7 @@ def setupUi(self): # signals self.ui.helpButton.clicked.connect(self.displayHelp) self.ui.closeButton.clicked.connect(self.closePanel) - self.ui.recalculateButton.clicked.connect(self.calculateSLD) + self.ui.calculateButton.clicked.connect(self.calculateSLD) def calculateSLD(self): self.recalculateSLD() diff --git a/src/sas/qtgui/Calculators/UI/SldPanel.ui b/src/sas/qtgui/Calculators/UI/SldPanel.ui index 23d0380348..df0197accc 100644 --- a/src/sas/qtgui/Calculators/UI/SldPanel.ui +++ b/src/sas/qtgui/Calculators/UI/SldPanel.ui @@ -322,7 +322,7 @@ - + true @@ -336,10 +336,10 @@ Qt::NoFocus - Recalculate + Calculate - false + true @@ -407,7 +407,7 @@ editNeutronLength closeButton helpButton - recalculateButton + calculateButton