Index: invariantview/perspectives/invariant/__init__.py
===================================================================
--- invariantview/perspectives/invariant/__init__.py	(revision c128284af74efc7f6888b98b55649a715e027bee)
+++ invariantview/perspectives/invariant/__init__.py	(revision 272d91e2fbdcfd97440ab338b45a8684146a0483)
@@ -1,2 +1,2 @@
 PLUGIN_ID = "Invariant plug-in 1.0"
-from pr import *
+from invariant import *
Index: invariantview/perspectives/invariant/invariant.py
===================================================================
--- invariantview/perspectives/invariant/invariant.py	(revision c128284af74efc7f6888b98b55649a715e027bee)
+++ invariantview/perspectives/invariant/invariant.py	(revision 272d91e2fbdcfd97440ab338b45a8684146a0483)
@@ -8,4 +8,5 @@
 copyright 2009, University of Tennessee
 """
+import wx
 from sans.invariant import invariant
 
@@ -63,5 +64,5 @@
         self.parent = parent
         #add error back to the data
-        self.parent.Bind( ERR_DATA, self._on_data_error)
+        self.parent.Bind(ERR_DATA, self._on_data_error)
         from invariant_panel import InvariantPanel
         self.invariant_panel = InvariantPanel(parent=self.parent)
@@ -188,14 +189,9 @@
                 else:
                     data = plottable
-                self.invariant_panel.set_data_name(data_name=data.name)
-                data_qmin = min (data.x)
-                data_qmax = max (data.x)
-                data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax))
-                self.invariant_panel.set_range(data_range=data_range)
-                #set an invariant calculator for the panel
-                inv = invariant.InvariantCalculator(data=data)
-                self.invariant_panel.set_invariant(inv)
+                #set the data for the panel
+                self.invariant_panel.set_data(data=data)
                
-    def _plot_data(self, data, name="Unknown"):
+               
+    def _plot_data(self, reel_data, extra_data, name="Unknown"):
         """
             Receive a data and post a NewPlotEvent to parent
@@ -211,7 +207,9 @@
         # Create a plottable data
         new_plot = Data1D(x=[], y=[], dx=None, dy=None)
-        self._plot_helper(new_plot=new_plot, data=data)
-        
-    def _plot_theory(self, data=None, name="Unknown"):
+        self._plot_helper(new_plot=new_plot,
+                          reel_data=reel_data, 
+                          extra_data=extra_data, name=name)
+        
+    def _plot_theory(self, reel_data, extra_data, name="Unknown"):
         """
             Receive a data and post a NewPlotEvent to parent
@@ -226,20 +224,25 @@
         # Create a plottable data
         new_plot = Theory1D(x=[], y=[], dy=None)
-        self._plot_helper(new_plot=new_plot, data=data)
-        
-    def _plot_helper(self, new_plot, data):
-        """
-            Complete information for the new plottable given a previous plottable
-            and set to plot
-        """
-        new_plot.copy_from_datainfo(data) 
-        data.clone_without_data(clone=new_plot) 
+        self._plot_helper(new_plot=new_plot,
+                          reel_data=reel_data,
+                           extra_data=extra_data, name=name)
+        
+    def _plot_helper(self, new_plot, reel_data, extra_data, name):
+        """
+            Put value of extra_data (created data) into a new plottable
+            (new_plot) and assign value of a plotpael of the reel data to 
+            the new plottable so that the new plottable is plot on the sama panel 
+            of the data used for invariant.
+        """
+        
+        new_plot.copy_from_datainfo(extra_data) 
+        extra_data.clone_without_data(clone=new_plot) 
             
         new_plot.name = name
-        title = self.data.name
-        new_plot.xaxis(self.data._xaxis, self.data._xunit)
-        new_plot.yaxis(self.data._yaxis, self.data._yunit)
-        new_plot.group_id = self.data.group_id
-        new_plot.id = self.data.id + name
+        title = reel_data.name
+        new_plot.xaxis(reel_data._xaxis, reel_data._xunit)
+        new_plot.yaxis(reel_data._yaxis, reel_data._yunit)
+        new_plot.group_id = reel_data.group_id
+        new_plot.id = reel_data.id + name
         ##post data to plot
         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title))
Index: invariantview/perspectives/invariant/invariant_panel.py
===================================================================
--- invariantview/perspectives/invariant/invariant_panel.py	(revision c128284af74efc7f6888b98b55649a715e027bee)
+++ invariantview/perspectives/invariant/invariant_panel.py	(revision 272d91e2fbdcfd97440ab338b45a8684146a0483)
@@ -6,4 +6,6 @@
 import wx
 import sys
+
+from sans.invariant import invariant
 
 from sans.guiframe.utils import format_number, check_float
@@ -47,5 +49,5 @@
     ## Flag to tell the AUI manager to put this panel in the center pane
     CENTER_PANE = True
-    def __init__(self, parent, manager=None, invariant=None):
+    def __init__(self, parent, data=None, manager=None):
         wx.ScrolledWindow.__init__(self, parent, style= wx.FULL_REPAINT_ON_RESIZE )
         #Font size 
@@ -53,10 +55,10 @@
         #Object that receive status event
         self.parent = parent
-        self.manager = manager
-        self.invariant = invariant
+        #plug-in using this panel
+        self._manager = manager 
         #Default power value
         self.power_law_exponant = 4 
-        #Name of the data to display
-        self.data_name = ""
+        #Data uses for computation
+        self._data = data
         #Draw the panel
         self._do_layout()
@@ -64,35 +66,25 @@
         self.SetAutoLayout(True)
         self.Layout()
+    
+    def set_data(self, data):
+        """
+            Set the data
+        """
+        self._data = data
+        #edit the panel
+        if self._data is not None:
+            data_name = self._data.name
+            data_qmin = min (self._data.x)
+            data_qmax = max (self._data.x)
+            data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax))
+            
+        self.data_name_txt.SetLabel('Data : '+str(data_name))
+        self.data_range_value_txt.SetLabel(str(data_range))
        
-    def set_invariant(self, invariant):
-        """
-            set the value of the invariant 
-        """
-        self.invariant = invariant
-        
-    def set_range(self, data_range ="[? - ?]"):
-        """
-            Display the range of data
-        """
-        self.data_range_value_txt.SetLabel(str(data_range))
-        
-    def set_data_name(self, data_name=""):
-        """
-            set value for data
-        """
-        self.data_name = str(data_name)
-        self.data_name_txt.SetLabel("Data : "+self.data_name)
-        
-    def get_data(self):
-        """
-            return data
-        """
-        return self.data 
-    
     def set_manager(self, manager):
         """
