Changeset 3b8cc00 in sasview for src/sas/qtgui


Ignore:
Timestamp:
Apr 25, 2018 2:32:11 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:
27689dc
Parents:
01ef3f7
Message:

Code review changes

Location:
src/sas/qtgui
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/MainWindow/GuiManager.py

    r01ef3f7 r3b8cc00  
    687687        """ 
    688688        """ 
    689         print("Open simple add / multiply editor") 
    690         # Add Simple Add / Multiple Editor 
     689        # Add Simple Add/Multiply Editor 
    691690        self.add_mult_editor = AddMultEditor(self) 
    692691        self.add_mult_editor.show() 
    693         # pass 
    694692 
    695693    #============ ANALYSIS ================= 
  • src/sas/qtgui/Utilities/AddMultEditor.py

    r01ef3f7 r3b8cc00  
    4545       (add or multiply) the resulting model will add a scale parameter and a 
    4646       background parameter. 
    47        The user also gives a brief help for the model in a description box and 
    48        must provide a unique name which is verified as unique before the new 
     47       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. 
    4949    """ 
    5050    def __init__(self, parent=None): 
    51         super(AddMultEditor, self).__init__() 
     51        super(AddMultEditor, self).__init__(parent._parent) 
    5252 
    5353        self.parent = parent 
     
    5757        #  uncheck self.chkOverwrite 
    5858        self.chkOverwrite.setChecked(False) 
     59        self.canOverwriteName = False 
    5960 
    6061        # Disabled Apply button until input of valid output plugin name 
     
    117118        # or when overwriting not allowed 
    118119        self.txtName.editingFinished.connect(self.onNameCheck) 
    119         self.chkOverwrite.stateChanged.connect(self.onNameCheck) 
     120        self.chkOverwrite.stateChanged.connect(self.onOverwrite) 
    120121 
    121122        self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply).clicked.connect(self.onApply) 
     
    126127        self.cbOperator.currentIndexChanged.connect(self.onOperatorChange) 
    127128 
     129    def onOverwrite(self): 
     130        """ 
     131        Modify state on checkbox change 
     132        """ 
     133        self.canOverwriteName = self.chkOverwrite.isChecked() 
     134 
    128135    def onNameCheck(self): 
    129136        """ 
     
    138145        filename = title + '.py' 
    139146 
    140         if self.chkOverwrite.isChecked(): 
     147        if self.canOverwriteName: 
    141148            # allow overwriting -> only valid name needs to be checked 
    142149            # (done with validator in __init__ above) 
     
    170177            QtWidgets.QDialogButtonBox.Apply).setEnabled(self.good_name) 
    171178 
    172         return self.good_name 
    173  
    174179    def onOperatorChange(self, index): 
    175180        """ Respond to operator combo box changes """ 
     
    182187        """ Validity check, save model to file """ 
    183188 
    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 
    187196 
    188197        self.write_new_model_to_file(self.plugin_filename, 
     
    191200                                     self.cbOperator.currentText()) 
    192201 
    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 
    199219 
    200220    def write_new_model_to_file(self, fname, model1_name, model2_name, operator): 
     
    221241            out_f.write(output) 
    222242 
    223     # same version as in TabbedModelEditor 
    224     @classmethod 
    225     def checkModel(cls, path): 
    226         """ Check that the model saved in file 'path' can run. """ 
    227  
    228         # try running the model 
    229         from sasmodels.sasview_model import load_custom_model 
    230         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 run 
    237         from sasmodels.model_test import run_one 
    238         # TODO see comments in TabbedModelEditor 
    239         # result = run_one(path) 
    240         result = True  # to be commented out 
    241         return result 
    242  
    243243    def updateModels(self): 
    244244        """ 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() 
    245250 
    246251        self.cbModel1.blockSignals(True) 
     
    257262        self.cbModel2.addItems(model_list) 
    258263 
     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 
    259268    def onHelp(self): 
    260269        """ Display related help section """ 
  • src/sas/qtgui/Utilities/GuiUtils.py

    rbb57068 r3b8cc00  
    1010import webbrowser 
    1111import urllib.parse 
     12 
     13import numpy as np 
    1214 
    1315warnings.simplefilter("ignore") 
     
    926928        input = input.replace(",", "") 
    927929 
     930def 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 
    928954 
    929955def enum(*sequential, **named): 
  • src/sas/qtgui/Utilities/PluginDefinition.py

    r8b480d27 r3b8cc00  
    5858 
    5959        # Validators 
    60         #rx = QtCore.QRegExp(r'^[\w,\s-]+$') 
    61         #rx = QtCore.QRegExp("[a-z-A-Z_]+") 
    6260        rx = QtCore.QRegExp("^[A-Za-z0-9_]*$") 
    6361 
  • src/sas/qtgui/Utilities/PluginManager.py

    r8b480d27 r3b8cc00  
    1919    """ 
    2020    def __init__(self, parent=None): 
    21         super(PluginManager, self).__init__() 
     21        super(PluginManager, self).__init__(parent._parent) 
    2222        self.setupUi(self) 
    2323 
  • src/sas/qtgui/Utilities/TabbedModelEditor.py

    r3790f7f r3b8cc00  
    1111from sas.sascalc.fit import models 
    1212 
     13import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    1314from sas.qtgui.Utilities.UI.TabbedModelEditor import Ui_TabbedModelEditor 
    1415from sas.qtgui.Utilities.PluginDefinition import PluginDefinition 
     
    2324    # Signals for intertab communication plugin -> editor 
    2425    def __init__(self, parent=None, edit_only=False): 
    25         super(TabbedModelEditor, self).__init__() 
     26        super(TabbedModelEditor, self).__init__(parent._parent) 
    2627 
    2728        self.parent = parent 
     
    238239        # Run the model test in sasmodels 
    239240        try: 
    240             _ = self.checkModel(full_path) 
     241            _ = GuiUtils.checkModel(full_path) 
    241242        except Exception as ex: 
    242243            msg = "Error building model: "+ str(ex) 
     
    405406 
    406407    @classmethod 
    407     def checkModel(cls, path): 
    408         """ 
    409         Check that the model save in file 'path' can run. 
    410         """ 
    411         # try running the model 
    412         from sasmodels.sasview_model import load_custom_model 
    413         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 run 
    421         from sasmodels.model_test import run_one 
    422         # 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] and 
    424         # test.info.tests will raise. 
    425         # Not sure how to change the behaviour here, most likely sasmodels will have to 
    426         # be modified 
    427         result = run_one(path) 
    428  
    429         return result 
    430  
    431     @classmethod 
    432408    def getParamHelper(cls, param_str): 
    433409        """ 
Note: See TracChangeset for help on using the changeset viewer.