Index: sansview/perspectives/fitting/fitpage1D.py
===================================================================
--- sansview/perspectives/fitting/fitpage1D.py	(revision 0b99881db3a31559d8bea44b140993d0b56d76fe)
+++ sansview/perspectives/fitting/fitpage1D.py	(revision fbc3e04d15ffaab1536bf382f5824db7c7239055)
@@ -18,7 +18,6 @@
 class FitPage1D(ModelPage):
     """
-        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.
+        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.
@@ -31,16 +30,25 @@
     name=None
     
-    def __init__(self, parent,data,model=None, name=None, *args, **kwargs):
+    def __init__(self, parent,data, *args, **kwargs):
+        wx.ScrolledWindow.__init__(self, parent, *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
-        
-    
-        
-    def draw_panel(self):
+        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)
@@ -79,5 +87,5 @@
         #---------sizer 1 draw--------------------------------
         #Filling the sizer containing data related fields
-        self.DataSource  =wx.StaticText(self, -1,str(self.data.name))
+        self.DataSource  =wx.StaticText(self, -1,str(data.name))
         ix = 0
         iy = 1
@@ -93,7 +101,7 @@
             iy = 1
             # Minimum value of data   
-            self.data_min = wx.StaticText(self, -1,str(format_number(numpy.min(self.data.x))))
+            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(self.data.x))))   
+            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),\
@@ -152,6 +160,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_Dispers_Param, id=self.disable_disp.GetId())
-        self.Bind(wx.EVT_RADIOBUTTON, self.set_Dispers_Param, id=self.enable_disp.GetId())
+        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
@@ -239,5 +247,31 @@
         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()
@@ -246,4 +280,8 @@
         self.SetScrollbars(20,20,55,40)
         
+        self.Centre()
+        self.Layout()
+        self.GrandParent.GetSizer().Layout()
+   
     def compute_chisqr2D(self):
         """ 
@@ -260,11 +298,9 @@
                     for j in range(len(self.data.y_bins)):
                         #Check the range containing data between self.qmin_x and self.qmax_x
-                        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]
+                        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) )
@@ -276,6 +312,6 @@
                 self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
             except:
-                msg= "Chisqr cannot be compute: %s"% sys.exc_value
-                wx.PostEvent(self.parent.GrandParent, StatusEvent(status= msg ))
+                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
+                            "Chisqr cannot be compute: %s"% sys.exc_value))
                 return
     
@@ -295,5 +331,5 @@
                     self.qmin_x = float(self.qmin.GetValue())
                     self.qmax_x = float(self.qmax.GetValue())
-                    # Compute residuals within self.qmin_x and self.qmax_x
+                    # 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: 
@@ -313,8 +349,7 @@
                     self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
             except:
-                msg=  "Chisqr cannot be compute: %s"% sys.exc_value
-                wx.PostEvent(self.parent.GrandParent, StatusEvent(status= msg))
+                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
+                            "Chisqr cannot be compute: %s"% sys.exc_value))
                 return 
-            
             
     def _on_select_model(self,event):
@@ -345,17 +380,16 @@
             
             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:
-                    self.text1_1.Hide()
-                    pass
+                    raise #ValueError,"model.name is not equal to model class name"
                 break  
-                 
+            
                  
     def onFit(self,event):
@@ -383,7 +417,24 @@
             self.parent.GetSizer().Layout()
         else:
-            msg= "Select at least one parameter to fit "
-            wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
+            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):
@@ -408,5 +459,4 @@
             self.compute_chisqr()
         except:
-            self.text1_1.Hide()
             pass
         
@@ -462,5 +512,5 @@
                 if item in self.param_toFit:
                     self.param_toFit.remove(item)           
-        #Set the value of checkbox that selected all checkboxes or not to true or false           
+        #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)
Index: sansview/perspectives/fitting/modelpage.py
===================================================================
--- sansview/perspectives/fitting/modelpage.py	(revision 0b99881db3a31559d8bea44b140993d0b56d76fe)
+++ sansview/perspectives/fitting/modelpage.py	(revision fbc3e04d15ffaab1536bf382f5824db7c7239055)
@@ -14,8 +14,11 @@
 
 
+
 class ModelPage(wx.ScrolledWindow):
     """
-        ModelPage is a panel that allows the user to view information related to a 
-        model. 
+        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.
   
     """
@@ -24,8 +27,7 @@
     ## Title to appear on top of the window
     window_caption = "Fit Page"
