Changeset ba01ad1 in sasview for src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py
- Timestamp:
- Jan 19, 2018 8:02:09 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:
- 0764593
- Parents:
- c5a2722f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py
rc5a2722f rba01ad1 25 25 # Remember previous content of modified cell 26 26 self.current_cell = "" 27 28 # Tabs used in simultaneous fitting 29 # tab_name : True/False 30 self.tabs_for_fitting = {} 27 31 28 32 # Set up the widgets … … 75 79 76 80 # QTableWidgets 77 self.tblTabList.cellChanged.connect(self.on MonikerEdit)81 self.tblTabList.cellChanged.connect(self.onTabCellEdit) 78 82 self.tblTabList.cellDoubleClicked.connect(self.onTabCellEntered) 79 83 self.tblConstraints.cellChanged.connect(self.onConstraintChange) 80 84 81 85 # External signals 82 self.parent.tabsModifiedSignal.connect(self.initializeFitList) 86 #self.parent.tabsModifiedSignal.connect(self.initializeFitList) 87 self.parent.tabsModifiedSignal.connect(self.onModifiedTabs) 83 88 84 89 def updateSignalsFromTab(self, tab=None): … … 95 100 single fit/batch fit 96 101 """ 102 source = self.sender().objectName() 103 self.currentType = "BatchPage" if source == "btnBatch" else "FitPage" 104 self.initializeFitList() 105 106 def onSpecialCaseChange(self, index): 107 """ 108 Respond to the combobox change for special case constraint sets 109 """ 97 110 pass 98 111 99 def on SpecialCaseChange(self, index):100 """ 101 Respond to the combobox change for special case constraint sets112 def onFit(self): 113 """ 114 Perform the constrained/simultaneous fit 102 115 """ 103 116 pass 104 117 105 def on Fit(self):106 """ 107 Perform the constrained/simultaneous fit118 def onHelp(self): 119 """ 120 Display the help page 108 121 """ 109 122 pass 110 123 111 def onHelp(self): 112 """ 113 Display the help page 114 """ 115 pass 116 117 def onMonikerEdit(self, row, column): 118 """ 119 Modify the model moniker 120 """ 124 def onTabCellEdit(self, row, column): 125 """ 126 Respond to check/uncheck and to modify the model moniker actions 127 """ 128 item = self.tblTabList.item(row, column) 129 if column == 0: 130 # Update the tabs for fitting list 131 tab_name = item.text() 132 self.tabs_for_fitting[tab_name] = (item.checkState() == QtCore.Qt.Checked) 133 # Enable fitting only when there are models to fit 134 self.cmdFit.setEnabled(any(self.tabs_for_fitting.values())) 135 121 136 if column not in self.editable_tab_columns: 122 137 return 123 item = self.tblTabList.item(row, column)124 138 new_moniker = item.data(0) 125 139 … … 131 145 item.setBackground(QtCore.Qt.red) 132 146 self.cmdFit.setEnabled(False) 133 else: 134 self.tblTabList.blockSignals(True) 135 item.setBackground(QtCore.Qt.white) 136 self.tblTabList.blockSignals(False) 137 self.cmdFit.setEnabled(True) 138 if not self.current_cell: 139 return 140 # Remember the value 141 if self.current_cell not in self.available_tabs: 142 return 143 temp_tab = self.available_tabs[self.current_cell] 144 # Remove the key from the dictionaries 145 self.available_tabs.pop(self.current_cell, None) 146 # Change the model name 147 model = temp_tab.kernel_module 148 model.name = new_moniker 149 # Replace constraint name 150 temp_tab.replaceConstraintName(self.current_cell, new_moniker) 151 # Reinitialize the display 152 self.initializeFitList() 153 pass 147 return 148 self.tblTabList.blockSignals(True) 149 item.setBackground(QtCore.Qt.white) 150 self.tblTabList.blockSignals(False) 151 self.cmdFit.setEnabled(True) 152 if not self.current_cell: 153 return 154 # Remember the value 155 if self.current_cell not in self.available_tabs: 156 return 157 temp_tab = self.available_tabs[self.current_cell] 158 # Remove the key from the dictionaries 159 self.available_tabs.pop(self.current_cell, None) 160 # Change the model name 161 model = temp_tab.kernel_module 162 model.name = new_moniker 163 # Replace constraint name 164 temp_tab.replaceConstraintName(self.current_cell, new_moniker) 165 # Reinitialize the display 166 self.initializeFitList() 154 167 155 168 def onConstraintChange(self, row, column): 156 169 """ 157 170 Modify the constraint in-place. 158 Tricky. 159 """ 160 pass 171 """ 172 item = self.tblConstraints.item(row, column) 173 if column == 0: 174 # Update the tabs for fitting list 175 constraint = self.available_constraints[row] 176 constraint.active = (item.checkState() == QtCore.Qt.Checked) 161 177 162 178 def onTabCellEntered(self, row, column): … … 168 184 return 169 185 self.current_cell = self.tblTabList.item(row, column).data(0) 186 187 def onModifiedTabs(self): 188 """ 189 Respond to tabs being deleted by deleting involved constraints 190 191 This should probably be done in FittingWidget as it is the owner of 192 all the fitting data, but I want to keep the FW oblivious about 193 dependence on other FW tabs, so enforcing the constraint deletion here. 194 """ 195 # Get the list of all constraints from querying the table 196 #constraints = getConstraintsForModel() 197 198 # Get the current list of tabs 199 #tabs = ObjectLibrary.listObjects() 200 201 # Check if any of the constraint dependencies got deleted 202 # Check the list of constraints 203 self.initializeFitList() 204 pass 170 205 171 206 def isTabImportable(self, tab): … … 339 374 Update a single line of the table widget with tab info 340 375 """ 341 model = ObjectLibrary.getObject(tab).kernel_module 376 fit_page = ObjectLibrary.getObject(tab) 377 model = fit_page.kernel_module 342 378 if model is None: 343 379 return … … 345 381 model_name = model.id 346 382 moniker = model.name 347 model_data = ObjectLibrary.getObject(tab).data383 model_data = fit_page.data 348 384 model_filename = model_data.filename 349 self.available_tabs[moniker] = ObjectLibrary.getObject(tab)385 self.available_tabs[moniker] = fit_page 350 386 351 387 # Update the model table widget 352 #item = QtWidgets.QTableWidgetItem(tab_name)353 #item.setCheckState(QtCore.Qt.Checked)354 #item.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )355 388 pos = self.tblTabList.rowCount() 356 389 self.tblTabList.insertRow(pos) 357 390 item = self.uneditableItem(tab_name) 358 391 item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable) 359 item.setCheckState(QtCore.Qt.Checked) 392 if tab_name in self.tabs_for_fitting: 393 state = QtCore.Qt.Checked if self.tabs_for_fitting[tab_name] else QtCore.Qt.Unchecked 394 item.setCheckState(state) 395 else: 396 item.setCheckState(QtCore.Qt.Checked) 397 self.tabs_for_fitting[tab_name] = True 398 360 399 self.tblTabList.setItem(pos, 0, item) 361 400 self.tblTabList.setItem(pos, 1, self.uneditableItem(model_name)) … … 369 408 370 409 # Check if any constraints present in tab 371 constraints = ObjectLibrary.getObject(tab).getConstraintsForModel() 410 constraint_names = fit_page.getConstraintsForModel() 411 constraints = fit_page.getConstraintObjectsForModel() 372 412 if not constraints: 373 413 return 374 414 self.tblConstraints.setEnabled(True) 375 for constraint in constraints:415 for constraint, constraint_name in zip(constraints, constraint_names): 376 416 # Create the text for widget item 377 label = moniker + ":"+ constraint[0] + " = " + constraint[1] 417 label = moniker + ":"+ constraint_name[0] + " = " + constraint_name[1] 418 pos = self.tblConstraints.rowCount() 419 self.available_constraints[pos] = constraint 378 420 379 421 # Show the text in the constraint table 380 item = QtWidgets.QTableWidgetItem(label) 422 item = self.uneditableItem(label) 423 item.setFlags(item.flags() ^ QtCore.Qt.ItemIsUserCheckable) 381 424 item.setCheckState(QtCore.Qt.Checked) 382 pos = self.tblConstraints.rowCount()383 425 self.tblConstraints.insertRow(pos) 384 426 self.tblConstraints.setItem(pos, 0, item) 385 self.available_constraints[pos] = constraints386 427 387 428 def initializeFitList(self): … … 461 502 462 503 constraint.func = constraint_text 463 #constraint.param = param1504 constraint.param = param1 464 505 # Find the right tab 465 506 constrained_tab = self.getObjectByName(model1)
Note: See TracChangeset
for help on using the changeset viewer.