Changeset 3b8cc00 in sasview for src/sas/qtgui
- Timestamp:
- Apr 25, 2018 2: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
- Location:
- src/sas/qtgui
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/MainWindow/GuiManager.py
r01ef3f7 r3b8cc00 687 687 """ 688 688 """ 689 print("Open simple add / multiply editor") 690 # Add Simple Add / Multiple Editor 689 # Add Simple Add/Multiply Editor 691 690 self.add_mult_editor = AddMultEditor(self) 692 691 self.add_mult_editor.show() 693 # pass694 692 695 693 #============ ANALYSIS ================= -
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 """ -
src/sas/qtgui/Utilities/GuiUtils.py
rbb57068 r3b8cc00 10 10 import webbrowser 11 11 import urllib.parse 12 13 import numpy as np 12 14 13 15 warnings.simplefilter("ignore") … … 926 928 input = input.replace(",", "") 927 929 930 def checkModel(path): 931 """ 932 Check that the model save in file 'path' can run. 933 """ 934 # try running the model 935 from sasmodels.sasview_model import load_custom_model 936 Model = load_custom_model(path) 937 model = Model() 938 q = np.array([0.01, 0.1]) 939 _ = model.evalDistribution(q) 940 qx, qy = np.array([0.01, 0.01]), np.array([0.1, 0.1]) 941 _ = model.evalDistribution([qx, qy]) 942 943 # check the model's unit tests run 944 from sasmodels.model_test import run_one 945 # TestSuite module in Qt5 now deletes tests in the suite after running, 946 # so suite[0] in run_one() in sasmodels/model_test.py will contain [None] and 947 # test.info.tests will raise. 948 # Not sure how to change the behaviour here, most likely sasmodels will have to 949 # be modified 950 result = run_one(path) 951 952 return result 953 928 954 929 955 def enum(*sequential, **named): -
src/sas/qtgui/Utilities/PluginDefinition.py
r8b480d27 r3b8cc00 58 58 59 59 # Validators 60 #rx = QtCore.QRegExp(r'^[\w,\s-]+$')61 #rx = QtCore.QRegExp("[a-z-A-Z_]+")62 60 rx = QtCore.QRegExp("^[A-Za-z0-9_]*$") 63 61 -
src/sas/qtgui/Utilities/PluginManager.py
r8b480d27 r3b8cc00 19 19 """ 20 20 def __init__(self, parent=None): 21 super(PluginManager, self).__init__( )21 super(PluginManager, self).__init__(parent._parent) 22 22 self.setupUi(self) 23 23 -
src/sas/qtgui/Utilities/TabbedModelEditor.py
r3790f7f r3b8cc00 11 11 from sas.sascalc.fit import models 12 12 13 import sas.qtgui.Utilities.GuiUtils as GuiUtils 13 14 from sas.qtgui.Utilities.UI.TabbedModelEditor import Ui_TabbedModelEditor 14 15 from sas.qtgui.Utilities.PluginDefinition import PluginDefinition … … 23 24 # Signals for intertab communication plugin -> editor 24 25 def __init__(self, parent=None, edit_only=False): 25 super(TabbedModelEditor, self).__init__( )26 super(TabbedModelEditor, self).__init__(parent._parent) 26 27 27 28 self.parent = parent … … 238 239 # Run the model test in sasmodels 239 240 try: 240 _ = self.checkModel(full_path)241 _ = GuiUtils.checkModel(full_path) 241 242 except Exception as ex: 242 243 msg = "Error building model: "+ str(ex) … … 405 406 406 407 @classmethod 407 def checkModel(cls, path):408 """409 Check that the model save in file 'path' can run.410 """411 # try running the model412 from sasmodels.sasview_model import load_custom_model413 Model = load_custom_model(path)414 model = Model()415 q = np.array([0.01, 0.1])416 _ = model.evalDistribution(q)417 qx, qy = np.array([0.01, 0.01]), np.array([0.1, 0.1])418 _ = model.evalDistribution([qx, qy])419 420 # check the model's unit tests run421 from sasmodels.model_test import run_one422 # TestSuite module in Qt5 now deletes tests in the suite after running,423 # so suite[0] in run_one() in sasmodels/model_test.py will contain [None] and424 # test.info.tests will raise.425 # Not sure how to change the behaviour here, most likely sasmodels will have to426 # be modified427 result = run_one(path)428 429 return result430 431 @classmethod432 408 def getParamHelper(cls, param_str): 433 409 """
Note: See TracChangeset
for help on using the changeset viewer.