Changeset c5e0d84 in sasview for src/sas


Ignore:
Timestamp:
Jun 23, 2018 2:26:14 PM (6 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, 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:
e20870bc
Parents:
44753d6
git-author:
Piotr Rozyczko <rozyczko@…> (06/23/18 14:25:26)
git-committer:
Piotr Rozyczko <rozyczko@…> (06/23/18 14:26:14)
Message:

Minor modifications in response to requests during demo session

Location:
src/sas/qtgui/Utilities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Utilities/GuiUtils.py

    r57be490 rc5e0d84  
    10141014    # The following return needs to be removed once 
    10151015    # the unittest related changes in Sasmodels are commited 
    1016     return True 
     1016    # return True 
    10171017    # try running the model 
    10181018    from sasmodels.sasview_model import load_custom_model 
  • src/sas/qtgui/Utilities/PluginDefinition.py

    r26970b3 rc5e0d84  
    3636        self.addWidgets() 
    3737 
    38     def addWidgets(self): 
     38    def addTooltip(self): 
    3939        """ 
    40         Initialize various widgets in the dialog 
     40        Add the default tooltip to the text field 
    4141        """ 
    42         # Set the tooltip 
    4342        hint_function = "#Example:\n\n" 
    4443        hint_function += "if x <= 0:\n" 
     
    4847        hint_function += "return y\n" 
    4948        self.txtFunction.setToolTip(hint_function) 
     49 
     50    def addWidgets(self): 
     51        """ 
     52        Initialize various widgets in the dialog 
     53        """ 
     54        self.addTooltip() 
     55 
    5056        # Initial text in the function table 
    5157        text = \ 
     
    154160        # keep in mind that this is called every time the text changes. 
    155161        # mind the performance! 
     162        self.addTooltip() 
    156163        self.model['text'] = self.txtFunction.toPlainText().lstrip().rstrip() 
    157164        self.modelModified.emit() 
  • src/sas/qtgui/Utilities/TabbedModelEditor.py

    rf9214aa rc5e0d84  
    7777        self.cmdLoad.clicked.connect(self.onLoad) 
    7878        # signals from tabs 
     79        self.plugin_widget.modelModified.connect(self.editorModelModified) 
    7980        self.editor_widget.modelModified.connect(self.editorModelModified) 
    8081        self.plugin_widget.txtName.editingFinished.connect(self.pluginTitleSet) 
     
    170171        """ 
    171172        self.setTabEdited(True) 
     173        self.plugin_widget.txtFunction.setStyleSheet("") 
    172174        self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply).setEnabled(True) 
    173175        self.is_modified = True 
     
    237239        self.writeFile(full_path, model_str) 
    238240 
     241        # disable "Apply" 
     242        self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply).setEnabled(False) 
    239243        # test the model 
    240244 
    241245        # Run the model test in sasmodels 
     246        if not self.isModelCorrect(full_path): 
     247            return 
     248 
     249        self.editor_widget.setEnabled(True) 
     250 
     251        # Update the editor here. 
     252        # Simple string forced into control. 
     253        self.editor_widget.blockSignals(True) 
     254        self.editor_widget.txtEditor.setPlainText(model_str) 
     255        self.editor_widget.blockSignals(False) 
     256 
     257        # Set the widget title 
     258        self.setTabEdited(False) 
     259 
     260        # Notify listeners 
     261        self.parent.communicate.customModelDirectoryChanged.emit() 
     262 
     263        # Notify the user 
     264        msg = "Custom model "+filename + " successfully created." 
     265        self.parent.communicate.statusBarUpdateSignal.emit(msg) 
     266        logging.info(msg) 
     267 
     268    def isModelCorrect(self, full_path): 
     269        """ 
     270        Run the sasmodels method for model check 
     271        and return True if the model is good. 
     272        False otherwise. 
     273        """ 
     274        successfulCheck = True 
    242275        try: 
    243276            model_results = GuiUtils.checkModel(full_path) 
    244277            logging.info(model_results) 
     278        # We can't guarantee the type of the exception coming from 
     279        # Sasmodels, so need the overreaching general Exception 
    245280        except Exception as ex: 
    246281            msg = "Error building model: "+ str(ex) 
     
    252287            logging.error(traceback_to_show) 
    253288 
     289            # Set the status bar message 
    254290            self.parent.communicate.statusBarUpdateSignal.emit("Model check failed") 
    255             return 
    256  
    257         self.editor_widget.setEnabled(True) 
    258  
    259         # Update the editor here. 
    260         # Simple string forced into control. 
    261         self.editor_widget.blockSignals(True) 
    262         self.editor_widget.txtEditor.setPlainText(model_str) 
    263         self.editor_widget.blockSignals(False) 
    264  
    265         # Set the widget title 
    266         self.setTabEdited(False) 
    267  
    268         # Notify listeners 
    269         self.parent.communicate.customModelDirectoryChanged.emit() 
    270  
    271         # Notify the user 
    272         msg = "Custom model "+filename + " successfully created." 
    273         self.parent.communicate.statusBarUpdateSignal.emit(msg) 
    274         logging.info(msg) 
     291 
     292            # Remove the file so it is not being loaded on refresh 
     293            os.remove(full_path) 
     294            # Put a thick, red border around the mini-editor 
     295            self.plugin_widget.txtFunction.setStyleSheet("border: 5px solid red") 
     296            # Use the last line of the traceback for the tooltip 
     297            last_lines = traceback.format_exc().split('\n')[-2:] 
     298            traceback_to_show = '\n'.join(last_lines) 
     299            self.plugin_widget.txtFunction.setToolTip(traceback_to_show) 
     300            successfulCheck = False 
     301        return successfulCheck 
    275302 
    276303    def updateFromEditor(self): 
Note: See TracChangeset for help on using the changeset viewer.