Index: prview/perspectives/pr/inversion_panel.py
===================================================================
--- prview/perspectives/pr/inversion_panel.py	(revision 3e41f43f7d0b8c4264182203e33d8cbf55977c98)
+++ prview/perspectives/pr/inversion_panel.py	(revision 75df58b1beae85913437ed9d779e48bb1169235d)
@@ -10,5 +10,6 @@
 import logging
 from wx.lib.scrolledpanel import ScrolledPanel
-from sans.guicomm.events import StatusEvent    
+from sans.guiframe.events import StatusEvent   
+from sans.guiframe.panel_base import PanelBase 
 from inversion_state import InversionState
 from pr_widgets import PrTextCtrl
@@ -18,5 +19,5 @@
 
 
-class InversionControl(ScrolledPanel):
+class InversionControl(ScrolledPanel, PanelBase):
     """
     """
@@ -35,4 +36,5 @@
         """
         ScrolledPanel.__init__(self, parent, id=id, **kwargs)
+        PanelBase.__init__(self)
         self.SetupScrolling()
         
@@ -72,18 +74,12 @@
         self.alpha_estimate_ctl = None
         self.nterms_estimate_ctl = None
-        
         ## D_max distance explorator
         self.distance_explorator_ctl = None
-        
         ## Data manager
         self.manager   = None
-        
         ## Standalone flage
         self.standalone = standalone
-        
         ## Default file location for save
         self._default_save_location = os.getcwd()
-        
-        
         # Default width
         self._default_width = 350
@@ -578,8 +574,8 @@
         hint_msg = "Radius of gyration for the computed P(r)."
         self.rg_ctl.SetToolTipString(hint_msg)
-        self.iq0_ctl   = OutputTextCtrl(self, -1, size=(60,20))
+        self.iq0_ctl   = OutputTextCtrl(self, -1, size=(60, 20))
         hint_msg = "Scattering intensity at Q=0 for the computed P(r)."
         self.iq0_ctl.SetToolTipString(hint_msg)
-        self.bck_ctl   = OutputTextCtrl(self, -1, size=(60,20))
+        self.bck_ctl   = OutputTextCtrl(self, -1, size=(60, 20))
         self.bck_ctl.SetToolTipString("Value of estimated constant background.")
         
@@ -592,13 +588,13 @@
         label_pos_err = wx.StaticText(self, -1, "1-sigma positive fraction")
         
-        self.time_ctl = OutputTextCtrl(self, -1, size=(60,20))
+        self.time_ctl = OutputTextCtrl(self, -1, size=(60, 20))
         hint_msg = "Computation time for the last inversion, in seconds."
         self.time_ctl.SetToolTipString(hint_msg)
         
-        self.chi2_ctl = OutputTextCtrl(self, -1, size=(60,20))
+        self.chi2_ctl = OutputTextCtrl(self, -1, size=(60, 20))
         self.chi2_ctl.SetToolTipString("Chi^2 over degrees of freedom.")
         
         # Oscillation parameter
-        self.osc_ctl = OutputTextCtrl(self, -1, size=(60,20))
+        self.osc_ctl = OutputTextCtrl(self, -1, size=(60, 20))
         hint_msg = "Oscillation parameter. P(r) for a sphere has an "
         hint_msg += " oscillation parameter of 1.1."
@@ -606,5 +602,5 @@
         
         # Positive fraction figure of merit
-        self.pos_ctl = OutputTextCtrl(self, -1, size=(60,20))
+        self.pos_ctl = OutputTextCtrl(self, -1, size=(60, 20))
         hint_msg = "Fraction of P(r) that is positive. "
         hint_msg += "Theoretically, P(r) is defined positive."
@@ -612,5 +608,5 @@
         
         # 1-simga positive fraction figure of merit
-        self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60,20))
+        self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60, 20))
         message  = "Fraction of P(r) that is at least 1 standard deviation"
         message += " greater than zero.\n"
@@ -775,8 +771,5 @@
         height = 0
         width  = 0
-        
         flag = True
-        
-        
         # Read slit height
         try:
@@ -917,25 +910,17 @@
             wx.PostEvent(self.parent, StatusEvent(status=message))
         
-    def _change_file(self, evt=None, filepath=None):
+    def _change_file(self, evt=None, filepath=None, data=None):
         """
         Choose a new input file for I(q)
         """
-        import os
-        if not self.manager==None:
-            path = self.manager.choose_file(path=filepath)
-            
-            if path and os.path.isfile(path):
-                self.plot_data.SetValue(str(path))
-                try:
-                    self.manager.show_data(path, reset=True)
-                    self._on_pars_changed(None)
-                
-                    # Perform inversion
-                    if self.standalone == True:
-                        self._on_invert(None)
-                except:
-                    # Invalid data
-                    msg = "InversionControl._change_file: %s" % sys.exc_value
-                    logging.error(msg)                    
+        if not self.manager is None:
+            self.plot_data.SetValue(str(data.name))
+            try:
+                self.manager.show_data(data=data, reset=True)
+                self._on_pars_changed(None)
+                self._on_invert(None)
+            except:
+                msg = "InversionControl._change_file: %s" % sys.exc_value
+                logging.error(msg)                    
 
 class HelpDialog(wx.Dialog):
@@ -954,5 +939,5 @@
         explanation = help()
            
-        label_explain = wx.StaticText(self, -1, explanation, size=(350,320))
+        label_explain = wx.StaticText(self, -1, explanation, size=(350, 320))
             
         vbox.Add(label_explain, 0, wx.ALL|wx.EXPAND, 15)
@@ -991,13 +976,12 @@
         
         label_npts = wx.StaticText(self, -1, "Number of points")
-        self.npts_ctl = PrTextCtrl(self, -1, size=(100,20))
+        self.npts_ctl = PrTextCtrl(self, -1, size=(100, 20))
                  
-        pars_sizer = wx.GridBagSizer(5,5)
+        pars_sizer = wx.GridBagSizer(5, 5)
         iy = 0
-        pars_sizer.Add(label_npts,      (iy,0), (1,1), wx.LEFT, 15)
-        pars_sizer.Add(self.npts_ctl,   (iy,1), (1,1), wx.RIGHT, 0)
+        pars_sizer.Add(label_npts, (iy, 0), (1, 1), wx.LEFT, 15)
+        pars_sizer.Add(self.npts_ctl, (iy, 1), (1, 1), wx.RIGHT, 0)
         
         vbox.Add(pars_sizer, 0, wx.ALL|wx.EXPAND, 15)
-
 
         static_line = wx.StaticLine(self, -1)
Index: prview/perspectives/pr/pr.py
===================================================================
--- prview/perspectives/pr/pr.py	(revision 3e41f43f7d0b8c4264182203e33d8cbf55977c98)
+++ prview/perspectives/pr/pr.py	(revision 75df58b1beae85913437ed9d779e48bb1169235d)
@@ -19,13 +19,20 @@
 import logging
 import time
-from sans.guiframe.dataFitting import Data1D, Theory1D
-from sans.guicomm.events import NewPlotEvent, StatusEvent    
-import math, numpy
+import copy
+import math
+import numpy
+import pylab
+from sans.guiframe.dataFitting import Data1D
+from sans.guiframe.dataFitting import Theory1D
+from sans.guiframe.events import NewPlotEvent
+from sans.guiframe.events import StatusEvent    
+
 from sans.pr.invertor import Invertor
 from DataLoader.loader import Loader
+from DataLoader.data_info import Data1D as LoaderData1D
 import DataLoader
 from sans.guiframe.data_loader import load_error 
-
-import copy
+from sans.guiframe.plugin_base import PluginBase
+
 
 PR_FIT_LABEL       = r"$P_{fit}(r)$"
@@ -35,8 +42,8 @@
 IQ_SMEARED_LABEL   = r"$I_{smeared}(q)$"
 
-import wx.lib
-(NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent()
-
-from sans.guiframe.plugin_base import PluginBase
+#import wx.lib
+#(NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent()
+
+
 
 class Plugin(PluginBase):
@@ -169,9 +176,7 @@
         """
         from sans.pr.invertor import Invertor