-    # name of the panel directly related to the model name selected
-    name =" "
-
-    def __init__(self, parent,model=None,name=None,data=None, *args, **kwargs):
+    name=""
+    
+    def __init__(self, parent,model,name, *args, **kwargs):
         wx.ScrolledWindow.__init__(self, parent, *args, **kwargs)
         """ 
@@ -37,6 +39,6 @@
         ## Data member to store the dispersion object created
         self._disp_obj_dict = {}
-        
-        #list of dispersion parameters
+
+        #list of dispersion paramaters
         self.disp_list=[]
         try:
@@ -49,35 +51,5 @@
         # this panel does contain data .existing data allow a different drawing
         #on set_model parameters
-        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):   
+        self.data=None
         #panel interface
         self.vbox  = wx.BoxSizer(wx.VERTICAL)
@@ -90,4 +62,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)
@@ -106,10 +79,16 @@
         # 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)
@@ -142,6 +121,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_Dispers_Param, id=self.disable_disp.GetId())
-        self.Bind(wx.EVT_RADIOBUTTON, self.set_Dispers_Param, id=self.enable_disp.GetId())
+        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
@@ -155,6 +134,9 @@
         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
@@ -208,4 +190,37 @@
         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) 
@@ -213,10 +228,9 @@
         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)
@@ -266,7 +280,10 @@
     
 
-    def set_Dispers_Param(self, event):
-        """
-             set a sizer with dispersion parameters 
+    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.
         """
         if self.enable_disp.GetValue():
@@ -287,10 +304,5 @@
                 return 
             else:
-                # 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()
-                
+                # Show the default dispersion/averaging sub-panel
                 self.populate_disp_box()
                 self.set_panel_dispers(self.disp_list)
@@ -323,7 +335,4 @@
             
     def populate_disp_box(self):
-        """
-            populate polydispersion combo box 
-        """
         self.sizer7.Clear(True)
         if len(self.disp_list)>0:
@@ -341,5 +350,5 @@
             for k,v in self.polydisp.iteritems():
                 if str(v)=="MyModel":
-    				# Remove the option until the rest of the code is ready for it
+                    # Remove the option until the rest of the code is ready for it
                     #self.disp_box.Insert("Select customized Model",id)
                     pass  
@@ -372,6 +381,4 @@
         self.qmax.SetValue(format_number(self.qmax_x))
         self.npts.SetValue(format_number(self.num_points))
-        
-        
     def checkFitRange(self):
         """
@@ -380,8 +387,10 @@
             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)):
@@ -401,4 +410,11 @@
         return flag
     
+
+        
+    def onClose(self,event):
+        """ close the page associated with this panel"""
+        self.parent.onClose()
+        
+  
         
     def onModel2D(self, event):
@@ -440,6 +456,5 @@
         type =event.GetString()
         self.set_panel_dispers( self.disp_list,type )
-          
-     
+                
     def _on_select_model(self,event):
         """
@@ -532,4 +547,5 @@
         self.text2_3.Hide() 
         
+       
         ix +=1
         self.text2_4 = wx.StaticText(self, -1, 'Units')
@@ -538,5 +554,4 @@
         self.text2_4.Hide()
         disp_list=self.model.getDispParamList()
-        # 
         for item in keys:
             if not item in disp_list:
@@ -599,7 +614,4 @@
         
     def _selectDlg(self):
-        """
-            Create a dialog to select files
-        """
         import os
         dlg = wx.FileDialog(self, "Choose a weight file", os.getcwd(), "", "*.*", wx.OPEN)
@@ -609,12 +621,5 @@
         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:
@@ -641,8 +646,5 @@
             return numpy.array(angles), numpy.array(weights)
         except:
-             msg= "Simultaneous Fit completed but Following error occurred: "
-             msg+= "%s"%sys.exc_value
-             wx.PostEvent(self.parent.parent, StatusEvent(status=msg))
-             return  
+            raise 
         
           
@@ -652,4 +654,6 @@
             @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:
@@ -713,9 +717,10 @@
                     self._draw_model()
         return
-       
+
+                      
+                      
                       
     def set_panel_dispers(self, disp_list, type="GaussianModel" ):
         """
-            Fill sizer with disperstion info
         """
         
@@ -838,5 +843,4 @@
             self.parent.GetSizer().Layout()  
           
-          
     def checkFitValues(self,val_min, val_max):
         """
@@ -894,10 +898,6 @@
         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,4 +915,5 @@
                          
                 except:
+                    #raise
                     wx.PostEvent(self.parent.parent, StatusEvent(status=\
                             "Model Drawing  Error:wrong value entered : %s"% sys.exc_value))
@@ -931,6 +932,7 @@
                          
                 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:
@@ -947,5 +949,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
                 
@@ -968,5 +970,4 @@
                 self._draw_model()            
             
-            
     def _draw_model(self, name=None):
         """
@@ -985,22 +986,17 @@
                                 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 unselecting  checkbutton
+             Allows selecting or delecting button
         """
         self.param_toFit=[]
