Changeset 47d7d2d in sasview for src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py
- Timestamp:
- Jan 17, 2018 4:53:35 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:
- 2d466e4
- Parents:
- be8f4b0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py
rbe8f4b0 r47d7d2d 21 21 self.currentType = "FitPage" 22 22 23 # Remember previous content of modified cell 24 self.current_cell = "" 25 23 26 # Set up the widgets 24 27 self.initializeWidgets() … … 38 41 Set up various widget states 39 42 """ 40 labels = ['FitPage', 'Model', 'Data', 'Mnemonic s']43 labels = ['FitPage', 'Model', 'Data', 'Mnemonic'] 41 44 # tab widget - headers 45 self.editable_tab_columns = [labels.index('Mnemonic')] 42 46 self.tblTabList.setColumnCount(len(labels)) 43 47 self.tblTabList.setHorizontalHeaderLabels(labels) … … 61 65 Set up signals/slots for this widget 62 66 """ 67 # simple widgets 63 68 self.btnSingle.toggled.connect(self.onFitTypeChange) 64 69 self.btnBatch.toggled.connect(self.onFitTypeChange) … … 66 71 self.cmdFit.clicked.connect(self.onFit) 67 72 self.cmdHelp.clicked.connect(self.onHelp) 73 74 # QTableWidgets 75 self.tblTabList.cellChanged.connect(self.onMonikerEdit) 76 self.tblTabList.cellDoubleClicked.connect(self.onTabCellEntered) 77 self.tblConstraints.cellChanged.connect(self.onConstraintChange) 78 79 # External signals 68 80 self.parent.tabsModifiedSignal.connect(self.initializeFitList) 69 81 … … 100 112 """ 101 113 pass 114 115 def onMonikerEdit(self, row, column): 116 """ 117 Modify the model moniker 118 """ 119 if column not in self.editable_tab_columns: 120 return 121 item = self.tblTabList.item(row, column) 122 new_moniker = item.data(0) 123 124 # The new name should be validated on the fly, with QValidator 125 # but let's just assure it post-factum 126 is_good_moniker = self.validateMoniker(new_moniker) 127 is_good_moniker = True 128 if not is_good_moniker: 129 item.setBackground(QtCore.Qt.red) 130 self.cmdFit.setEnabled(False) 131 else: 132 self.tblTabList.blockSignals(True) 133 item.setBackground(QtCore.Qt.white) 134 self.tblTabList.blockSignals(False) 135 self.cmdFit.setEnabled(True) 136 if not self.current_cell: 137 return 138 # Remember the value 139 if self.current_cell not in self.available_tabs: 140 return 141 temp_tab = self.available_tabs[self.current_cell] 142 # Remove the key from the dictionaries 143 self.available_tabs.pop(self.current_cell, None) 144 # Change the model name 145 model = temp_tab.kernel_module 146 model.name = new_moniker 147 # Replace constraint name 148 temp_tab.replaceConstraintName(self.current_cell, new_moniker) 149 # Reinitialize the display 150 self.initializeFitList() 151 pass 152 153 def onConstraintChange(self, row, column): 154 """ 155 Modify the constraint in-place. 156 Tricky. 157 """ 158 pass 159 160 def onTabCellEntered(self, row, column): 161 """ 162 Remember the original tab list cell data. 163 Needed for reverting back on bad validation 164 """ 165 if column != 3: 166 return 167 self.current_cell = self.tblTabList.item(row, column).data(0) 102 168 103 169 def isTabImportable(self, tab): … … 151 217 #self.actionConstrain.triggered.connect(self.addSimpleConstraint) 152 218 #self.actionRemoveConstraint.triggered.connect(self.deleteConstraint) 153 #self.actionMutualMultiConstrain.triggered.connect(self.showMultiConstraint)219 self.actionMutualMultiConstrain.triggered.connect(self.showMultiConstraint) 154 220 self.actionSelect.triggered.connect(self.selectModels) 155 221 self.actionDeselect.triggered.connect(self.deselectModels) … … 246 312 Delete all selected constraints. 247 313 """ 314 # Removing rows from the table we're iterating over, 315 # so prepare a list of data first 248 316 constraints_to_delete = [] 249 317 for row in self.selectedParameters(self.tblConstraints): … … 257 325 self.initializeFitList() 258 326 327 def uneditableItem(self, data=""): 328 """ 329 Returns an uneditable Table Widget Item 330 """ 331 item = QtWidgets.QTableWidgetItem(data) 332 item.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) 333 return item 334 259 335 def updateFitLine(self, tab): 260 336 """ … … 272 348 273 349 # Update the model table widget 274 item = QtWidgets.QTableWidgetItem(tab_name) 275 item.setCheckState(QtCore.Qt.Checked) 350 #item = QtWidgets.QTableWidgetItem(tab_name) 351 #item.setCheckState(QtCore.Qt.Checked) 352 #item.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) 276 353 pos = self.tblTabList.rowCount() 277 354 self.tblTabList.insertRow(pos) 355 item = self.uneditableItem(tab_name) 356 item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable) 357 item.setCheckState(QtCore.Qt.Checked) 278 358 self.tblTabList.setItem(pos, 0, item) 279 self.tblTabList.setItem(pos, 1, QtWidgets.QTableWidgetItem(model_name)) 280 self.tblTabList.setItem(pos, 2, QtWidgets.QTableWidgetItem(model_filename)) 281 self.tblTabList.setItem(pos, 3, QtWidgets.QTableWidgetItem(moniker)) 282 283 #self.available_tabs[pos] = (model, model_data) 284 #self.available_tabs[moniker] = tab 359 self.tblTabList.setItem(pos, 1, self.uneditableItem(model_name)) 360 self.tblTabList.setItem(pos, 2, self.uneditableItem(model_filename)) 361 # Moniker is editable, so no option change 362 item = QtWidgets.QTableWidgetItem(moniker) 363 # Disable signals so we don't get infinite call recursion 364 self.tblTabList.blockSignals(True) 365 self.tblTabList.setItem(pos, 3, item) 366 self.tblTabList.blockSignals(False) 285 367 286 368 # Check if any constraints present in tab … … 332 414 # We have at least 1 fit page, allow fitting 333 415 self.cmdFit.setEnabled(True) 416 417 def validateMoniker(self, new_moniker=None): 418 """ 419 Check new_moniker for correctness. 420 It must be non-empty. 421 It must not be the same as other monikers. 422 """ 423 if not new_moniker: 424 return False 425 426 for existing_moniker in self.available_tabs: 427 if existing_moniker == new_moniker and existing_moniker != self.current_cell: 428 return False 429 430 return True 431 432 def showMultiConstraint(self): 433 """ 434 Invoke the complex constraint editor 435 """ 436 pass
Note: See TracChangeset
for help on using the changeset viewer.