Index: sansview/perspectives/fitting/fitpage1D.py
===================================================================
--- sansview/perspectives/fitting/fitpage1D.py	(revision 76dab10160264001ae6d3cceaf2f7790e119c110)
+++ sansview/perspectives/fitting/fitpage1D.py	(revision 0b99881db3a31559d8bea44b140993d0b56d76fe)
@@ -18,6 +18,7 @@
 class FitPage1D(ModelPage):
     """
-        FitPanel class contains fields allowing to display results when
-        fitting  a model and one data
+        FitPage1D class contains fields allowing to display results when
+        fitting  a model and one data.
+        This class used most of the methods of ModelPage class.
         @note: For Fit to be performed the user should check at least one parameter
         on fit Panel window.
@@ -30,25 +31,16 @@
     name=None
     
-    def __init__(self, parent,data, *args, **kwargs):
-        wx.ScrolledWindow.__init__(self, parent, *args, **kwargs)
-        
+    def __init__(self, parent,data,model=None, name=None, *args, **kwargs):
         """ 
             Initialization of the Panel
         """
+        ModelPage.__init__(self, parent,model,name,data,*args, **kwargs)
+       
         #TODO: remove this once the inheritence is cleaned up
         ## Data member to store the dispersion object created
-        self._disp_obj_dict = {}
-
-        #Data used for fitting 
-        self.data = data
-        # flag to allow data2D plot
-        self.enable2D=False
-        #fit page manager 
-        self.manager = None
-        #Store the parent of this panel parent
-        # For this application fitpanel is the parent
-        self.parent  = parent
-        # Event_owner is the owner of model event
-        self.event_owner = None
+        
+    
+        
+    def draw_panel(self):
         #panel interface
         self.vbox  = wx.BoxSizer(wx.VERTICAL)
@@ -87,5 +79,5 @@
         #---------sizer 1 draw--------------------------------
         #Filling the sizer containing data related fields
-        self.DataSource  =wx.StaticText(self, -1,str(data.name))
+        self.DataSource  =wx.StaticText(self, -1,str(self.data.name))
         ix = 0
         iy = 1
@@ -101,7 +93,7 @@
             iy = 1
             # Minimum value of data   
-            self.data_min    = wx.StaticText(self, -1,str(format_number(numpy.min(data.x))))
+            self.data_min = wx.StaticText(self, -1,str(format_number(numpy.min(self.data.x))))
             # Maximum value of data  
-            self.data_max    =  wx.StaticText(self, -1,str(format_number(numpy.max(data.x))))   
+            self.data_max =  wx.StaticText(self, -1,str(format_number(numpy.max(self.data.x))))   
             self.text4_3 = wx.StaticText(self, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT)
             self.sizer2.Add(self.text4_3,(iy,ix),(1,1),\
@@ -160,6 +152,6 @@
         self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP)
         self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30))
-        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId())
-        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId())
+        self.Bind(wx.EVT_RADIOBUTTON, self.set_Dispers_Param, id=self.disable_disp.GetId())
+        self.Bind(wx.EVT_RADIOBUTTON, self.set_Dispers_Param, id=self.enable_disp.GetId())
         ix= 0
         iy=1
@@ -247,31 +239,5 @@
         iy+=1 
         self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        
-        # Contains link between  model ,all its parameters, and panel organization
-        self.parameters=[]
-        # Contains list of parameters that cannot be fitted and reference to 
-        #panel objects 
-        self.fixed_param=[]
-        # Contains list of parameters with dispersity and reference to 
-        #panel objects 
-        self.fittable_param=[]
-        #list of dispersion paramaters
-        self.disp_list=[]
-        #contains link between a model and selected parameters to fit 
-        self.param_toFit=[]
-        # model on which the fit would be performed
-        self.model=None
-        
-        self.back_up_model= None
-        #dictionary of model name and model class
-        self.model_list_box={}    
-                     
-        if self.model == None:
-            self.qmin.Disable()
-            self.qmax.Disable() 
-        else:
-            self.qmin.Enable()
-            self.qmax.Enable() 
-
+       
     
         self.vbox.Layout()
@@ -280,8 +246,4 @@
         self.SetScrollbars(20,20,55,40)
         
-        self.Centre()
-        self.Layout()
-        self.GrandParent.GetSizer().Layout()
-   
     def compute_chisqr2D(self):
         """ 
@@ -298,9 +260,11 @@
                     for j in range(len(self.data.y_bins)):
                         #Check the range containing data between self.qmin_x and self.qmax_x
-                        if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)>=math.pow(self.qmin_x,2):
-                            if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)<=math.pow(self.qmax_x,2):
-                                chisqrji=(self.data.data[j][i]- self.model.runXY(\
-                                                                                    [self.data.y_bins[j],self.data.x_bins[i]]))\
-                                                                                    /self.data.err_data[j][i]
+                        radius = math.pow(self.data.x_bins[i],2)\
+                            + math.pow(self.data.y_bins[j],2)
+                            
+                        if radius >= math.pow(self.qmin_x,2):
+                            if radius <=math.pow(self.qmax_x,2):
+                                temp= self.model.runXY( [self.data.y_bins[j],self.data.x_bins[i]] )
+                                chisqrji=(self.data.data[j][i]- temp)/self.data.err_data[j][i]
                                 #Vector containing residuals
                                 res.append( math.pow(chisqrji,2) )
@@ -312,6 +276,6 @@
                 self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
             except:
-                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
-                            "Chisqr cannot be compute: %s"% sys.exc_value))
+                msg= "Chisqr cannot be compute: %s"% sys.exc_value
+                wx.PostEvent(self.parent.GrandParent, StatusEvent(status= msg ))
                 return
     
@@ -331,5 +295,5 @@
                     self.qmin_x = float(self.qmin.GetValue())
                     self.qmax_x = float(self.qmax.GetValue())
-                    # return residuals within self.qmin_x and self.qmax_x
+                    # Compute residuals within self.qmin_x and self.qmax_x
                     x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)]
                     if self.qmin_x==None and self.qmax_x==None: 
@@ -349,7 +313,8 @@
                     self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
             except:
-                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
-                            "Chisqr cannot be compute: %s"% sys.exc_value))
+                msg=  "Chisqr cannot be compute: %s"% sys.exc_value
+                wx.PostEvent(self.parent.GrandParent, StatusEvent(status= msg))
                 return 
+            
             
     def _on_select_model(self,event):
@@ -380,16 +345,17 @@
             
             if name ==event.GetString():
+                self.model=item()
+                self.back_up_model= self.model.clone()
+                evt = ModelEventbox(model=self.model,name=name)
+                wx.PostEvent(self.event_owner, evt)
                 try:
-                    self.model=item()
-                    self.back_up_model= self.model.clone()
-                    evt = ModelEventbox(model=self.model,name=name)
-                    wx.PostEvent(self.event_owner, evt)
-                    self.text1_1.Show()
                     self.compute_chisqr()
                     self.tcChi.Show()
+                    self.text1_1.Show()
                 except:
-                    raise #ValueError,"model.name is not equal to model class name"
+                    self.text1_1.Hide()
+                    pass
                 break  
-            
+                 
                  
     def onFit(self,event):
@@ -417,24 +383,7 @@
             self.parent.GetSizer().Layout()
         else:
-            wx.PostEvent(self.parent.parent, StatusEvent(status=\
-                            "Select at least one parameter to fit "))
+            msg= "Select at least one parameter to fit "
+            wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
   
-   
-    def _onTextEnter(self,event):
-        """
-            set a flag to determine if the fitting range entered by the user is valid
-        """
-      
-        try:
-            flag=self.checkFitRange()
-            if flag==True and self.model!=None:
-                self.manager.redraw_model(float(self.xmin.GetValue())\
-                                               ,float(self.xmax.GetValue()))
-        except:
-
-            wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
-                            "Drawing  Error:wrong value entered %s"% sys.exc_value))
-        
-   
     
     def get_param_list(self):
@@ -459,4 +408,5 @@
             self.compute_chisqr()
         except:
+            self.text1_1.Hide()
             pass
         
@@ -512,5 +462,5 @@
                 if item in self.param_toFit:
                     self.param_toFit.remove(item)           
-        #Set the value of checkbox that selected every checkbox or not            
+        #Set the value of checkbox that selected all checkboxes or not to true or false           
         if len(self.parameters)+len(self.fittable_param) ==len(self.param_toFit):
             self.cb1.SetValue(True)
Index: sansview/perspectives/fitting/fitpanel.py
===================================================================
--- sansview/perspectives/fitting/fitpanel.py	(revision 925a30e1970e2e81bed1969735af0a4824905734)
+++ sansview/perspectives/fitting/fitpanel.py	(revision 0b99881db3a31559d8bea44b140993d0b56d76fe)
@@ -126,5 +126,5 @@
         if not name in self.fit_page_name :
             from fitpage1D import FitPage1D
-            panel = FitPage1D(self,data, -1)
+            panel = FitPage1D(parent=self,data=data, id=-1)
             panel.name=name
             
