Changes in src/sas/qtgui/Perspectives/Fitting/ComplexConstraint.py [305114c:d72ac57] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/ComplexConstraint.py
r305114c rd72ac57 15 15 from sas.qtgui.Perspectives.Fitting import FittingUtilities 16 16 import sas.qtgui.Utilities.GuiUtils as GuiUtils 17 ALLOWED_OPERATORS = ['=','<','>','>=','<='] 17 from sas.qtgui.Perspectives.Fitting.Constraint import Constraint 18 19 #ALLOWED_OPERATORS = ['=','<','>','>=','<='] 20 ALLOWED_OPERATORS = ['='] 18 21 19 22 # Local UI … … 21 24 22 25 class ComplexConstraint(QtWidgets.QDialog, Ui_ComplexConstraintUI): 26 constraintReadySignal = QtCore.pyqtSignal(tuple) 23 27 def __init__(self, parent=None, tabs=None): 24 28 super(ComplexConstraint, self).__init__() … … 32 36 self.tab_names = None 33 37 self.operator = '=' 38 self._constraint = Constraint() 34 39 35 40 self.warning = self.lblWarning.text() … … 53 58 Signals from various elements 54 59 """ 55 self.cmdOK.clicked.connect(self. accept)60 self.cmdOK.clicked.connect(self.onApply) 56 61 self.cmdHelp.clicked.connect(self.onHelp) 57 62 self.cmdRevert.clicked.connect(self.onRevert) … … 69 74 self.txtName2.setText(self.tab_names[1]) 70 75 71 # Show only parameters not already constrained 76 self.setupParamWidgets() 77 78 # Add menu to the Apply button 79 all_menu = QtWidgets.QMenu() 80 self.actionAddAll = QtWidgets.QAction(self) 81 self.actionAddAll.setObjectName("actionAddAll") 82 self.actionAddAll.setText(QtCore.QCoreApplication.translate("self", "Add all")) 83 ttip = "Add constraints between all identically named parameters in both fitpages" 84 self.actionAddAll.setToolTip(ttip) 85 self.actionAddAll.triggered.connect(self.onSetAll) 86 all_menu.addAction(self.actionAddAll) 87 # https://bugreports.qt.io/browse/QTBUG-13663 88 all_menu.setToolTipsVisible(True) 89 self.cmdOK.setMenu(all_menu) 90 91 def setupParamWidgets(self): 92 """ 93 Fill out comboboxes and set labels with non-constrained parameters 94 """ 72 95 self.cbParam1.clear() 73 items = [param for i,param in enumerate(self.params[0]) if not self.tabs[0].rowHasConstraint(i)] 74 self.cbParam1.addItems(items) 96 items1 = [param for param in self.params[0] if not self.tabs[0].paramHasConstraint(param)] 97 self.cbParam1.addItems(items1) 98 99 # M2 doesn't have to be non-constrained 75 100 self.cbParam2.clear() 76 items = [param for i,param in enumerate(self.params[1]) if not self.tabs[1].rowHasConstraint(i)] 77 self.cbParam2.addItems(items) 101 #items2 = [param for param in self.params[1] if not self.tabs[1].paramHasConstraint(param)] 102 items2 = [param for param in self.params[1]] 103 self.cbParam2.addItems(items2) 78 104 79 105 self.txtParam.setText(self.tab_names[0] + ":" + self.cbParam1.currentText()) … … 84 110 85 111 self.txtConstraint.setText(self.tab_names[1]+"."+self.cbParam2.currentText()) 112 113 # disable Apply if no parameters available 114 if len(items1)==0: 115 self.cmdOK.setEnabled(False) 116 txt = "No parameters in model "+self.tab_names[0] +\ 117 " are available for constraining." 118 self.lblWarning.setText(txt) 119 else: 120 self.cmdOK.setEnabled(True) 121 txt = "" 122 self.lblWarning.setText(txt) 86 123 87 124 def setupTooltip(self): … … 144 181 145 182 # Original indices 183 index2 = index2 if index2 >= 0 else 0 184 index1 = index1 if index1 >= 0 else 0 146 185 self.cbParam1.setCurrentIndex(index2) 147 186 self.cbParam2.setCurrentIndex(index1) … … 205 244 def constraint(self): 206 245 """ 207 Return the generated constraint as tuple (model1, param1, operator, constraint) 208 """ 209 return (self.txtName1.text(), self.cbParam1.currentText(), self.cbOperator.currentText(), self.txtConstraint.text()) 246 Return the generated constraint 247 """ 248 param = self.cbParam1.currentText() 249 value = self.cbParam2.currentText() 250 func = self.txtConstraint.text() 251 value_ex = self.txtName2.text() + "." + self.cbParam2.currentText() 252 model1 = self.txtName1.text() 253 operator = self.cbOperator.currentText() 254 255 con = Constraint(self, 256 param=param, 257 value=value, 258 func=func, 259 value_ex=value_ex, 260 operator=operator) 261 262 return (model1, con) 263 264 def onApply(self): 265 """ 266 Respond to Add constraint action. 267 Send a signal that the constraint is ready to be applied 268 """ 269 cons_tuple = self.constraint() 270 self.constraintReadySignal.emit(cons_tuple) 271 # reload the comboboxes 272 self.setupParamWidgets() 273 274 def onSetAll(self): 275 """ 276 Set constraints on all identically named parameters between two fitpages 277 """ 278 # loop over parameters in constrained model 279 items1 = [param for param in self.params[0] if not self.tabs[0].paramHasConstraint(param)] 280 #items2 = [param for param in self.params[1] if not self.tabs[1].paramHasConstraint(i)] 281 items2 = self.params[1] 282 for item in items1: 283 if item not in items2: continue 284 param = item 285 value = item 286 func = self.txtName2.text() + "." + param 287 value_ex = self.txtName1.text() + "." + param 288 model1 = self.txtName1.text() 289 operator = self.cbOperator.currentText() 290 291 con = Constraint(self, 292 param=param, 293 value=value, 294 func=func, 295 value_ex=value_ex, 296 operator=operator) 297 298 self.constraintReadySignal.emit((model1, con)) 299 300 # reload the comboboxes 301 self.setupParamWidgets() 210 302 211 303 def onHelp(self):
Note: See TracChangeset
for help on using the changeset viewer.