-        import numpy
-        import pylab
-        import math
-        from sans.guicomm.events import NewPlotEvent            
-        from danse.common.plottools import Data1D, Theory1D
+            
+        from danse.common.plottools import Data1D as PlotData1D
+        from danse.common.plottools import Theory1D as Theory1D
         
         # Generate P(r) for sphere
@@ -205,8 +210,9 @@
 
         # Show input P(r)
-        new_plot = Data1D(pr.x, pr.y, dy=pr.err)
+        new_plot = PlotData1D(pr.x, pr.y, dy=pr.err)
         new_plot.name = "P_{obs}(r)"
         new_plot.xaxis("\\rm{r}", 'A')
         new_plot.yaxis("\\rm{P(r)} ","cm^{-3}")
+        print "_fit_pr"
         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Pr"))
 
@@ -221,9 +227,5 @@
         """
         """
-        import numpy
-        import pylab
-        import math
-        from sans.guicomm.events import NewPlotEvent            
-        from danse.common.plottools import Data1D, Theory1D
+        from danse.common.plottools import Theory1D as PlotTheory1D
         # Show P(r)
         y_true = numpy.zeros(len(x))
@@ -237,12 +239,12 @@
         
         # Show the theory P(r)
-        new_plot = Theory1D(x, y_true)
+        new_plot = PlotTheory1D(x, y_true)
         new_plot.name = "P_{true}(r)"
         new_plot.xaxis("\\rm{r}", 'A')
         new_plot.yaxis("\\rm{P(r)} ","cm^{-3}")
         
