Changeset ed8ad21 in sasview


Ignore:
Timestamp:
Jan 31, 2011 7:51:23 AM (13 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:
d0ecb36
Parents:
ec02ddd
Message:

added 2D save as a file in context menu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guiframe/local_perspectives/plotting/Plotter2D.py

    r55a0dc1 red8ad21  
    1313import wx 
    1414import sys 
     15import os 
    1516import math 
    1617import pylab 
     
    240241        wx.EVT_MENU(self, id, self.onPrinterPreview) 
    241242         
     243        # saving data 
     244        plot = self.data2D 
     245        id = wx.NewId() 
     246        name = plot.name 
     247        slicerpop.Append(id, "&Save as a file (DAT)" ) 
     248        self.action_ids[str(id)] = plot 
     249        wx.EVT_MENU(self, id, self._onSave) 
     250 
    242251        slicerpop.AppendSeparator() 
    243252        if len(self.data2D.detector) == 1:         
     
    554563            event = self._getEmptySlicerEvent() 
    555564            wx.PostEvent(self, event) 
    556     
     565             
     566    def _onSave(self, evt): 
     567        """ 
     568        Save a data set to a dat(text) file 
     569         
     570        :param evt: Menu event 
     571         
     572        """ 
     573        id = str(evt.GetId()) 
     574        if id in self.action_ids:          
     575             
     576            path = None 
     577            wildcard = "IGOR/DAT 2D file in Q_map (*.dat)|*.DAT" 
     578            dlg = wx.FileDialog(self, "Choose a file", 
     579                                self._default_save_location, 
     580                                 "", wildcard , wx.SAVE) 
     581            
     582            if dlg.ShowModal() == wx.ID_OK: 
     583                path = dlg.GetPath() 
     584                mypath = os.path.basename(path) 
     585                 
     586                #TODO: This is bad design. The DataLoader is designed  
     587                #to recognize extensions. 
     588                # It should be a simple matter of calling the . 
     589                #save(file, data, '.xml') method 
     590                # of the DataLoader.loader.Loader class. 
     591                from DataLoader.loader import  Loader 
     592                #Instantiate a loader  
     593                loader = Loader()  
     594                data = self.data2D 
     595 
     596                format = ".dat" 
     597                if os.path.splitext(mypath)[1].lower() == format: 
     598                    loader.save(path, data, format) 
     599                try: 
     600                    self._default_save_location = os.path.dirname(path) 
     601                except: 
     602                    pass     
     603            dlg.Destroy() 
Note: See TracChangeset for help on using the changeset viewer.