Index: sansview/perspectives/fitting/modelpage.py
===================================================================
--- sansview/perspectives/fitting/modelpage.py	(revision a38c284583276d299fa883d887dada33fe5c5c30)
+++ sansview/perspectives/fitting/modelpage.py	(revision 0b99881db3a31559d8bea44b140993d0b56d76fe)
@@ -14,11 +14,8 @@
 
 
-
 class ModelPage(wx.ScrolledWindow):
     """
-        FitPanel class contains fields allowing to display results when
-        fitting  a model and one data
-        @note: For Fit to be performed the user should check at least one parameter
-        on fit Panel window.
+        ModelPage is a panel that allows the user to view information related to a 
+        model. 
   
     """
@@ -27,7 +24,8 @@
     ## Title to appear on top of the window
     window_caption = "Fit Page"
-    name=""
-    
-    def __init__(self, parent,model,name, *args, **kwargs):
+    # name of the panel directly related to the model name selected
+    name =" "
+
+    def __init__(self, parent,model=None,name=None,data=None, *args, **kwargs):
         wx.ScrolledWindow.__init__(self, parent, *args, **kwargs)
         """ 
@@ -39,6 +37,6 @@
         ## Data member to store the dispersion object created
         self._disp_obj_dict = {}
-
-        #list of dispersion paramaters
+        
+        #list of dispersion parameters
         self.disp_list=[]
         try:
@@ -51,5 +49,35 @@
         # this panel does contain data .existing data allow a different drawing
         #on set_model parameters
-        self.data=None
+        self.data=data
+        
+        
+        # contains link between  model ,all its parameters, and panel organization
+        self.parameters=[]
+        #list of parameters that cannot be fitted and panel object related to this parameters
+        #values
+        self.fixed_param=[]
+        #
+        self.fittable_param=[]
+        self.polydisp= {}
+        #contains link between a model and selected parameters to fit 
+        self.param_toFit=[]
+        
+        self.prevmodel_name=name
+        self.draw_panel()
+        #dictionary of model name and model class
+        self.model_list_box={}
+        #Draw initial panel
+        if self.model!=None:
+            self.set_panel(self.model)
+        self.theta_cb=None
+        # flag to allow data2D plot
+        self.enable2D=False
+        
+    
+        self.Centre()
+        self.Layout()
+        self.parent.GetSizer().Layout()
+        
+    def draw_panel(self):   
         #panel interface
         self.vbox  = wx.BoxSizer(wx.VERTICAL)
@@ -62,5 +90,4 @@
         self.sizer5 = wx.GridBagSizer(5,5)
         self.sizer4 = wx.GridBagSizer(5,5)
-       
         #model selection
         self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
@@ -79,16 +106,10 @@
         # plotting range
         self.vbox.Add(self.sizer9)
-        #close layer
-        #self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
-        #self.vbox.Add(self.sizer10)
-        
-      
+    
         #------------------ sizer 4  draw------------------------  
-       
-       
         # define combox box
         self.modelbox = wx.ComboBox(self, -1)
          # preview selected model name
-        self.prevmodel_name=name
+        
         #print "model view prev_model",name
         self.modelbox.SetValue(self.prevmodel_name)
@@ -121,6 +142,6 @@
         self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP)
         self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30))
-        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId())
-        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId())
+        self.Bind(wx.EVT_RADIOBUTTON, self.set_Dispers_Param, id=self.disable_disp.GetId())
+        self.Bind(wx.EVT_RADIOBUTTON, self.set_Dispers_Param, id=self.enable_disp.GetId())
         ix= 0
         iy=1
@@ -134,9 +155,6 @@
         iy+=1
         self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)  
-
-        
         #---------sizer 9 draw----------------------------------------
-       
-         ## Q range
+        ## Q range
         self.qmin_x= 0.001
         self.qmax_x= 0.1
@@ -190,37 +208,4 @@
         iy+=1 
         self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        #----------sizer 10 draw------------------------------------------------------
-        """
-        id = wx.NewId()
-        self.btClose =wx.Button(self,id,'Close')
-        self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id)
-        self.btClose.SetToolTipString("Close page.")
-        
-        ix= 3
-        iy= 1
-        self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        ix +=1
-        self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        ix =0
-        iy+=1
-        self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        """
-        # contains link between  model ,all its parameters, and panel organization
-        self.parameters=[]
-        self.fixed_param=[]
-        self.fittable_param=[]
-        self.polydisp= {}
-        #contains link between a model and selected parameters to fit 
-        self.param_toFit=[]
-        
-        #dictionary of model name and model class
-        self.model_list_box={}
-        #Draw initial panel
-         #-----sizer 11--------------------model description------
-        if self.model!=None:
-            self.set_panel(self.model)
-        self.theta_cb=None
-       
-       
         self.vbox.Layout()
         self.vbox.Fit(self) 
@@ -228,9 +213,10 @@
         self.SetScrollbars(20,20,55,40)
         
-        self.Centre()
-        self.Layout()
-        self.parent.GetSizer().Layout()
+        
     def set_model_description(self, model):
-        
+        """
+            Set a sizer with model description field
+            @param model: the model select that provides the description
+        """
         if model !=None and str(model.description)!=""and self.data==None:
             self.sizer11.Clear(True)
@@ -280,10 +266,7 @@
     
 
-    def Set_DipersParam(self, event):
-        """
-            This method is called when the user changes the state 
-            of the "dispersity" radio buttons.
-            
-            #TODO: correct the spelling mistake in the name of this method, start name with lowercase.
+    def set_Dispers_Param(self, event):
+        """
+             set a sizer with dispersion parameters 
         """
         if self.enable_disp.GetValue():
@@ -304,5 +287,10 @@
                 return 
             else:
-                # Show the default dispersion/averaging sub-panel
+                # allow to recognize data panel from model panel
+                if self.data !=None and self.model !=None: 
+                    
+                    self.cb1.SetValue(False)
+                    self.select_all_param_helper()
+                
                 self.populate_disp_box()
                 self.set_panel_dispers(self.disp_list)
@@ -335,4 +323,7 @@
             
     def populate_disp_box(self):
+        """
+            populate polydispersion combo box 
+        """
         self.sizer7.Clear(True)
         if len(self.disp_list)>0:
@@ -381,4 +372,6 @@
         self.qmax.SetValue(format_number(self.qmax_x))
         self.npts.SetValue(format_number(self.num_points))
+        
+        
     def checkFitRange(self):
         """
@@ -387,10 +380,8 @@
             background is colored in pink.
         """
-       
         flag = True
         valueMin = self.qmin.GetValue()
         valueMax = self.qmax.GetValue()
         # Check for possible values entered
-        #print "fitpage: checkfitrange:",valueMin,valueMax
         try:
             if (float(valueMax)> float(valueMin)):
@@ -410,11 +401,4 @@
         return flag
     
-
-        
-    def onClose(self,event):
-        """ close the page associated with this panel"""
-        self.parent.onClose()
-        
-  
         
     def onModel2D(self, event):
@@ -456,5 +440,6 @@
         type =event.GetString()
         self.set_panel_dispers( self.disp_list,type )
-                
+          
+     
     def _on_select_model(self,event):
         """
@@ -547,5 +532,4 @@
         self.text2_3.Hide() 
         
-       
         ix +=1
         self.text2_4 = wx.StaticText(self, -1, 'Units')
@@ -554,4 +538,5 @@
         self.text2_4.Hide()
         disp_list=self.model.getDispParamList()
+        # 
         for item in keys:
             if not item in disp_list:
@@ -614,4 +599,7 @@
         
     def _selectDlg(self):
+        """
+            Create a dialog to select files
+        """
         import os
         dlg = wx.FileDialog(self, "Choose a weight file", os.getcwd(), "", "*.*", wx.OPEN)
@@ -621,5 +609,12 @@
         dlg.Destroy()
         return path
+    
+    
     def read_file(self, path):
+        """
+            Read a file  of 2 colons
+            @param path: the path to the file
+            @return 2 numpy arrays containing numbers
+        """
         try:
             if path==None:
@@ -646,5 +641,8 @@
             return numpy.array(angles), numpy.array(weights)
         except:
-            raise 
+             msg= "Simultaneous Fit completed but Following error occurred: "
+             msg+= "%s"%sys.exc_value
+             wx.PostEvent(self.parent.parent, StatusEvent(status=msg))
+             return  
         
           
@@ -654,6 +652,4 @@
             @param event: check box event
         """
-        
-        
         # Go through the list of dispersion check boxes to identify which one has changed 
         for p in self.disp_cb_dict:
@@ -717,10 +713,9 @@
                     self._draw_model()
         return
-
-                      
-                      
+       
                       
     def set_panel_dispers(self, disp_list, type="GaussianModel" ):
         """
+            Fill sizer with disperstion info
         """
         
@@ -843,4 +838,5 @@
             self.parent.GetSizer().Layout()  
           