-        
         #Put this call in plottables/guitools    
         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Sphere P(r)"))
+       
         
     def get_npts(self):
@@ -257,10 +259,6 @@
     def show_iq(self, out, pr, q=None):
         """
-        """
-        import numpy
-        import pylab
-        import math
-        from sans.guicomm.events import NewPlotEvent            
-        from danse.common.plottools import Data1D, Theory1D
+        """  
+        from danse.common.plottools import Theory1D as PlotTheory1D
 
         qtemp = pr.x
@@ -294,5 +292,5 @@
                 print "Error getting error", value, x[i]
                 
-        new_plot = Theory1D(x, y)
+        new_plot = PlotTheory1D(x, y)
         new_plot.name = IQ_FIT_LABEL
         new_plot.xaxis("\\rm{Q}", 'A^{-1}')
@@ -348,10 +346,7 @@
     def show_pr(self, out, pr, cov=None):
         """
-        """
-        import numpy
-        import pylab
-        import math
-        from sans.guicomm.events import NewPlotEvent            
-        from danse.common.plottools import Data1D, Theory1D
+        """     
+        from danse.common.plottools import Data1D as PlotData1D 
+        from danse.common.plottools import Theory1D as PlotTheory1D
         
         # Show P(r)
@@ -387,10 +382,11 @@
         
         if cov2==None:
-            new_plot = Theory1D(x, y)
+            new_plot = PlotTheory1D(x, y)
         else:
-            new_plot = Data1D(x, y, dy=dy)
+            new_plot = PlotData1D(x, y, dy=dy)
         new_plot.name = PR_FIT_LABEL
         new_plot.xaxis("\\rm{r}", 'A')
         new_plot.yaxis("\\rm{P(r)} ","cm^{-3}")
+        new_plot.title = "P(r) fit"
         # Make sure that the plot is linear
         new_plot.xtransform="x"
@@ -400,13 +396,6 @@
         return x, pr.d_max
         
