Skip to content

Commit

Permalink
Merge pull request #2853 from SasView/2800-sld-calculator-allow-user-…
Browse files Browse the repository at this point in the history
…to-finish-typing

2800 sld calculator allow user to finish typing
  • Loading branch information
juliuskarliczek authored Apr 18, 2024
2 parents a8253a9 + 13bacb4 commit d170380
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
14 changes: 3 additions & 11 deletions src/sas/qtgui/Calculators/SldPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -130,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()
Expand All @@ -147,11 +144,6 @@ 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.modelReset()

def setupMapper(self):
Expand Down
15 changes: 12 additions & 3 deletions src/sas/qtgui/Calculators/UI/SldPanel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="recalculateButton">
<widget class="QPushButton" name="calculateButton">
<property name="enabled">
<bool>true</bool>
</property>
Expand All @@ -336,7 +336,10 @@
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Recalculate</string>
<string>Calculate</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
Expand Down Expand Up @@ -364,6 +367,9 @@
<property name="text">
<string>Close</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="3">
Expand All @@ -377,6 +383,9 @@
<property name="text">
<string>Help</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
Expand All @@ -398,7 +407,7 @@
<tabstop>editNeutronLength</tabstop>
<tabstop>closeButton</tabstop>
<tabstop>helpButton</tabstop>
<tabstop>recalculateButton</tabstop>
<tabstop>calculateButton</tabstop>
</tabstops>
<resources/>
<connections/>
Expand Down
15 changes: 7 additions & 8 deletions src/sas/qtgui/Utilities/GuiUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d170380

Please sign in to comment.