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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.