-        
-    def choose_file(self, path=None):
-        """
-        """
-        #TODO: this should be in a common module
-        return self.parent.choose_file(path=path)
-                
-                
-    def load(self, path):
+                
+    def load(self, data):
         """
         Load data. This will eventually be replaced
@@ -422,9 +411,9 @@
                 self.path = path
                 
-        self._current_file_data = FileData(path)
+        self._current_file_data = FileData(data.path)
         
         # Use data loader to load file
-        dataread = Loader().load(path)
-        
+        #dataread = Loader().load(path)
+        dataread = data
         # Notify the user if we could not read the file
         if dataread is None:
@@ -574,19 +563,21 @@
         #if graph.selected_plottable==IQ_DATA_LABEL:
         for item in graph.plottables:
-            if item.name==PR_FIT_LABEL:
-                m_list = [["Add P(r) data", "Load a data file and display it on this plot", self._on_add_data],
-                       ["Change number of P(r) points", "Change the number of points on the P(r) output", self._on_pr_npts]]
-
-                if self._scale_output_unity==True or self._normalize_output==True:
-                    m_list.append(["Disable P(r) scaling", 
-                                   "Let the output P(r) keep the scale of the data", 
+            if item.name == PR_FIT_LABEL:
+                #add_data_hint = "Load a data file and display it on this plot"
+                #["Add P(r) data",add_data_hint , self._on_add_data],
+                change_n_hint = "Change the number of"
+                change_n_hint += " points on the P(r) output"
+                change_n_label = "Change number of P(r) points"
+                m_list = [[change_n_label, change_n_hint , self._on_pr_npts]]
+
+                if self._scale_output_unity or self._normalize_output:
+                    hint = "Let the output P(r) keep the scale of the data"
+                    m_list.append(["Disable P(r) scaling", hint, 
                                    self._on_disable_scaling])
-                
-                if self._scale_output_unity==False:
+                if not self._scale_output_unity:
                     m_list.append(["Scale P_max(r) to unity", 
                                    "Scale P(r) so that its maximum is 1", 
                                    self._on_scale_unity])
-                    
-                if self._normalize_output==False:
+                if not self._normalize_output:
                     m_list.append(["Normalize P(r) to unity", 
                                    "Normalize the integral of P(r) to 1", 
@@ -594,12 +585,19 @@
                     
                 return m_list
-                #return [["Add P(r) data", "Load a data file and display it on this plot", self._on_add_data],
-                #       ["Change number of P(r) points", "Change the number of points on the P(r) output", self._on_pr_npts]]
-
-            elif item.name==graph.selected_plottable:
-	            #TODO: we might want to check that the units are consistent with I(q)
-	            #      before allowing this menu item
-                if not self.standalone and issubclass(item.__class__, DataLoader.data_info.Data1D):
-                    return [["Compute P(r)", "Compute P(r) from distribution", self._on_context_inversion]]      
+                #return [["Add P(r) data", 
+                #"Load a data file and display it on this plot",
+                # self._on_add_data],
+                #       ["Change number of P(r) points",
+                # "Change the number of points on the P(r) output",
+                # self._on_pr_npts]]
+
+            elif item.name == graph.selected_plottable:
+	            #TODO: we might want to check that the units are 
+	            #     consistent with I(q) before allowing this menu item
+                if not self.standalone and \
+                issubclass(item.__class__, DataLoader.data_info.Data1D):
+                    return [["Compute P(r)", 
+                             "Compute P(r) from distribution", 
+                             self._on_context_inversion]]      
                 
         return []
@@ -619,6 +617,7 @@
         for plot in self._added_plots:
             self._added_plots[plot].y = numpy.copy(self._default_Iq[plot])
-            wx.PostEvent(self.parent, NewPlotEvent(plot=self._added_plots[plot], 
-                                                   title=self._added_plots[plot].name,
+            wx.PostEvent(self.parent, 
+                         NewPlotEvent(plot=self._added_plots[plot], 
+                                      title=self._added_plots[plot].name,
                                                    update=True))        
         
@@ -651,6 +650,7 @@
             new_plot.yaxis("\\rm{P(r)} ","cm^{-3}")
             
-            wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, update=True,
-                                                   title=self._added_plots[plot].name))
+            wx.PostEvent(self.parent, 
+                         NewPlotEvent(plot=new_plot, update=True,
+                                         title=self._added_plots[plot].name))
         
     def _on_scale_unity(self, evt):
@@ -679,6 +679,7 @@
             new_plot.yaxis("\\rm{P(r)} ","cm^{-3}")
             
-            wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, update=True,
-                                                   title=self._added_plots[plot].name))        
+            wx.PostEvent(self.parent, 
+                         NewPlotEvent(plot=new_plot, update=True,
+                                title=self._added_plots[plot].name))        
         
         
@@ -714,5 +715,6 @@
                     wx.PostEvent(self.parent, StatusEvent(status=msg))
                 else:
-                    wx.PostEvent(self.parent, StatusEvent(status="This tool can only read 1D data"))
+                    msg = "This tool can only read 1D data"
+                    wx.PostEvent(self.parent, StatusEvent(status=msg))
                     return
             
@@ -748,5 +750,7 @@
                 
         pr = self.pr.clone()
-        self.calc_thread = CalcPr(pr, self.nfunc, error_func=self._thread_error, completefn=self._completed, updatefn=None)
+        self.calc_thread = CalcPr(pr, self.nfunc,
+                                   error_func=self._thread_error, 
+                                   completefn=self._completed, updatefn=None)
         self.calc_thread.queue()
         self.calc_thread.ready(2.5)
@@ -815,5 +819,6 @@
         self.pr = pr
         
-        #message = "Computation completed in %g seconds [chi2=%g]" % (elapsed, pr.chi2)
+        #message = "Computation completed in"
+        #message +=  %g seconds [chi2=%g]" % (elapsed, pr.chi2)
         #wx.PostEvent(self.parent, StatusEvent(status=message))
 
@@ -835,5 +840,6 @@
             for i in range(len(out)):
                 try:
-                    print "%d: %g +- %g" % (i, out[i], math.sqrt(math.fabs(cov[i][i])))
+                    print "%d: %g +- %g" % (i, out[i],
+                                             math.sqrt(math.fabs(cov[i][i])))
                 except: 
                     print sys.exc_value
@@ -855,7 +861,8 @@
         
         # Popup result panel
-        #result_panel = InversionResults(self.parent, -1, style=wx.RAISED_BORDER)
-        
-    def show_data(self, path=None, reset=False):
+        #result_panel = InversionResults(self.parent, 
+        #-1, style=wx.RAISED_BORDER)
+        
+    def show_data(self, path=None, data=None, reset=False):
         """
         Show data read from a file
