Ignore:
Timestamp:
Apr 5, 2017 9:08:59 AM (7 years ago)
Author:
krzywon
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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
278ddee
Parents:
69400ec
git-author:
Jeff Krzywon <krzywon@…> (04/05/17 09:08:59)
git-committer:
krzywon <krzywon@…> (04/05/17 09:08:59)
Message:

More explicit error messages when file loading fails. see #889

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py

    r69400ec r7f75a3f  
    99 
    1010from sas.sascalc.dataloader.loader import Loader 
     11from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 
    1112from sas.sasgui.guiframe.plugin_base import PluginBase 
    1213from sas.sasgui.guiframe.events import StatusEvent 
     
    3940APPLICATION_WLIST = config.APPLICATION_WLIST 
    4041 
     42 
    4143class Plugin(PluginBase): 
    4244 
     
    5456        """ 
    5557        # menu for data files 
    56         menu_list = [] 
    5758        data_file_hint = "load one or more data in the application" 
    5859        menu_list = [('&Load Data File(s)', data_file_hint, self.load_data)] 
    5960        gui_style = self.parent.get_style() 
    6061        style = gui_style & GUIFRAME.MULTIPLE_APPLICATIONS 
    61         style1 = gui_style & GUIFRAME.DATALOADER_ON 
    6262        if style == GUIFRAME.MULTIPLE_APPLICATIONS: 
    6363            # menu for data from folder 
     
    100100        self.get_data(file_list) 
    101101 
    102  
    103102    def can_load_data(self): 
    104103        """ 
     
    106105        """ 
    107106        return True 
    108  
    109107 
    110108    def _load_folder(self, event): 
     
    114112        path = None 
    115113        self._default_save_location = self.parent._default_save_location 
    116         if self._default_save_location == None: 
     114        if self._default_save_location is None: 
    117115            self._default_save_location = os.getcwd() 
    118116        dlg = wx.DirDialog(self.parent, "Choose a directory", 
     
    138136        """ 
    139137        if error is not None or str(error).strip() != "": 
    140             dial = wx.MessageDialog(self.parent, str(error), 'Error Loading File', 
     138            dial = wx.MessageDialog(self.parent, str(error), 
     139                                    'Error Loading File', 
    141140                                    wx.OK | wx.ICON_EXCLAMATION) 
    142141            dial.ShowModal() 
     
    147146        """ 
    148147        if os.path.isdir(path): 
    149             return [os.path.join(os.path.abspath(path), filename) for filename in os.listdir(path)] 
     148            return [os.path.join(os.path.abspath(path), filename) for filename 
     149                    in os.listdir(path)] 
    150150 
    151151    def _process_data_and_errors(self, item, p_file, output, message): 
     
    220220                info="info") 
    221221 
     222            except NoKnownLoaderException as e: 
     223                logging.error(e.message) 
     224                self.load_update(output=None, message=e.message, info="warning") 
     225                self.load_complete(output=None, 
     226                                   message="Loading data failed!", 
     227                                   info="warning") 
    222228            except: 
    223229                logging.error(sys.exc_value) 
    224230 
    225                 error_message = "The Data file you selected could not be loaded.\n" 
    226                 error_message += "Make sure the content of your file" 
     231                error_message = "The Data file you selected could not be " 
     232                error_message += "loaded.\nMake sure the content of your file" 
    227233                error_message += " is properly formatted.\n" 
    228234                error_message += "When contacting the SasView team, mention the" 
     
    230236                error_message += "Error: " + str(sys.exc_info()[1]) 
    231237                file_errors[basename] = [error_message] 
    232                 self.load_update(output=output, message=error_message, info="warning") 
     238                self.load_update(output=output, message=error_message, 
     239                                 info="warning") 
    233240 
    234241        if len(file_errors) > 0: 
     
    243250 
    244251        self.load_complete(output=output, message="Loading data complete!", 
    245             info="info") 
     252                           info="info") 
    246253 
    247254    def load_update(self, output=None, message="", info="warning"): 
     
    252259            wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
    253260                                                  type="progress")) 
    254     def load_complete(self, output, message="", error_message="", path=None, 
    255                       info="warning"): 
    256         """ 
    257          post message to  status bar and return list of data 
    258         """ 
    259         wx.PostEvent(self.parent, StatusEvent(status=message, 
    260                                               info=info, 
     261 
     262    def load_complete(self, output, message="", info="warning"): 
     263        """ 
     264         post message to status bar and return list of data 
     265        """ 
     266        wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
    261267                                              type="stop")) 
    262         # if error_message != "": 
    263         #    self.load_error(error_message) 
    264268        self.parent.add_data(data_list=output) 
Note: See TracChangeset for help on using the changeset viewer.