Ignore:
Timestamp:
Jan 18, 2018 9:44:26 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
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
Message:

Complex constraint widget updating the main constraint widget and fitting tabs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/ComplexConstraint.py

    r2d466e4 rc5a2722f  
    1515# Local UI 
    1616from sas.qtgui.Perspectives.Fitting.UI.ComplexConstraintUI import Ui_ComplexConstraintUI 
     17from sas.qtgui.Perspectives.Fitting.Constraints import Constraint 
    1718 
    1819class ComplexConstraint(QtWidgets.QDialog, Ui_ComplexConstraintUI): 
     
    5253        self.cmdHelp.clicked.connect(self.onHelp) 
    5354        self.cmdRevert.clicked.connect(self.onRevert) 
    54         #self.txtConstraint.editingFinished.connect(self.validateFormula) 
     55        self.txtConstraint.editingFinished.connect(self.validateFormula) 
    5556 
    5657        self.cbParam1.currentIndexChanged.connect(self.onParamIndexChange) 
     
    9596            self.txtParam.setText(self.tab_names[0] + ":" + self.cbParam1.currentText()) 
    9697        else: 
    97             self.txtConstraint.setText(self.cbParam2.currentText()) 
     98            self.txtConstraint.setText(self.tab_names[1] + "." + self.cbParam2.currentText()) 
    9899        pass 
    99100 
     
    148149            return False 
    149150 
    150         param_str = str(self.params[1]) 
     151        # M1.scale  --> model_str='M1', constraint_text='scale' 
     152        param_str = self.cbParam2.currentText() 
    151153        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+".",'') 
    152163 
    153164        # 1. just the parameter 
     
    161172        parameter_string_end = parameter_string_start + len(param_str) 
    162173 
    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 
    175175        try: 
    176176            expression_to_evaluate = constraint_text.replace(param_str, "1.0") 
     
    185185        return True 
    186186 
     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 
    187193    def onHelp(self): 
    188194        """ 
Note: See TracChangeset for help on using the changeset viewer.