@@ -865,9 +872,12 @@
         
         """
-        if path is not None:
+        print "show_data", data.name
+        #if path is not None:
+        if data is not None:
             try:
-                pr = self._create_file_pr(path)
+                #pr = self._create_file_pr(path)
+                pr = self._create_file_pr(data)
             except:
-                status="Problem reading data: %s" % sys.exc_value
+                status = "Problem reading data: %s" % sys.exc_value
                 wx.PostEvent(self.parent, StatusEvent(status=status))
                 raise RuntimeError, status
@@ -878,5 +888,5 @@
             
             self.pr = pr
-              
+       
         # Make a plot of I(q) data
         if self.pr.err==None:
@@ -889,5 +899,6 @@
         new_plot.interactive = True
         #new_plot.group_id = "test group"
-        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="I(q)", reset=reset))
+        wx.PostEvent(self.parent, 
+                     NewPlotEvent(plot=new_plot, title="I(q)", reset=reset))
         
         self.current_plottable = new_plot
@@ -918,8 +929,11 @@
         # Write the output to file
         # First, check that the data is of the right type
-        if issubclass(self.current_plottable.__class__, DataLoader.data_info.Data1D):
+        if issubclass(self.current_plottable.__class__,
+                       DataLoader.data_info.Data1D):
             self.state_reader.write(filepath, self.current_plottable, prstate)
         else:
-            raise RuntimeError, "pr.save_data: the data being saved is not a DataLoader.data_info.Data1D object" 
+            msg = "pr.save_data: the data being saved is not a"
+            msg += " DataLoader.data_info.Data1D object" 
+            raise RuntimeError, msg
         
         
@@ -945,5 +959,6 @@
             wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value))
 
-    def estimate_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, 
+    def estimate_plot_inversion(self, alpha, nfunc, d_max, 
+                                q_min=None, q_max=None, 
                                 bck=False, height=0, width=0):
         """
