Changeset 2d443fd in sasview


Ignore:
Timestamp:
Sep 13, 2011 5:29:59 PM (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:
3858e0f
Parents:
4e2fc799
Message:

fixed sld dialog saving

Location:
sansguiframe/src/sans/guiframe/local_perspectives/plotting
Files:
2 edited

Legend:

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

    rc553b18 r2d443fd  
    373373            name = plot.name 
    374374            self._slicerpop.Append(id, "&Save Points as a File") 
     375            wx.EVT_MENU(self, id, self._onSave) 
    375376            self._slicerpop.AppendSeparator() 
    376377            if plot.name != 'SLD': 
    377                 wx.EVT_MENU(self, id, self._onSave) 
    378378                id = wx.NewId() 
    379379                self._slicerpop.Append(id, '&Linear Fit') 
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/profile_dialog.py

    r9a3d433 r2d443fd  
    33""" 
    44import wx 
     5import os 
    56import sys 
    67from copy import deepcopy 
     
    3435    """ 
    3536    ## Internal nickname for the window, used by the AUI manager 
    36     window_name = "SLD Profile" 
     37    window_name = "Scattering Length Density Profile" 
    3738    ## Name to appear on the window title bar 
    38     window_caption = "SLD Profile" 
     39    window_caption = "Scattering Length Density Profile" 
    3940    ## Flag to tell the AUI manager to put this panel in the center pane 
    4041    CENTER_PANE = True 
     
    4950            kwds = [] 
    5051            self.SetWindowVariant(variant=FONT_VARIANT) 
     52 
    5153            self.SetTitle("Scattering Length Density Profile") 
    52             self.parent = base 
     54            self.parent = parent 
    5355            self.data = data 
    5456            self.str = self.data.__str__() 
     
    167169        # NOt implemented 
    168170        pass 
    169  
     171     
     172    def on_change_caption(self, name, old_caption, new_caption): 
     173        """ 
     174        """ 
     175        self.parent.parent.parent.on_change_caption(name, old_caption, new_caption) 
    170176     
    171177     
     
    184190        # Keep track of the parent Frame 
    185191        self.parent = parent 
     192        self.window_name = "Scattering Length Density Profile" 
     193        self.window_caption = self.window_name 
    186194        # Internal list of plottable names (because graph  
    187195        # doesn't have a dictionary of handles for the plottables) 
     
    191199        for idx in range(0, len(axes)): 
    192200            self.axes_label.append(axes[idx]) 
     201        self.xaxis_label = '' 
     202        self.xaxis_unit = '' 
     203        self.yaxis_label = '' 
     204        self.yaxis_unit = '' 
    193205         
    194206    def add_image(self, plot): 
     
    204216        #add axes 
    205217        x1_label = self.axes_label[0] 
    206         self.graph.xaxis('\\rm{%s} '% x1_label, 'A') 
    207         self.graph.yaxis('\\rm{SLD} ', '10^{-6}A^{-2}') 
     218        self.xaxis_label = '\\rm{%s} '% x1_label 
     219        self.xaxis_unit = 'A' 
     220        self.graph.xaxis(self.xaxis_label, self.xaxis_unit) 
     221        self.yaxis_label = '\\rm{SLD} ' 
     222        self.yaxis_unit = '10^{-6}A^{-2}' 
     223        self.graph.yaxis(self.yaxis_label, self.yaxis_unit) 
    208224        #draw 
    209225        self.graph.render(self) 
     
    235251        """ 
    236252        pass  
    237          
     253     
     254    def onChangeCaption(self, event): 
     255        """ 
     256        Not implemented 
     257        """ 
     258        pass 
     259     
     260    def _onSave(self, evt): 
     261        """ 
     262        Save a data set to a text file 
     263         
     264        :param evt: Menu event 
     265         
     266        """ 
     267        
     268        path = None 
     269        wildcard = "Text files (*.txt)|*.txt|"\ 
     270                    "CanSAS 1D files(*.xml)|*.xml"  
     271        default_name = "sld_profile" 
     272        if self.parent != None: 
     273            self._default_save_location = self.parent.parent._default_save_location 
     274        dlg = wx.FileDialog(self, "Choose a file", 
     275                            self._default_save_location, 
     276                            default_name, wildcard , wx.SAVE) 
     277        
     278        if dlg.ShowModal() == wx.ID_OK: 
     279            path = dlg.GetPath() 
     280            # ext_num = 0 for .txt, ext_num = 1 for .xml 
     281            # This is MAC Fix 
     282            ext_num = dlg.GetFilterIndex() 
     283            if ext_num == 0: 
     284                format = '.txt' 
     285            else: 
     286                format = '.xml' 
     287            path = os.path.splitext(path)[0] + format 
     288            mypath = os.path.basename(path) 
     289             
     290            #TODO: This is bad design. The DataLoader is designed  
     291            #to recognize extensions. 
     292            # It should be a simple matter of calling the . 
     293            #save(file, data, '.xml') method 
     294            # of the sans.dataloader.loader.Loader class. 
     295            from sans.dataloader.loader import  Loader 
     296            #Instantiate a loader  
     297            loader = Loader()  
     298            data = self.parent.data 
     299            format = ".txt" 
     300            if os.path.splitext(mypath)[1].lower() == format: 
     301                # Make sure the ext included in the file name 
     302                # especially on MAC 
     303                fName = os.path.splitext(path)[0] + format 
     304                self._onsaveTXT(fName) 
     305            format = ".xml" 
     306            if os.path.splitext(mypath)[1].lower() == format: 
     307                # Make sure the ext included in the file name 
     308                # especially on MAC 
     309                fName = os.path.splitext(path)[0] + format 
     310                loader.save(fName, data, format) 
     311            try: 
     312                self._default_save_location = os.path.dirname(path) 
     313                self.parent.parent._default_save_location = self._default_save_location 
     314            except: 
     315                pass     
     316        dlg.Destroy() 
     317          
    238318class ViewerFrame(wx.Frame): 
    239319    """ 
Note: See TracChangeset for help on using the changeset viewer.