Ignore:
Timestamp:
May 20, 2016 8:37:21 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
5dfbb24
Parents:
cd54205
Message:

make sure compiler/test errors on custom models are reported to the user

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/calculator/model_editor.py

    rcb4ef58 r26d6e045  
    3030from wx.py.editwindow import EditWindow 
    3131from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
     32from .pyconsole import show_model_output, check_model 
    3233 
    3334 
     
    4546PANEL_WIDTH = 500 
    4647_BOX_WIDTH = 55 
    47  
    48  
    49 def _compile_file(path): 
    50     """ 
    51     Compile the file in the path 
    52     """ 
    53     try: 
    54         import py_compile 
    55         py_compile.compile(file=path, doraise=True) 
    56         return '' 
    57     except: 
    58         _, value, _ = sys.exc_info() 
    59         return value 
    6048 
    6149def _delete_file(path): 
     
    384372            name2 = label[1] 
    385373            self.write_string(fname, name1, name2) 
    386             self.compile_file(fname) 
    387             self.parent.update_custom_combo() 
     374            success = show_model_output(self, fname) 
     375            if success: 
     376                self.parent.update_custom_combo() 
    388377            msg = self._notes 
    389378            info = 'Info' 
     
    618607        """ 
    619608        path = self.fname 
    620         _compile_file(path) 
     609        show_model_output(self, path) 
    621610 
    622611    def delete_file(self, path): 
     
    954943        info = 'Info' 
    955944        msg = '' 
     945        result, check_err = '', '' 
    956946        # Sort out the errors if occur 
    957947        # First check for valid python name then if the name already exists 
     
    969959                    self.write_file(self.fname, name, description, param_str, 
    970960                                    pd_param_str, func_str) 
     961                    try: 
     962                        result, msg = check_model(self.fname), None 
     963                    except Exception: 
     964                        import traceback 
     965                        result, msg = None, "error building model" 
     966                        check_err = "\n"+traceback.format_exc(limit=2) 
     967 
    971968                    # Modified compiling test, as it will fail for sasmodels.sasview_model class 
    972969                    # Should add a test to check that the class is correctly built  
     
    10311028            color = 'red' 
    10321029        else: 
    1033             msg = "Successful! " 
     1030            self._notes = result 
     1031            msg = "Successful! Please look for %s in Customized Models."%name 
    10341032            msg += "  " + self._notes 
    1035             msg += " Please look for it in the Customized Models." 
    10361033            info = 'Info' 
    10371034            color = 'blue' 
     
    10411038        if self.base != None: 
    10421039            from sas.sasgui.guiframe.events import StatusEvent 
    1043             wx.PostEvent(self.base.parent, StatusEvent(status=msg, info=info)) 
     1040            wx.PostEvent(self.base.parent, 
     1041                         StatusEvent(status=msg+check_err, info=info)) 
    10441042        self.warning = msg 
    10451043 
Note: See TracChangeset for help on using the changeset viewer.