@@ -1016,5 +1031,6 @@
                     min_err = 0.01*pr.y[i]
                 err[i] = scale*math.sqrt( math.fabs(pr.y[i]) ) + min_err
-            message = "The loaded file had no error bars, statistical errors are assumed."
+            message = "The loaded file had no error bars, "
+            message += "statistical errors are assumed."
             wx.PostEvent(self.parent, StatusEvent(status=message))
 
@@ -1024,5 +1040,6 @@
 
           
-    def setup_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, 
+    def setup_file_inversion(self, alpha, nfunc, d_max, data,
+                             path=None, q_min=None, q_max=None, 
                              bck=False, height=0, width=0):
         """
@@ -1038,5 +1055,6 @@
         
         try:
-            pr = self._create_file_pr(path)
+            #pr = self._create_file_pr(path)
+            pr = self._create_file_pr(data)
             if not pr==None:
                 self.pr = pr
@@ -1045,5 +1063,6 @@
             wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value))
           
-    def estimate_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, 
+    def estimate_file_inversion(self, alpha, nfunc, d_max, data,
+                                path=None, q_min=None, q_max=None, 
                                 bck=False, height=0, width=0):
         """
@@ -1059,6 +1078,7 @@
         
         try:
-            pr = self._create_file_pr(path)
-            if not pr==None:
+            pr = self._create_file_pr(data)
+            #pr = self._create_file_pr(path)
+            if not pr is None:
                 self.pr = pr
                 self.perform_estimate()
@@ -1067,5 +1087,5 @@
                 
           
-    def _create_file_pr(self, path):
+    def _create_file_pr(self, data):
         """
         Create and prepare invertor instance from
@@ -1076,64 +1096,78 @@
         """
         # Load data
