Changeset 3790f7f in sasview for src


Ignore:
Timestamp:
Mar 22, 2018 4:13:40 PM (6 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:
bb57068
Parents:
8ac3551
Message:

More user friendly model editor.
Enabled model check while pending sasmodel change.

File:
1 edited

Legend:

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

    r8b480d27 r3790f7f  
    55import numpy as np 
    66import logging 
     7import traceback 
    78 
    89from PyQt5 import QtWidgets 
     
    7576        # signals from tabs 
    7677        self.editor_widget.modelModified.connect(self.editorModelModified) 
    77         self.plugin_widget.modelModified.connect(self.pluginModelModified) 
     78        self.plugin_widget.txtName.editingFinished.connect(self.pluginTitleSet) 
    7879 
    7980    def setPluginActive(self, is_active=True): 
     
    169170        self.is_modified = True 
    170171 
    171     def pluginModelModified(self): 
    172         """ 
    173         User modified the model in the Plugin Editor. 
    174         Show that the model is changed. 
     172    def pluginTitleSet(self): 
     173        """ 
     174        User modified the model name. 
     175        Display the model name in the window title 
     176        and allow for model save. 
    175177        """ 
    176178        # Ensure plugin name is non-empty 
     
    179181            self.setWindowTitle(self.window_title + " - " + model['filename']) 
    180182            self.setTabEdited(True) 
    181             # Enable editor 
    182             self.editor_widget.setEnabled(True) 
    183183            self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply).setEnabled(True) 
    184184            self.is_modified = True 
    185185        else: 
     186            # the model name is empty - disable Apply and clear the editor 
    186187            self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply).setEnabled(False) 
     188            self.editor_widget.blockSignals(True) 
     189            self.editor_widget.txtEditor.setPlainText('') 
     190            self.editor_widget.blockSignals(False) 
     191            self.editor_widget.setEnabled(False) 
    187192 
    188193    def setTabEdited(self, is_edited): 
     
    228233        model_str = self.generateModel(model, full_path) 
    229234        self.writeFile(full_path, model_str) 
    230         # TODO: 
    231         # Temporarily disable model check - 
    232         # unittest.suite() gives weird results in qt5. 
    233         # needs investigating 
    234         #try: 
    235         #    _, msg = self.checkModel(full_path), None 
    236         #except Exception as ex: 
    237         #    result, msg = None, "Error building model: "+ str(ex) 
     235 
     236        # test the model 
     237 
     238        # Run the model test in sasmodels 
     239        try: 
     240            _ = self.checkModel(full_path) 
     241        except Exception as ex: 
     242            msg = "Error building model: "+ str(ex) 
     243            logging.error(msg) 
     244            #print three last lines of the stack trace 
     245            # this will point out the exact line failing 
     246            last_lines = traceback.format_exc().split('\n')[-4:] 
     247            traceback_to_show = '\n'.join(last_lines) 
     248            logging.error(traceback_to_show) 
     249 
     250            self.parent.communicate.statusBarUpdateSignal.emit("Model check failed") 
     251            return 
     252 
     253        self.editor_widget.setEnabled(True) 
    238254 
    239255        # Update the editor here. 
     
    248264        # Notify listeners 
    249265        self.parent.communicate.customModelDirectoryChanged.emit() 
     266 
     267        # Notify the user 
     268        msg = "Custom model "+filename + " successfully created." 
     269        self.parent.communicate.statusBarUpdateSignal.emit(msg) 
     270        logging.info(msg) 
    250271 
    251272    def updateFromEditor(self): 
     
    261282        # Update the tab title 
    262283        self.setTabEdited(False) 
    263          
     284        # notify the user 
     285        msg = self.filename + " successfully saved." 
     286        self.parent.communicate.statusBarUpdateSignal.emit(msg) 
     287        logging.info(msg) 
     288 
    264289    def canWriteModel(self, model=None, full_path=""): 
    265290        """ 
     
    395420        # check the model's unit tests run 
    396421        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 
    397427        result = run_one(path) 
    398428 
Note: See TracChangeset for help on using the changeset viewer.