Ignore:
Timestamp:
Aug 29, 2017 5:30:45 PM (7 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
25a42f99
Parents:
7c64911 (diff), f001bc9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ticket-887-reorg

File:
1 edited

Legend:

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

    r914ba0a r759a8ab  
    1111 
    1212from sas.sascalc.dataloader.loader import Loader 
     13from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 
    1314 
    1415from sas.sasgui import get_local_config 
     
    2627APPLICATION_WLIST = config.APPLICATION_WLIST 
    2728 
     29 
    2830class Plugin(PluginBase): 
    2931 
     
    4143        """ 
    4244        # menu for data files 
    43         menu_list = [] 
    4445        data_file_hint = "load one or more data in the application" 
    4546        menu_list = [('&Load Data File(s)', data_file_hint, self.load_data)] 
    4647        gui_style = self.parent.get_style() 
    4748        style = gui_style & GUIFRAME.MULTIPLE_APPLICATIONS 
    48         style1 = gui_style & GUIFRAME.DATALOADER_ON 
    4949        if style == GUIFRAME.MULTIPLE_APPLICATIONS: 
    5050            # menu for data from folder 
     
    8787        self.get_data(file_list) 
    8888 
    89  
    9089    def can_load_data(self): 
    9190        """ 
     
    9392        """ 
    9493        return True 
    95  
    9694 
    9795    def _load_folder(self, event): 
     
    125123        """ 
    126124        if error is not None or str(error).strip() != "": 
    127             dial = wx.MessageDialog(self.parent, str(error), 'Error Loading File', 
     125            dial = wx.MessageDialog(self.parent, str(error), 
     126                                    'Error Loading File', 
    128127                                    wx.OK | wx.ICON_EXCLAMATION) 
    129128            dial.ShowModal() 
     
    134133        """ 
    135134        if os.path.isdir(path): 
    136             return [os.path.join(os.path.abspath(path), filename) for filename in os.listdir(path)] 
     135            return [os.path.join(os.path.abspath(path), filename) for filename 
     136                    in os.listdir(path)] 
    137137 
    138138    def _process_data_and_errors(self, item, p_file, output, message): 
     
    163163        for p_file in path: 
    164164            basename = os.path.basename(p_file) 
     165            # Skip files that start with a period 
     166            if basename.startswith("."): 
     167                msg = "The folder included a potential hidden file - %s." \ 
     168                      % basename 
     169                msg += " Do you wish to load this file as data?" 
     170                msg_box = wx.MessageDialog(None, msg, 'Warning', 
     171                                           wx.OK | wx.CANCEL) 
     172                if msg_box.ShowModal() == wx.ID_CANCEL: 
     173                    continue 
    165174            _, extension = os.path.splitext(basename) 
    166175            if extension.lower() in EXTENSIONS: 
     
    198207                info="info") 
    199208 
    200             except: 
    201                 logger.error(sys.exc_value) 
    202  
    203                 error_message = "The Data file you selected could not be loaded.\n" 
    204                 error_message += "Make sure the content of your file" 
    205                 error_message += " is properly formatted.\n" 
    206                 error_message += "When contacting the SasView team, mention the" 
    207                 error_message += " following:\n" 
    208                 error_message += "Error: " + str(sys.exc_info()[1]) 
    209                 file_errors[basename] = [error_message] 
    210                 self.load_update(output=output, message=error_message, info="warning") 
     209            except NoKnownLoaderException as e: 
     210                exception_occurred = True 
     211                logger.error(e.message) 
     212 
     213                error_message = "Loading data failed!\n" + e.message 
     214                self.load_update(output=None, message=e.message, info="warning") 
     215 
     216            except Exception as e: 
     217                exception_occurred = True 
     218                logger.error(e.message) 
     219 
     220                file_err = "The Data file you selected could not be " 
     221                file_err += "loaded.\nMake sure the content of your file" 
     222                file_err += " is properly formatted.\n" 
     223                file_err += "When contacting the SasView team, mention the" 
     224                file_err += " following:\n" 
     225                file_err += e.message 
     226                file_errors[basename] = [file_err] 
    211227 
    212228        if len(file_errors) > 0: 
     
    218234                    error_message += message + "\n" 
    219235                error_message += "\n" 
    220             self.load_update(output=output, message=error_message, info="error") 
    221  
    222         self.load_complete(output=output, message="Loading data complete!", 
    223             info="info") 
     236            if not exception_occurred: # Some data loaded but with errors 
     237                self.load_update(output=output, message=error_message, info="error") 
     238 
     239        if not exception_occurred: # Everything loaded as expected 
     240            self.load_complete(output=output, message="Loading data complete!", 
     241                               info="info") 
     242        else: 
     243            self.load_complete(output=None, message=error_message, info="error") 
     244 
    224245 
    225246    def load_update(self, output=None, message="", info="warning"): 
     
    230251            wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
    231252                                                  type="progress")) 
    232     def load_complete(self, output, message="", error_message="", path=None, 
    233                       info="warning"): 
    234         """ 
    235          post message to  status bar and return list of data 
    236         """ 
    237         wx.PostEvent(self.parent, StatusEvent(status=message, 
    238                                               info=info, 
     253 
     254    def load_complete(self, output, message="", info="warning"): 
     255        """ 
     256         post message to status bar and return list of data 
     257        """ 
     258        wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
    239259                                              type="stop")) 
    240         # if error_message != "": 
    241         #    self.load_error(error_message) 
    242         self.parent.add_data(data_list=output) 
     260        if output is not None: 
     261            self.parent.add_data(data_list=output) 
Note: See TracChangeset for help on using the changeset viewer.