-        if os.path.isfile(path):
-            
-            if self._current_file_data is not None \
-                and self._current_file_data.path==path:
-                # Protect against corrupted data from 
-                # previous failed load attempt
-                if self._current_file_data.x is None:
-                    return None
-                x = self._current_file_data.x
-                y = self._current_file_data.y
-                err = self._current_file_data.err
-                
-                message = "The data from this file has already been loaded."
-                wx.PostEvent(self.parent, StatusEvent(status=message))
-            else:
-                # Reset the status bar so that we don't get mixed up
-                # with old messages. 
-                #TODO: refactor this into a proper status handling
-                wx.PostEvent(self.parent, StatusEvent(status=''))
-                try:
-                    x, y, err = self.load(path)
-                except:
-                    load_error(sys.exc_value)
-                    return None
-                
-                # If the file contains no data, just return
-                if x is None or len(x)==0:
-                    load_error("The loaded file contains no data")
-                    return None
-            
-            # If we have not errors, add statistical errors
-            if err==None and y is not None:
-                err = numpy.zeros(len(y))
-                scale = None
-                min_err = 0.0
-                for i in range(len(y)):
-                    # Scale the error so that we can fit over several decades of Q
-                    if scale==None:
-                        scale = 0.05*math.sqrt(y[i])
-                        min_err = 0.01*y[i]
-                    err[i] = scale*math.sqrt( math.fabs(y[i]) ) + min_err
-                message = "The loaded file had no error bars, statistical errors are assumed."
-                wx.PostEvent(self.parent, StatusEvent(status=message))
-            
-            try:
-                # Get the data from the chosen data set and perform inversion
-                pr = Invertor()
-                pr.d_max = self.max_length
-                pr.alpha = self.alpha
-                pr.q_min = self.q_min
-                pr.q_max = self.q_max
-                pr.x = x
-                pr.y = y
-                pr.err = err
-                pr.has_bck = self.has_bck
-                pr.slit_height = self.slit_height
-                pr.slit_width = self.slit_width
-                return pr
-            except:
-                load_error(sys.exc_value)
+        #if os.path.isfile(path):
+        """    
+        if self._current_file_data is not None \
+            and self._current_file_data.path==path:
+            # Protect against corrupted data from 
+            # previous failed load attempt
+            if self._current_file_data.x is None:
+                return None
+            x = self._current_file_data.x
+            y = self._current_file_data.y
+            err = self._current_file_data.err
+            
+            message = "The data from this file has already been loaded."
+            wx.PostEvent(self.parent, StatusEvent(status=message))
+        else:
+        """
+        # Reset the status bar so that we don't get mixed up
+        # with old messages. 
+        #TODO: refactor this into a proper status handling
+        wx.PostEvent(self.parent, StatusEvent(status=''))
+        try:
+            class FileData:
+                x = None
+                y = None
+                err = None
+                path = None
+                def __init__(self, path):
+                    self.path = path
+                
+            self._current_file_data = FileData(data.path)
+            self._current_file_data.x = data.x
+            self._current_file_data.y = data.y
+            self._current_file_data.err = data.dy
+            x, y, err = data.x, data.y, data.dy
+        except:
+            load_error(sys.exc_value)
+            return None
+        
+        # If the file contains no data, just return
+        if x is None or len(x) == 0:
+            load_error("The loaded file contains no data")
+            return None
+        
+        # If we have not errors, add statistical errors
+        if err is not None and y is not None:
+            err = numpy.zeros(len(y))
+            scale = None
+            min_err = 0.0
+            for i in range(len(y)):
+                # Scale the error so that we can fit over several decades of Q
+                if scale == None:
+                    scale = 0.05 * math.sqrt(y[i])
+                    min_err = 0.01 * y[i]
+                err[i] = scale * math.sqrt(math.fabs(y[i])) + min_err
+            message = "The loaded file had no error bars, "
+            message += "statistical errors are assumed."
+            wx.PostEvent(self.parent, StatusEvent(status=message))
+        
+        try:
+            # Get the data from the chosen data set and perform inversion
+            pr = Invertor()
+            pr.d_max = self.max_length
+            pr.alpha = self.alpha
+            pr.q_min = self.q_min
+            pr.q_max = self.q_max
+            pr.x = x
+            pr.y = y
+            pr.err = err
+            pr.has_bck = self.has_bck
+            pr.slit_height = self.slit_height
+            pr.slit_width = self.slit_width
+            return pr
+        except:
+            load_error(sys.exc_value)
         return None
         
@@ -1145,10 +1179,12 @@
         
         # If a thread is already started, stop it
-        if self.estimation_thread != None and self.estimation_thread.isrunning():
+        if self.estimation_thread != None and \
+            self.estimation_thread.isrunning():
             self.estimation_thread.stop()
                 
         pr = self.pr.clone()
