Changeset aa4b8379 in sasview


Ignore:
Timestamp:
Jun 18, 2008 4:10:06 PM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
3fd1ebc
Parents:
4972de2
Message:

Updated for interactive graphs. Improved for standalone use.

Location:
prview
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • prview/perspectives/pr/inversion_panel.py

    rb659551 raa4b8379  
    115115    pos_err  = 1.0 
    116116     
    117     def __init__(self, parent, id = -1, plots = None, **kwargs): 
     117    def __init__(self, parent, id = -1, plots = None, standalone=False, **kwargs): 
    118118        wx.Panel.__init__(self, parent, id = id, **kwargs) 
    119119         
     
    147147        ## Data manager 
    148148        self.manager   = None 
     149         
     150        ## Standalone flage 
     151        self.standalone = standalone 
    149152         
    150153        self._do_layout() 
     
    181184            #self.label_sugg.Show() 
    182185        elif name=='plotname': 
    183             self.plot_data.SetValue(str(value)) 
    184             self.plot_radio.SetValue(True) 
     186            if self.standalone==False: 
     187                self.plot_data.SetValue(str(value)) 
     188                self.plot_radio.SetValue(True) 
     189                self._on_pars_changed(None) 
     190        elif name=='datafile': 
     191            self.data_file.SetValue(str(value)) 
     192            self.file_radio.SetValue(True) 
    185193            self._on_pars_changed(None) 
    186194        else: 
     
    214222            self.alpha_estimate_ctl.GetValue() 
    215223        elif name=='plotname': 
    216             self.plot_data.GetValue() 
     224            if self.standalone==False: 
     225                self.plot_data.GetValue() 
     226        elif name=='datafile': 
     227            self.data_file.GetValue() 
    217228        else: 
    218229            wx.Panel.__getattr__(self, name) 
     
    230241 
    231242        # ----- I(q) data ----- 
    232         databox = wx.StaticBox(self, -1, "I(q) data") 
     243        databox = wx.StaticBox(self, -1, "I(q) data source") 
    233244         
    234245        boxsizer1 = wx.StaticBoxSizer(databox, wx.VERTICAL) 
     
    248259        pars_sizer.Add(choose_button, (iy,3), (1,1), wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    249260         
    250         iy += 1 
    251         self.plot_radio = wx.RadioButton(self, -1, "Plot data:") 
    252         self.plot_data = wx.TextCtrl(self, -1, size=(100,20)) 
    253         self.plot_data.SetEditable(False) 
    254         pars_sizer.Add(self.plot_radio, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    255         pars_sizer.Add(self.plot_data, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     261        if self.standalone==False: 
     262            iy += 1 
     263            self.plot_radio = wx.RadioButton(self, -1, "Plot data:") 
     264            self.plot_data = wx.TextCtrl(self, -1, size=(100,20)) 
     265            self.plot_data.SetEditable(False) 
     266            pars_sizer.Add(self.plot_radio, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     267            pars_sizer.Add(self.plot_data, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    256268         
    257269        boxsizer1.Add(pars_sizer, 0, wx.EXPAND) 
     
    476488        # If the pars are valid, estimate alpha 
    477489        if flag: 
    478             if self.plot_radio.GetValue(): 
     490            if self.standalone==False and self.plot_radio.GetValue(): 
    479491                dataset = self.plot_data.GetValue() 
    480492                self.manager.estimate_plot_inversion(alpha=alpha, nfunc=nfunc,  
     
    571583         
    572584        if flag: 
    573             if self.plot_radio.GetValue(): 
     585            if self.standalone==False and self.plot_radio.GetValue(): 
    574586                dataset = self.plot_data.GetValue() 
    575                 self.manager.setup_plot_inversion(alpha=alpha, nfunc=nfunc,  
    576                                                   d_max=dmax, 
    577                                                   q_min=qmin, q_max=qmax) 
     587                if len(dataset.strip())==0: 
     588                    message = "No data to invert. Select a data set before proceeding with P(r) inversion." 
     589                    wx.PostEvent(self.manager.parent, StatusEvent(status=message)) 
     590                else: 
     591                    self.manager.setup_plot_inversion(alpha=alpha, nfunc=nfunc,  
     592                                                      d_max=dmax, 
     593                                                      q_min=qmin, q_max=qmax) 
    578594            else: 
    579595                path = self.data_file.GetValue() 
    580                 self.manager.setup_file_inversion(alpha=alpha, nfunc=nfunc,  
    581                                                   d_max=dmax, path=path, 
    582                                                   q_min=qmin, q_max=qmax 
    583                                                   ) 
     596                if len(path.strip())==0: 
     597                    message = "No data to invert. Select a data set before proceeding with P(r) inversion." 
     598                    wx.PostEvent(self.manager.parent, StatusEvent(status=message)) 
     599                else: 
     600                    self.manager.setup_file_inversion(alpha=alpha, nfunc=nfunc,  
     601                                                      d_max=dmax, path=path, 
     602                                                      q_min=qmin, q_max=qmax 
     603                                                      ) 
    584604                 
    585605        else: 
  • prview/perspectives/pr/pr.py

    rb659551 raa4b8379  
    66import sys 
    77import wx 
     8import logging 
    89from sans.guitools.plottables import Data1D, Theory1D 
    910from sans.guicomm.events import NewPlotEvent, StatusEvent     
    1011import math, numpy 
    1112from sans.pr.invertor import Invertor 
     13 
     14PR_FIT_LABEL    = "P_{fit}(r)" 
     15PR_LOADED_LABEL = "P_{loaded}(r)" 
     16IQ_DATA_LABEL   = "I_{obs}(q)" 
     17 
     18import wx.lib 
     19(NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent() 
     20 
    1221 
    1322class Plugin: 
     
    4150        # Start with a good default 
    4251        self.elapsed = 0.022 
     52        self.iq_data_shown = False 
    4353         
    4454        ## Current invertor 
     
    5464        ## Number of P(r) points to display on the output plot 
    5565        self._pr_npts = 51 
     66        ## Flag to let the plug-in know that it is running standalone 
     67        self.standalone = True 
     68         
     69        # Log startup 
     70        logging.info("Pr(r) plug-in started") 
     71         
     72         
    5673 
    5774    def populate_menu(self, id, owner): 
     
    332349        """ 
    333350        # Look whether this Graph contains P(r) data 
     351        #if graph.selected_plottable==IQ_DATA_LABEL: 
    334352        for item in graph.plottables: 
    335             if item.name=="P_{fit}(r)": 
    336                  
    337                 return [["Compute P(r)", "Compute P(r) from distribution", self._on_context_inversion], 
    338                        ["Add P(r) data", "Load a data file and display it on this plot", self._on_add_data], 
     353            if item.name==PR_FIT_LABEL: 
     354                return [["Add P(r) data", "Load a data file and display it on this plot", self._on_add_data], 
    339355                       ["Change number of P(r) points", "Change the number of points on the P(r) output", self._on_pr_npts]] 
    340                  
    341         return [["Compute P(r)", "Compute P(r) from distribution", self._on_context_inversion]] 
     356 
     357            elif item.name==graph.selected_plottable: 
     358                return [["Compute P(r)", "Compute P(r) from distribution", self._on_context_inversion]]       
     359                 
     360        return [] 
    342361 
    343362    def _on_add_data(self, evt): 
     
    429448         
    430449        # Make a plot of I(q) data 
    431         new_plot = Data1D(self.pr.x, self.pr.y, dy=self.pr.err) 
    432         new_plot.name = "I_{obs}(q)" 
    433         new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
    434         new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    435         #new_plot.group_id = "test group" 
    436         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 
     450        if False: 
     451            new_plot = Data1D(self.pr.x, self.pr.y, dy=self.pr.err) 
     452            new_plot.name = "I_{obs}(q)" 
     453            new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
     454            new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
     455            #new_plot.group_id = "test group" 
     456            wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 
    437457                 
    438458        # Show I(q) fit 
     
    454474        new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
    455475        new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
     476        new_plot.interactive = True 
    456477        #new_plot.group_id = "test group" 
    457478        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 
    458479         
     480        # Get Q range 
     481        self.control_panel.q_min = self.pr.x.min() 
     482        self.control_panel.q_max = self.pr.x.max() 
     483             
     484 
    459485         
    460486    def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None): 
     
    510536             
    511537        self.pr = pr 
     538        self.iq_data_shown = True 
    512539 
    513540           
     
    624651         
    625652        # If we have more than one displayed plot, make the user choose 
    626         if len(panel.plots)>1: 
    627             dialog = InversionDlg(None, -1, "P(r) Inversion", panel.plots, pars=False) 
    628             dialog.set_content(self.last_data, self.nfunc, self.alpha, self.max_length) 
    629             if dialog.ShowModal() == wx.ID_OK: 
    630                 dataset = dialog.get_content() 
    631                 dialog.Destroy() 
    632             else: 
    633                 dialog.Destroy() 
    634                 return 
     653        if len(panel.plots)>1 and panel.graph.selected_plottable in panel.plots: 
     654            dataset = panel.graph.selected_plottable 
     655            if False: 
     656                dialog = InversionDlg(None, -1, "P(r) Inversion", panel.plots, pars=False) 
     657                dialog.set_content(self.last_data, self.nfunc, self.alpha, self.max_length) 
     658                if dialog.ShowModal() == wx.ID_OK: 
     659                    dataset = dialog.get_content() 
     660                    dialog.Destroy() 
     661                else: 
     662                    dialog.Destroy() 
     663                    return 
    635664        elif len(panel.plots)==1: 
    636665            dataset = panel.plots.keys()[0] 
     
    646675        self.control_panel.alpha = self.alpha 
    647676        self.parent.set_perspective(self.perspective) 
     677        self.control_panel._on_invert(None) 
    648678             
    649679    def get_panels(self, parent): 
     
    654684         
    655685        self.parent = parent 
    656         self.control_panel = InversionControl(self.parent, -1, style=wx.RAISED_BORDER) 
     686        self.control_panel = InversionControl(self.parent, -1,  
     687                                              style=wx.RAISED_BORDER, 
     688                                              standalone=self.standalone) 
    657689        self.control_panel.set_manager(self) 
    658690        self.control_panel.nfunc = self.nfunc 
     
    662694        self.perspective = [] 
    663695        self.perspective.append(self.control_panel.window_name) 
     696         
     697        self.parent.Bind(EVT_PR_FILE, self._on_new_file) 
     698         
    664699        return [self.control_panel] 
     700     
     701    def _on_new_file(self, evt): 
     702        """ 
     703            Called when the application manager posted an 
     704            EVT_PR_FILE event. Just prompt the control 
     705            panel to load a new data file. 
     706        """ 
     707        self.control_panel._change_file(None) 
    665708     
    666709    def get_perspective(self): 
  • prview/sansview.py

    r4a5de6f raa4b8379  
    1  
     1import wx 
    22#import gui_manager 
    33from sans.guiframe import gui_manager 
     
    55# For py2exe, import config here 
    66import local_config 
     7from perspectives.pr.pr import NewPrFileEvent 
    78 
     9class PrFrame(gui_manager.ViewerFrame): 
     10    def _on_open(self, event): 
     11        wx.PostEvent(self, NewPrFileEvent()) 
     12 
     13class PrApp(gui_manager.ViewApp): 
     14    def OnInit(self): 
     15        #from gui_manager import ViewerFrame 
     16        self.frame = PrFrame(None, -1, local_config.__appname__)     
     17        self.frame.Show(True) 
     18 
     19        if hasattr(self.frame, 'special'): 
     20            print "Special?", self.frame.special.__class__.__name__ 
     21            self.frame.special.SetCurrent() 
     22        self.SetTopWindow(self.frame) 
     23        return True 
     24     
    825class SansView(): 
    926     
     
    1330        """ 
    1431        #from gui_manager import ViewApp 
    15         self.gui = gui_manager.ViewApp(0) 
     32        #self.gui = gui_manager.ViewApp(0)  
     33        self.gui = PrApp(0) 
    1634         
    1735        # Add perspectives to the basic application 
     
    1937        # dynamically 
    2038        import perspectives.pr as module 
    21         plug = module.Plugin() 
    22         self.gui.add_perspective(plug) 
     39        self.pr_plug = module.Plugin() 
     40        self.gui.add_perspective(self.pr_plug) 
    2341             
    2442        # Build the GUI 
     
    3048        # Start the main loop 
    3149        self.gui.MainLoop()   
     50         
    3251 
    3352if __name__ == "__main__":  
Note: See TracChangeset for help on using the changeset viewer.