Ignore:
Timestamp:
Dec 30, 2011 3:33:16 PM (12 years ago)
Author:
Jae Cho <jhjcho@…>
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:
c067d12
Parents:
2365c0b
Message:

data/theory now can be saved from right-click-context menu in datapanel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter1D.py

    r45b6bfb r176fbf1  
    608608        #self.graph.render(self) 
    609609        #self.subplot.figure.canvas.draw_idle() 
    610          
    611          
    612          
    613     def _onsaveTXT(self, path): 
    614         """ 
    615         Save file as txt 
    616              
    617         :TODO: Refactor and remove this method. See TODO in _onSave. 
     610                        
     611    def _onSave(self, evt): 
     612        """ 
     613        Save a data set to a text file 
     614         
     615        :param evt: Menu event 
    618616         
    619617        """ 
    620618        data = self.plots[self.graph.selected_plottable] 
    621         
    622         if not path == None: 
    623             out = open(path, 'w') 
    624             has_errors = True 
    625             if data.dy == None or data.dy == []: 
    626                 has_errors = False 
    627             # Sanity check 
    628             if has_errors: 
    629                 try: 
    630                     if len(data.y) != len(data.dy): 
    631                         has_errors = False 
    632                 except: 
    633                     has_errors = False 
    634             if has_errors: 
    635                 if data.dx != None and data.dx != []: 
    636                     out.write("<X>   <Y>   <dY>   <dX>\n") 
    637                 else: 
    638                     out.write("<X>   <Y>   <dY>\n") 
    639             else: 
    640                 out.write("<X>   <Y>\n") 
    641                  
    642             for i in range(len(data.x)): 
    643                 if has_errors: 
    644                     if data.dx != None and data.dx != []: 
    645                         out.write("%g  %g  %g  %g\n" % (data.x[i],  
    646                                                     data.y[i], 
    647                                                     data.dy[i], 
    648                                                     data.dx[i])) 
    649                     else: 
    650                         out.write("%g  %g  %g\n" % (data.x[i],  
    651                                                     data.y[i], 
    652                                                     data.dy[i])) 
    653                 else: 
    654                     out.write("%g  %g\n" % (data.x[i],  
    655                                             data.y[i])) 
    656             out.close()                  
    657             try: 
    658                 self._default_save_location = os.path.dirname(path) 
    659                 self.parent._default_save_location = self._default_save_location 
    660             except: 
    661                 pass     
    662                  
    663     def _onSave(self, evt): 
    664         """ 
    665         Save a data set to a text file 
    666          
    667         :param evt: Menu event 
    668          
    669         """ 
    670         
    671         path = None 
    672         wildcard = "Text files (*.txt)|*.txt|"\ 
    673                     "CanSAS 1D files(*.xml)|*.xml"  
    674         default_name = self.plots[self.graph.selected_plottable].label 
     619        default_name = data.label 
    675620        if default_name.count('.') > 0: 
    676621            default_name = default_name.split('.')[0] 
    677622        default_name += "_out" 
    678623        if self.parent != None: 
    679             self._default_save_location = self.parent._default_save_location 
    680         dlg = wx.FileDialog(self, "Choose a file", 
    681                             self._default_save_location, 
    682                             default_name, wildcard , wx.SAVE) 
    683         
    684         if dlg.ShowModal() == wx.ID_OK: 
    685             path = dlg.GetPath() 
    686             # ext_num = 0 for .txt, ext_num = 1 for .xml 
    687             # This is MAC Fix 
    688             ext_num = dlg.GetFilterIndex() 
    689             if ext_num == 0: 
    690                 format = '.txt' 
    691             else: 
    692                 format = '.xml' 
    693             path = os.path.splitext(path)[0] + format 
    694             mypath = os.path.basename(path) 
    695              
    696             #TODO: This is bad design. The DataLoader is designed  
    697             #to recognize extensions. 
    698             # It should be a simple matter of calling the . 
    699             #save(file, data, '.xml') method 
    700             # of the sans.dataloader.loader.Loader class. 
    701             from sans.dataloader.loader import  Loader 
    702             #Instantiate a loader  
    703             loader = Loader()  
    704             data = self.plots[self.graph.selected_plottable] 
    705             format = ".txt" 
    706             if os.path.splitext(mypath)[1].lower() == format: 
    707                 # Make sure the ext included in the file name 
    708                 # especially on MAC 
    709                 fName = os.path.splitext(path)[0] + format 
    710                 self._onsaveTXT(fName) 
    711             format = ".xml" 
    712             if os.path.splitext(mypath)[1].lower() == format: 
    713                 # Make sure the ext included in the file name 
    714                 # especially on MAC 
    715                 fName = os.path.splitext(path)[0] + format 
    716                 loader.save(fName, data, format) 
    717             try: 
    718                 self._default_save_location = os.path.dirname(path) 
    719                 self.parent._default_save_location = self._default_save_location 
    720             except: 
    721                 pass     
    722         dlg.Destroy() 
     624            self.parent.save_data1d(data, default_name) 
    723625 
    724626    def _add_more_tool(self): 
Note: See TracChangeset for help on using the changeset viewer.