Changeset 96d293da in sasview for src


Ignore:
Timestamp:
Aug 24, 2016 11:15:28 AM (8 years ago)
Author:
lewis
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, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
d45d590
Parents:
5a525e1
git-author:
Lewis O'Driscoll <lewis.o'driscoll@…> (08/24/16 10:59:41)
git-committer:
Lewis O'Driscoll <lewis.o'driscoll@…> (08/24/16 11:15:28)
Message:

Implement save analysis in corfunc

Location:
src/sas/sasgui/perspectives/corfunc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/corfunc/corfunc.py

    r5a525e1 r96d293da  
    3333        self.state_reader = Reader(self.set_state) 
    3434        self._extensions = '.cor' 
    35         l = Loader() 
    36         l.associate_file_reader('.cor', self.state_reader) 
    3735 
    3836    def get_panels(self, parent): 
     
    4846        self._frame_set_helper() 
    4947        self.perspective.append(self.corfunc_panel.window_name) 
     48 
     49        l = Loader() 
     50        l.associate_file_reader('.cor', self.state_reader) 
    5051 
    5152        return [self.corfunc_panel] 
     
    8283        Callback for CorfuncState reader. Called when a .cor file is loaded 
    8384        """ 
    84         self.corfunc_panel.set_state(state=state, data=datainfo) 
     85        if isinstance(datainfo, list): 
     86            data = datainfo[0] 
     87        else: 
     88            data = datainfo 
     89        self.corfunc_panel.set_state(state=state, data=data) 
     90        self.on_perspective(event=None) 
     91        data = self.parent.create_gui_data(data, None) 
     92        self.parent.add_data({ data.id: data }) 
    8593 
    8694    def set_data(self, data_list=None): 
  • src/sas/sasgui/perspectives/corfunc/corfunc_panel.py

    r204f628 r96d293da  
    11import wx 
    22import sys 
     3import os 
    34import numpy as np 
    45from wx.lib.scrolledpanel import ScrolledPanel 
    56from sas.sasgui.guiframe.events import PlotQrangeEvent 
    67from sas.sasgui.guiframe.events import StatusEvent 
     8from sas.sasgui.guiframe.events import PanelOnFocusEvent 
    79from sas.sasgui.guiframe.panel_base import PanelBase 
    810from sas.sasgui.guiframe.utils import check_float 
     
    299301        doc_viewer = DocumentationWindow(self, -1, tree_location, "", 
    300302                                          "Correlation Function Help") 
     303 
     304    def get_save_flag(self): 
     305        if self._data is not None: 
     306            return True 
     307        return False 
     308 
     309    def on_set_focus(self, event=None): 
     310        if self._manager.parent is not None: 
     311            wx.PostEvent(self._manager.parent, PanelOnFocusEvent(panel=self)) 
     312 
     313    def on_save(self, event=None): 
     314        """ 
     315        Save corfunc state into a file 
     316        """ 
     317        # Ask the user the location of the file to write to. 
     318        path = None 
     319        default_save_location = os.getcwd() 
     320        if self._manager.parent != None: 
     321            default_save_location = self._manager.parent.get_save_location() 
     322 
     323        dlg = wx.FileDialog(self, "Choose a file", 
     324                            default_save_location, \ 
     325                            self.window_caption, "*.cor", wx.SAVE) 
     326        if dlg.ShowModal() == wx.ID_OK: 
     327            path = dlg.GetPath() 
     328            default_save_location = os.path.dirname(path) 
     329            if self._manager.parent != None: 
     330                self._manager.parent._default_save_location = default_save_location 
     331        else: 
     332            return None 
     333 
     334        dlg.Destroy() 
     335        # MAC always needs the extension for saving 
     336        extens = ".cor" 
     337        # Make sure the ext included in the file name 
     338        f_name = os.path.splitext(path)[0] + extens 
     339        self._manager.state_reader.write(f_name, self._data, self.get_state()) 
    301340 
    302341    def save_project(self, doc=None): 
  • src/sas/sasgui/perspectives/corfunc/corfunc_state.py

    rcaeb382 r96d293da  
    1010from sas.sasgui.guiframe.gui_style import GUIFRAME_ID 
    1111from sas.sasgui.guiframe.dataFitting import Data1D 
     12from sas.sascalc.dataloader.data_info import Data1D as LoaderData1D 
    1213from sas.sascalc.dataloader.loader import Loader 
    1314 
     
    250251    type_name = "Corfunc" 
    251252 
    252     type = ["Invariant file (*.inv)|*.inv", 
     253    type = ["Corfunc file (*.cor)|*.cor", 
    253254            "SASView file (*.svs)|*.svs"] 
    254255 
     
    312313        if datainfo is None: 
    313314            datainfo = Data1D(x=[], y=[]) 
    314         elif not issubclass(datainfo.__class__, Data1D): 
    315             msg = ("The CanSAS writer expects a Data1D instance. {} was ", 
     315        elif not (isinstance(datainfo, Data1D) or isinstance(datainfo, LoaderData1D)): 
     316            msg = ("The CanSAS writer expects a Data1D instance. {} was " 
    316317                "provided").format(datainfo.__class__.__name__) 
    317318            raise RuntimeError, msg 
Note: See TracChangeset for help on using the changeset viewer.