Changeset bde1a6b in sasview for src/sas/qtgui/Perspectives/PrInversion/PrInversionPerspective.py
- Timestamp:
- Oct 27, 2017 9:48:48 AM (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:
- dab3351
- Parents:
- 406f420
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/PrInversion/PrInversionPerspective.py
r406f420 rbde1a6b 8 8 # pr inversion gui elements 9 9 from PrInversionUtils import WIDGETS 10 import UI.TabbedPrInversionUI 10 11 from UI.TabbedPrInversionUI import Ui_PrInversion 12 13 # pr inversion calculation elements 14 from sas.sascalc.pr.invertor import Invertor 15 from sas.sasgui.perspectives.pr import pr_thread as pr_thread 16 11 17 12 18 class PrInversionWindow(QtGui.QTabWidget, Ui_PrInversion): … … 27 33 self._helpView = QtWebKit.QWebView() 28 34 35 self.communicate = GuiUtils.Communicate() 36 37 # The window should not close 38 self._allow_close = False 39 40 # is there data 41 self._has_data = False 42 43 # Current data object in view 44 self._data_index = 0 45 # list mapping data to p(r) calculation 46 self._data_list = [] 29 47 if not isinstance(data, list): 30 48 data = [data] 31 self._data = data 32 33 # The tabs need to be closeable 34 self._allow_close = False 35 36 # Set initial values 37 self._data_index = 0 38 self._path = "" 39 self._background = 0.0 40 self._qmin = 0.0 41 self._qmax = 1.0 42 self._slit_height = 0.0 43 self._slit_width = 0.0 44 self._terms = 10 45 self._regularization = 0.0001 46 self._max_distance = 140 47 self._bgd_input = False 48 self._terms_button = False 49 self._reg_button = False 50 self._terms_label = "" 51 self._reg_label = "" 52 # Set results 53 self._rg = 0.0 54 self._i_0 = 0.0 55 self._comp_time = 0.0 56 self._chi_dof = 0.0 57 self._oscillations = 0.0 58 self._pos_fraction = 0.0 59 self._sigma_pos_fraction = 0.0 60 61 # Let's choose the Standard Item Model. 49 for datum in data: 50 self._data_list.append({datum : None}) 51 52 # p(r) calculator 53 self._calculator = Invertor() 54 62 55 self.model = QtGui.QStandardItemModel(self) 56 self.mapper = QtGui.QDataWidgetMapper(self) 57 # Link user interactions with methods 58 self.setupLinks() 59 # Set values 60 self.setupModel() 63 61 # Set up the Widget Map 64 62 self.setupMapper() 65 # Set values66 self.setupModel()67 # Link user interactions with methods68 self.setupLinks()69 70 self.communicate = GuiUtils.Communicate()71 63 72 64 ###################################################################### … … 74 66 75 67 def allowBatch(self): 76 return True68 return False 77 69 78 70 def setClosable(self, value=True): … … 100 92 101 93 def setupLinks(self): 102 self.dataList.currentIndexChanged.connect(self.displayChange) 103 self.calculateButton.clicked.connect(self.calculatePrInversion) 94 """Connect the use controls to their appropriate methods""" 95 self.enableButtons() 96 self.checkBgdClicked(False) 97 # TODO: enable the drop down box once batch is working 98 self.dataList.setEnabled(False) 99 # TODO: enable displayChange once batch is working 100 # self.dataList.currentIndexChanged.connect(self.displayChange) 101 self.calculateButton.clicked.connect(self._calculation) 104 102 self.statusButton.clicked.connect(self.status) 105 103 self.helpButton.clicked.connect(self.help) … … 107 105 self.manualBgd.toggled.connect(self.toggleBgd) 108 106 self.explorerButton.clicked.connect(self.openExplorerWindow) 109 pass107 self.model.itemChanged.connect(self.model_changed) 110 108 111 109 def setupMapper(self): 112 110 # Set up the mapper. 113 self.mapper = QtGui.QDataWidgetMapper(self)114 111 self.mapper.setOrientation(QtCore.Qt.Vertical) 115 112 self.mapper.setModel(self.model) … … 118 115 self.mapper.addMapping(self.dataList, WIDGETS.W_FILENAME) 119 116 # Background 120 self.mapper.addMapping(self.backgroundInput, WIDGETS.W_BACKGROUND )117 self.mapper.addMapping(self.backgroundInput, WIDGETS.W_BACKGROUND_INPUT) 121 118 self.mapper.addMapping(self.estimateBgd, WIDGETS.W_ESTIMATE) 122 119 self.mapper.addMapping(self.manualBgd, WIDGETS.W_MANUAL_INPUT) … … 144 141 self.mapper.addMapping(self.rgValue, WIDGETS.W_RG) 145 142 self.mapper.addMapping(self.iQ0Value, WIDGETS.W_I_ZERO) 146 self.mapper.addMapping(self.backgroundValue, WIDGETS.W_BACKGROUND )143 self.mapper.addMapping(self.backgroundValue, WIDGETS.W_BACKGROUND_OUTPUT) 147 144 self.mapper.addMapping(self.computationTimeValue, WIDGETS.W_COMP_TIME) 148 145 self.mapper.addMapping(self.chiDofValue, WIDGETS.W_CHI_SQUARED) … … 159 156 self.mapper.toFirst() 160 157 158 def setupModel(self): 159 """ 160 Update boxes with initial values 161 """ 162 item = QtGui.QStandardItem("") 163 self.model.setItem(WIDGETS.W_FILENAME, item) 164 item = QtGui.QStandardItem('0.0') 165 self.model.setItem(WIDGETS.W_BACKGROUND_INPUT, item) 166 item = QtGui.QStandardItem("") 167 self.model.setItem(WIDGETS.W_QMIN, item) 168 item = QtGui.QStandardItem("") 169 self.model.setItem(WIDGETS.W_QMAX, item) 170 item = QtGui.QStandardItem("") 171 self.model.setItem(WIDGETS.W_SLIT_WIDTH, item) 172 item = QtGui.QStandardItem("") 173 self.model.setItem(WIDGETS.W_SLIT_HEIGHT, item) 174 item = QtGui.QStandardItem("10") 175 self.model.setItem(WIDGETS.W_NO_TERMS, item) 176 item = QtGui.QStandardItem("0.0001") 177 self.model.setItem(WIDGETS.W_REGULARIZATION, item) 178 item = QtGui.QStandardItem("140.0") 179 self.model.setItem(WIDGETS.W_MAX_DIST, item) 180 item = QtGui.QStandardItem("") 181 self.model.setItem(WIDGETS.W_RG, item) 182 item = QtGui.QStandardItem("") 183 self.model.setItem(WIDGETS.W_I_ZERO, item) 184 item = QtGui.QStandardItem("") 185 self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, item) 186 item = QtGui.QStandardItem("") 187 self.model.setItem(WIDGETS.W_COMP_TIME, item) 188 item = QtGui.QStandardItem("") 189 self.model.setItem(WIDGETS.W_CHI_SQUARED, item) 190 item = QtGui.QStandardItem("") 191 self.model.setItem(WIDGETS.W_OSCILLATION, item) 192 item = QtGui.QStandardItem("") 193 self.model.setItem(WIDGETS.W_POS_FRACTION, item) 194 item = QtGui.QStandardItem("") 195 self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, item) 196 161 197 ###################################################################### 162 198 # Methods for updating GUI 163 199 164 def setupModel(self):165 """166 Update boxes with latest values167 """168 item = QtGui.QStandardItem(self._path)169 self.model.setItem(WIDGETS.W_FILENAME, item)170 item = QtGui.QStandardItem(self._background)171 self.model.setItem(WIDGETS.W_BACKGROUND, item)172 self.checkBgdClicked(self._bgd_input)173 item = QtGui.QStandardItem(self._qmin)174 self.model.setItem(WIDGETS.W_QMIN, item)175 item = QtGui.QStandardItem(self._qmax)176 self.model.setItem(WIDGETS.W_QMAX, item)177 item = QtGui.QStandardItem(self._slit_width)178 self.model.setItem(WIDGETS.W_SLIT_WIDTH, item)179 item = QtGui.QStandardItem(self._slit_height)180 self.model.setItem(WIDGETS.W_SLIT_HEIGHT, item)181 item = QtGui.QStandardItem(self._terms)182 self.model.setItem(WIDGETS.W_NO_TERMS, item)183 item = QtGui.QStandardItem(self._regularization)184 self.model.setItem(WIDGETS.W_REGULARIZATION, item)185 item = QtGui.QStandardItem(self._max_distance)186 self.model.setItem(WIDGETS.W_MAX_DIST, item)187 item = QtGui.QStandardItem(self._rg)188 self.model.setItem(WIDGETS.W_RG, item)189 item = QtGui.QStandardItem(self._i_0)190 self.model.setItem(WIDGETS.W_I_ZERO, item)191 item = QtGui.QStandardItem(self._background)192 self.model.setItem(WIDGETS.W_BACKGROUND, item)193 item = QtGui.QStandardItem(self._comp_time)194 self.model.setItem(WIDGETS.W_COMP_TIME, item)195 item = QtGui.QStandardItem(self._chi_dof)196 self.model.setItem(WIDGETS.W_CHI_SQUARED, item)197 item = QtGui.QStandardItem(self._oscillations)198 self.model.setItem(WIDGETS.W_OSCILLATION, item)199 item = QtGui.QStandardItem(self._pos_fraction)200 self.model.setItem(WIDGETS.W_POS_FRACTION, item)201 item = QtGui.QStandardItem(self._sigma_pos_fraction)202 self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, item)203 self.enableButtons()204 205 200 def enableButtons(self): 206 201 """ 207 Disable buttons when no data present, else enable them 208 """ 209 if self._path == "" and len(self._data) == 1: 202 Enable buttons when data is present, else disable them 203 """ 204 if self._has_data: 205 self.statusButton.setEnabled(True) 206 self.explorerButton.setEnabled(True) 207 self.calculateButton.setEnabled(True) 208 else: 210 209 self.calculateButton.setEnabled(False) 211 210 self.explorerButton.setEnabled(False) 212 211 self.statusButton.setEnabled(False) 213 else: 214 self.statusButton.setEnabled(True) 215 self.explorerButton.setEnabled(True) 216 self.calculateButton.setEnabled(True) 217 218 def reDraw(self): 219 """ 220 Redraws the window with any and all necessary updates. 221 """ 222 self.populateDataComboBox() 223 self.dataList.setCurrentIndex(self._data_index) 224 self._get_data_from_data_set() 225 226 def populateDataComboBox(self): 227 string_list = QtCore.QStringList() 228 for item in self._path: 229 qt_item = QtCore.QString.fromUtf8(item) 230 string_list.append(qt_item) 231 self.dataList.addItems(string_list) 232 233 def _addPr(self, data_list): 234 """ 235 Add a new data set to the P(r) window and updates as needed. 236 :param data_list: List of data sent from the data manager 237 """ 238 assert data_list is not None 239 for data in data_list: 240 # TODO: Get get object via GuiUtils 241 self._data.append(None) 242 self.reDraw() 243 244 def _get_data_from_data_set(self): 245 data = self._data[self._data_index] 246 # TODO: Get all items from data 247 # self._qmin = data.qmin 248 # self._qmax = data.qmax 249 self.setupModel() 212 213 def populateDataComboBox(self, filename): 214 """ 215 Append a new file name to the data combobox 216 :param data: Data1D object 217 """ 218 qt_item = QtCore.QString.fromUtf8(filename) 219 self.dataList.addItem(qt_item) 250 220 251 221 ###################################################################### 252 222 # GUI Actions 253 223 254 def calculatePrInversion(self):224 def _calculation(self): 255 225 """ 256 226 Calculate the P(r) for every data set in the data list 257 227 """ 228 # TODO: Run the calculations 258 229 pass 259 230 231 def model_changed(self): 232 """Update the values when user makes changes""" 233 if not self.mapper: 234 return 235 self.mapper.toFirst() 236 # TODO: Update plots, etc. 237 260 238 def status(self): 261 239 """ 262 240 Show the status of the calculations 263 241 """ 242 # TODO: Status - is this even needed/wanted? 264 243 pass 265 244 … … 281 260 self.manualBgd.setChecked(True) 282 261 self.toggleBgd(self.manualBgd) 283 self._bgd_input = True284 262 else: 285 263 self.estimateBgd.setChecked(True) 286 264 self.toggleBgd(self.estimateBgd) 287 self._bgd_input = False288 265 289 266 def toggleBgd(self, item=None): … … 307 284 pass 308 285 309 def displayChange(self):310 """311 Display the values of the data set selected from the data combo box312 """313 self._data_index = self.dataList.currentIndex()314 self.setupModel()315 316 286 ###################################################################### 317 287 # Response Actions … … 333 303 raise AttributeError, msg 334 304 335 self._addPr(data_item) 305 for data in data_item: 306 data_object = GuiUtils.dataFromItem(data) 307 self._data_list.append({data_object: None}) 308 self._has_data = True 309 self.enableButtons() 310 self.populateDataComboBox(data_object.filename) 311 self.model.setItem(WIDGETS.W_QMIN, 312 QtGui.QStandardItem(str(data_object.x.min()))) 313 self.model.setItem(WIDGETS.W_QMAX, 314 QtGui.QStandardItem(str(data_object.x.max()))) 315 316 # TODO: Get value estimates 317 no_terms, alpha, _ = self._calculator.estimate_numterms( 318 self._calculator) 319 self.noOfTermsSuggestionButton.setText( 320 QtCore.QString(str(no_terms))) 321 self.noOfTermsSuggestionButton.setEnabled(True) 322 self.regConstantSuggestionButton.setText(QtCore.QString(str(alpha))) 323 self.regConstantSuggestionButton.setEnabled(True) 324 325 # TODO: Only load in the 1st data until batch mode is working 326 break
Note: See TracChangeset
for help on using the changeset viewer.