Changeset 3b8cc00 in sasview for src/sas/qtgui/Utilities/AddMultEditor.py
- Timestamp:
- Apr 25, 2018 4:32:11 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:
- 27689dc
- Parents:
- 01ef3f7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Utilities/AddMultEditor.py
r01ef3f7 r3b8cc00 45 45 (add or multiply) the resulting model will add a scale parameter and a 46 46 background parameter. 47 The user also gives a brief help for the model in adescription box and48 must provide a unique name which is verified as unique before the new47 The user can also give a brief help for the model in the description box and 48 must provide a unique name which is verified before the new model is saved. 49 49 """ 50 50 def __init__(self, parent=None): 51 super(AddMultEditor, self).__init__( )51 super(AddMultEditor, self).__init__(parent._parent) 52 52 53 53 self.parent = parent … … 57 57 # uncheck self.chkOverwrite 58 58 self.chkOverwrite.setChecked(False) 59 self.canOverwriteName = False 59 60 60 61 # Disabled Apply button until input of valid output plugin name … … 117 118 # or when overwriting not allowed 118 119 self.txtName.editingFinished.connect(self.onNameCheck) 119 self.chkOverwrite.stateChanged.connect(self.on NameCheck)120 self.chkOverwrite.stateChanged.connect(self.onOverwrite) 120 121 121 122 self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply).clicked.connect(self.onApply) … … 126 127 self.cbOperator.currentIndexChanged.connect(self.onOperatorChange) 127 128 129 def onOverwrite(self): 130 """ 131 Modify state on checkbox change 132 """ 133 self.canOverwriteName = self.chkOverwrite.isChecked() 134 128 135 def onNameCheck(self): 129 136 """ … … 138 145 filename = title + '.py' 139 146 140 if self.c hkOverwrite.isChecked():147 if self.canOverwriteName: 141 148 # allow overwriting -> only valid name needs to be checked 142 149 # (done with validator in __init__ above) … … 170 177 QtWidgets.QDialogButtonBox.Apply).setEnabled(self.good_name) 171 178 172 return self.good_name173 174 179 def onOperatorChange(self, index): 175 180 """ Respond to operator combo box changes """ … … 182 187 """ Validity check, save model to file """ 183 188 184 # if name OK write file and test 185 self.buttonBox.button( 186 QtWidgets.QDialogButtonBox.Apply).setEnabled(False) 189 # Set the button enablement, so no double clicks can be made 190 self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply).setEnabled(False) 191 192 # Check the name/overwrite combination again, in case we managed to confuse the UI 193 self.onNameCheck() 194 if not self.good_name: 195 return 187 196 188 197 self.write_new_model_to_file(self.plugin_filename, … … 191 200 self.cbOperator.currentText()) 192 201 193 success = self.checkModel(self.plugin_filename) 194 195 if success: 196 # Update list of models in FittingWidget and AddMultEditor 197 self.parent.communicate.customModelDirectoryChanged.emit() 198 self.updateModels() 202 success = GuiUtils.checkModel(self.plugin_filename) 203 204 if not success: 205 return 206 207 # Update list of models in FittingWidget and AddMultEditor 208 self.parent.communicate.customModelDirectoryChanged.emit() 209 # Re-read the model list so the new model is included 210 self.list_models = self.readModels() 211 self.updateModels() 212 213 # Notify the user 214 title = self.txtName.text().lstrip().rstrip() 215 msg = "Custom model "+title + " successfully created." 216 self.parent.communicate.statusBarUpdateSignal.emit(msg) 217 logging.info(msg) 218 199 219 200 220 def write_new_model_to_file(self, fname, model1_name, model2_name, operator): … … 221 241 out_f.write(output) 222 242 223 # same version as in TabbedModelEditor224 @classmethod225 def checkModel(cls, path):226 """ Check that the model saved in file 'path' can run. """227 228 # try running the model229 from sasmodels.sasview_model import load_custom_model230 Model = load_custom_model(path)231 model = Model()232 q = np.array([0.01, 0.1])233 _ = model.evalDistribution(q)234 qx, qy = np.array([0.01, 0.01]), np.array([0.1, 0.1])235 _ = model.evalDistribution([qx, qy])236 # check the model's unit tests run237 from sasmodels.model_test import run_one238 # TODO see comments in TabbedModelEditor239 # result = run_one(path)240 result = True # to be commented out241 return result242 243 243 def updateModels(self): 244 244 """ Update contents of comboboxes with new plugin models """ 245 246 # Keep pointers to the current indices so we can show the comboboxes with 247 # original selection 248 model_1 = self.cbModel1.currentText() 249 model_2 = self.cbModel2.currentText() 245 250 246 251 self.cbModel1.blockSignals(True) … … 257 262 self.cbModel2.addItems(model_list) 258 263 264 # Scroll back to the user chosen models 265 self.cbModel1.setCurrentIndex(self.cbModel1.findText(model_1)) 266 self.cbModel2.setCurrentIndex(self.cbModel2.findText(model_2)) 267 259 268 def onHelp(self): 260 269 """ Display related help section """
Note: See TracChangeset
for help on using the changeset viewer.