+          
     def checkFitValues(self,val_min, val_max):
         """
@@ -898,6 +894,10 @@
         self.set_model_parameter()
         
+        
+        
     def set_model_parameter(self):
         """
+            Value Enter by the user on the parameter fields are used to reset the model
+            and model will be drawn again if the user enters different values
         """
         if len(self.parameters) !=0 and self.model !=None:
@@ -915,5 +915,4 @@
                          
                 except:
-                    #raise
                     wx.PostEvent(self.parent.parent, StatusEvent(status=\
                             "Model Drawing  Error:wrong value entered : %s"% sys.exc_value))
@@ -932,7 +931,6 @@
                          
                 except:
-                    raise
                     wx.PostEvent(self.parent.parent, StatusEvent(status=\
-                            "Model Drawing  Error:wrong value entered : %s"% sys.exc_value))
+                            "Model Drawing Error:wrong value entered : %s"% sys.exc_value))
                 
             for item in self.parameters:
@@ -949,5 +947,5 @@
                     #raise 
                     wx.PostEvent(self.parent.parent, StatusEvent(status=\
-                           "Model Drawing  Error:wrong value entered : %s"% sys.exc_value))
+                           "Model Drawing Error:wrong value entered : %s"% sys.exc_value))
                     return
                 
@@ -970,4 +968,5 @@
                 self._draw_model()            
             
+            
     def _draw_model(self, name=None):
         """
@@ -986,17 +985,22 @@
                                 enable2D=self.enable2D)
        
+       
     def select_param(self,event):
         """
-        
+            Select_parameter is implemented in fitpage.py 
         """
         pass
+    
+    
     def select_all_param(self,event): 
         """
-        
+            Implemented in fitpage.py
         """
         pass
+    
+    
     def select_all_param_helper(self):
         """
-             Allows selecting or delecting button
+             Allows selecting or unselecting  checkbutton
         """
         self.param_toFit=[]