-            Define the manager of this panel 
-        """
-        self.manager = manager 
+            set value for the manager
+        """
+        self._manager = manager 
         
     def compute_invariant(self, event):
@@ -100,9 +92,4 @@
             compute invariant 
         """
-        #check if the panel has an invariant calculator
-        if self.invariant is None:
-            msg = "No invariant calculator available! Hint: Add data?"
-            wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
-            return 
         #clear outputs textctrl 
         self._reset_output()
@@ -114,5 +101,8 @@
             scale = 1
         if check_float(self.background_ctl) and check_float(self.scale_ctl):
-           
+            inv = invariant.InvariantCalculator(data=self._data,
+                                      background=float(background),
+                                       scale=float(scale))
+            
             #Get the number of points to extrapolated
             npts_low = self.npts_low_ctl.GetValue()
@@ -150,15 +140,13 @@
                 
             #Set the invariant calculator
-            self.invariant.set_extrapolation(range="low", npts=npts_low,
+            inv.set_extrapolation(range="low", npts=npts_low,
                                        function=function_low, power=power_low)
-            self.invariant.set_extrapolation(range="high", npts=npts_high,
+            inv.set_extrapolation(range="high", npts=npts_high,
                                        function=function_high, power=power_high)
             #Compute invariant
             try:
-                qstar, qstar_err = self.invariant.get_qstar_with_error()
+                qstar, qstar_err = inv.get_qstar_with_error()
                 self.invariant_ctl.SetValue(format_number(qstar))
                 self.invariant_err_ctl.SetValue(format_number(qstar))
-                check_float(self.invariant_ctl)
-                check_float(self.invariant_err_ctl)
             except:
                 msg= "Error occurs for invariant: %s"%sys.exc_value
@@ -167,40 +155,36 @@
             #Compute qstar extrapolated to low q range
             #Clear the previous extrapolated plot
-           
             if low_q:
                 try: 
-                    qstar_low = self.invariant.get_qstar_low()
+                    qstar_low = inv.get_qstar_low()
                     self.invariant_low_ctl.SetValue(format_number(qstar_low))
-                    check_float(self.invariant_low_ctl)
                     #plot data
-                    low_out_data, low_in_data = self.invariant.get_extra_data_low()
-                    theory_name_low = self.data_name+" Extra_low_Q"
-                    self.manager._plot_theory(data=low_out_data,
-                                               name=theory_name_low)
-                    data_name_low = self.data_name+"Fitted data for low_Q"
-                    self.manager._plot_data(data=low_in_data,
-                                            name=data_name_low)
+                    low_out_data, low_in_data = inv.get_extra_data_low()
+                    self._manager._plot_theory(reel_data=self._data,
+                                               extra_data=low_out_data,
+                                     name=self._data.name+" Extra_low_Q")
+                    self._manager._plot_data(reel_data=self._data,
+                                             extra_data=low_in_data, 
+                                name=self._data.name+"Fitted data for low_Q")
                 except:
                     msg= "Error occurs for low q invariant: %s"%sys.exc_value
-                    wx.PostEvent(self.parent, StatusEvent(status= msg,
-                                                           type="stop"))
+                    wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
             if high_q:
                 try: 
-                    qstar_high = self.invariant.get_qstar_high()
+                    qstar_high = inv.get_qstar_high()
                     self.invariant_high_ctl.SetValue(format_number(qstar_high))
-                    check_float(self.invariant_high_ctl)
                     #plot data
-                    high_out_data, high_in_data = self.invariant.get_extra_data_high(q_end=Q_MAXIMUM_PLOT)
-                    theory_name_high = self.data_name + " Extra_high_Q"
-                    self.manager._plot_theory(data=high_out_data,
-                                                name=theory_name_high)
-                    data_name_low = self.data_name + "Fitted data for high_Q"
-                    self.manager._plot_data(data=high_in_data,
-                                         name=data_name_low)
+                    high_out_data, high_in_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT)
+                    self._manager._plot_theory(reel_data=self._data,
+                                               extra_data=high_out_data,
+                                     name=self._data.name+" Extra_high_Q")
+                    self._manager._plot_data(reel_data=self._data,
+                                             extra_data=high_in_data,
+                                 name=self._data.name+"Fitted data for high_Q")
                 except:
                     msg= "Error occurs for high q invariant: %s"%sys.exc_value
                     wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
             try:
-                qstar_total, qstar_total_err = self.invariant.get_qstar_with_error(extrapolation)
+                qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation)
                 self.invariant_total_ctl.SetValue(format_number(qstar_total))
                 self.invariant_total_err_ctl.SetValue(format_number(qstar_total))
@@ -209,42 +193,40 @@
             except:
                 msg= "Error occurs for total invariant: %s"%sys.exc_value
-                wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
-                
+                wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))  
+            
+            porod_const = self.porod_const_ctl.GetValue().lstrip().rstrip()
+            if porod_const == "":
+                porod_const = None
+            if not (porod_const is None):
+                if check_float(self.porod_const_ctl):
+                    porod_const = float(porod_const)
+                    try:
+                        v, dv = inv.get_volume_fraction_with_error(contrast=contrast)
+                        self.volume_ctl.SetValue(format_number(v))
+                        self.volume_err_ctl.SetValue(format_number(dv))
+                    except:
+                        msg= "Error occurs for volume fraction: %s"%sys.exc_value
+                        wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
             contrast = self.contrast_ctl.GetValue().lstrip().rstrip()
-            if not check_float(self.contrast_ctl):
+            if contrast == "":
                 contrast = None
-            else:
-                contrast = float(contrast)
-            porod_const = self.porod_const_ctl.GetValue().lstrip().rstrip()
-            if not check_float(self.porod_const_ctl):
-                porod_const = None
-            else:
-                porod_const = float(porod_const)
-            try:
-                v, dv = self.invariant.get_volume_fraction_with_error(contrast=contrast)
-                self.volume_ctl.SetValue(format_number(v))
-                self.volume_err_ctl.SetValue(format_number(dv))
-                check_float(self.volume_ctl)
-                check_float(self.volume_err_ctl)
-            except:
-                msg= "Error occurs for volume fraction: %s"%sys.exc_value
-                wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
-            try:
-                s, ds = self.invariant.get_surface_with_error(contrast=contrast,
-                                        porod_const=porod_const)
-                self.surface_ctl.SetValue(format_number(s))
-                self.surface_err_ctl.SetValue(format_number(ds))
-                check_float(self.surface_ctl)
-                check_float(self.surface_err_ctl)
-            except:
-                msg= "Error occurs for surface: %s"%sys.exc_value
-                wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
-                
+            if not (contrast is None):
+                if check_float(self.contrast_ctl):
+                    contrast = float(contrast)
+                    try:
+                        if not (porod_const is None):
+                            s, ds = inv.get_surface_with_error(contrast=contrast,
+                                                    porod_const=porod_const)
+                            self.surface_ctl.SetValue(format_number(s))
+                            self.surface_err_ctl.SetValue(format_number(ds))
+                    except:
+                        msg= "Error occurs for surface: %s"%sys.exc_value
+                        wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
+                        
         else:
             msg= "invariant: Need float for background and scale"
             wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))
             return
-        
-    
+  
     def _reset_output(self):
         """
