Changeset d79bb7e in sasview for src/sas/qtgui/Perspectives
- Timestamp:
- Apr 26, 2018 2:43:31 PM (7 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:
- 6bd0d81
- Parents:
- 0662f53
- Location:
- src/sas/qtgui/Perspectives/Inversion
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
r044454d rd79bb7e 89 89 self.dataDeleted = False 90 90 91 self.enableButtons()92 93 91 self.model = QtGui.QStandardItemModel(self) 94 92 self.mapper = QtWidgets.QDataWidgetMapper(self) … … 175 173 self.explorerButton.clicked.connect(self.openExplorerWindow) 176 174 177 self.backgroundInput. editingFinished.connect(175 self.backgroundInput.textChanged.connect( 178 176 lambda: self.set_background(self.backgroundInput.text())) 179 self.minQInput. editingFinished.connect(177 self.minQInput.textChanged.connect( 180 178 lambda: self._calculator.set_qmin(is_float(self.minQInput.text()))) 181 self.regularizationConstantInput. editingFinished.connect(179 self.regularizationConstantInput.textChanged.connect( 182 180 lambda: self._calculator.set_alpha(is_float(self.regularizationConstantInput.text()))) 183 self.maxDistanceInput. editingFinished.connect(181 self.maxDistanceInput.textChanged.connect( 184 182 lambda: self._calculator.set_dmax(is_float(self.maxDistanceInput.text()))) 185 self.maxQInput. editingFinished.connect(183 self.maxQInput.textChanged.connect( 186 184 lambda: self._calculator.set_qmax(is_float(self.maxQInput.text()))) 187 self.slitHeightInput. editingFinished.connect(185 self.slitHeightInput.textChanged.connect( 188 186 lambda: self._calculator.set_slit_height(is_float(self.slitHeightInput.text()))) 189 self.slitWidthInput. editingFinished.connect(190 lambda: self._calculator.set_slit_width(is_float(self.slit HeightInput.text())))187 self.slitWidthInput.textChanged.connect( 188 lambda: self._calculator.set_slit_width(is_float(self.slitWidthInput.text()))) 191 189 192 190 self.model.itemChanged.connect(self.model_changed) … … 245 243 Update boxes with initial values 246 244 """ 247 blank_item = QtGui.QStandardItem("") 245 bgd_item = QtGui.QStandardItem(str(BACKGROUND_INPUT)) 246 self.model.setItem(WIDGETS.W_BACKGROUND_INPUT, bgd_item) 247 blank_item = QtGui.QStandardItem("") 248 self.model.setItem(WIDGETS.W_QMIN, blank_item) 249 blank_item = QtGui.QStandardItem("") 250 self.model.setItem(WIDGETS.W_QMAX, blank_item) 251 blank_item = QtGui.QStandardItem("") 252 self.model.setItem(WIDGETS.W_SLIT_WIDTH, blank_item) 253 blank_item = QtGui.QStandardItem("") 254 self.model.setItem(WIDGETS.W_SLIT_HEIGHT, blank_item) 248 255 no_terms_item = QtGui.QStandardItem(str(NUMBER_OF_TERMS)) 256 self.model.setItem(WIDGETS.W_NO_TERMS, no_terms_item) 257 reg_item = QtGui.QStandardItem(str(REGULARIZATION)) 258 self.model.setItem(WIDGETS.W_REGULARIZATION, reg_item) 259 max_dist_item = QtGui.QStandardItem(str(MAX_DIST)) 260 self.model.setItem(WIDGETS.W_MAX_DIST, max_dist_item) 261 blank_item = QtGui.QStandardItem("") 262 self.model.setItem(WIDGETS.W_RG, blank_item) 263 blank_item = QtGui.QStandardItem("") 264 self.model.setItem(WIDGETS.W_I_ZERO, blank_item) 249 265 bgd_item = QtGui.QStandardItem(str(BACKGROUND_INPUT)) 250 reg_item = QtGui.QStandardItem(str(REGULARIZATION))251 max_dist_item = QtGui.QStandardItem(str(MAX_DIST))252 self.model.setItem(WIDGETS.W_BACKGROUND_INPUT, bgd_item)253 self.model.setItem(WIDGETS.W_QMIN, blank_item)254 self.model.setItem(WIDGETS.W_QMAX, blank_item)255 self.model.setItem(WIDGETS.W_SLIT_WIDTH, blank_item)256 self.model.setItem(WIDGETS.W_SLIT_HEIGHT, blank_item)257 self.model.setItem(WIDGETS.W_NO_TERMS, no_terms_item)258 self.model.setItem(WIDGETS.W_REGULARIZATION, reg_item)259 self.model.setItem(WIDGETS.W_MAX_DIST, max_dist_item)260 self.model.setItem(WIDGETS.W_RG, blank_item)261 self.model.setItem(WIDGETS.W_I_ZERO, blank_item)262 266 self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, bgd_item) 267 blank_item = QtGui.QStandardItem("") 263 268 self.model.setItem(WIDGETS.W_COMP_TIME, blank_item) 269 blank_item = QtGui.QStandardItem("") 264 270 self.model.setItem(WIDGETS.W_CHI_SQUARED, blank_item) 271 blank_item = QtGui.QStandardItem("") 265 272 self.model.setItem(WIDGETS.W_OSCILLATION, blank_item) 273 blank_item = QtGui.QStandardItem("") 266 274 self.model.setItem(WIDGETS.W_POS_FRACTION, blank_item) 275 blank_item = QtGui.QStandardItem("") 267 276 self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, blank_item) 268 277 … … 296 305 self.explorerButton.setEnabled(self.logic.data_is_loaded) 297 306 self.regConstantSuggestionButton.setEnabled( 307 self.logic.data_is_loaded and 298 308 self._calculator.suggested_alpha != self._calculator.alpha) 299 309 self.noOfTermsSuggestionButton.setEnabled( 310 self.logic.data_is_loaded and 300 311 self._calculator.nfunc != self.nTermsSuggested) 301 312 … … 522 533 """Remove the existing data reference from the P(r) Persepective""" 523 534 self.dataDeleted = True 535 self.batchResults = {} 524 536 if not data_list: 525 537 data_list = [self._data] … … 555 567 556 568 def startThreadAll(self): 569 self.isBatch = True 570 self.batchComplete = [] 557 571 self.calculateAllButton.setText("Calculating...") 558 self.batchComplete = [] 559 self.isBatch = True 572 self.enableButtons() 573 self.batchResultsWindow = BatchInversionOutputPanel( 574 parent=self, output_data=self.batchResults) 560 575 self.performEstimate() 561 576 … … 571 586 else: 572 587 # If no data sets left, end batch calculation 588 self.batchComplete = [] 573 589 self.calculateAllButton.setText("Calculate All") 574 590 self.showBatchOutput() -
src/sas/qtgui/Perspectives/Inversion/UnitTesting/InversionPerspectiveTest.py
r0662f53 rd79bb7e 1 import sys1 import time 2 2 import unittest 3 import logging4 3 from unittest.mock import MagicMock 5 4 6 5 from PyQt5 import QtGui, QtWidgets 7 from PyQt5.QtTest import QTest 8 from PyQt5 import QtCore 9 10 import sas.qtgui.path_prepare 6 7 from sas.qtgui.Utilities.GuiUtils import * 11 8 from sas.qtgui.Perspectives.Inversion.InversionPerspective import InversionWindow 12 9 from sas.qtgui.Perspectives.Inversion.InversionUtils import WIDGETS 13 from sas.sascalc.dataloader.loader import Loader14 10 from sas.qtgui.Plotting.PlotterData import Data1D 15 11 16 from sas.qtgui.MainWindow.DataManager import DataManager17 import sas.qtgui.Utilities.LocalConfig18 12 import sas.qtgui.Utilities.GuiUtils as GuiUtils 19 13 … … 22 16 23 17 18 class dummy_manager(object): 19 HELP_DIRECTORY_LOCATION = "html" 20 communicate = Communicate() 21 22 def communicator(self): 23 return self.communicate 24 25 24 26 class InversionTest(unittest.TestCase): 25 27 """ Test the Inversion Perspective GUI """ … … 27 29 def setUp(self): 28 30 """ Create the InversionWindow """ 29 self.widget = InversionWindow( None)30 self.widget. performEstimate = MagicMock()31 self.widget = InversionWindow(dummy_manager()) 32 self.widget.show() 31 33 self.fakeData1 = GuiUtils.HashableStandardItem("A") 32 34 self.fakeData2 = GuiUtils.HashableStandardItem("B") 33 35 reference_data1 = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 36 reference_data1.filename = "Test A" 34 37 reference_data2 = Data1D(x=[0.1, 0.2], y=[0.0, 0.0], dy=[0.0, 0.0]) 35 GuiUtils.updateModelItem(self.fakeData1, [reference_data1]) 36 GuiUtils.updateModelItem(self.fakeData2, [reference_data2]) 38 reference_data2.filename = "Test B" 39 GuiUtils.updateModelItem(self.fakeData1, reference_data1) 40 GuiUtils.updateModelItem(self.fakeData2, reference_data2) 37 41 38 42 def tearDown(self): 39 43 """ Destroy the InversionWindow """ 40 self.widget.setClosable( True)44 self.widget.setClosable(False) 41 45 self.widget.close() 42 46 self.widget = None … … 44 48 def removeAllData(self): 45 49 """ Cleanup method to restore widget to its base state """ 46 while len(self.widget.dataList) > 0: 47 self.widget.removeData() 50 if len(self.widget.dataList) > 0: 51 remove_me = list(self.widget._dataList.keys()) 52 self.widget.removeData(remove_me) 48 53 49 54 def baseGUIState(self): … … 105 110 self.assertEqual(self.widget.backgroundInput.text(), "0.0") 106 111 self.assertEqual(self.widget.minQInput.text(), "") 107 self.assertEqual(self.widget.maxQInput.text(), self.widget.minQInput.text())112 self.assertEqual(self.widget.maxQInput.text(), "") 108 113 self.assertEqual(self.widget.regularizationConstantInput.text(), "0.0001") 109 114 self.assertEqual(self.widget.noOfTermsInput.text(), "10") … … 116 121 self.assertEqual(self.widget.dataList.count(), 1) 117 122 # See that the buttons are now enabled properly 123 self.widget.enableButtons() 118 124 self.assertFalse(self.widget.calculateAllButton.isEnabled()) 119 125 self.assertTrue(self.widget.calculateThisButton.isEnabled()) … … 127 133 self.assertEqual(self.widget.dataList.count(), 2) 128 134 # See that the buttons are now enabled properly 135 self.widget.enableButtons() 136 self.assertTrue(self.widget.calculateThisButton.isEnabled()) 129 137 self.assertTrue(self.widget.calculateAllButton.isEnabled()) 130 self.assertTrue(self.widget.calculateThisButton.isEnabled())131 138 self.assertTrue(self.widget.removeButton.isEnabled()) 132 139 self.assertTrue(self.widget.explorerButton.isEnabled()) … … 137 144 self.zeroDataSetState() 138 145 self.baseBatchState() 146 self.removeAllData() 139 147 140 148 def testAllowBatch(self): 141 149 """ Batch P(r) Tests """ 150 self.baseBatchState() 151 self.widget.setData([self.fakeData1]) 152 self.oneDataSetState() 153 self.widget.setData([self.fakeData2]) 154 self.twoDataSetState() 155 self.widget.calculateAllButton.click() 156 self.assertTrue(self.widget.batchResultsWindow is not None) 157 self.assertEqual(self.widget.batchResultsWindow.tblParams.columnCount(), 9) 158 self.assertEqual(self.widget.batchResultsWindow.tblParams.rowCount(), 2) 159 if self.widget.isBatch: 160 self.widget.isBatch = False 161 self.widget.batchResultsWindow.close() 162 self.assertTrue(self.widget.batchResultsWindow is None) 163 # Last test 164 self.widget.removeData() 165 self.removeAllData() 142 166 self.baseBatchState() 143 167 … … 153 177 self.removeAllData() 154 178 self.zeroDataSetState() 179 self.removeAllData() 155 180 156 181 def testRemoveData(self): … … 161 186 self.widget.removeData() 162 187 self.oneDataSetState() 188 self.removeAllData() 163 189 164 190 def testClose(self): … … 166 192 self.assertFalse(self.widget.isClosable()) 167 193 self.widget.close() 168 self.assertTrue(self.widget.isVisible()) 194 self.assertTrue(self.widget.isMinimized()) 195 self.assertTrue(self.widget.dmaxWindow is None) 196 self.assertTrue(self.widget.batchResultsWindow is None) 169 197 self.widget.setClosable(False) 170 198 self.assertFalse(self.widget.isClosable()) 171 199 self.widget.close() 172 self.assertTrue(self.widget.is Visible())200 self.assertTrue(self.widget.isMinimized()) 173 201 self.widget.setClosable(True) 174 202 self.assertTrue(self.widget.isClosable()) 175 203 self.widget.setClosable() 176 204 self.assertTrue(self.widget.isClosable()) 177 self.widget.close() 178 self.assertFalse(self.widget.isVisible()) 205 self.removeAllData() 179 206 180 207 def testGetNFunc(self): … … 198 225 self.assertEqual(cm.output, ['ERROR:root:Incorrect number of terms specified: Nordvest Pizza']) 199 226 self.assertEqual(self.widget.getNFunc(), 10) 227 self.removeAllData() 200 228 201 229 def testSetCurrentData(self): … … 214 242 self.widget.setCurrentData(self.fakeData1) 215 243 self.assertEqual(self.widget._data, self.fakeData1) 216 217 def notestModelChanged(self): 218 """ test the model update """ 219 self.assertTrue(self.widget._calculator.get_dmax(), 140.0) 220 self.widget.maxDistanceInput.setText("750.0") 221 self.assertTrue(self.widget._calculator.get_dmax(), 750.0) 222 self.assertTrue(self.widget._calculator.get_qmax(), 0.0) 223 self.widget.maxQInput.setText("100.0") 224 self.assertTrue(self.widget._calculator.get_dmax(), 100.0) 244 self.removeAllData() 245 246 def testModelChanged(self): 247 """ Test setting the input and the model and vice-versa """ 248 # Initial values 249 self.assertEqual(self.widget._calculator.get_dmax(), 140.0) 250 self.assertEqual(self.widget._calculator.get_qmax(), -1.0) 251 self.assertEqual(self.widget._calculator.get_qmin(), -1.0) 252 self.assertEqual(self.widget._calculator.slit_height, 0.0) 253 self.assertEqual(self.widget._calculator.slit_width, 0.0) 254 self.assertEqual(self.widget._calculator.alpha, 0.0001) 255 # Set new values 256 self.widget.maxDistanceInput.setText("1.0") 257 self.widget.maxQInput.setText("3.0") 258 self.widget.minQInput.setText("5.0") 259 self.widget.slitHeightInput.setText("7.0") 260 self.widget.slitWidthInput.setText("9.0") 261 self.widget.regularizationConstantInput.setText("11.0") 262 # Check new values 263 self.assertEqual(self.widget._calculator.get_dmax(), 1.0) 264 self.assertEqual(self.widget._calculator.get_qmax(), 3.0) 265 self.assertEqual(self.widget._calculator.get_qmin(), 5.0) 266 self.assertEqual(self.widget._calculator.slit_height, 7.0) 267 self.assertEqual(self.widget._calculator.slit_width, 9.0) 268 self.assertEqual(self.widget._calculator.alpha, 11.0) 269 # Change model directly 270 self.widget.model.setItem(WIDGETS.W_MAX_DIST, QtGui.QStandardItem("2.0")) 271 self.widget.model.setItem(WIDGETS.W_QMIN, QtGui.QStandardItem("4.0")) 272 self.widget.model.setItem(WIDGETS.W_QMAX, QtGui.QStandardItem("6.0")) 273 self.widget.model.setItem(WIDGETS.W_SLIT_HEIGHT, QtGui.QStandardItem("8.0")) 274 self.widget.model.setItem(WIDGETS.W_SLIT_WIDTH, QtGui.QStandardItem("10.0")) 275 self.widget.model.setItem(WIDGETS.W_REGULARIZATION, QtGui.QStandardItem("12.0")) 276 # Check values 277 self.assertEqual(self.widget._calculator.get_dmax(), 2.0) 278 self.assertEqual(self.widget._calculator.get_qmin(), 4.0) 279 self.assertEqual(self.widget._calculator.get_qmax(), 6.0) 280 self.assertEqual(self.widget._calculator.slit_height, 8.0) 281 self.assertEqual(self.widget._calculator.slit_width, 10.0) 282 self.assertEqual(self.widget._calculator.alpha, 12.0) 283 self.removeAllData() 225 284 226 285 def notestHelp(self):
Note: See TracChangeset
for help on using the changeset viewer.