Changes in src/sas/qtgui/Perspectives/Fitting/ComplexConstraint.py [d72ac57:9c207f5] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/ComplexConstraint.py
rd72ac57 r9c207f5 37 37 self.operator = '=' 38 38 self._constraint = Constraint() 39 self.all_menu = None 39 40 40 41 self.warning = self.lblWarning.text() … … 60 61 self.cmdOK.clicked.connect(self.onApply) 61 62 self.cmdHelp.clicked.connect(self.onHelp) 62 self.cmdRevert.clicked.connect(self.onRevert)63 63 self.txtConstraint.editingFinished.connect(self.validateFormula) 64 self.cbModel1.currentIndexChanged.connect(self.onModelIndexChange) 65 self.cbModel2.currentIndexChanged.connect(self.onModelIndexChange) 64 66 65 67 self.cbParam1.currentIndexChanged.connect(self.onParamIndexChange) … … 71 73 Setup widgets based on current parameters 72 74 """ 73 self. txtName1.setText(self.tab_names[0])74 self. txtName2.setText(self.tab_names[1])75 self.cbModel1.insertItems(0, self.tab_names) 76 self.cbModel2.insertItems(0, self.tab_names) 75 77 76 78 self.setupParamWidgets() 77 79 78 # Add menu to the Apply button 79 all_menu = QtWidgets.QMenu() 80 self.setupMenu() 81 82 def setupMenu(self): 83 # Add menu to the Apply button, if necessary 84 if self.cbModel1.currentText() ==self.cbModel2.currentText(): 85 self.cmdOK.setArrowType(QtCore.Qt.NoArrow) 86 self.cmdOK.setPopupMode(QtWidgets.QToolButton.DelayedPopup) 87 self.cmdOK.setMenu(None) 88 return 89 self.all_menu = QtWidgets.QMenu() 80 90 self.actionAddAll = QtWidgets.QAction(self) 81 91 self.actionAddAll.setObjectName("actionAddAll") … … 84 94 self.actionAddAll.setToolTip(ttip) 85 95 self.actionAddAll.triggered.connect(self.onSetAll) 86 all_menu.addAction(self.actionAddAll)96 self.all_menu.addAction(self.actionAddAll) 87 97 # https://bugreports.qt.io/browse/QTBUG-13663 88 all_menu.setToolTipsVisible(True) 89 self.cmdOK.setMenu(all_menu) 98 self.all_menu.setToolTipsVisible(True) 99 self.cmdOK.setPopupMode(QtWidgets.QToolButton.MenuButtonPopup) 100 self.cmdOK.setArrowType(QtCore.Qt.DownArrow) 101 self.cmdOK.setMenu(self.all_menu) 90 102 91 103 def setupParamWidgets(self): … … 94 106 """ 95 107 self.cbParam1.clear() 96 items1 = [param for param in self.params[0] if not self.tabs[0].paramHasConstraint(param)] 108 tab_index1 = self.cbModel1.currentIndex() 109 items1 = [param for param in self.params[tab_index1] if not self.tabs[tab_index1].paramHasConstraint(param)] 97 110 self.cbParam1.addItems(items1) 98 111 99 112 # M2 doesn't have to be non-constrained 100 113 self.cbParam2.clear() 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]]114 tab_index2 = self.cbModel2.currentIndex() 115 items2 = [param for param in self.params[tab_index2]] 103 116 self.cbParam2.addItems(items2) 104 117 105 self.txtParam.setText(self.tab_names[ 0] + ":" + self.cbParam1.currentText())118 self.txtParam.setText(self.tab_names[tab_index1] + ":" + self.cbParam1.currentText()) 106 119 107 120 self.cbOperator.clear() … … 109 122 self.txtOperator.setText(self.cbOperator.currentText()) 110 123 111 self.txtConstraint.setText(self.tab_names[ 1]+"."+self.cbParam2.currentText())124 self.txtConstraint.setText(self.tab_names[tab_index2]+"."+self.cbParam2.currentText()) 112 125 113 126 # disable Apply if no parameters available … … 155 168 self.lblWarning.setText(txt) 156 169 170 def onModelIndexChange(self, index): 171 """ 172 Respond to mode combo box changes 173 """ 174 # disable/enable Add All 175 self.setupMenu() 176 # Reload parameters 177 self.setupParamWidgets() 157 178 158 179 def onOperatorChange(self, index): … … 162 183 self.txtOperator.setText(self.cbOperator.currentText()) 163 184 164 def onRevert(self):165 """166 switch M1 <-> M2167 """168 # Switch parameters169 self.params[1], self.params[0] = self.params[0], self.params[1]170 self.tab_names[1], self.tab_names[0] = self.tab_names[0], self.tab_names[1]171 self.tabs[1], self.tabs[0] = self.tabs[0], self.tabs[1]172 # Try to swap parameter names in the line edit173 current_text = self.txtConstraint.text()174 new_text = current_text.replace(self.cbParam1.currentText(), self.cbParam2.currentText())175 self.txtConstraint.setText(new_text)176 # Update labels and tooltips177 index1 = self.cbParam1.currentIndex()178 index2 = self.cbParam2.currentIndex()179 indexOp = self.cbOperator.currentIndex()180 self.setupWidgets()181 182 # Original indices183 index2 = index2 if index2 >= 0 else 0184 index1 = index1 if index1 >= 0 else 0185 self.cbParam1.setCurrentIndex(index2)186 self.cbParam2.setCurrentIndex(index1)187 self.cbOperator.setCurrentIndex(indexOp)188 self.setupTooltip()189 190 185 def validateFormula(self): 191 186 """ 192 187 Add visual cues when formula is incorrect 193 188 """ 189 # temporarily disable validation 190 return 191 # 194 192 formula_is_valid = self.validateConstraint(self.txtConstraint.text()) 195 193 if not formula_is_valid: … … 208 206 return False 209 207 210 # M1.scale 208 # M1.scale --> model_str='M1', constraint_text='scale' 211 209 param_str = self.cbParam2.currentText() 212 210 constraint_text = constraint_text.strip() 213 model_str = self. txtName2.text()211 model_str = self.cbModel2.currentText() 214 212 215 213 # 0. Has to contain the model name 216 if model_str != self.txtName2.text():214 if model_str != model_str: 217 215 return False 218 216 … … 249 247 value = self.cbParam2.currentText() 250 248 func = self.txtConstraint.text() 251 value_ex = self. txtName2.text() + "." + self.cbParam2.currentText()252 model1 = self. txtName1.text()249 value_ex = self.cbModel2.currentText() + "." + self.cbParam2.currentText() 250 model1 = self.cbModel1.currentText() 253 251 operator = self.cbOperator.currentText() 254 252 … … 277 275 """ 278 276 # 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] 277 index1 = self.cbModel1.currentIndex() 278 index2 = self.cbModel2.currentIndex() 279 items1 = [param for param in self.params[index1] if not self.tabs[index1].paramHasConstraint(param)] 280 items2 = self.params[index2] 282 281 for item in items1: 283 282 if item not in items2: continue 284 283 param = item 285 284 value = item 286 func = self. txtName2.text() + "." + param287 value_ex = self. txtName1.text() + "." + param288 model1 = self. txtName1.text()285 func = self.cbModel2.currentText() + "." + param 286 value_ex = self.cbModel1.currentText() + "." + param 287 model1 = self.cbModel1.currentText() 289 288 operator = self.cbOperator.currentText() 290 289
Note: See TracChangeset
for help on using the changeset viewer.