-        self.estimation_thread = EstimatePr(pr, self.nfunc, error_func=self._thread_error, 
-                                            completefn = self._estimate_completed, 
+        self.estimation_thread = EstimatePr(pr, self.nfunc,
+                                             error_func=self._thread_error, 
+                                         completefn = self._estimate_completed, 
                                             updatefn   = None)
         self.estimation_thread.queue()
@@ -1170,6 +1206,7 @@
         pr.slit_height = 0.0
         pr.slit_width  = 0.0
-        self.estimation_thread = EstimateNT(pr, self.nfunc, error_func=self._thread_error, 
-                                            completefn = self._estimateNT_completed, 
+        self.estimation_thread = EstimateNT(pr, self.nfunc, 
+                                            error_func=self._thread_error, 
+                                        completefn = self._estimateNT_completed, 
                                             updatefn   = None)
         self.estimation_thread.queue()
@@ -1195,5 +1232,6 @@
         for i in range(len(out)):
             try:
-                print "%d: %g +- %g" % (i, out[i], math.sqrt(math.fabs(cov[i][i])))
+                print "%d: %g +- %g" % (i, out[i],
+                                         math.sqrt(math.fabs(cov[i][i])))
             except: 
                 print "%d: %g +- ?" % (i, out[i])        
@@ -1205,23 +1243,22 @@
         new_plot.yaxis("\\rm{Intensity} ","cm^{-1}")
         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq"))
-                
         # Show I(q) fit
         self.show_iq(out, self.pr)
-        
         # Show P(r) fit
         x_values, x_range = self.show_pr(out, self.pr, cov=cov)
         
-        
-          
     def _on_context_inversion(self, event):
+        """
+        """
         panel = event.GetEventObject()
 
         # If we have more than one displayed plot, make the user choose
-        if len(panel.plots)>1 and panel.graph.selected_plottable in panel.plots:
+        if len(panel.plots) > 1 and \
+            panel.graph.selected_plottable in panel.plots:
             dataset = panel.graph.selected_plottable
-        elif len(panel.plots)==1:
+        elif len(panel.plots) == 1:
             dataset = panel.plots.keys()[0]
         else:
-            print "Error: No data is available"
+            logging.info("Prview Error: No data is available")
             return
         
@@ -1233,5 +1270,5 @@
         except:
             self.control_panel.alpha = self.alpha
-            print "No estimate yet"
+            logging.info("Prview :Alpha Not estimate yet")
             pass
         try:
@@ -1240,5 +1277,5 @@
         except:
             self.control_panel.nfunc = self.nfunc
-            print "No estimate yet"
+            logging.info("Prview : ntemrs Not estimate yet")
             pass
         
@@ -1264,20 +1301,25 @@
         self.control_panel.d_max = self.max_length
         self.control_panel.alpha = self.alpha
-        
         self.perspective = []
         self.perspective.append(self.control_panel.window_name)
-        
-        self.parent.Bind(EVT_PR_FILE, self._on_new_file)
-        
+     
         return [self.control_panel]
     
-    def _on_new_file(self, evt):
-        """
-            Called when the application manager posted an
-            EVT_PR_FILE event. Just prompt the control
-            panel to load a new data file.
-        """
-        self.control_panel._change_file(None)
-
+    def set_data(self, data_list):
+        """
+        receive a list of data to compute pr
+        """
+        if len(data_list) > 1:
+            msg = "Pr panel does not allow more than one value"
+            msg += " at this time"
+            raise ValueError, msg
+        elif len(data_list) == 1:
+            if issubclass(data_list[0].__class__, LoaderData1D):
+                self.control_panel._change_file(evt=None, data=data_list[0])
+            else:
+                msg = "Pr cannot be computed for"
+                msg += " data of type %s" % (data_list[0].__class__.__name__)
+                raise ValueError, msg
+            
     def post_init(self):
         """
Index: prview/perspectives/pr/pr_thread.py
===================================================================
--- prview/perspectives/pr/pr_thread.py	(revision 7116b6e08b4906240b8a779bf2f7c0f6e2623f6f)
+++ prview/perspectives/pr/pr_thread.py	(revision 75df58b1beae85913437ed9d779e48bb1169235d)
@@ -1,3 +1,15 @@
-import sys, time
+
+################################################################################
+#This software was developed by the University of Tennessee as part of the
+#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+#project funded by the US National Science Foundation. 
+#
+#See the license text in license.txt
+#
+#copyright 2009, University of Tennessee
+################################################################################
+
+import sys
+import time
 from data_util.calcthread import CalcThread
 