@@ -285,8 +267,13 @@
         sizer3.SetMinSize((_STATICBOX_WIDTH, -1))
         #---------inputs----------------
-        
-        self.data_name = ""
+        data_name = ""
         data_range = "[? - ?]"
-        self.data_name_txt = wx.StaticText(self, -1,"Data : "+str(self.data_name))
+        if self._data is not None:
+            data_name = self._data.name
+            data_qmin = min (self._data.x)
+            data_qmax = max (self._data.x)
+            data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax))
+            
+        self.data_name_txt = wx.StaticText(self, -1, 'Data : '+str(data_name))
         data_range_txt = wx.StaticText(self, -1, "Range : ")
         self.data_range_value_txt = wx.StaticText(self, -1, str(data_range))
@@ -309,7 +296,6 @@
         self.porod_const_ctl.SetToolTipString(str(msg_hint))
        
-        
-        sizer_input.Add(self.data_name_txt, wx.LEFT, 5)
-        sizer_input.Add((20,20))
+        sizer_input.Add(self.data_name_txt, 0, wx.LEFT, 5)
+        sizer_input.Add((10,10), 0, wx.LEFT, 5)
         sizer_input.Add(data_range_txt, 0, wx.LEFT, 10)
         sizer_input.Add(self.data_range_value_txt)
