Changeset 1176137 in sasview


Ignore:
Timestamp:
Apr 17, 2018 9:29:25 AM (6 years ago)
Author:
GitHub <noreply@…>
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, unittest-saveload
Children:
666454e, 1cf490b6, cd10013, c192960
Parents:
94f074c4 (diff), 91552b5 (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.
git-author:
Paul Butler <butlerpd@…> (04/17/18 09:29:25)
git-committer:
GitHub <noreply@…> (04/17/18 09:29:25)
Message:

Merge pull request #149 from SasView?/ticket-1079

Removing save button from OSX

closes #1079

Files:
6 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/fit/pagestate.py

    r9e6aeaf r3b070a0  
    646646                    name = value.split(':', 1)[1].strip() 
    647647                    file_value = "File name:" + name 
     648                    #Truncating string so print doesn't complain of being outside margins 
     649                    if sys.platform != "win32": 
     650                        MAX_STRING_LENGHT = 50 
     651                        if len(file_value) > MAX_STRING_LENGHT: 
     652                            file_value = "File name:.."+file_value[-MAX_STRING_LENGHT+10:] 
    648653                    file_name = CENTRE % file_value 
    649654                    if len(title) == 0: 
     
    721726        html_str, text_str, title = self._get_report_string() 
    722727        # Allow 2 figures to append 
    723         image_links = [FEET_2%fig for fig in fig_urls] 
    724  
     728        #Constraining image width for OSX and linux, so print doesn't complain of being outside margins 
     729        if sys.platform == "win32": 
     730            image_links = [FEET_2%fig for fig in fig_urls] 
     731        else: 
     732            image_links = [FEET_2_unix%fig for fig in fig_urls] 
    725733        # final report html strings 
    726734        report_str = html_str + ELINE.join(image_links) 
    727  
     735        report_str += FEET_3 
    728736        return report_str, text_str 
    729737 
     
    13681376""" 
    13691377FEET_2 = \ 
    1370 """<img src="%s" ></img> 
     1378"""<img src="%s"></img> 
     1379""" 
     1380FEET_2_unix = \ 
     1381"""<img src="%s" width="540"></img> 
    13711382""" 
    13721383FEET_3 = \ 
  • src/sas/sasgui/guiframe/report_dialog.py

    r69a6897 r91552b5  
    2727class BaseReportDialog(wx.Dialog): 
    2828 
    29     def __init__(self, report_list, *args, **kwds): 
     29    def __init__(self, report_list, imgRAM, fig_urls, *args, **kwds): 
    3030        """ 
    3131        Initialization. The parameters added to Dialog are: 
     
    3737        kwds["image"] = 'Dynamic Image' 
    3838 
     39        #MemoryFSHandle for storing images 
     40        self.imgRAM = imgRAM 
     41        #Images location in urls 
     42        self.fig_urls = fig_urls 
    3943        # title 
    4044        self.SetTitle("Report") 
     
    7579        hbox.Add(button_print) 
    7680 
    77         button_save = wx.Button(self, wx.NewId(), "Save") 
    78         button_save.SetToolTipString("Save this report.") 
    79         button_save.Bind(wx.EVT_BUTTON, self.onSave, id=button_save.GetId()) 
    80         hbox.Add(button_save) 
     81        if sys.platform != "darwin": 
     82            button_save = wx.Button(self, wx.NewId(), "Save") 
     83            button_save.SetToolTipString("Save this report.") 
     84            button_save.Bind(wx.EVT_BUTTON, self.onSave, id=button_save.GetId()) 
     85            hbox.Add(button_save) 
    8186 
    8287        # panel for report page 
     
    111116        printh.PrintText(self.report_html) 
    112117 
     118 
    113119    def OnClose(self, event=None): 
    114120        """ 
     
    116122        : event: Close button event 
    117123        """ 
     124        for fig in self.fig_urls: 
     125            self.imgRAM.RemoveFile(fig) 
     126 
    118127        self.Close() 
    119128 
  • src/sas/sasgui/perspectives/fitting/basepage.py

    r1f4d708 r5818dae  
    641641        # get the strings for report 
    642642        report_str, text_str = self.state.report(fig_urls=refs) 
    643  
    644643        # Show the dialog 
    645644        report_list = [report_str, text_str, images] 
    646         dialog = ReportDialog(report_list, None, wx.ID_ANY, "") 
     645        dialog = ReportDialog(report_list, imgRAM, refs, None, wx.ID_ANY, "") 
    647646        dialog.Show() 
    648647 
     
    677676            refs.append('memory:' + name) 
    678677            imgRAM.AddFile(name, canvas.bitmap, wx.BITMAP_TYPE_PNG) 
    679  
    680678            # append figs 
    681679            images.append(fig) 
  • build_tools/requirements.txt

    r36ca21e rc16172d  
    33pylint 
    44unittest-xml-reporting==1.10.0 
    5 pyparsing==1.5.5 
     5pyparsing>=2.0 
    66html5lib==0.95 
    77reportlab==2.5 
  • setup.py

    r1a3602d rc16172d  
    402402 
    403403required = [ 
    404     'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing<2.0.0', 
     404    'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing>=2.0.0', 
    405405 
    406406    # 'lxml>=2.2.2', 
  • src/sas/sascalc/dataloader/file_reader_base_class.py

    ra58b5a0 r4a8d55c  
    3131FIELDS_2D = ('data', 'qx_data', 'qy_data', 'q_data', 'err_data', 
    3232                 'dqx_data', 'dqy_data', 'mask') 
    33  
     33DEPRECATION_MESSAGE = ("\rThe extension of this file suggests the data set migh" 
     34                       "t not be fully reduced. Support for the reader associat" 
     35                       "ed with this file type has been removed. An attempt to " 
     36                       "load the file was made, but, should it be successful, " 
     37                       "SasView cannot guarantee the accuracy of the data.") 
    3438 
    3539class FileReader(object): 
     
    4044    # List of allowed extensions 
    4145    ext = ['.txt'] 
     46    # Deprecated extensions 
     47    deprecated_extensions = ['.asc', '.nxs'] 
    4248    # Bypass extension check and try to load anyway 
    4349    allow_all = False 
     
    8793                    if not self.f_open.closed: 
    8894                        self.f_open.close() 
     95                    if any(filepath.lower().endswith(ext) for ext in 
     96                           self.deprecated_extensions): 
     97                        self.handle_error_message(DEPRECATION_MESSAGE) 
    8998                    if len(self.output) > 0: 
    9099                        # Sort the data that's been loaded 
     
    146155        else: 
    147156            logger.warning(msg) 
     157            raise NoKnownLoaderException(msg) 
    148158 
    149159    def send_to_output(self): 
  • src/sas/sascalc/dataloader/loader.py

    rdc8d1c2 r4a8d55c  
    9090            ascii_loader = ascii_reader.Reader() 
    9191            return ascii_loader.read(path) 
     92        except NoKnownLoaderException: 
     93            pass  # Try the Cansas XML reader 
    9294        except DefaultReaderException: 
    9395            pass  # Loader specific error to try the cansas XML reader 
     
    100102            cansas_loader = cansas_reader.Reader() 
    101103            return cansas_loader.read(path) 
     104        except NoKnownLoaderException: 
     105            pass  # Try the NXcanSAS reader 
    102106        except DefaultReaderException: 
    103107            pass  # Loader specific error to try the NXcanSAS reader 
  • src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py

    r20fa5fe r2924532  
    185185            try: 
    186186                message = "Loading {}...\n".format(p_file) 
    187                 self.load_update(output=output, message=message, info="info") 
     187                self.load_update(message=message, info="info") 
    188188                temp = self.loader.load(p_file, format) 
    189189                if not isinstance(temp, list): 
     
    201201                        else: 
    202202                            file_errors[basename] = [error_message] 
    203                         self.load_update(output=output, 
    204                             message=error_message, info="warning") 
    205  
    206                 self.load_update(output=output, 
    207                 message="Loaded {}\n".format(p_file), 
    208                 info="info") 
     203 
     204                self.load_update(message="Loaded {}\n".format(p_file), 
     205                                 info="info") 
    209206 
    210207            except NoKnownLoaderException as e: 
    211208                exception_occurred = True 
    212                 logger.error(e.message) 
    213  
    214209                error_message = "Loading data failed!\n" + e.message 
    215                 self.load_update(output=None, message=e.message, info="warning") 
     210                self.load_complete(output=None, 
     211                                   message=error_message, 
     212                                   info="warning") 
    216213 
    217214            except Exception as e: 
    218215                exception_occurred = True 
    219                 logger.error(e.message) 
    220  
    221216                file_err = "The Data file you selected could not be " 
    222217                file_err += "loaded.\nMake sure the content of your file" 
     
    225220                file_err += " following:\n" 
    226221                file_err += e.message 
    227                 file_errors[basename] = [file_err] 
     222                self.load_complete(output=None, 
     223                                   message=file_err, 
     224                                   info="error") 
    228225 
    229226        if len(file_errors) > 0: 
    230227            error_message = "" 
    231228            for filename, error_array in file_errors.iteritems(): 
    232                 error_message += "The following errors occured whilst " 
     229                error_message += "The following issues were found whilst " 
    233230                error_message += "loading {}:\n".format(filename) 
    234231                for message in error_array: 
    235232                    error_message += message + "\n" 
    236                 error_message += "\n" 
    237             if not exception_occurred: # Some data loaded but with errors 
    238                 self.load_update(output=output, message=error_message, info="error") 
    239  
    240         if not exception_occurred: # Everything loaded as expected 
     233                error_message = error_message[:-1] 
     234            self.load_complete(output=output, 
     235                               message=error_message, 
     236                               info="error") 
     237 
     238        elif not exception_occurred: # Everything loaded as expected 
    241239            self.load_complete(output=output, message="Loading data complete!", 
    242240                               info="info") 
     
    244242            self.load_complete(output=None, message=error_message, info="error") 
    245243 
    246  
    247     def load_update(self, output=None, message="", info="warning"): 
     244    def load_update(self, message="", info="warning"): 
    248245        """ 
    249246        print update on the status bar 
    250247        """ 
    251248        if message != "": 
    252             wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
     249            wx.PostEvent(self.parent, StatusEvent(status=message, 
     250                                                  info=info, 
    253251                                                  type="progress")) 
    254252 
     
    257255         post message to status bar and return list of data 
    258256        """ 
    259         wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
     257        wx.PostEvent(self.parent, StatusEvent(status=message, 
     258                                              info=info, 
    260259                                              type="stop")) 
    261260        if output is not None: 
  • test/sasdataloader/test/utest_generic_file_reader_class.py

    rf53d684 r4a8d55c  
    88import numpy as np 
    99 
    10 from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D 
     10from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D, Data1D 
     11from sas.sascalc.dataloader.loader import Loader 
     12from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 
    1113from sas.sascalc.dataloader.file_reader_base_class import FileReader 
    1214 
     
    2426        self.bad_file = find("ACB123.txt") 
    2527        self.good_file = find("123ABC.txt") 
     28        self.generic_reader = Loader() 
     29        self.deprecated_file_type = find("FEB18012.ASC") 
    2630 
    2731    def test_bad_file_path(self): 
    28         output = self.reader.read(self.bad_file) 
    29         self.assertEqual(output, []) 
     32        self.assertRaises(NoKnownLoaderException, self.reader.read, 
     33                          self.bad_file) 
    3034 
    3135    def test_good_file_path(self): 
     
    3640        self.assertEqual(len(output), 1) 
    3741        self.assertEqual(output[0].meta_data["blah"], '123ABC exists!') 
     42 
     43    def test_old_file_types(self): 
     44        f = self.generic_reader.load(self.deprecated_file_type) 
     45        last_f = f[0] 
     46        if hasattr(last_f, "errors"): 
     47            self.assertEquals(len(last_f.errors), 1) 
     48        else: 
     49            self.fail("Errors did not propogate to the file properly.") 
     50 
     51    def test_same_file_unknown_extensions(self): 
     52        # Five files, all with the same content, but different file extensions 
     53        no_ext = find("test_data//TestExtensions") 
     54        not_xml = find("test_data//TestExtensions.notxml") 
     55        # Deprecated extensions 
     56        asc_dep = find("test_data//TestExtensions.asc") 
     57        nxs_dep = find("test_data//TestExtensions.nxs") 
     58        # Native extension as a baseline 
     59        xml_native = find("test_data//TestExtensions.xml") 
     60        # Load the files and check contents 
     61        no_ext_load = self.generic_reader.load(no_ext) 
     62        asc_load = self.generic_reader.load(asc_dep) 
     63        nxs_load = self.generic_reader.load(nxs_dep) 
     64        not_xml_load = self.generic_reader.load(not_xml) 
     65        xml_load = self.generic_reader.load(xml_native) 
     66        self.check_unknown_extension(no_ext_load[0]) 
     67        self.check_unknown_extension(asc_load[0]) 
     68        self.check_unknown_extension(nxs_load[0]) 
     69        self.check_unknown_extension(not_xml_load[0]) 
     70        self.check_unknown_extension(xml_load[0]) 
     71        # Be sure the deprecation warning is passed with the file 
     72        self.assertEquals(len(asc_load[0].errors), 1) 
     73        self.assertEquals(len(nxs_load[0].errors), 1) 
     74 
     75    def check_unknown_extension(self, data): 
     76        self.assertTrue(isinstance(data, Data1D)) 
     77        self.assertEquals(len(data.x), 138) 
     78        self.assertEquals(data.sample.ID, "TK49 c10_SANS") 
     79        self.assertEquals(data.meta_data["loader"], "CanSAS XML 1D") 
    3880 
    3981    def tearDown(self): 
Note: See TracChangeset for help on using the changeset viewer.