Index: sansview/perspectives/fitting/fitpage1D.py
===================================================================
--- sansview/perspectives/fitting/fitpage1D.py	(revision 0aac36fb40791fbe95c080bfc82a9f9adc04e22b)
+++ sansview/perspectives/fitting/fitpage1D.py	(revision d23544dc7fd696d91cd1cad277cfeaadecd7e55d)
@@ -24,6 +24,7 @@
         return "%-5.3g" % value
 
-    
-class FitPage1D(wx.ScrolledWindow):
+from modelpage import format_number
+from modelpage import ModelPage
+class FitPage1D(ModelPage):
     """
         FitPanel class contains fields allowing to display results when
@@ -202,30 +203,7 @@
        
 
-        
-        
-        
-        
-        
-        
-    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 onClose(self,event):
-        """ close the page associated with this panel"""
-        self.GrandParent.onClose()
-        
         
     def compute_chisqr(self):
@@ -273,24 +251,5 @@
               wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
                             "Select at least on parameter to fit "))
-    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 _on_select_model(self,event):
@@ -361,8 +320,4 @@
         return flag
     
-
-    def get_model_box(self): 
-        """ return reference to combox box self.model"""
-        return self.modelbox
 
     
@@ -543,4 +498,5 @@
             for item in self.parameters:
                 try:
+                    self.text2_3.Hide()
                     item[2].Hide()
                     item[3].Clear()
@@ -567,10 +523,6 @@
             
             if is_modified:
-                self.manager.redraw_model(
-                                        qmin=self.qmin, qmax=self.qmax,
-                                        )
-            #self.manager.draw_model(self,model,description=None,
-            # enable1D=True,qmin=None,qmax=None, qstep=None)
-           
+                self.manager.redraw_model(qmin=self.qmin, qmax=self.qmax)
+         
     def select_all_param(self,event): 
         """
Index: sansview/perspectives/fitting/fitpage2D.py
===================================================================
--- sansview/perspectives/fitting/fitpage2D.py	(revision 0aac36fb40791fbe95c080bfc82a9f9adc04e22b)
+++ sansview/perspectives/fitting/fitpage2D.py	(revision d23544dc7fd696d91cd1cad277cfeaadecd7e55d)
@@ -9,21 +9,8 @@
 _BOX_WIDTH = 80
 
-def format_number(value, high=False):
-    """
-        Return a float in a standardized, human-readable formatted string 
-    """
-    try: 
-        value = float(value)
-    except:
-        print "returning 0"
-        return "0"
+from modelpage import format_number
+from fitpage1D import FitPage1D
     
