Changeset c5a2722f in sasview for src/sas/qtgui
- Timestamp:
- Jan 18, 2018 9:44:26 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:
- ba01ad1
- Parents:
- 2d466e4
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/ComplexConstraint.py
r2d466e4 rc5a2722f 15 15 # Local UI 16 16 from sas.qtgui.Perspectives.Fitting.UI.ComplexConstraintUI import Ui_ComplexConstraintUI 17 from sas.qtgui.Perspectives.Fitting.Constraints import Constraint 17 18 18 19 class ComplexConstraint(QtWidgets.QDialog, Ui_ComplexConstraintUI): … … 52 53 self.cmdHelp.clicked.connect(self.onHelp) 53 54 self.cmdRevert.clicked.connect(self.onRevert) 54 #self.txtConstraint.editingFinished.connect(self.validateFormula)55 self.txtConstraint.editingFinished.connect(self.validateFormula) 55 56 56 57 self.cbParam1.currentIndexChanged.connect(self.onParamIndexChange) … … 95 96 self.txtParam.setText(self.tab_names[0] + ":" + self.cbParam1.currentText()) 96 97 else: 97 self.txtConstraint.setText(self. cbParam2.currentText())98 self.txtConstraint.setText(self.tab_names[1] + "." + self.cbParam2.currentText()) 98 99 pass 99 100 … … 148 149 return False 149 150 150 param_str = str(self.params[1]) 151 # M1.scale --> model_str='M1', constraint_text='scale' 152 param_str = self.cbParam2.currentText() 151 153 constraint_text = constraint_text.strip() 154 model_str = constraint_text[:constraint_text.index('.')] 155 #constraint_text = constraint_text[constraint_text.index('.')+1:] 156 157 # 0. Has to contain the model name 158 if model_str != self.txtName2.text(): 159 return False 160 161 # Remove model name from constraint text 162 constraint_text = constraint_text.replace(model_str+".",'') 152 163 153 164 # 1. just the parameter … … 161 172 parameter_string_end = parameter_string_start + len(param_str) 162 173 163 # 3. parameter name should be a separate word, but can have "()[]*+-/ " around 164 valid_neighbours = "()[]*+-/ " 165 has_only_parameter = False 166 start_loc = parameter_string_start -1 167 end_loc = parameter_string_end 168 if not any([constraint_text[start_loc] == char for char in valid_neighbours]): 169 return False 170 if end_loc < len(constraint_text): 171 if not any([constraint_text[end_loc] == char for char in valid_neighbours]): 172 return False 173 174 # 4. replace parameter name with "1" and try to evaluate the expression 174 # 3. replace parameter name with "1" and try to evaluate the expression 175 175 try: 176 176 expression_to_evaluate = constraint_text.replace(param_str, "1.0") … … 185 185 return True 186 186 187 def constraint(self): 188 """ 189 Return the generated constraint as tuple (model1, param1, operator, constraint) 190 """ 191 return (self.txtName1.text(), self.cbParam1.currentText(), self.cbOperator.currentText(), self.txtConstraint.text()) 192 187 193 def onHelp(self): 188 194 """ -
src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py
r2d466e4 rc5a2722f 10 10 from sas.qtgui.Perspectives.Fitting.FittingWidget import FittingWidget 11 11 from sas.qtgui.Perspectives.Fitting.ComplexConstraint import ComplexConstraint 12 from sas.qtgui.Perspectives.Fitting.Constraints import Constraint 12 13 13 14 class ConstraintWidget(QtWidgets.QWidget, Ui_ConstraintWidgetUI): … … 431 432 return True 432 433 434 def getObjectByName(self, name): 435 for object_name in ObjectLibrary.listObjects(): 436 object = ObjectLibrary.getObject(object_name) 437 if isinstance(object, FittingWidget): 438 try: 439 if object.kernel_module.name == name: 440 return object 441 except AttributeError: 442 # Disregard atribute errors - empty fit widgets 443 continue 444 return None 445 433 446 def showMultiConstraint(self): 434 447 """ … … 444 457 return 445 458 446 #constraint = Constraint() 447 #c_text = cc_widget.txtConstraint.text() 448 pass 459 constraint = Constraint() 460 model1, param1, operator, constraint_text = cc_widget.constraint() 461 462 constraint.func = constraint_text 463 # constraint.param = param1 464 # Find the right tab 465 constrained_tab = self.getObjectByName(model1) 466 if constrained_tab is None: 467 return 468 469 # Find the constrained parameter row 470 constrained_row = constrained_tab.getRowFromName(param1) 471 472 # Update the tab 473 constrained_tab.addConstraintToRow(constraint, constrained_row) 474 pass -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r2d466e4 rc5a2722f 601 601 Return list of all parameters for the current model 602 602 """ 603 #params = []604 #for row in range(self._model_model.rowCount()):605 # params.append(self._model_model.item(row).text())606 #return params607 603 return [self._model_model.item(row).text() for row in range(self._model_model.rowCount())] 608 604 … … 625 621 self._model_model.item(row, column).setEditable(fields_enabled) 626 622 self._model_model.blockSignals(False) 623 624 def addConstraintToRow(self, constraint=None, row=0): 625 """ 626 Adds the constraint object to requested row 627 """ 628 # Create a new item and add the Constraint object as a child 629 assert(isinstance(constraint, Constraint)) 630 assert(0<=row<=self._model_model.rowCount()) 631 632 item = QtGui.QStandardItem() 633 item.setData(constraint) 634 self._model_model.item(row, 1).setChild(0, item) 635 # Set min/max to the value constrained 636 self.constraintAddedSignal.emit([row]) 637 # Show visual hints for the constraint 638 font = QtGui.QFont() 639 font.setItalic(True) 640 brush = QtGui.QBrush(QtGui.QColor('blue')) 641 self.modifyViewOnRow(row, font=font, brush=brush) 642 self.communicate.statusBarUpdateSignal.emit('Constraint added') 627 643 628 644 def addSimpleConstraint(self): … … 759 775 if func == value: 760 776 return "" 777 761 778 return model_name + "." 762 779 params = [(self._model_model.item(s, 0).text(), 763 preamble(s) +self._model_model.item(s, 1).child(0).data().func) 780 #preamble(s) +self._model_model.item(s, 1).child(0).data().func) 781 self._model_model.item(s, 1).child(0).data().func) 764 782 for s in range(param_number) if self.rowHasConstraint(s)] 765 783 return params
Note: See TracChangeset
for help on using the changeset viewer.