Index: sansview/perspectives/fitting/old_fitpage1D.py
===================================================================
--- sansview/perspectives/fitting/old_fitpage1D.py	(revision 0b99881db3a31559d8bea44b140993d0b56d76fe)
+++ sansview/perspectives/fitting/old_fitpage1D.py	(revision 0b99881db3a31559d8bea44b140993d0b56d76fe)
@@ -0,0 +1,592 @@
+import sys
+import wx
+import wx.lib
+import numpy,math
+import copy
+
+from sans.guicomm.events import StatusEvent 
+from sans.guiframe.utils import format_number
+from modelpage import ModelPage  
+from modelpage import format_number
+(ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()
+_BOX_WIDTH = 80
+
+
+#TODO: FitPage1D inherits from ModelPage but doesn't call its __init__ method!
+#TODO: refactor this class to have an __init__ that deals with data only, then calls a UI builder method.
+
+class FitPage1D(ModelPage):
+    """
+        FitPanel class contains fields allowing to display results when
+        fitting  a model and one data
+        @note: For Fit to be performed the user should check at least one parameter
+        on fit Panel window.
+    """
+    ## Internal name for the AUI manager
+    window_name = "Fit page"
+    ## Title to appear on top of the window
+    window_caption = "Fit Page"
+    
+    name=None
+    
+    def __init__(self, parent,data, *args, **kwargs):
+        wx.ScrolledWindow.__init__(self, parent, *args, **kwargs)
+        
+        """ 
+            Initialization of the Panel
+        """
+        #TODO: remove this once the inheritence is cleaned up
+        ## Data member to store the dispersion object created
+        self._disp_obj_dict = {}
+
+        #Data used for fitting 
+        self.data = data
+        # flag to allow data2D plot
+        self.enable2D=False
+        #fit page manager 
+        self.manager = None
+        #Store the parent of this panel parent
+        # For this application fitpanel is the parent
+        self.parent  = parent
+        # Event_owner is the owner of model event
+        self.event_owner = None
+        #panel interface
+        self.vbox  = wx.BoxSizer(wx.VERTICAL)
+    
+        self.sizer9 = wx.GridBagSizer(5,5)
+        self.sizer8 = wx.GridBagSizer(5,5)
+        self.sizer7 = wx.GridBagSizer(5,5)
+        self.sizer6 = wx.GridBagSizer(5,5)
+        self.sizer5 = wx.GridBagSizer(5,5)
+        self.sizer4 = wx.GridBagSizer(5,5)
+        self.sizer3 = wx.GridBagSizer(5,5)
+        self.sizer2 = wx.GridBagSizer(5,5)
+        self.sizer1 = wx.GridBagSizer(5,5)
+        # Add layer
+        #data info layer
+        self.vbox.Add(self.sizer1)
+        #data range 
+        self.vbox.Add(self.sizer2)
+        #instrument smearing selection layer
+        self.vbox.Add(self.sizer3)
+        #model selection
+        self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
+        self.vbox.Add(self.sizer4)
+        #model paramaters layer
+        self.vbox.Add(self.sizer5)
+        #polydispersion selected
+        self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
+        self.vbox.Add(self.sizer6)
+        #combox box for type of dispersion
+        self.vbox.Add(self.sizer7)
+        #dispersion parameters layer
+        self.vbox.Add(self.sizer8)
+        #fit info layer
+        self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
+        self.vbox.Add(self.sizer9)
+        #---------sizer 1 draw--------------------------------
+        #Filling the sizer containing data related fields
+        self.DataSource  =wx.StaticText(self, -1,str(data.name))
+        ix = 0
+        iy = 1
+        self.sizer1.Add(wx.StaticText(self, -1, 'Data Source Name : '),(iy,ix),\
+                 (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1
+        self.sizer1.Add(self.DataSource,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        
+        #---------sizer 2 draw--------------------------------
+        #set maximum range for x in linear scale
+        if not hasattr(self.data,"data"): #Display only for 1D data fit
+            ix = 0
+            iy = 1
+            # Minimum value of data   
+            self.data_min    = wx.StaticText(self, -1,str(format_number(numpy.min(data.x))))
+            # Maximum value of data  
+            self.data_max    =  wx.StaticText(self, -1,str(format_number(numpy.max(data.x))))   
+            self.text4_3 = wx.StaticText(self, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT)
+            self.sizer2.Add(self.text4_3,(iy,ix),(1,1),\
+                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+            ix += 2
+            self.sizer2.Add(wx.StaticText(self, -1, 'Min :'),(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            ix += 1
+            self.sizer2.Add(self.data_min,(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            ix += 1
+            self.sizer2.Add(wx.StaticText(self, -1, 'Max : '),(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            ix += 1
+            self.sizer2.Add(self.data_max,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        
+        #----sizer 3 draw--------------------------------
+        #Filling the sizer containing instruments smearing info.
+        self.disable_smearer = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP)
+        self.enable_smearer = wx.RadioButton(self, -1, 'Yes', (10, 30))
+        self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId())
+        self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId())
+        ix = 0
+        iy = 1
+        self.sizer3.Add(wx.StaticText(self,-1,'Instrument Smearing'),(iy,ix),(1,1)\
+                  , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1
+        self.sizer3.Add(self.enable_smearer,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer3.Add(self.disable_smearer,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix =0
+        iy+=1
+        self.sizer3.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)  
+            
+        #------------------ sizer 4  draw------------------------   
+        # This sizer contains model list and chisqr value 
+        #filling sizer4
+        self.modelbox = wx.ComboBox(self, -1)
+        self.tcChi    =  wx.StaticText(self, -1, str(0), style=wx.ALIGN_LEFT)
+        self.tcChi.Hide()
+        self.text1_1 = wx.StaticText(self, -1, 'Chi2/dof', style=wx.ALIGN_LEFT)
+        self.text1_1.Hide()
+        ix = 0
+        iy = 1
+        self.sizer4.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\
+                  , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1
+        self.sizer4.Add(self.modelbox,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer4.Add(self.text1_1,(iy,ix),(1,1),\
+                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1
+        self.sizer4.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        #----------sizer6-------------------------------------------------
+        #Sizer containing info on polydispersity
+        self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP)
+        self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30))
+        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId())
+        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId())
+        ix= 0
+        iy=1
+        self.sizer6.Add(wx.StaticText(self,-1,'Polydispersity: '),(iy,ix),(1,1)\
+                  , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1
+        self.sizer6.Add(self.enable_disp ,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix =0
+        iy+=1
+        self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)  
+        #---------sizer 9 draw----------------------------------------
+        
+        
+        id = wx.NewId()
+        self.btFit =wx.Button(self,id,'Fit')
+        self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id=id)
+        self.btFit.SetToolTipString("Perform fit.")
+        ## Q range
+        # Reversed to the codes; Need to think  carefully about consistency in q between 2D plot and fitting
+        if not hasattr(self.data,"data"):
+            self.qmin_x= numpy.min(self.data.x)
+            self.qmax_x= numpy.max(self.data.x)
+            self.num_points= len(self.data.x)
+        else:
+            # Reversed to the codes; Need to think  carefully about consistency in q between 2D plot and fitting
+            radius1= math.sqrt(math.pow(self.data.xmin, 2)+ math.pow(self.data.ymin, 2))
+            radius2= math.sqrt(math.pow(self.data.xmax, 2)+ math.pow(self.data.ymin, 2))
+            radius3= math.sqrt(math.pow(self.data.xmin, 2)+ math.pow(self.data.ymax, 2))
+            radius4= math.sqrt(math.pow(self.data.xmax, 2)+ math.pow(self.data.ymax, 2))
+            
+            self.qmin_x= 0
+            self.qmax_x= math.sqrt(math.pow(max(math.fabs(self.data.xmax),math.fabs(self.data.xmin)),2)
+                            +math.pow(max(math.fabs(self.data.ymax),math.fabs(self.data.ymin)),2))#self.data.xmax           
+        
+        self.num_points= 100
+        # The minimum fitting range
+        self.qmin    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
+        self.qmin.SetValue(str(format_number(self.qmin_x)))
+        self.qmin.SetToolTipString("Minimun value of x in linear scale.")
+        self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+        self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
+        self.qmin.Enable()
+        #The maximum fitting range
+        self.qmax    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
+        self.qmax.SetValue(str(format_number(self.qmax_x)))
+        self.qmax.SetToolTipString("Maximum value of x in linear scale.")
+        self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+        self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
+        self.qmax.Enable()
+        #The number of points to plots
+        self.npts    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
+        self.npts.SetValue(format_number(self.num_points))
+        self.npts.SetToolTipString("Number of point to plot.")
+        self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+        self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
+        self.npts.Disable()
+        self.npts.Hide()
+        ix = 0
+        iy = 1 
+        self.sizer9.Add(wx.StaticText(self, -1, 'Fitting Range'),(iy, ix),(1,1),\
+                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1 
+        self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix = 0
+        iy += 1
+        self.sizer9.Add(wx.StaticText(self, -1, 'Q range'),(iy, ix),(1,1),\
+                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1
+        self.sizer9.Add(self.qmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer9.Add(self.qmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer9.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        
+        ix += 1
+        self.sizer9.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+       
+        ix =0
+        iy+=1 
+        self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        
+        # Contains link between  model ,all its parameters, and panel organization
+        self.parameters=[]
+        # Contains list of parameters that cannot be fitted and reference to 
+        #panel objects 
+        self.fixed_param=[]
+        # Contains list of parameters with dispersity and reference to 
+        #panel objects 
+        self.fittable_param=[]
+        #list of dispersion paramaters
+        self.disp_list=[]
+        #contains link between a model and selected parameters to fit 
+        self.param_toFit=[]
+        # model on which the fit would be performed
+        self.model=None
+        
+        self.back_up_model= None
+        #dictionary of model name and model class
+        self.model_list_box={}    
+                     
+        if self.model == None:
+            self.qmin.Disable()
+            self.qmax.Disable() 
+        else:
+            self.qmin.Enable()
+            self.qmax.Enable() 
+
+    
+        self.vbox.Layout()
+        self.vbox.Fit(self) 
+        self.SetSizer(self.vbox)
+        self.SetScrollbars(20,20,55,40)
+        
+        self.Centre()
+        self.Layout()
+        self.GrandParent.GetSizer().Layout()
+   
+    def compute_chisqr2D(self):
+        """ 
+            compute chi square given a model and data 2D and set the value
+            to the tcChi txtcrl
+        """
+        flag=self.checkFitRange()
+        res=[]
+        if flag== True:
+            try:
+                self.qmin_x = float(self.qmin.GetValue())
+                self.qmax_x = float(self.qmax.GetValue())
+                for i in range(len(self.data.x_bins)):
+                    for j in range(len(self.data.y_bins)):
+                        #Check the range containing data between self.qmin_x and self.qmax_x
+                        if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)>=math.pow(self.qmin_x,2):
+                            if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)<=math.pow(self.qmax_x,2):
+                                chisqrji=(self.data.data[j][i]- self.model.runXY(\
+                                                                                    [self.data.y_bins[j],self.data.x_bins[i]]))\
+                                                                                    /self.data.err_data[j][i]
+                                #Vector containing residuals
+                                res.append( math.pow(chisqrji,2) )
+                # compute sum of residual
+                sum=0
+                for item in res:
+                    if numpy.isfinite(item):
+                        sum +=item
+                self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
+            except:
+                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
+                            "Chisqr cannot be compute: %s"% sys.exc_value))
+                return
+    
+        
+    def compute_chisqr(self):
+        """ 
+            compute chi square given a model and data 1D and set the value
+            to the tcChi txtcrl
+        """
+        flag=self.checkFitRange()
+        if flag== True:
+            try:
+                if hasattr(self.data,"data"):
+                    self.compute_chisqr2D()
+                    return
+                else:
+                    self.qmin_x = float(self.qmin.GetValue())
+                    self.qmax_x = float(self.qmax.GetValue())
+                    # return residuals within self.qmin_x and self.qmax_x
+                    x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)]
+                    if self.qmin_x==None and self.qmax_x==None: 
+                        fx =numpy.asarray([self.model.run(v) for v in x])
+                        temp=(y - fx)/dy
+                        res= temp*temp
+                    else:
+                        idx = (x>= self.qmin_x) & (x <=self.qmax_x)
+                        fx = numpy.asarray([self.model.run(item)for item in x[idx ]])
+                        temp=(y[idx] - fx)/dy[idx]
+                        res= temp*temp
+                    #sum of residuals
+                    sum=0
+                    for item in res:
+                        if numpy.isfinite(item):
+                            sum +=item
+                    self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
+            except:
+                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
+                            "Chisqr cannot be compute: %s"% sys.exc_value))
+                return 
+            
+    def _on_select_model(self,event):
+        """
+            react when a model is selected from page's combo box
+            post an event to its owner to draw an appropriate theory
+        """
+        self.btFit.SetFocus()
+        self.disable_disp.SetValue(True)
+        self.sizer8.Clear(True)
+        self.sizer7.Clear(True)       
+        self.vbox.Layout()
+        self.SetScrollbars(20,20,55,40)
+        self.Layout()
+        self.parent.GetSizer().Layout()
+
+        for item in self.model_list_box.itervalues():
+            name = item.__name__
+            if hasattr(item, "name"):
+                name = item.name
+            
+            if name == None:
+                self.qmin.Disable()
+                self.qmax.Disable() 
+            else:
+                self.qmin.Enable()
+                self.qmax.Enable() 
+            
+            if name ==event.GetString():
+                try:
+                    self.model=item()
+                    self.back_up_model= self.model.clone()
+                    evt = ModelEventbox(model=self.model,name=name)
+                    wx.PostEvent(self.event_owner, evt)
+                    self.text1_1.Show()
+                    self.compute_chisqr()
+                    self.tcChi.Show()
+                except:
+                    raise #ValueError,"model.name is not equal to model class name"
+                break  
+            
+                 
+    def onFit(self,event):
+        """ signal for fitting"""
+         
+        flag=self.checkFitRange()
+        self.set_manager(self.manager)
+     
+        self.qmin_x=float(self.qmin.GetValue())
+        self.qmax_x =float( self.qmax.GetValue())
+        if len(self.param_toFit) >0 and flag==True:
+            self.manager.schedule_for_fit( value=1,fitproblem =None) 
+            if hasattr(self.data, "data"):
+                #single fit for Data2D
+                self.manager._on_single_fit(qmin=self.qmin_x,qmax=self.qmax_x,
+                                            ymin=self.data.ymin, ymax=self.data.ymax,
+                                            xmin=self.data.xmin,xmax=self.data.xmax)
+            else:
+                #single fit for Data1D
+                self.manager._on_single_fit(qmin=self.qmin_x,qmax=self.qmax_x)
+                
+            self.vbox.Layout()
+            self.SetScrollbars(20,20,55,40)
+            self.Layout()
+            self.parent.GetSizer().Layout()
+        else:
+            wx.PostEvent(self.parent.parent, StatusEvent(status=\
+                            "Select at least one parameter to fit "))
+  
+   
+    def _onTextEnter(self,event):
+        """
+            set a flag to determine if the fitting range entered by the user is valid
+        """
+      
+        try:
+            flag=self.checkFitRange()
+            if flag==True and self.model!=None:
+                self.manager.redraw_model(float(self.xmin.GetValue())\
+                                               ,float(self.xmax.GetValue()))
+        except:
+
+            wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
+                            "Drawing  Error:wrong value entered %s"% sys.exc_value))
+        
+   
+    
+    def get_param_list(self):
+        """
+            @return self.param_toFit: list containing  references to TextCtrl
+            checked.Theses TextCtrl will allow reference to parameters to fit.
+            @raise: if return an empty list of parameter fit will nnote work 
+            properly so raise ValueError,"missing parameter to fit"
+        """
+        if self.param_toFit !=[]:
+            return self.param_toFit
+        else:
+            raise ValueError,"missing parameter to fit"
+        
+    
+    def _onparamEnter(self,event):
+        """ 
+            when enter value on panel redraw model according to changed
+        """
+        self.set_model()
+        try:
+            self.compute_chisqr()
+        except:
+            pass
+        
+    def set_model(self): 
+        """
+            Hide panel object related to the previous fit and set
+            values entered by the used inside the model
+        """
+        if len(self.parameters) !=0 and self.model !=None:
+            # Flag to register when a parameter has changed.
+            for item in self.parameters:
+                try:
+                    self.text2_3.Hide()
+                    item[2].Hide()
+                    item[3].Clear()
+                    item[3].Hide()
+                except:
+                    pass
+        self.set_model_parameter()
+        
+    
+    def select_all_param(self,event): 
+        """
+             set to true or false all checkBox given the main checkbox value cb1
+        """
+        self.select_all_param_helper()
+                
+                
+    def select_param(self,event):
+        """ 
+            Select TextCtrl  checked for fitting purpose and stores them
+            in  self.param_toFit=[] list
+        """
+        self.param_toFit=[]
+        for item in self.parameters:
+            #Select parameters to fit for list of primary parameters
+            if item[0].GetValue()==True:
+                list= [item[0],item[1],item[2],item[3]]
+                if not (list  in self.param_toFit):
+                    self.param_toFit.append(list )  
+            else:
+                #remove parameters from the fitting list
+                if item in self.param_toFit:
+                    self.param_toFit.remove(item)
+        #Select parameters to fit for list of fittable parameters with dispersion          
+        for item in self.fittable_param:
+            if item[0].GetValue()==True:
+                list= [item[0],item[1],item[2],item[3]]
+                if not (list  in self.param_toFit):
+                    self.param_toFit.append(list )  
+            else:
+                #remove parameters from the fitting list
+                if item in self.param_toFit:
+                    self.param_toFit.remove(item)           
+        #Set the value of checkbox that selected every checkbox or not            
+        if len(self.parameters)+len(self.fittable_param) ==len(self.param_toFit):
+            self.cb1.SetValue(True)
+        else:
+            self.cb1.SetValue(False)
+       
+       
+    def onsetValues(self,chisqr, out,cov):
+        """
+            Build the panel from the fit result
+            @param chisqr:Value of the goodness of fit metric
+            @param out:list of parameter with the best value found during fitting
+            @param cov:Covariance matrix
+       
+        """
+        self.tcChi.SetLabel(format_number(chisqr))
+        params = {}
+        is_modified = False
+        has_error = False
+        #set the panel when fit result are float not list
+        if out.__class__==numpy.float64:
+            self.param_toFit[0][1].SetValue(format_number(out))
+            self.param_toFit[0][1].Refresh()
+            if cov !=None :
+                self.text2_3.Show()
+                self.param_toFit[0][2].Show()
+                self.param_toFit[0][3].Clear()
+                self.param_toFit[0][3].SetValue(format_number(cov[0]))
+                self.param_toFit[0][3].Show()
+        else:
+            i=0
+            j=0
+            #Set the panel when fit result are list
+            for item in self.param_toFit:
+                if( out != None ) and len(out)<=len(self.param_toFit)and i < len(out):
+                    item[1].SetValue(format_number(self.model.getParam(item[0].GetLabelText())))
+                    item[1].Refresh()
+                if(cov !=None)and len(cov)<=len(self.param_toFit)and i < len(cov):
+                    self.text2_3.Show() 
+                    item[2].Show()
+                    item[3].Clear()
+                    for j in range(len(out)):
+                        if out[j]==self.model.getParam(item[0].GetLabelText()):
+                            break
+                    item[3].SetValue(format_number(cov[j]))
+                    item[3].Show()   
+                i+=1
+        
+        self.vbox.Layout()
+        self.SetScrollbars(20,20,55,40)
+        self.Layout()
+        self.GrandParent.GetSizer().Layout()
+        
+        
+    def onSmear(self, event):
+        """
+            Create a smear object that will change the way residuals
+            are compute when fitting
+        """
+        smear =None
+        msg=""
+        if self.enable_smearer.GetValue():
+            from DataLoader.qsmearing import smear_selection
+            smear =smear_selection( self.data )
+            if hasattr(self.data,"dxl"):
+                msg= ": Resolution smearing parameters"
+            if hasattr(self.data,"dxw"):
+                msg= ": Slit smearing parameters"
+            if smear ==None:
+                wx.PostEvent(self.manager.parent, StatusEvent(status=\
+                            "Data contains no smearing information"))
+            else:
+                wx.PostEvent(self.manager.parent, StatusEvent(status=\
+                            "Data contains smearing information %s"%msg))
+        self.manager.set_smearer(smear)   
+            
+              
+        
+       
Index: sansview/perspectives/fitting/old_modelpage.py
===================================================================
--- sansview/perspectives/fitting/old_modelpage.py	(revision 0b99881db3a31559d8bea44b140993d0b56d76fe)
+++ sansview/perspectives/fitting/old_modelpage.py	(revision 0b99881db3a31559d8bea44b140993d0b56d76fe)
@@ -0,0 +1,1015 @@
+import sys
+import wx
+import wx.lib
+import numpy
+import copy
+import math
+from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion
+
+from sans.guicomm.events import StatusEvent   
+from sans.guiframe.utils import format_number
+(ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()
+_BOX_WIDTH = 80
+
+
+
+
+class ModelPage(wx.ScrolledWindow):
+    """
+        FitPanel class contains fields allowing to display results when
+        fitting  a model and one data
+        @note: For Fit to be performed the user should check at least one parameter
+        on fit Panel window.
+  
+    """
+    ## Internal name for the AUI manager
+    window_name = "Fit page"
+    ## Title to appear on top of the window
+    window_caption = "Fit Page"
+    name=""
+    def __init__(self, parent,model,name, *args, **kwargs):
+        wx.ScrolledWindow.__init__(self, parent, *args, **kwargs)
+        """ 
+            Initialization of the Panel
+        """
+        # model on which the fit would be performed
+        self.model=model
+        # Data member to store the dispersion object created
+        self._disp_obj_dict = {}
+        self.back_up_model= model.clone()
+        #list of dispersion paramaters
+        self.disp_list=[]
+        try:
+            self.disp_list=self.model.getDispParamList()
+        except:
+            pass 
+        self.manager = None
+        self.parent  = parent
+        self.event_owner = None
+        # this panel does contain data .existing data allow a different drawing
+        #on set_model parameters
+        self.data=None
+        #panel interface
+        self.vbox  = wx.BoxSizer(wx.VERTICAL)
+        self.sizer11 = wx.BoxSizer(wx.HORIZONTAL)
+        #self.sizer10 = wx.GridBagSizer(5,5)
+        self.sizer9 = wx.GridBagSizer(5,5)
+        self.sizer8 = wx.GridBagSizer(5,5)
+        self.sizer7 = wx.GridBagSizer(5,5)
+        self.sizer6 = wx.GridBagSizer(5,5)
+        self.sizer5 = wx.GridBagSizer(5,5)
+        self.sizer4 = wx.GridBagSizer(5,5)
+       
+        #model selection
+        self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
+        self.vbox.Add(self.sizer4)
+        #model description
+        self.vbox.Add(self.sizer11)
+        #model paramaters layer
+        self.vbox.Add(self.sizer5)
+        #polydispersion selected
+        self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
+        self.vbox.Add(self.sizer6)
+        #combox box for type of dispersion
+        self.vbox.Add(self.sizer7)
+        #dispersion parameters layer
+        self.vbox.Add(self.sizer8)
+        # plotting range
+        self.vbox.Add(self.sizer9)
+        #close layer
+        #self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
+        #self.vbox.Add(self.sizer10)
+        
+      
+        #------------------ sizer 4  draw------------------------  
+       
+       
+        # define combox box
+        self.modelbox = wx.ComboBox(self, -1)
+         # preview selected model name
+        self.prevmodel_name=name
+        #print "model view prev_model",name
+        self.modelbox.SetValue(self.prevmodel_name)
+        #enable model 2D draw
+        self.enable2D= False
+        #filling sizer2
+        ix = 0
+        iy = 1
+        self.sizer4.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\
+                  , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1
+        self.sizer4.Add(self.modelbox,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        id = wx.NewId()
+        self.model_view =wx.Button(self,id,'View 2D')
+        self.model_view.Bind(wx.EVT_BUTTON, self.onModel2D,id=id)
+        self.model_view.SetToolTipString("View model in 2D")
+        
+        self.sizer4.Add(self.model_view,(iy,ix),(1,1),\
+                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        
+        self.model_view.Enable()
+        self.model_view.SetFocus()
+        
+        ix = 0
+        iy += 1
+        self.sizer4.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+
+        #----------sizer6-------------------------------------------------
+        self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP)
+        self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30))
+        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId())
+        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId())
+        ix= 0
+        iy=1
+        self.sizer6.Add(wx.StaticText(self,-1,'Polydispersity: '),(iy,ix),(1,1)\
+                  , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1
+        self.sizer6.Add(self.enable_disp ,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix =0
+        iy+=1
+        self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)  
+
+        
+        #---------sizer 9 draw----------------------------------------
+       
+         ## Q range
+        self.qmin_x= 0.001
+        self.qmax_x= 0.1
+        self.num_points= 100
+        
+        
+        self.qmin    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
+        self.qmin.SetValue(format_number(self.qmin_x))
+        self.qmin.SetToolTipString("Minimun value of Q in linear scale.")
+        self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+        self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
+     
+        self.qmax    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
+        self.qmax.SetValue(format_number(self.qmax_x))
+        self.qmax.SetToolTipString("Maximum value of Q in linear scale.")
+        self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+        self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
+     
+
+        self.npts    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
+        self.npts.SetValue(format_number(self.num_points))
+        self.npts.SetToolTipString("Number of point to plot.")
+        self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+        self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
+       
+        ix = 0
+        iy = 1 
+        self.sizer9.Add(wx.StaticText(self, -1, 'Plotting Range'),(iy, ix),(1,1),\
+                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1 
+        self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer9.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix = 0
+        iy += 1
+        self.sizer9.Add(wx.StaticText(self, -1, 'Q range'),(iy, ix),(1,1),\
+                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1
+        self.sizer9.Add(self.qmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer9.Add(self.qmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer9.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        
+        ix =0
+        iy+=1 
+        self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        #----------sizer 10 draw------------------------------------------------------
+        """
+        id = wx.NewId()
+        self.btClose =wx.Button(self,id,'Close')
+        self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id)
+        self.btClose.SetToolTipString("Close page.")
+        
+        ix= 3
+        iy= 1
+        self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix +=1
+        self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix =0
+        iy+=1
+        self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        """
+        # contains link between  model ,all its parameters, and panel organization
+        self.parameters=[]
+        self.fixed_param=[]
+        self.fittable_param=[]
+        self.polydisp= {}
+        #contains link between a model and selected parameters to fit 
+        self.param_toFit=[]
+        
+        #dictionary of model name and model class
+        self.model_list_box={}
+        #Draw initial panel
+         #-----sizer 11--------------------model description------
+        if self.model!=None:
+            self.set_panel(self.model)
+        self.theta_cb=None
+       
+       
+        self.vbox.Layout()
+        self.vbox.Fit(self) 
+        self.SetSizer(self.vbox)
+        self.SetScrollbars(20,20,55,40)
+        
+        self.Centre()
+        self.Layout()
+        self.parent.GetSizer().Layout()
+    def set_model_description(self, model):
+        
+        if model !=None and str(model.description)!=""and self.data==None:
+            self.sizer11.Clear(True)
+            self.box_description= wx.StaticBox(self, -1, 'Model Description')
+            boxsizer1 = wx.StaticBoxSizer(self.box_description, wx.VERTICAL)
+            boxsizer1.SetMinSize((320,20))
+            self.description = wx.StaticText(self,-1,str(model.description))
+            boxsizer1.Add(self.description, 0, wx.EXPAND)  
+            self.sizer11.Add(boxsizer1,1, wx.EXPAND | wx.ALL, 2)
+      
+        
+    def set_owner(self,owner):
+        """ 
+            set owner of fitpage
+            @param owner: the class responsible of plotting
+        """
+        self.event_owner=owner    
+   
+  
+    def set_manager(self, manager):
+        """
+             set panel manager
+             @param manager: instance of plugin fitting
+        """
+        self.manager = manager  
+        
+    def populate_box(self, dict):
+        """
+            Populate each combox box of each page
+            @param page: the page to populate
+        """
+        id=0
+        self.model_list_box=dict
+        list_name=[]
+        for item in  self.model_list_box.itervalues():
+            name = item.__name__
+            if hasattr(item, "name"):
+                name = item.name
+            list_name.append(name)
+        list_name.sort() 
+         
+        for name in list_name:
+            self.modelbox.Insert(name,int(id))
+            id+=1
+        wx.EVT_COMBOBOX(self.modelbox,-1, self._on_select_model) 
+        return 0
+    
+
+    def Set_DipersParam(self, event):
+        if self.enable_disp.GetValue():
+            if len(self.disp_list)==0:
+                ix=0
+                iy=1
+                self.fittable_param=[]
+                self.fixed_param=[]
+                self.sizer8.Clear(True)
+                model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model')
+                self.sizer7.Add(model_disp,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+                self.vbox.Layout()
+                self.SetScrollbars(20,20,55,40)
+                self.Layout()
+                self.parent.GetSizer().Layout()
+                return 
+            else:
+                if self.data !=None and self.model !=None: # allow to recognize data panel from model panel
+                    
+                
+                    self.cb1.SetValue(False)
+                    self.select_all_param_helper()
+                
+                self.populate_disp_box()
+                self.set_panel_dispers(self.disp_list)
+                
+        else:
+            if self.data !=None and self.model!=None:
+                if self.cb1.GetValue():
+                    self.select_all_param_helper()
+            
+            if self.back_up_model!=None:
+                keys = self.back_up_model.getDispParamList()
+                keys.sort()
+                #disperse param into the initial state
+                for item in keys:
+                    value= self.back_up_model.getParam(item)
+                    self.model.setParam(item, value)
+                self._draw_model() 
+            
+                
+            self.fittable_param=[]        
+            self.fixed_param=[]
+            self.sizer7.Clear(True)
+            self.sizer8.Clear(True)
+            self.vbox.Layout()
+            self.SetScrollbars(20,20,55,40)
+            self.Layout()
+            self.parent.GetSizer().Layout()
+            
+    def populate_disp_box(self):
+        self.sizer7.Clear(True)
+        if len(self.disp_list)>0:
+            ix=0
+            iy=1
+            model_disp = wx.StaticText(self, -1, 'Model Disp')
+            self.sizer7.Add(model_disp,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+            ix += 1 
+            # set up the combox box
+            id = 0
+            import sans.models.dispersion_models 
+            self.polydisp= sans.models.dispersion_models.models
+            self.disp_box = wx.ComboBox(self, -1)
+            self.disp_box.SetValue("GaussianModel")
+            for k,v in self.polydisp.iteritems():
+                if str(v)=="MyModel":
+    				# Remove the option until the rest of the code is ready for it
+                    #self.disp_box.Insert("Select customized Model",id)
+                    pass  
+                else:
+                    self.disp_box.Insert(str(v),id)         
+                id+=1
+            
+            wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) 
+            self.sizer7.Add(self.disp_box,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            self.vbox.Layout()
+            self.SetScrollbars(20,20,55,40)
+            self.Layout()
+            self.parent.GetSizer().Layout()  
+            
+            
+    def set_range(self, qmin_x, qmax_x, npts):
+        """
+            Set the range for the plotted models
+            @param qmin: minimum Q
+            @param qmax: maximum Q
+            @param npts: number of Q bins
+        """
+        # Set the data members
+        self.qmin_x = qmin_x
+        self.qmax_x = qmax_x
+        self.num_points = npts
+        
+        # Set the controls
+        self.qmin.SetValue(format_number(self.qmin_x))
+        self.qmax.SetValue(format_number(self.qmax_x))
+        self.npts.SetValue(format_number(self.num_points))
+    def checkFitRange(self):
+        """
+            Check the validity of fitting range
+            @note: qmin should always be less than qmax or else each control box
+            background is colored in pink.
+        """
+       
+        flag = True
+        valueMin = self.qmin.GetValue()
+        valueMax = self.qmax.GetValue()
+        # Check for possible values entered
+        #print "fitpage: checkfitrange:",valueMin,valueMax
+        try:
+            if (float(valueMax)> float(valueMin)):
+                self.qmax.SetBackgroundColour(wx.WHITE)
+                self.qmin.SetBackgroundColour(wx.WHITE)
+            else:
+                flag = False
+                self.qmin.SetBackgroundColour("pink")
+                self.qmax.SetBackgroundColour("pink")      
+        except:
+            flag = False
+            self.qmin.SetBackgroundColour("pink")
+            self.qmax.SetBackgroundColour("pink")
+            
+        self.qmin.Refresh()
+        self.qmax.Refresh()
+        return flag
+    
+
+        
+    def onClose(self,event):
+        """ close the page associated with this panel"""
+        self.parent.onClose()
+        
+  
+        
+    def onModel2D(self, event):
+        """
+         call manager to plot model in 2D
+        """
+        # If the 2D display is not currently enabled, plot the model in 2D 
+        # and set the enable2D flag.
+        if self.enable2D==False:
+            self.enable2D=True
+            self._draw_model()
+            self.model_view.Disable()
+            
+    
+    def select_model(self, model, name):
+        """
+            Select a new model
+            @param model: model object 
+        """
+        self.model = model
+        self.parent.model_page.name = name
+        self.parent.draw_model_name = name
+        
+        self.set_panel(model)
+        self._draw_model(name)
+        
+        # Select the model from the combo box
+        items = self.modelbox.GetItems()
+        for i in range(len(items)):
+            if items[i]==name:
+                self.modelbox.SetSelection(i)
+                self.model_view.SetFocus()
+                
+    def _on_select_Disp(self,event):
+        """
+             allow selecting different dispersion
+             self.disp_list should change type later .now only gaussian
+        """
+        type =event.GetString()
+        self.set_panel_dispers( self.disp_list,type )
+                
+    def _on_select_model(self,event):
+        """
+            react when a model is selected from page's combo box
+            post an event to its owner to draw an appropriate theory
+        """
+        self.disable_disp.SetValue(True)
+        self.sizer8.Clear(True)
+        self.sizer7.Clear(True)       
+        self.vbox.Layout()
+        self.SetScrollbars(20,20,55,40)
+        self.Layout()
+        self.parent.GetSizer().Layout()
+        for item in self.model_list_box.itervalues():
+            name = item.__name__
+            if hasattr(item, "name"):
+                name = item.name
+            if name ==event.GetString():
+                model=item()
+                self.model= model
+                self.set_panel(model)
+                self.name= name
+                self.model_view.SetFocus()
+                self.parent.model_page.name=name
+                self.parent.draw_model_name=name
+               
+                self._draw_model(name)
+            
+            
+    def get_model_box(self): 
+        """ return reference to combox box self.model"""
+        return self.modelbox
+
+    
+    def get_param_list(self):
+        """
+            @return self.param_toFit: list containing  references to TextCtrl
+            checked.Theses TextCtrl will allow reference to parameters to fit.
+            @raise: if return an empty list of parameter fit will nnote work 
+            properly so raise ValueError,"missing parameter to fit"
+        """
+        if self.param_toFit !=[]:
+            return self.param_toFit
+        else:
+            raise ValueError,"missing parameter to fit"
+        
+        
+    def set_panel(self,model):
+        """
+            Build the panel from the model content
+            @param model: the model selected in combo box for fitting purpose
+        """
+       
+        self.sizer5.Clear(True)
+        self.parameters = []
+        self.param_toFit=[]
+        self.fixed_param=[]
+        self.model = model
+        
+        self.set_model_description( self.model) 
+        
+        keys = self.model.getParamList()
+        #list of dispersion paramaters
+        self.disp_list=self.model.getDispParamList()
+       
+        keys.sort()
+        ik=0
+        im=1
+        
+        iy = 1
+        ix = 0
+        self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10))
+        if self.data!=None:
+            wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param)
+            self.cb1.SetValue(False)
+        else:
+            self.cb1.Disable()
+            self.cb1.Hide()
+       
+        self.sizer5.Add(self.cb1,(iy, ix),(1,1),\
+                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix +=1
+        self.text2_2 = wx.StaticText(self, -1, 'Values')
+        self.sizer5.Add(self.text2_2,(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
+        ix +=2
+        self.text2_3 = wx.StaticText(self, -1, 'Errors')
+        self.sizer5.Add(self.text2_3,(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        self.text2_3.Hide() 
+        
+       
+        ix +=1
+        self.text2_4 = wx.StaticText(self, -1, 'Units')
+        self.sizer5.Add(self.text2_4,(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
+        self.text2_4.Hide()
+        disp_list=self.model.getDispParamList()
+        for item in keys:
+            if not item in disp_list:
+                iy += 1
+                ix = 0
+    
+                cb = wx.CheckBox(self, -1, item, (10, 10))
+                if self.data!=None:
+                    cb.SetValue(False)
+                    wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param)
+                else:
+                    cb.Disable()
+                self.sizer5.Add( cb,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+               
+                ix += 1
+                value= self.model.getParam(item)
+                ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)
+                ctl1.SetValue(str (format_number(value)))
+                ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+                ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter)
+                self.sizer5.Add(ctl1, (iy,ix),(1,1), wx.EXPAND)
+                
+                ix += 1
+                text2=wx.StaticText(self, -1, '+/-')
+                self.sizer5.Add(text2,(iy, ix),(1,1),\
+                                wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
+                text2.Hide()  
+                ix += 1
+                ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)
+                self.sizer5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+                ctl2.Hide()
+               
+                ix +=1
+                # Units
+                try:
+                    units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT)
+                except:
+                    units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT)
+                self.sizer5.Add(units, (iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+           
+                self.parameters.append([cb,ctl1,text2,ctl2])
+                
+        iy+=1
+        self.sizer5.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        
+        #Display units text on panel
+        for item in keys:   
+            if self.model.details[item][0]!='':
+                self.text2_4.Show()
+                break
+            else:
+                self.text2_4.Hide()
+        
+        self.vbox.Layout()
+        self.SetScrollbars(20,20,55,40)
+        self.Layout()
+        self.parent.GetSizer().Layout()
+        
+        
+        
+    def _selectDlg(self):
+        import os
+        dlg = wx.FileDialog(self, "Choose a weight file", os.getcwd(), "", "*.*", wx.OPEN)
+        path = None
+        if dlg.ShowModal() == wx.ID_OK:
+            path = dlg.GetPath()
+        dlg.Destroy()
+        return path
+    def read_file(self, path):
+        try:
+            if path==None:
+                wx.PostEvent(self.parent.parent, StatusEvent(status=\
+                            " Selected Distribution was not loaded: %s"%path))
+                return None, None
+            input_f = open(path, 'r')
+            buff = input_f.read()
+            lines = buff.split('\n')
+            
+            angles = []
+            weights=[]
+            for line in lines:
+                toks = line.split()
+                if len(toks)==2:
+                    try:
+                        angle = float(toks[0])
+                        weight = float(toks[1])
+                    except:
+                        # Skip non-data lines
+                        pass
+                    angles.append(angle)
+                    weights.append(weight)
+            return numpy.array(angles), numpy.array(weights)
+        except:
+            raise 
+        
+          
+    def select_disp_angle(self, event): 
+        """
+            Event for when a user select a parameter to average over.
+            @param event: check box event
+        """
+        
+        
+        # Go through the list of dispersion check boxes to identify which one has changed 
+        for p in self.disp_cb_dict:
+            # Catch which one of the box was just checked or unchecked.
+            if event.GetEventObject() == self.disp_cb_dict[p]:              
+
+                
+                if self.disp_cb_dict[p].GetValue() == True:
+                    # The user wants this parameter to be averaged. 
+                    # Pop up the file selection dialog.
+                    path = self._selectDlg()
+                    
+                    # If nothing was selected, just return
+                    if path is None:
+                        self.disp_cb_dict[p].SetValue(False)
+                        return
+                    
+                    try:
+                        values,weights = self.read_file(path)
+                    except:
+                        wx.PostEvent(self.parent.parent, StatusEvent(status=\
+                            "Could not read input file"))
+                        return
+                    
+                    # If any of the two arrays is empty, notify the user that we won't
+                    # proceed 
+                    if values is None or weights is None:
+                        wx.PostEvent(self.parent.parent, StatusEvent(status=\
+                            "The loaded %s distrubtion is corrupted or empty" % p))
+                        return
+                        
+                    # Tell the user that we are about to apply the distribution
+                    wx.PostEvent(self.parent.parent, StatusEvent(status=\
+                            "Applying loaded %s distribution: %s" % (p, path)))  
+                    
+                    # Create the dispersion objects
+                    disp_model = ArrayDispersion()
+                    disp_model.set_weights(values, weights)
+                    # Store the object to make it persist outside the scope of this method
+                    #TODO: refactor model to clean this up?
+                    self._disp_obj_dict[p] = disp_model
+                    
+                    # Set the new model as the dispersion object for the selected parameter
+                    self.model.set_dispersion(p, disp_model)
+                    
+                    
+                    # Redraw the model
+                    self._draw_model()
+                         
+                else:
+                    # The parameter was un-selected. Go back to Gaussian model (with 0 pts)
+                    disp_model = GaussianDispersion()
+                    # Store the object to make it persist outside the scope of this method
+                    #TODO: refactor model to clean this up?
+                    self._disp_obj_dict[p] = disp_model
+                    
+                    # Set the new model as the dispersion object for the selected parameter
+                    self.model.set_dispersion(p, disp_model)
+                    
+                    # Redraw the model
+                    self._draw_model()
+        return
+
+                      
+                      
+                      
+    def set_panel_dispers(self, disp_list, type="GaussianModel" ):
+        """
+        """
+        
+        self.fittable_param=[]
+        self.fixed_param=[]
+        
+        ix=0
+        iy=1
+                ### this will become a separate method
+        if type== "Select customized Model":
+            ix=0
+            iy=1
+            self.sizer8.Clear(True)        
+            disp1 = wx.StaticText(self, -1, 'Array Dispersion')
+            self.sizer8.Add(disp1,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+            
+            # Look for model parameters to which we can apply an ArrayDispersion model
+            # Add a check box for each parameter.
+            self.disp_cb_dict = {}
+            for p in self.model.dispersion.keys():
+                ix+=1 
+                self.disp_cb_dict[p] = wx.CheckBox(self, -1, p, (10, 10))
+                
+                wx.EVT_CHECKBOX(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle)
+                self.sizer8.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            
+            ix =0
+            iy +=1 
+            self.sizer8.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)        
+            self.vbox.Layout()
+            self.SetScrollbars(20,20,55,40)
+            self.Layout()
+            self.parent.GetSizer().Layout()  
+           
+        if type== "GaussianModel" :
+
+            self.sizer8.Clear(True)
+            disp = wx.StaticText(self, -1, 'Dispersion')
+            self.sizer8.Add(disp,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+            ix += 1 
+            values = wx.StaticText(self, -1, 'Values')
+            self.sizer8.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            ix +=2
+            self.text2_3 = wx.StaticText(self, -1, 'Errors')
+            self.sizer8.Add(self.text2_3,(iy, ix),(1,1),\
+                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            self.text2_3.Hide() 
+           
+            ix += 1 
+            npts = wx.StaticText(self, -1, 'Npts')
+            self.sizer8.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            ix += 1 
+            nsigmas = wx.StaticText(self, -1, 'Nsigmas')
+            self.sizer8.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            
+            disp_list.sort()
+            #print disp_list,self.model.dispersion
+            for item in self.model.dispersion.keys():
+                name1=item+".width"
+                name2=item+".npts"
+                name3=item+".nsigmas"
+                iy += 1
+                for p in self.model.dispersion[item].keys():
+                    #print "name 1 2 3", name1, name2, name3
+                    if p=="width":
+                        ix = 0
+                        cb = wx.CheckBox(self, -1, name1, (10, 10))
+                        if self.data !=None:
+                            cb.SetValue(False)
+                            wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param)
+                        else:
+                            cb.Disable()
+                        self.sizer8.Add( cb,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+                        ix = 1
+                        value= self.model.getParam(name1)
+                        ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)
+                        ctl1.SetValue(str (format_number(value)))
+                        ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+                        ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter)
+                        self.sizer8.Add(ctl1, (iy,ix),(1,1), wx.EXPAND)
+                        
+                        ix = 2
+                        text2=wx.StaticText(self, -1, '+/-')
+                        self.sizer8.Add(text2,(iy, ix),(1,1),\
+                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
+                        text2.Hide()  
+                        ix = 3
+                        ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)
+                        self.sizer8.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+                        ctl2.Hide()
+                        self.fittable_param.append([cb,ctl1,text2,ctl2])
+                       
+                        
+                    elif p=="npts":
+                            ix =4 
+                            value= self.model.getParam(name2)
+                            Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER)
+                            Tctl.SetValue(str (format_number(value)))
+                            Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+                            Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter)
+                            self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+                            self.fixed_param.append([name2, Tctl])
+                    elif p=="nsigmas":
+                            ix =5 
+                            value= self.model.getParam(name3)
+                            Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER)
+                            Tctl.SetValue(str (format_number(value)))
+                            Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+                            Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter)
+                            self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+                            self.fixed_param.append([name3, Tctl])
+                wx.PostEvent(self.parent.parent, StatusEvent(status=\
+                            " Selected Distribution: Gaussian"))   
+            ix =0
+            iy +=1 
+            self.sizer8.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)        
+            self.vbox.Layout()
+            self.SetScrollbars(20,20,55,40)
+            self.Layout()
+            self.parent.GetSizer().Layout()  
+          
+    def checkFitValues(self,val_min, val_max):
+        """
+            Check the validity of input values
+        """
+        flag = True
+        min_value = val_min.GetValue()
+        max_value = val_max.GetValue()
+        # Check for possible values entered
+        if min_value.lstrip().rstrip() =="-inf":
+            min_value= -numpy.inf
+        if max_value.lstrip().rstrip() =="+inf":
+            max_value= numpy.inf
+        if  min_value==-numpy.inf and max_value== numpy.inf:
+            val_min.SetBackgroundColour(wx.WHITE)
+            val_min.Refresh()
+            val_max.SetBackgroundColour(wx.WHITE)
+            val_max.Refresh()
+            return flag
+        elif max_value== numpy.inf:
+            try:
+                float(min_value)
+                val_min.SetBackgroundColour(wx.WHITE)
+                val_min.Refresh()
+            except:
+                flag = False
+                val_min.SetBackgroundColour("pink")
+                val_min.Refresh()
+            return flag
+        elif min_value==-numpy.inf:
+            try:
+                float(max_value)
+                val_max.SetBackgroundColour(wx.WHITE)
+                val_max.Refresh()
+            except:
+                flag = False
+                val_max.SetBackgroundColour("pink")
+                val_max.Refresh()
+            return flag
+        else:    
+            if (float(min_value)< float(max_value)):
+                val_min.SetBackgroundColour(wx.WHITE)
+                val_min.Refresh()
+            else:
+                flag = False
+                val_min.SetBackgroundColour("pink")
+                val_min.Refresh()
+            return flag   
+           
+        
+    def _onparamEnter(self,event):
+        """ 
+            when enter value on panel redraw model according to changed
+        """
+        self.set_model_parameter()
+        
+    def set_model_parameter(self):
+        """
+        """
+        if len(self.parameters) !=0 and self.model !=None:
+            # Flag to register when a parameter has changed.
+            is_modified = False
+            for item in self.fittable_param:
+                try:
+                     name=str(item[0].GetLabelText())
+                     value= float(item[1].GetValue())
+                     # If the value of the parameter has changed,
+                     # update the model and set the is_modified flag
+                     if value != self.model.getParam(name):
+                         self.model.setParam(name,value)
+                         is_modified = True
+                         
+                except:
+                    #raise
+                    wx.PostEvent(self.parent.parent, StatusEvent(status=\
+                            "Model Drawing  Error:wrong value entered : %s"% sys.exc_value))
+                    return 
+                
+                
+            for item in self.fixed_param:
+                try:
+                     name=str(item[0])
+                     value= float(item[1].GetValue())
+                     # If the value of the parameter has changed,
+                     # update the model and set the is_modified flag
+                     if value != self.model.getParam(name):
+                         self.model.setParam(name,value)
+                         is_modified = True
+                         
+                except:
+                    raise
+                    wx.PostEvent(self.parent.parent, StatusEvent(status=\
+                            "Model Drawing  Error:wrong value entered : %s"% sys.exc_value))
+                
+            for item in self.parameters:
+                try:
+                     name=str(item[0].GetLabelText())
+                     value= float(item[1].GetValue())
+                     # If the value of the parameter has changed,
+                     # update the model and set the is_modified flag
+                     if value != self.model.getParam(name):
+                         self.model.setParam(name,value)
+                         is_modified = True
+                   
+                except:
+                    #raise 
+                    wx.PostEvent(self.parent.parent, StatusEvent(status=\
+                           "Model Drawing  Error:wrong value entered : %s"% sys.exc_value))
+                    return
+                
+                
+            # Here we should check whether the boundaries have been modified.
+            # If qmin and qmax have been modified, update qmin and qmax and 
+            # set the is_modified flag to True
+            if float(self.qmin.GetValue()) != self.qmin_x:
+                self.qmin_x = float(self.qmin.GetValue())
+                is_modified = True
+            if float(self.qmax.GetValue()) != self.qmax_x:
+                self.qmax_x = float(self.qmax.GetValue())
+                is_modified = True
+            
+            if float(self.npts.GetValue()) !=  self.num_points:
+                self.num_points = float(self.npts.GetValue())
+                is_modified = True
+          
+            if is_modified:
+                self._draw_model()            
+            
+    def _draw_model(self, name=None):
+        """
+            Method to draw or refresh a plotted model.
+            The method will use the data member from the model page
+            to build a call to the fitting perspective manager.
+            
+            [Note to coder: This way future changes will be done in only one place.] 
+        """
+        if name==None:
+            name= self.model.name
+       
+        self.manager.draw_model(self.model, name, data=self.data,
+                                qmin=self.qmin_x, qmax=self.qmax_x,
+                                qstep= self.num_points,
+                                enable2D=self.enable2D)
+       
+    def select_param(self,event):
+        """
+        
+        """
+        pass
+    def select_all_param(self,event): 
+        """
+        
+        """
+        pass
+    def select_all_param_helper(self):
+        """
+             Allows selecting or delecting button
+        """
+        self.param_toFit=[]
+        if  self.parameters !=[]:
+            if  self.cb1.GetValue()==True:
+                for item in self.parameters:
+                    item[0].SetValue(True)
+                    list= [item[0],item[1],item[2],item[3]]
+                    self.param_toFit.append(list )
+                if len(self.fittable_param)>0:
+                    for item in self.fittable_param:
+                        item[0].SetValue(True)
+                        list= [item[0],item[1],item[2],item[3]]
+                        self.param_toFit.append(list )
+            else:
+                for item in self.parameters:
+                    item[0].SetValue(False)
+                for item in self.fittable_param:
+                    item[0].SetValue(False)
+                self.param_toFit=[]
+               
+                
+       