-    if high:
-        return "%-6.4g" % value
-    else:
-        return "%-5.3g" % value
-
-    
-class FitPage2D(wx.ScrolledWindow):
+class FitPage2D(FitPage1D):
     """
         FitPanel class contains fields allowing to display results when
@@ -49,4 +36,5 @@
         #panel interface
         self.vbox  = wx.BoxSizer(wx.VERTICAL)
+        self.sizer6 = wx.GridBagSizer(5,5)
         self.sizer5 = wx.GridBagSizer(5,5)
         self.sizer4 = wx.GridBagSizer(5,5)
@@ -54,4 +42,5 @@
         self.sizer2 = wx.GridBagSizer(5,5)
         self.sizer1 = wx.GridBagSizer(5,5)
+        
         #self.DataSource      = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
         #self.DataSource.SetToolTipString("name of data to fit")
@@ -70,4 +59,5 @@
         self.vbox.Add(self.static_line_1, 0, wx.EXPAND, 0)
         self.vbox.Add(self.sizer5)
+        self.vbox.Add(self.sizer6)
         self.vbox.Add(self.sizer4)
         self.vbox.Add(self.sizer1)
@@ -174,4 +164,5 @@
         # contains link between  model ,all its parameters, and panel organization
         self.parameters=[]
+        self.fixed_param=[]
         #contains link between a model and selected parameters to fit 
         self.param_toFit=[]
@@ -191,25 +182,5 @@
         self.Centre()
         
-        
-    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 onClose(self,event):
-        """ close the page associated with this panel"""
-        self.GrandParent.onClose()
-        
         
     def compute_chisqr(self):
@@ -225,11 +196,11 @@
                 ymin = float(self.ymin.GetValue())
                 ymax = float(self.ymax.GetValue())
-               
-                for i in range(len(self.data.y_bins)):
-                    if self.data.y_bins[i]>= ymin and self.data.y_bins[i]<= ymax:
-                        for j in range(len(self.data.x_bins)):
-                            if self.data.x_bins[j]>= xmin and self.data.x_bins[j]<= xmax:
+                for i in range(len(self.data.x_bins)):
+                    if self.data.x_bins[i]>= xmin and self.data.x_bins[i]<= xmax:
+                        for j in range(len(self.data.y_bins)):
+                            if self.data.y_bins[j]>= ymin and self.data.y_bins[j]<= ymax:
+                                print "data error ",self.data.err_data[j][i]
                                 res.append( (self.data.data[j][i]- self.model.runXY(\
-                                 [self.data.x_bins[j],self.data.y_bins[i]]))\
+                                 [self.data.x_bins[i],self.data.y_bins[j]]))\
                                     /self.data.err_data[j][i] )
                 sum=0
@@ -238,415 +209,10 @@
                     if numpy.isfinite(item):
                         sum +=item
+                print "chisqr : sum 2D", xmin, xmax, ymin, ymax,sum
+                #print res
                 self.tcChi.SetValue(format_number(math.fabs(sum)))
             except:
                 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
                             "Chisqr cannot be compute: %s"% sys.exc_value))
-            
-            
-    def onFit(self,event):
-        """ signal for fitting"""
-        flag=self.checkFitRange()
-        self.set_manager(self.manager)
-     
-        qmin=float(self.xmin.GetValue())
-        qmax =float( self.xmax.GetValue())
-        if len(self.param_toFit) >0 and flag==True:
-            self.manager.schedule_for_fit( value=1,fitproblem =None) 
-            self.manager._on_single_fit(qmin=qmin,qmax=qmax)
-        else:
-            wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
-                            "Select at least on parameter to fit "))
-    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 _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()
-        for item in self.model_list_box.itervalues():
-            name = item.__name__
-            if hasattr(item, "name"):
-                name = item.name
-            #print "fitpage: _on_select_model model name",name ,event.GetString()
-            if name ==event.GetString():
-                try:
-                    evt = ModelEventbox(model=item(),name=name)
-                    wx.PostEvent(self.event_owner, evt)
-                except:
-                    raise #ValueError,"model.name is not equal to model class name"
-                break
-    
-    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:
-                print"fit page",self.xmin.GetValue(),self.xmax.GetValue()
-                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 checkFitRange(self):
-        """
-            Check the validity of fitting range
-            @note: xmin should always be less than xmax or else each control box
-            background is colored in pink.
-        """
-       
-        flag = True
-        valueMin = self.xmin.GetValue()
-        valueMax = self.xmax.GetValue()
-        # Check for possible values entered
-        print "fitpage: checkfitrange:",valueMin,valueMax
-        try:
-            if (float(valueMax)> float(valueMin)):
-                self.xmax.SetBackgroundColour(wx.WHITE)
-                self.xmin.SetBackgroundColour(wx.WHITE)
-            else:
-                flag = False
-                self.xmin.SetBackgroundColour("pink")
-                self.xmax.SetBackgroundColour("pink")      
-        except:
-            flag = False
-            self.xmin.SetBackgroundColour("pink")
-            self.xmax.SetBackgroundColour("pink")
-            
-        self.xmin.Refresh()
-        self.xmax.Refresh()
-        return flag
-    
-  
-    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.sizer2.Clear(True)
-        self.sizer5.Clear(True)
-        self.parameters = []
-        self.param_toFit=[]
-        self.model = model
-        keys = self.model.getParamList()
-        #print "fitpage1D : dispersion list",self.model.getDispParamList()
-        keys.sort()
-        disp_list=self.model.getDispParamList()
-        ip=0
-        iq=1
-        if len(disp_list)>0:
-            disp = wx.StaticText(self, -1, 'Dispersion')
-            self.sizer5.Add(disp,( iq, ip),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-            ip += 1 
-            values = wx.StaticText(self, -1, 'Values')
-            self.sizer5.Add(values,( iq, ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-            
-        disp_list.sort()
-        iy = 1
-        ix = 0
-        self.cb1 = wx.CheckBox(self, -1,'Parameters', (10, 10))
-        wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param)
-        self.sizer2.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.sizer2.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.sizer2.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.sizer2.Add(self.text2_4,(iy, ix),(1,1),\
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
-        self.text2_4.Hide()
-        
-        for item in keys:
-            if not item in disp_list:
-                iy += 1
-                ix = 0
-    
-                cb = wx.CheckBox(self, -1, item, (10, 10))
-                cb.SetValue(False)
-                self.sizer2.Add( cb,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-                wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param)
-                
-                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.sizer2.Add(ctl1, (iy,ix),(1,1), wx.EXPAND)
-                ix += 1
-                text2=wx.StaticText(self, -1, '+/-')
-                self.sizer2.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.sizer2.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.sizer2.Add(units, (iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-            else:
-                ip = 0
-                iq += 1
-                cb = wx.CheckBox(self, -1, item, (10, 10))
-                cb.SetValue(False)
-                self.sizer5.Add( cb,( iq, ip),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-                wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param)
-                
-                ip += 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, (iq,ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-                
-            #save data
-            self.parameters.append([cb,ctl1,text2,ctl2])
-                
-        iy+=1
-        self.sizer2.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()
-        #Disable or enable fit button
-        
-        if not (len(self.param_toFit ) >0):
-            self.xmin.Disable()
-            self.xmax.Disable()
-            self.ymin.Disable()
-            self.ymax.Disable()
-        else:
-            self.xmin.Enable()
-            self.xmax.Enable()
-            self.ymin.Enable()
-            self.ymax.Enable()
-     
-        self.compute_chisqr()
-        self.vbox.Layout()
-        self.SetScrollbars(20,20,55,40)
-        self.Layout()
-        
-        self.GrandParent.GetSizer().Layout()
-        
-    
-        
-    def _onparamEnter(self,event):
-        """ 
-            when enter value on panel redraw model according to changed
-        """
-        self.set_model_parameter()
-        self.compute_chisqr()
-     
-    def set_model_parameter(self):
-        """
-            this method redraws the model according to parameters values changes
-            and the reset model according to paramaters changes
-        """
-        print "went here",len(self.parameters) ,self.model
-        if len(self.parameters) !=0 and self.model !=None:
-            # Flag to register when a parameter has changed.
-            is_modified = False
-            for item in self.parameters:
-                try:
-                    item[2].Hide()
-                    item[3].Clear()
-                    item[3].Hide()
-                    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:
-                     wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
-                            "Drawing  Error:wrong value entered : %s"% sys.exc_value))
-            # 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.xmin.GetValue()) != self.qmin:
-                self.qmin = float(self.xmin.GetValue())
-                is_modified = True
-            if float(self.xmax.GetValue()) != self.qmax:
-                self.qmax = float(self.xmax.GetValue())
-                is_modified = True
-            
-            if is_modified:
-                
-                self.manager.redraw_model( 
-                                        qmin=self.qmin, qmax=self.qmax,
-                                        )
-                #self.manager.draw_model(self,model,description=None,
-                # enable1D=True,qmin=None,qmax=None, qstep=None)
-           
-    def select_all_param(self,event): 
-        """
-             set to true or false all checkBox given the main checkbox value cb1
-        """
-        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 not (len(self.param_toFit ) >0):
-                    self.xmin.Disable()
-                    self.xmax.Disable()
-                    self.ymin.Disable()
-                    self.ymax.Disable()
-                else:
-                    self.xmin.Enable()
-                    self.xmax.Enable()
-                    self.ymin.Enable()
-                    self.ymax.Enable()
-            else:
-                for item in self.parameters:
-                    item[0].SetValue(False)
-                self.param_toFit=[]
-              
-                self.xmin.Disable()
-                self.xmax.Disable()
-                self.ymin.Disable()
-                self.ymax.Disable()
-                
-                
-    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:
-            if item[0].GetValue()==True:
-                list= [item[0],item[1],item[2],item[3]]
-                self.param_toFit.append(list )  
-            else:
-                if item in self.param_toFit:
-                    self.param_toFit.remove(item)
-        if len(self.parameters)==len(self.param_toFit):
-            self.cb1.SetValue(True)
-        else:
-            self.cb1.SetValue(False)
-       
-        if not (len(self.param_toFit ) >0):
-            self.xmin.Disable()
-            self.xmax.Disable()
-            self.ymin.Disable()
-            self.ymax.Disable()
-        else:
-            self.xmin.Enable()
-            self.xmax.Enable()
-            self.ymin.Enable()
-            self.ymax.Enable()
-      
-   
-       
-  
-    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
-       
-        """
-        #print "fitting : onsetvalues out",out
-        self.tcChi.Clear()
-        self.tcChi.SetValue(format_number(chisqr))
-        params = {}
-        is_modified = False
-        has_error = False
-        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()
-        #out is a list : set parameters and errors in TextCtrl
-        else:
-            i=0
-            #print "fitpage: list param  model",list
-            #for item in self.param_toFit:
-            #    print "fitpage: list display",item[0].GetLabelText()
-            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(out[i]))
-                    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()
-                    item[3].SetValue(format_number(cov[i]))
-                    item[3].Show()   
-                i+=1
-        
-        self.vbox.Layout()
-        self.SetScrollbars(20,20,55,40)
-        self.Layout()
-        self.GrandParent.GetSizer().Layout()
-    
+        
+ 
Index: sansview/perspectives/fitting/fitting.py
===================================================================
--- sansview/perspectives/fitting/fitting.py	(revision e8d1066ef2c0e8981ef284b656fb716b3040979f)
+++ sansview/perspectives/fitting/fitting.py	(revision d23544dc7fd696d91cd1cad277cfeaadecd7e55d)
@@ -120,5 +120,6 @@
         #create the fitting panel
         return [self.fit_panel]