@@ -339,9 +325,4 @@
                                          (10, 10),style=wx.RB_GROUP)
         self.power_law_low = wx.RadioButton(self, -1, 'Power_law', (10, 10))
-        #self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param,
-        #           id=self.guinier.GetId())
-        #self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param,
-        #           id=self.power_law_law.GetId())
-        #MAC needs SetValue
         self.guinier.SetValue(True)
         
@@ -429,9 +410,7 @@
         extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !"
         extra_enable_hint_txt= wx.StaticText(self, -1, extra_enable_hint )
-        #enable_sizer = wx.BoxSizer(wx.HORIZONTAL)
+       
         enable_sizer = wx.GridBagSizer(5,5)
-        #enable_sizer.Add(extra_hint_txt, 0, wx.ALL, 5)
-        #enable_sizer.Add(extra_range_value_txt, 0, wx.ALL, 5)
-        
+       
         iy = 0
         ix = 0
@@ -624,19 +603,19 @@
 class InvariantDialog(wx.Dialog):
     def __init__(self, parent=None, id=1,graph=None,
-                 data=None, title="Invariant"):
-        wx.Dialog.__init__(self, parent, id, title, size=( PANEL_WIDTH,
+                 data=None, title="Invariant",base=None):
+        wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH,
                                                              PANEL_HEIGHT))
-        self.panel = InvariantPanel(self,invariant=None)
+        self.panel = InvariantPanel(self)
         self.Centre()
         self.Show(True)
         
 class InvariantWindow(wx.Frame):
-    def __init__(self, parent=None, id=1, 
-                 data=None, title="Invariant",):
-        
-        wx.Frame.__init__(self, parent, id, title, size=( PANEL_WIDTH,
+    def __init__(self, parent=None, id=1,graph=None, 
+                 data=None, title="Invariant",base=None):
+        
+        wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH,
                                                              PANEL_HEIGHT))
         
-        self.panel = InvariantPanel(self,invariant=None)
+        self.panel = InvariantPanel(self)
         self.Centre()
         self.Show(True)
@@ -650,11 +629,5 @@
         
         return True
-        #wx.InitAllImageHandlers()
-        #dialog = InvariantDialog(None)
-        #if dialog.ShowModal() == wx.ID_OK:
-        #    pass
-        #dialog.Destroy()
-        #return 1
-   
+      
 # end of class MyApp
 
