Changeset e4676c8 in sasview
- Timestamp:
- Nov 3, 2016 4:07:10 AM (8 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- ca8b853
- Parents:
- f140169
- Location:
- src/sas/qtgui
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/DensityPanel.py
rf140169 re4676c8 2 2 import logging 3 3 import functools 4 from PyQt4 import QtGui, QtCore 4 5 5 6 from periodictable import formula as Formula 6 7 7 from PyQt4 import QtGui, QtCore8 from GuiUtils import FormulaValidator 8 9 9 10 # Local UI … … 34 35 except: 35 36 return "" 36 37 38 class FormulaValidator(QtGui.QValidator):39 def __init__(self, parent=None):40 super(FormulaValidator, self).__init__(parent)41 42 def validate(self, input, pos):43 try:44 Formula(str(input))45 self._setStyleSheet("")46 return QtGui.QValidator.Acceptable, pos47 48 except Exception as e:49 self._setStyleSheet("background-color:pink;")50 return QtGui.QValidator.Intermediate, pos51 52 def _setStyleSheet(self, value):53 try:54 if self.parent():55 self.parent().setStyleSheet(value)56 except:57 pass58 37 59 38 -
src/sas/qtgui/GuiUtils.py
- Property mode changed from 100755 to 100644
r39551a68 re4676c8 25 25 #from sas.sasgui.guiframe.events import StatusEvent 26 26 #from sas.sasgui.guiframe.events import NewPlotEvent 27 28 from periodictable import formula as Formula 27 29 28 30 from sas.sasgui.guiframe.dataFitting import Data1D … … 535 537 if os.path.splitext(filename)[1].lower() == ext_format: 536 538 loader.save(filename, data, ext_format) 539 540 class FormulaValidator(QtGui.QValidator): 541 def __init__(self, parent=None): 542 super(FormulaValidator, self).__init__(parent) 543 544 def validate(self, input, pos): 545 try: 546 Formula(str(input)) 547 self._setStyleSheet("") 548 return QtGui.QValidator.Acceptable, pos 549 550 except Exception as e: 551 self._setStyleSheet("background-color:pink;") 552 return QtGui.QValidator.Intermediate, pos 553 554 def _setStyleSheet(self, value): 555 try: 556 if self.parent(): 557 self.parent().setStyleSheet(value) 558 except: 559 pass -
src/sas/qtgui/SldPanel.py
r1d85b5e re4676c8 1 1 # global 2 2 import logging 3 from PyQt4 import QtGui, QtCore 4 3 5 from periodictable import formula as Formula 4 6 from periodictable.xsf import xray_energy, xray_sld_from_atoms 5 7 from periodictable.nsf import neutron_scattering 6 8 7 from PyQt4 import QtGui, QtCore9 from GuiUtils import FormulaValidator 8 10 9 11 # Local UI … … 93 95 94 96 95 class FormulaValidator(QtGui.QValidator):96 def __init__(self, parent=None):97 super(FormulaValidator, self).__init__(parent)98 99 def validate(self, input, pos):100 try:101 Formula(str(input))102 self._setStyleSheet("")103 return QtGui.QValidator.Acceptable, pos104 105 except Exception as e:106 self._setStyleSheet("background-color:pink;")107 return QtGui.QValidator.Intermediate, pos108 109 def _setStyleSheet(self, value):110 try:111 if self.parent():112 self.parent().setStyleSheet(value)113 except:114 pass115 116 117 97 class SldPanel(QtGui.QDialog): 118 98 -
src/sas/qtgui/UnitTesting/DensityCalculatorTest.py
rf140169 re4676c8 15 15 from DensityPanel import DensityPanel 16 16 from DensityPanel import toMolarMass 17 from DensityPanelimport FormulaValidator17 from GuiUtils import FormulaValidator 18 18 19 19 import LocalConfig … … 37 37 def testBadInputStr(self): 38 38 self.assertEqual(toMolarMass("Im a bad string"), "") 39 40 class FormulaValidatorTest(unittest.TestCase):41 """ Test the formula validator """42 def setUp(self):43 '''Create the validator'''44 self.validator = FormulaValidator()45 46 def tearDown(self):47 '''Destroy the validator'''48 self.validator = None49 50 def testValidateGood(self):51 """Test a valid Formula """52 formula_good = "H24O12C4C6N2Pu"53 self.assertEqual(self.validator.validate(formula_good, 1)[0], QtGui.QValidator.Acceptable)54 55 formula_good = "(H2O)0.5(D2O)0.5"56 self.assertEqual(self.validator.validate(formula_good, 1)[0], QtGui.QValidator.Acceptable)57 58 def testValidateBad(self):59 """Test a valid Formula """60 formula_bad = "H24 %%%O12C4C6N2Pu"61 self.assertRaises(self.validator.validate(formula_bad, 1)[0])62 self.assertEqual(self.validator.validate(formula_bad, 1)[0], QtGui.QValidator.Intermediate)63 64 formula_bad = [1]65 self.assertEqual(self.validator.validate(formula_bad, 1)[0], QtGui.QValidator.Intermediate)66 39 67 40 class DensityCalculatorTest(unittest.TestCase): -
src/sas/qtgui/UnitTesting/GuiUtilsTest.py
r9968d6a re4676c8 324 324 self.assertFalse(os.path.isfile(file_name)) 325 325 326 class FormulaValidatorTest(unittest.TestCase): 327 """ Test the formula validator """ 328 def setUp(self): 329 '''Create the validator''' 330 self.validator = FormulaValidator() 331 332 def tearDown(self): 333 '''Destroy the validator''' 334 self.validator = None 335 336 def testValidateGood(self): 337 """Test a valid Formula """ 338 formula_good = "H24O12C4C6N2Pu" 339 self.assertEqual(self.validator.validate(formula_good, 1)[0], QtGui.QValidator.Acceptable) 340 341 formula_good = "(H2O)0.5(D2O)0.5" 342 self.assertEqual(self.validator.validate(formula_good, 1)[0], QtGui.QValidator.Acceptable) 343 344 def testValidateBad(self): 345 """Test a valid Formula """ 346 formula_bad = "H24 %%%O12C4C6N2Pu" 347 self.assertRaises(self.validator.validate(formula_bad, 1)[0]) 348 self.assertEqual(self.validator.validate(formula_bad, 1)[0], QtGui.QValidator.Intermediate) 349 350 formula_bad = [1] 351 self.assertEqual(self.validator.validate(formula_bad, 1)[0], QtGui.QValidator.Intermediate) 352 326 353 327 354 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.