-   
+    def _on_show_panel(self, event):
+        print "_on_show_panel: fitting"
       
     def get_perspective(self):
@@ -653,6 +654,8 @@
                 except:
                     raise
-    def update(self, output):
-        print "Got an update"
+    def update(self, output,elapsed):
+        print "Got an update", elapsed
+        wx.PostEvent(self.parent, StatusEvent(status="Plot \
+        updating ... %g sec" % elapsed))
     
     def complete(self, output, elapsed, model, qmin, qmax):
Index: sansview/perspectives/fitting/modelpage.py
===================================================================
--- sansview/perspectives/fitting/modelpage.py	(revision d15c02022d76c57e7bc024e447f04fd9510dff8b)
+++ sansview/perspectives/fitting/modelpage.py	(revision d23544dc7fd696d91cd1cad277cfeaadecd7e55d)
@@ -187,4 +187,6 @@
          call manager to plot model in 2D
         """
+        if self.enable2D== True:
+            print "modelpage already plot",
         # If the 2D display is not currently enabled, plot the model in 2D 
         # and set the enable2D flag.
@@ -197,4 +199,5 @@
                                      qmin=float(self.qmin),
                                     qmax=float(self.qmax))
+       
             
     def populate_box(self, dict):
@@ -225,5 +228,5 @@
             post an event to its owner to draw an appropriate theory
         """
-        #print "modelpage: self.model_list_box ",self.model_list_box
+        self.model_view.SetFocus()
         for item in self.model_list_box.itervalues():
             name = item.__name__
@@ -239,5 +242,5 @@
                 self.manager.draw_model(model, name)
                 
-            self.model_view.SetFocus()
+            
             
     def get_model_box(self): 
