Index: sansview/perspectives/fitting/fitting.py
===================================================================
--- sansview/perspectives/fitting/fitting.py	(revision 68dada4186cf20bcf5b82b8075b3a1db20a3eac8)
+++ sansview/perspectives/fitting/fitting.py	(revision c80c06f9182eb95705aa07e379064743d2a79ebd)
@@ -445,4 +445,5 @@
                             wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value))
                             return
+                    # need to check this print "new model "
                     new_model=Model(model)
                     param=value.get_model_param()
@@ -458,5 +459,5 @@
                             #new_model.set( exec "%s"%(param_nam) = param_value)
                             new_model.parameterset[ param_name].set( param_value )
-                            
+                          
                     self.fitter.set_model(new_model, self.id, pars) 
                     self.fitter.set_data(metadata,self.id,qmin,qmax,ymin,ymax)
Index: sansview/perspectives/fitting/new_fitpage1D.py
===================================================================
--- sansview/perspectives/fitting/new_fitpage1D.py	(revision 68dada4186cf20bcf5b82b8075b3a1db20a3eac8)
+++ sansview/perspectives/fitting/new_fitpage1D.py	(revision c80c06f9182eb95705aa07e379064743d2a79ebd)
@@ -5,25 +5,12 @@
 import copy
 import sans.models.dispersion_models 
-from sans.guicomm.events import StatusEvent   
+from sans.guicomm.events import StatusEvent 
+from modelpage import ModelPage  
+from modelpage import format_number
 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()
 _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"
-    
-    if high:
-        return "%-6.4g" % value
-    else:
-        return "%-5.3g" % value
 
-from modelpage import format_number
-from modelpage import ModelPage
+
 class FitPage1D(ModelPage):
     """
@@ -52,4 +39,5 @@
         #panel interface
         self.vbox  = wx.BoxSizer(wx.VERTICAL)
+        self.sizer10 = wx.GridBagSizer(5,5)
         self.sizer9 = wx.GridBagSizer(5,5)
         self.sizer8 = wx.GridBagSizer(5,5)
@@ -76,13 +64,14 @@
         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(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
-        self.vbox.Add(self.sizer7)
+        self.vbox.Add(self.sizer8)
         #fit info layer
         self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
-        self.vbox.Add(self.sizer8)
+        self.vbox.Add(self.sizer9)
         #close layer
         self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
-        self.vbox.Add(self.sizer9)
+        self.vbox.Add(self.sizer10)
         
         #---------sizer 1 draw--------------------------------
@@ -117,5 +106,5 @@
         #---------sizer 2 draw--------------------------------
         ix = 0
-        iy = 0
+        iy = 1
         #set maximum range for x in linear scale
         self.text4_3 = wx.StaticText(self, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT)
@@ -136,5 +125,5 @@
         #----sizer 3 draw--------------------------------
         ix = 0
-        iy = 0
+        iy = 1
         self.sizer3.Add(wx.StaticText(self,-1,'Instrument Smearing'),(iy,ix),(1,1)\
                   , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
@@ -159,6 +148,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_DipersParam, id=self.disable_disp.GetId())
+        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId())
         ix= 0
         iy=1
@@ -169,7 +158,10 @@
         ix += 1
         self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        
-        
-        #---------sizer 8 draw----------------------------------------
+        ix =0
+        iy+=1
+        self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)  
+
+        
+        #---------sizer 9 draw----------------------------------------
         self.tcChi    =  wx.StaticText(self, -1, str(0), style=wx.ALIGN_LEFT)
         self.tcChi.Hide()
@@ -209,37 +201,37 @@
         ix = 0
         iy = 1 
-        self.sizer8.Add(wx.StaticText(self, -1, 'Fitting Range'),(iy, ix),(1,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.sizer8.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\
+        self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\
                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)
         ix += 1
-        self.sizer8.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\
+        self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\
                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)
         ix += 1
-        self.sizer8.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\
+        self.sizer9.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\
                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)
         ix = 0
         iy += 1
-        self.sizer8.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\
+        self.sizer9.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\
                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
         ix += 1
-        self.sizer8.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        ix += 1
-        self.sizer8.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        ix += 1
-        self.sizer8.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        self.sizer9.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer9.Add(self.xmax,(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.sizer8.Add(self.text1_1,(iy,ix),(1,1),\
+        self.sizer9.Add(self.text1_1,(iy,ix),(1,1),\
                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
         ix += 1
-        self.sizer8.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        self.sizer9.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
         ix +=2
-        self.sizer8.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        self.sizer9.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|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, 0)
-        #----------sizer 9 draw------------------------------------------------------
+        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')
@@ -247,12 +239,12 @@
         self.btClose.SetToolTipString("Close page.")
         
-        ix= 0
+        ix= 3
         iy= 1
-        self.sizer9.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        ix +=3
-        self.sizer9.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        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.sizer9.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        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
@@ -278,10 +270,6 @@
         self.Layout()
         self.GrandParent.GetSizer().Layout()
-       
-
-  
-  
- 
-        
+   
+   
     def compute_chisqr(self):
         """ @param fn: function that return model value
@@ -308,10 +296,30 @@
                     if numpy.isfinite(item):
                         sum +=item
-                self.tcChi.SetValue(format_number(math.fabs(sum)))
+                self.tcChi.SetLabel(format_number(math.fabs(sum)))
             except:
                 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
                             "Chisqr cannot be compute: %s"% sys.exc_value))
             
-            
+    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:
+                    self.model=item()
+                    evt = ModelEventbox(model=self.model,name=name)
+                    wx.PostEvent(self.event_owner, evt)
+                    #self.model= item()
+                    #self.set_panel(self.model)
+                except:
+                    raise #ValueError,"model.name is not equal to model class name"
+                break       
     def onFit(self,event):
         """ signal for fitting"""
@@ -329,27 +337,5 @@
                             "Select at least on parameter to fit "))
   
-    
-    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:
-                    self.model=item()
-                    evt = ModelEventbox(model=self.model,name=name)
-                    wx.PostEvent(self.event_owner, evt)
-                    #self.model= item()
-                    #self.set_panel(self.model)
-                except:
-                    raise #ValueError,"model.name is not equal to model class name"
-                break
-    
+   
     def _onTextEnter(self,event):
         """
@@ -368,34 +354,5 @@
                             "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_param_list(self):
@@ -411,13 +368,12 @@
             raise ValueError,"missing parameter to fit"
         
-        
-    def set_panel(self,model):
+    
+           
+    def old_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.sizer6.Clear(True)
         self.parameters = []
         self.param_toFit=[]
@@ -426,45 +382,28 @@
         #print "fitpage1D : dispersion list",self.model.getDispParamList()
         keys.sort()
-        disp_list=self.model.getDispParamList()
-        fixed=self.model.fixed
-        print "fixed",fixed
-        #model.setParam("scale", 2)
-        #print "model sphere scale fixed?", self.model.is_fittable("scale")
-        ip=0
-        iq=1
-        
         ik=0
         im=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,"Select all", (10, 10))
         wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param)
-        self.sizer2.Add(self.cb1,(iy, ix),(1,1),\
+        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.sizer2.Add(self.text2_2,(iy, ix),(1,1),\
+        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.sizer2.Add(self.text2_3,(iy, ix),(1,1),\
+        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.sizer2.Add(self.text2_4,(iy, ix),(1,1),\
+        self.sizer5.Add(self.text2_4,(iy, ix),(1,1),\
                             wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
         self.text2_4.Hide()
-        #print "keys", keys
-        #print "disp_list", disp_list
-        #print "fix_list",fixed
+        disp_list=self.model.getDispParamList()
         for item in keys:
             if not item in disp_list:
@@ -474,5 +413,5 @@
                 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)
+                self.sizer5.Add( cb,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
                 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param)
             
@@ -483,14 +422,14 @@
                 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)
+                self.sizer5.Add(ctl1, (iy,ix),(1,1), wx.EXPAND)
                 
                 ix += 1
                 text2=wx.StaticText(self, -1, '+/-')
-                self.sizer2.Add(text2,(iy, ix),(1,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.sizer2.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+                self.sizer5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
                 ctl2.Hide()
                 ix +=1
@@ -500,5 +439,6 @@
                 except:
                     units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT)
-                self.sizer2.Add(units, (iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+                self.sizer5.Add(units, (iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            """
             else:
                 if not item in fixed:
@@ -532,9 +472,9 @@
                     im += 1
             #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)
+        self.sizer5.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
         
         #Display units text on panel
@@ -583,51 +523,5 @@
         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.fixed_param:
-                
-                try:
-                     name=str(item[0])
-                     value= float(item[1].GetValue())
-#                     print "model para", name,value
-                     # 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=\
-                            "Model Drawing  Error:wrong value entered : %s"% sys.exc_value))
-                
-            for item in self.parameters:
-#                print "paramters",str(item[0].GetLabelText())
-                try:
-                     name=str(item[0].GetLabelText())
-                     value= float(item[1].GetValue())
-#                     print "model para", name,value
-                     # 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=\
-                            "Model 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)
-         
+    
     def select_all_param(self,event): 
         """
Index: sansview/perspectives/fitting/new_fitpanel.py
===================================================================
--- sansview/perspectives/fitting/new_fitpanel.py	(revision 68dada4186cf20bcf5b82b8075b3a1db20a3eac8)
+++ sansview/perspectives/fitting/new_fitpanel.py	(revision c80c06f9182eb95705aa07e379064743d2a79ebd)
@@ -8,6 +8,6 @@
 
 
-    
-class FitPanel(wx.Panel):
+class FitPanel(wx.aui.AuiNotebook):    
+#class FitPanel(wx.aui.AuiNotebook,wx.panel):
     """
         FitPanel class contains fields allowing to fit  models and  data
@@ -21,24 +21,22 @@
     window_caption = "Fit Panel "
     CENTER_PANE = True
-       
-    
     def __init__(self, parent, *args, **kwargs):
-        wx.Panel.__init__(self, parent, *args, **kwargs)
+        
+        wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_SCROLL_BUTTONS )
+        
         self.manager=None
         self.parent=parent
         self.event_owner=None
-        #self.menu_mng = models.ModelManager()
-        #self.nb = wx.Notebook(self)
-        #self.nb = wx.aui.AuiNotebook(self,-1, style=wx.aui.AUI_NB_TAB_SPLIT  )
-        self.nb = wx.aui.AuiNotebook(self,-1, style=wx.aui.AUI_NB_SCROLL_BUTTONS  )
-        self.sizer = wx.BoxSizer()
-        self.sizer.Add(self.nb, 1, wx.EXPAND)
+        
+        pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE
+        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)
+
         #Creating an initial page for simultaneous fitting
         from simfitpage import SimultaneousFitPage
-        self.sim_page = SimultaneousFitPage(self.nb, -1)
-        
-        #self.fit_panel.add_page(self.sim_page,"Simultaneous Fit")
-        self.nb.AddPage(self.sim_page,"Simultaneous Fit")
-        #(wxWindow* page, const wxString& caption, bool select = false, const wxBitmap& bitmap = 
+        self.sim_page = SimultaneousFitPage(self, -1)
+        self.AddPage(self.sim_page,"Simultaneous Fit")
+        
+
+        
         #dictionary of miodel {model class name, model class}
         self.model_list_box={}
@@ -53,9 +51,19 @@
         self.count=0
         #updating the panel
-        self.nb.Update()
-        self.SetSizer(self.sizer)
-        self.sizer.Fit(self)
+        self.Update()
         self.Center()
-        
+    def onClosePage(self, event):
+        self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
+        print "went here",self.get_current_page(), self.GetPage(0)
+        #event.Skip()
+        if self.GetPageCount() <= 2:
+            print "wente here"
+            
+            # Prevent last tab from being closed
+            self.ToggleWindowStyle(~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
+            
+
+   
+
 
         
@@ -91,15 +99,15 @@
             if data.__class__.__name__=='Data2D':
                  from fitpage2D import FitPage2D
-                 panel = FitPage2D(self.nb,data, -1)
+                 panel = FitPage2D(self,data, -1)
                  
             else:
                 
                 from fitpage1D import FitPage1D
-                panel = FitPage1D(self.nb,data, -1)
+                panel = FitPage1D(self,data, -1)
             m_name= "M"+str(self.count)  
             panel.set_manager(self.manager)
             panel.set_owner(self.event_owner)
             
-            self.nb.AddPage(page=panel,caption=name,select=True)
+            self.AddPage(page=panel,caption=name,select=True)
             panel.populate_box( self.model_list_box)
             self.fit_page_name = name
@@ -115,13 +123,12 @@
         """
         from modelpage import ModelPage
-        panel = ModelPage(self.nb,model,page_title, -1)
+        panel = ModelPage(self,model,page_title, -1)
         panel.set_manager(self.manager)
         panel.set_owner(self.event_owner)
-        #self.nb.AddPage(page=panel,text=page_title,select=True)
-        self.nb.AddPage(page=panel,caption="Model",select=True)
+        self.AddPage(page=panel,caption="Model",select=True)
         panel.populate_box( self.model_list_box)
         self.draw_model_name=page_title
-        self.model_page_number=self.nb.GetSelection()
-        self.model_page=self.nb.GetPage(self.nb.GetSelection())
+        self.model_page_number=self.GetSelection()
+        self.model_page=self.GetPage(self.GetSelection())
         
         
@@ -153,39 +160,13 @@
             self.model_page.select_model(model, page_title)
            
-    def get_notebook(self):
-        """
-            @return self.nb: return its own notebook mostly used by fitting module 
-        """
-        return self.nb
+    def get_current_page(self):
+        """
+            @return the current page selected
+        """
+        #return self.nb.GetCurrentPage()
+        return self.GetPage(self.GetSelection() )
+  
     
-    def get_page(self, n):
-        """
-            @return page at position n
-            @param n: page number
-        """
-        return self.nb.GetPage(n)
-    
-    
-    def get_page_count(self):
-        """ @return  number total of pages contained in notebook"""
-        return self.nb.GetPageCount()
-        
-        
-    def get_current_page(self):
-        """
-            @return the current page selected
-        """
-        #return self.nb.GetCurrentPage()
-        return self.nb.GetPage(self.nb.GetSelection() )
-    
-    def get_selected_page(self):
-        """ @return the page just selected by the user """
-        return self.nb.GetPage(self.nb.GetSelection())
-    
-    
-    def get_page_number(self):
-        return self.nb.GetSelection()
-    
-    def onClose(self, page=None,page_number=None):
+    def old_onClose(self, page=None,page_number=None):
         """
              close the current page except the simpage. remove each check box link to the model
Index: sansview/perspectives/fitting/new_fitting.py
===================================================================
--- sansview/perspectives/fitting/new_fitting.py	(revision c80c06f9182eb95705aa07e379064743d2a79ebd)
+++ sansview/perspectives/fitting/new_fitting.py	(revision c80c06f9182eb95705aa07e379064743d2a79ebd)
@@ -0,0 +1,816 @@
+import os,os.path, re
+import sys, wx, logging
+import string, numpy, math
+
+from copy import deepcopy 
+from danse.common.plottools.plottables import Data1D, Theory1D,Data2D
+from danse.common.plottools.PlotPanel import PlotPanel
+from sans.guicomm.events import NewPlotEvent, StatusEvent  
+from sans.guicomm.events import EVT_SLICER_PANEL,EVT_MODEL2D_PANEL
+
+from sans.fit.AbstractFitEngine import Model,Data,FitData1D,FitData2D
+from fitproblem import FitProblem
+from fitpanel import FitPanel
+from fit_thread import FitThread
+import models,modelpage
+import fitpage1D,fitpage2D
+import park
+DEFAULT_BEAM = 0.005
+DEFAULT_QMIN = 0.0
+DEFAULT_QMAX = 0.15
+DEFAULT_NPTS = 40
+import time
+import thread
+print "main",thread.get_ident()
+
+class Plugin:
+    """
+        Fitting plugin is used to perform fit 
+    """
+    def __init__(self):
+        ## Plug-in name
+        self.sub_menu = "Fitting"
+        
+        ## Reference to the parent window
+        self.parent = None
+        self.menu_mng = models.ModelManager()
+        ## List of panels for the simulation perspective (names)
+        self.perspective = []
+        self.mypanels=[]
+        self.calc_thread = None
+        self.done = False
+        # Start with a good default
+        self.elapsed = 0.022
+        self.fitter  = None
+       
+        #Flag to let the plug-in know that it is running standalone
+        self.standalone=True
+        ## Fit engine
+        self._fit_engine = 'scipy'
+        self.enable_model2D=False
+        # Log startup
+        logging.info("Fitting plug-in started")   
+        # model 2D view
+        self.model2D_id=None
+
+    def populate_menu(self, id, owner):
+        """
+            Create a menu for the Fitting plug-in
+            @param id: id to create a menu
+            @param owner: owner of menu
+            @ return : list of information to populate the main menu
+        """
+        self.parent.Bind(EVT_MODEL2D_PANEL, self._on_model2D_show)
+        #Menu for fitting
+        self.menu1 = wx.Menu()
+        id1 = wx.NewId()
+        self.menu1.Append(id1, '&Show fit panel')
+        wx.EVT_MENU(owner, id1, self.on_perspective)
+        id3 = wx.NewId()
+        self.menu1.AppendCheckItem(id3, "park") 
+        wx.EVT_MENU(owner, id3, self._onset_engine)
+        
+        #menu for model
+        menu2 = wx.Menu()
+    
+        self.menu_mng.populate_menu(menu2, owner)
+        id2 = wx.NewId()
+        owner.Bind(models.EVT_MODEL,self._on_model_menu)
+        #owner.Bind(modelpage.EVT_MODEL,self._on_model_menu)
+        self.fit_panel.set_owner(owner)
+        self.fit_panel.set_model_list(self.menu_mng.get_model_list())
+        owner.Bind(fitpage1D.EVT_MODEL_BOX,self._on_model_panel)
+        owner.Bind(fitpage2D.EVT_MODEL_BOX,self._on_model_panel)
+        #create  menubar items
+        return [(id, self.menu1, "Fitting"),(id2, menu2, "Model")]
+    
+    
+    def help(self, evt):
+        """
+            Show a general help dialog. 
+            TODO: replace the text with a nice image
+        """
+        from helpDialog import  HelpWindow
+        dialog = HelpWindow(None, -1, 'HelpWindow')
+        if dialog.ShowModal() == wx.ID_OK:
+            pass
+        dialog.Destroy()
+        
+    
+    def get_context_menu(self, graph=None):
+        """
+            Get the context menu items available for P(r)
+            @param graph: the Graph object to which we attach the context menu
+            @return: a list of menu items with call-back function
+        """
+        self.graph=graph
+        for item in graph.plottables:
+            if item.__class__.__name__ is "Data2D":
+                return [["Select data  for Fitting",\
+                          "Dialog with fitting parameters ", self._onSelect]] 
+            else:
+                if item.name==graph.selected_plottable and\
+                 item.__class__.__name__ is  "Data1D":
+                    return [["Select data  for Fitting", \
+                             "Dialog with fitting parameters ", self._onSelect]] 
+        return []   
+
+
+    def get_panels(self, parent):
+        """
+            Create and return a list of panel objects
+        """
+        self.parent = parent
+        # Creation of the fit panel
+        self.fit_panel = FitPanel(self.parent, -1)
+        #Set the manager forthe main panel
+        self.fit_panel.set_manager(self)
+        # List of windows used for the perspective
+        self.perspective = []
+        self.perspective.append(self.fit_panel.window_name)
+        # take care of saving  data, model and page associated with each other
+        self.page_finder = {}
+        #index number to create random model name
+        self.index_model = 0
+        self.parent.Bind(EVT_SLICER_PANEL, self._on_slicer_event)
+        
+        #create the fitting panel
+        #return [self.fit_panel]
+        
+        self.mypanels.append(self.fit_panel)
+        return self.mypanels
+    def _on_model2D_show(self, event ):
+        print "model2D get the id ", event.id
+    def _on_slicer_event(self, event):
+        print "fitting:slicer event ", event.panel
+        new_panel = event.panel
+        # Set group ID if available
+        event_id = self.parent.popup_panel(new_panel)
+        self.menu1.Append(event_id, new_panel.window_caption, 
+                         "Show %s plot panel" % new_panel.window_caption)
+        # Set UID to allow us to reference the panel later
+        new_panel.uid = event_id
+        new_panel
+        self.mypanels.append(new_panel) 
+        return        
+    def _on_show_panel(self, event):
+        print "_on_show_panel: fitting"
+      
+    def get_perspective(self):
+        """
+            Get the list of panel names for this perspective
+        """
+        return self.perspective
+    
+    
+    def on_perspective(self, event):
+        """
+            Call back function for the perspective menu item.
+            We notify the parent window that the perspective
+            has changed.
+        """
+        self.parent.set_perspective(self.perspective)
+    
+    
+    def post_init(self):
+        """
+            Post initialization call back to close the loose ends
+            [Somehow openGL needs this call]
+        """
+        self.parent.set_perspective(self.perspective)
+        
+        
+    def _onSelect(self,event):
+        """ 
+            when Select data to fit a new page is created .Its reference is 
+            added to self.page_finder
+        """
+        self.panel = event.GetEventObject()
+        for item in self.panel.graph.plottables:
+            if item.name == self.panel.graph.selected_plottable or\
+                 item.__class__.__name__ is "Data2D":
+                #find a name for the page created for notebook
+                try:
+                    page, model_name = self.fit_panel.add_fit_page(item)
+                    # add data associated to the page created
+                    
+                    if page !=None:    
+                        #create a fitproblem storing all link to data,model,page creation
+                        self.page_finder[page]= FitProblem()
+                        self.page_finder[page].save_model_name(model_name)  
+                        self.page_finder[page].add_data(item)
+                except:
+                    raise
+                    wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\
+                    %sys.exc_value))
+    def schedule_for_fit(self,value=0,fitproblem =None):  
+        """
+        
+        """   
+        if fitproblem !=None:
+            fitproblem.schedule_tofit(value)
+        else:
+            current_pg=self.fit_panel.get_current_page() 
+            for page, val in self.page_finder.iteritems():
+                if page ==current_pg :
+                    val.schedule_tofit(value)
+                    break
+                      
+                    
+    def get_page_finder(self):
+        """ @return self.page_finder used also by simfitpage.py"""  
+        return self.page_finder 
+    
+    
+    def set_page_finder(self,modelname,names,values):
+        """
+             Used by simfitpage.py to reset a parameter given the string constrainst.
+             @param modelname: the name ot the model for with the parameter has to reset
+             @param value: can be a string in this case.
+             @param names: the paramter name
+             @note: expecting park used for fit.
+        """  
+        sim_page=self.fit_panel.get_page(0)
+        for page, value in self.page_finder.iteritems():
+            if page != sim_page:
+                list=value.get_model()
+                model=list[0]
+                #print "fitting",model.name,modelname
+                if model.name== modelname:
+                    value.set_model_param(names,values)
+                    break
+
+   
+                            
+    def split_string(self,item): 
+        """
+            receive a word containing dot and split it. used to split parameterset
+            name into model name and parameter name example:
+            paramaterset (item) = M1.A
+            @return model_name =M1 , parameter name =A
+        """
+        if string.find(item,".")!=-1:
+            param_names= re.split("\.",item)
+            model_name=param_names[0]
+            param_name=param_names[1]  
+            return model_name,param_name
+        
+   
+    def _single_fit_completed(self,result,pars,cpage,qmin,qmax,elapsed,ymin=None, ymax=None):
+        """
+            Display fit result on one page of the notebook.
+            @param result: result of fit 
+            @param pars: list of names of parameters fitted
+            @param current_pg: the page where information will be displayed
+            @param qmin: the minimum value of x to replot the model 
+            @param qmax: the maximum value of x to replot model
+          
+        """
+        #print "single fit ", pars,result.pvec,result.stderr,result.fitness
+        #self.done = True
+        #wx.PostEvent(self.parent, StatusEvent(status="Fitting Completed: %g" % elapsed))
+        try:
+            for page, value in self.page_finder.iteritems():
+                if page==cpage :
+                    #fitdata = value.get_data()
+                    list = value.get_model()
+                    model= list[0]
+                    break
+            i = 0
+            #print "fitting: single fit pars ", pars
+            for name in pars:
+                if result.pvec.__class__==numpy.float64:
+                    model.setParam(name,result.pvec)
+                else:
+                    model.setParam(name,result.pvec[i])
+#                    print "fitting: single fit", name, result.pvec[i]
+                    i += 1
+#            print "fitting result : chisqr",result.fitness
+#            print "fitting result : pvec",result.pvec
+#            print "fitting result : stderr",result.stderr
+            
+            cpage.onsetValues(result.fitness, result.pvec,result.stderr)
+            self.plot_helper(currpage=cpage,qmin=qmin,qmax=qmax,ymin=ymin, ymax=ymax, title="Fitted model 2D ")
+        except:
+            #raise
+            wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value))
+            
+       
+    def _simul_fit_completed(self,result,qmin,qmax, elapsed,pars=None,cpage=None, ymin=None, ymax=None):
+        """
+            Parameter estimation completed, 
+            display the results to the user
+            @param alpha: estimated best alpha
+            @param elapsed: computation time
+        """
+        wx.PostEvent(self.parent, StatusEvent(status="Fitting Completed: %g" % elapsed))
+        try:
+            for page, value in self.page_finder.iteritems():
+                if value.get_scheduled()==1:
+                    #fitdata = value.get_data()
+                    list = value.get_model()
+                    model= list[0]
+                   
+                    small_out = []
+                    small_cov = []
+                    i = 0
+                    #Separate result in to data corresponding to each page
+                    for p in result.parameters:
+                        model_name,param_name = self.split_string(p.name)  
+                        if model.name == model_name:
+                            small_out.append(p.value )
+                            small_cov.append(p.stderr)
+                            model.setParam(param_name,p.value)  
+                    # Display result on each page 
+                    page.onsetValues(result.fitness, small_out,small_cov)
+                    #Replot model
+                    self.plot_helper(currpage= page,qmin= qmin,qmax= qmax,ymin=ymin, ymax=ymax) 
+        except:
+             wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value))
+            
+  
+    def _on_single_fit(self,id=None,qmin=None,qmax=None,ymin=None,ymax=None):
+        """ 
+            perform fit for the  current page  and return chisqr,out and cov
+            @param engineName: type of fit to be performed
+            @param id: unique id corresponding to a fit problem(model, set of data)
+            @param model: model to fit
+            
+        """
+        #print "in single fitting"
+        #set an engine to perform fit
+        from sans.fit.Fitting import Fit
+        self.fitter= Fit(self._fit_engine)
+        #Setting an id to store model and data in fit engine
+        if id==None:
+            id=0
+        self.id = id
+        page_fitted=None
+        fit_problem=None
+        #Get information (model , data) related to the page on 
+        #with the fit will be perform
+        #current_pg=self.fit_panel.get_current_page() 
+        #simul_pg=self.fit_panel.get_page(0)
+            
+        for page, value in self.page_finder.iteritems():
+            if  value.get_scheduled() ==1 :
+                metadata = value.get_data()
+                list=value.get_model()
+                model=list[0]
+                smearer= value.get_smearer()
+                print "single fit", model, smearer
+                #Create list of parameters for fitting used
+                pars=[]
+                templist=[]
+                try:
+                    #templist=current_pg.get_param_list()
+                    templist=page.get_param_list()
+                    for element in templist:
+                        pars.append(str(element[0].GetLabelText()))
+                    pars.sort()
+                    #print "single fit start pars:", pars
+                    #Do the single fit
+                    self.fitter.set_model(Model(model), self.id, pars) 
+                   
+                    self.fitter.set_data(metadata,self.id,smearer, qmin,qmax)
+                    self.fitter.select_problem_for_fit(Uid=self.id,value=value.get_scheduled())
+                    page_fitted=page
+                    self.id+=1
+                    self.schedule_for_fit( 0,value) 
+                except:
+                    raise 
+                    #wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value))
+                    return
+                # make sure to keep an alphabetic order 
+                #of parameter names in the list      
+        try:
+            # If a thread is already started, stop it
+            if self.calc_thread != None and self.calc_thread.isrunning():
+                self.calc_thread.stop()
+                    
+            self.calc_thread =FitThread(parent =self.parent,
+                                        fn= self.fitter,
+                                        pars= pars,
+                                        cpage= page_fitted,
+                                       qmin=qmin,
+                                       qmax=qmax,
+                                       ymin= ymin,
+                                       ymax= ymax,
+                                       completefn=self._single_fit_completed,
+                                       updatefn=None)
+            self.calc_thread.queue()
+            self.calc_thread.ready(2.5)
+            #while not self.done:
+                #print "when here"
+             #   time.sleep(1)
+            
+           
+        except:
+            raise
+            wx.PostEvent(self.parent, StatusEvent(status="Single Fit error: %s" % sys.exc_value))
+            return
+         
+    def _on_simul_fit(self, id=None,qmin=None,qmax=None, ymin=None, ymax=None):
+        """ 
+            perform fit for all the pages selected on simpage and return chisqr,out and cov
+            @param engineName: type of fit to be performed
+            @param id: unique id corresponding to a fit problem(model, set of data)
+             in park_integration
+            @param model: model to fit
+            
+        """
+        #set an engine to perform fit
+        from sans.fit.Fitting import Fit
+        self.fitter= Fit(self._fit_engine)
+        
+        #Setting an id to store model and data
+        if id==None:
+             id = 0
+        self.id = id
+        
+        for page, value in self.page_finder.iteritems():
+            try:
+                if value.get_scheduled()==1:
+                    metadata = value.get_data()
+                    list = value.get_model()
+                    model= list[0]
+                    #Create dictionary of parameters for fitting used
+                    pars = []
+                    templist = []
+                    templist = page.get_param_list()
+                    for element in templist:
+                        try:
+                            name = str(element[0].GetLabelText())
+                            pars.append(name)
+                        except:
+                            wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value))
+                            return
+                    # need to check this print "new model "
+                    new_model=Model(model)
+                    param=value.get_model_param()
+                    
+                    if len(param)>0:
+                        for item in param:
+                            param_value = item[1]
+                            param_name = item[0]
+                            #print "fitting ", param,param_name, param_value
+                           
+                            #new_model.set( model.getParam(param_name[0])= param_value)
+                            #new_model.set( exec"%s=%s"%(param_name[0], param_value))
+                            #new_model.set( exec "%s"%(param_nam) = param_value)
+                            new_model.parameterset[ param_name].set( param_value )
+                          
+                    self.fitter.set_model(new_model, self.id, pars) 
+                    self.fitter.set_data(metadata,self.id,qmin,qmax,ymin,ymax)
+                    self.fitter.select_problem_for_fit(Uid=self.id,value=value.get_scheduled())
+                    self.id += 1 
+            except:
+                #raise
+                wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value))
+                return 
+        #Do the simultaneous fit
+        try:
+            # If a thread is already started, stop it
+            if self.calc_thread != None and self.calc_thread.isrunning():
+                self.calc_thread.stop()
+                    
+            self.calc_thread =FitThread(parent =self.parent,
+                                        fn= self.fitter,
+                                       qmin=qmin,
+                                       qmax=qmax,
+                                       ymin= ymin,
+                                       ymax= ymax,
+                                       completefn= self._simul_fit_completed,
+                                       updatefn=None)
+            self.calc_thread.queue()
+            self.calc_thread.ready(2.5)
+            
+        except:
+            #raise
+            wx.PostEvent(self.parent, StatusEvent(status="Simultaneous Fitting error: %s" % sys.exc_value))
+            return
+        
+        
+    def _onset_engine(self,event):
+        """ set engine to scipy"""
+        if self._fit_engine== 'park':
+            self._on_change_engine('scipy')
+        else:
+            self._on_change_engine('park')
+        wx.PostEvent(self.parent, StatusEvent(status="Engine set to: %s" % self._fit_engine))
+  
+    
+    def _on_change_engine(self, engine='park'):
+        """
+            Allow to select the type of engine to perform fit 
+            @param engine: the key work of the engine
+        """
+        self._fit_engine = engine
+   
+   
+    def _on_model_panel(self, evt):
+        """
+            react to model selection on any combo box or model menu.plot the model  
+        """
+       
+        model = evt.model
+        name = evt.name
+        
+        sim_page=self.fit_panel.GetPage(0)
+        current_pg = self.fit_panel.get_current_page() 
+        if current_pg != sim_page:
+            current_pg.set_panel(model)
+            model.name = self.page_finder[current_pg].get_name()
+            try:
+                metadata=self.page_finder[current_pg].get_data()
+                M_name=model.name+"= "+name+"("+metadata.group_id+")"
+            except:
+                M_name=model.name+"= "+name
+            #model.name="M"+str(self.index_model)
+            self.index_model += 1  
+            # save model name
+            
+            # save the name containing the data name with the appropriate model
+            self.page_finder[current_pg].set_model(model,M_name)
+            self.plot_helper(currpage= current_pg,qmin= None,qmax= None)
+            sim_page.add_model(self.page_finder)
+        
+    def  set_smearer(self,smearer):     
+         current_pg=self.fit_panel.get_current_page()
+         self.page_finder[current_pg].set_smearer(smearer)
+         
+    def redraw_model(self,qmin= None,qmax= None):
+        """
+            Draw a theory according to model changes or data range.
+            @param qmin: the minimum value plotted for theory
+            @param qmax: the maximum value plotted for theory
+        """
+        current_pg=self.fit_panel.get_current_page()
+        for page, value in self.page_finder.iteritems():
+            if page ==current_pg :
+                break 
+        self.plot_helper(currpage=page,qmin= qmin,qmax= qmax)
+        
+    def plot_helper(self,currpage, fitModel=None, qmin=None,qmax=None,
+                    ymin=None,ymax=None, title=None ):
+        """
+            Plot a theory given a model and data
+            @param model: the model from where the theory is derived
+            @param currpage: page in a dictionary referring to some data
+        """
+        if self.fit_panel.GetPageCount() >1:
+            for page in self.page_finder.iterkeys():
+                if  page==currpage :  
+                    data=self.page_finder[page].get_data()
+                    list=self.page_finder[page].get_model()
+                    model=list[0]
+                    break 
+            
+            if data!=None and data.__class__.__name__ != 'Data2D':
+                theory = Theory1D(x=[], y=[])
+                theory.name = model.name
+                theory.group_id = data.group_id
+                theory.id = "Model"
+                x_name, x_units = data.get_xaxis() 
+                y_name, y_units = data.get_yaxis() 
+                theory.xaxis(x_name, x_units)
+                theory.yaxis(y_name, y_units)
+                if qmin == None :
+                   qmin = min(data.x)
+                if qmax == None :
+                    qmax = max(data.x)
+                try:
+                    tempx = qmin
+                    tempy = model.run(qmin)
+                    theory.x.append(tempx)
+                    theory.y.append(tempy)
+                except :
+                        wx.PostEvent(self.parent, StatusEvent(status="fitting \
+                        skipping point x %g %s" %(qmin, sys.exc_value)))
+                           
+                for i in range(len(data.x)):
+                    try:
+                        if data.x[i]> qmin and data.x[i]< qmax:
+                            tempx = data.x[i]
+                            tempy = model.run(tempx)
+                            theory.x.append(tempx) 
+                            theory.y.append(tempy)
+                           
+                    except:
+                        wx.PostEvent(self.parent, StatusEvent(status="fitting \
+                        skipping point x %g %s" %(data.x[i], sys.exc_value)))   
+                try:
+                    tempx = qmax
+                    tempy = model.run(qmax)
+                    theory.x.append(tempx)
+                    theory.y.append(tempy)
+                except:
+                    wx.PostEvent(self.parent, StatusEvent(status="fitting \
+                        skipping point x %g %s" %(qmin, sys.exc_value)) )
+                wx.PostEvent(self.parent, NewPlotEvent(plot=theory,
+                                                title=str(data.name)))
+            else:
+               
+                theory=Data2D(data.data, data.err_data)
+                theory.name= model.name
+                if title !=None:
+                    self.title = title
+                    theory.id= self.title
+                    theory.group_id= self.title+data.name
+                else:
+                    self.title= "Analytical model 2D "
+                    theory.id= "Model"
+                    theory.group_id= "Model"+data.name
+                theory.x_bins= data.x_bins
+                theory.y_bins= data.y_bins
+                tempy=[]
+                if qmin==None:
+                    qmin=data.xmin
+                if qmax==None:
+                    qmax=data.xmax
+                if ymin==None:
+                    ymin=data.ymin
+                if ymax==None:
+                    ymax=data.ymax
+                    
+                theory.data = numpy.zeros((len(data.y_bins),len(data.x_bins)))
+                for i in range(len(data.y_bins)):
+                    if data.y_bins[i]>= ymin and data.y_bins[i]<= ymax:
+                        for j in range(len(data.x_bins)):
+                            if data.x_bins[i]>= qmin and data.x_bins[i]<= qmax:
+                                theory.data[j][i]=model.runXY([data.x_bins[j],data.y_bins[i]])
+               
+                #print "fitting : plot_helper:", theory.image
+                #print data.image
+                #print "fitting : plot_helper:",theory.image
+                theory.detector= data.detector
+                theory.source= data.source
+                theory.zmin= data.zmin
+                theory.zmax= data.zmax
+                theory.xmin= qmin
+                theory.xmax= qmax
+                theory.ymin= ymin
+                theory.ymax= ymax
+        
+                wx.PostEvent(self.parent, NewPlotEvent(plot=theory,
+                                                title=self.title +str(data.name)))
+        
+        
+    def _on_model_menu(self, evt):
+        """
+            Plot a theory from a model selected from the menu
+        """
+        name = evt.model.__name__
+        if hasattr(evt.model, "name"):
+            name = evt.model.name
+        print "on model menu", name
+        model=evt.model()
+        description=model.description
+        
+        # Create a model page. If a new page is created, the model
+        # will be plotted automatically. If a page already exists,
+        # the content will be updated and the plot refreshed
+        self.fit_panel.add_model_page(model,description,name,topmenu=True)
+        
+    def draw_model(self,model,name ,data=None,description=None,enable1D=True, enable2D=False,
+                   qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, qstep=DEFAULT_NPTS):
+        """
+             draw model with default data value
+        """
+        if data !=None:
+            self.redraw_model(qmin,qmax)
+            return 
+        self._draw_model2D(model=model,
+                           description=model.description,
+                           enable2D= enable2D,
+                           qmin=qmin,
+                           qmax=qmax,
+                           qstep=qstep)
+        self._draw_model1D(model,name,model.description, enable1D,qmin,qmax, qstep)
+              
+    def _draw_model1D(self,model,name,description=None, enable1D=True,
+                      qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, qstep=DEFAULT_NPTS):
+        
+        if enable1D:
+            x=  numpy.linspace(start= qmin,
+                               stop= qmax,
+                               num= qstep,
+                               endpoint=True
+                               )      
+            xlen= len(x)
+            y = numpy.zeros(xlen)
+            if not enable1D:
+                for i in range(xlen):
+                    y[i] = model.run(x[i])
+                
+                try:
+                    new_plot = Theory1D(x, y)
+                    
+                    new_plot.name = name
+                    new_plot.xaxis("\\rm{Q}", 'A^{-1}')
+                    new_plot.yaxis("\\rm{Intensity} ","cm^{-1}")
+                    new_plot.id = "Model"
+                    new_plot.group_id ="Model"
+                    wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Analytical model 1D"))
+                except:
+                    wx.PostEvent(self.parent, StatusEvent(status="Draw model 1D error: %s" % sys.exc_value))
+                    #raise
+            else:
+                for i in range(xlen):
+                    y[i] = model.run(x[i])
+                #print x, y   
+                try:
+                    new_plot = Theory1D(x, y)
+                    print "draw model 1D", name
+                    new_plot.name = name
+                    new_plot.xaxis("\\rm{Q}", 'A^{-1}')
+                    new_plot.yaxis("\\rm{Intensity} ","cm^{-1}")
+                    new_plot.id ="Model"
+                    new_plot.group_id ="Model"
+                    
+                    # Pass the reset flag to let the plotting event handler
+                    # know that we are replacing the whole plot
+                    wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot,
+                                     title="Analytical model 1D ", reset=True ))
+                    
+                except:
+                    #raise
+                    wx.PostEvent(self.parent, StatusEvent(status="Draw model 1D error: %s" % sys.exc_value))
+    def update(self, output,time):
+        pass
+    
+    def complete(self, output, elapsed, model, qmin, qmax,qstep=DEFAULT_NPTS):
+       
+        wx.PostEvent(self.parent, StatusEvent(status="Calc \
+        complete in %g sec" % elapsed))
+        #print "complete",output, model,qmin, qmax
+        data = output
+        theory= Data2D(data)
+        #print data.detector
+        #theory.detector= data.detector
+        from DataLoader.data_info import Detector, Source
+        
+        detector = Detector()
+        theory.detector=[]
+        theory.detector.append(detector)
+            
+        theory.detector[0].pixel_size.x= qmax/(qstep/2-1)#5.0
+        theory.detector[0].pixel_size.y= qmax/(qstep/2-1)#5.0
+        theory.detector[0].beam_center.x= qmax
+        theory.detector[0].beam_center.y= qmax
+        theory.detector[0].distance= 1e+12#13705.0
+        theory.source= Source()
+        theory.source.wavelength= 2*math.pi/1e+12#8.4
+        
+        theory.name= model.name
+        theory.group_id ="Model"
+        theory.id ="Model"
+        theory.xmin= -qmax
+        theory.xmax= qmax
+        theory.ymin= -qmax
+        theory.ymax= qmax
+        
+        print "model draw comptele xmax",theory.xmax,model.name
+        wx.PostEvent(self.parent, NewPlotEvent(plot=theory,
+                         title="Analytical model 2D ", reset=True ))
+         
+        
+         
+    def _draw_model2D(self,model,description=None, enable2D=False,
+                      qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, qstep=DEFAULT_NPTS):
+       
+        x=  numpy.linspace(start= -1*qmax,
+                               stop= qmax,
+                               num= qstep,
+                               endpoint=True )  
+        y = numpy.linspace(start= -1*qmax,
+                               stop= qmax,
+                               num= qstep,
+                               endpoint=True )
+       
+        lx = len(x)
+        #print x
+        data=numpy.zeros([len(x),len(y)])
+        self.model= model
+        if enable2D:
+            from model_thread import Calc2D
+            self.calc_thread = Calc2D(parent =self.parent,x=x,
+                                       y=y,model= self.model, 
+                                       qmin=qmin,
+                                       qmax=qmax,
+                                       qstep=qstep,
+                            completefn=self.complete,
+                            updatefn=None)
+            self.calc_thread.queue()
+            self.calc_thread.ready(2.5)
+            
+    def show_panel2D(self, id=None ):
+        self.parent.show_panel(self.model2D_id)
+           
+   
+if __name__ == "__main__":
+    i = Plugin()
+    
+    
+    
+    
Index: sansview/perspectives/fitting/new_modelpage.py
===================================================================
--- sansview/perspectives/fitting/new_modelpage.py	(revision c80c06f9182eb95705aa07e379064743d2a79ebd)
+++ sansview/perspectives/fitting/new_modelpage.py	(revision c80c06f9182eb95705aa07e379064743d2a79ebd)
@@ -0,0 +1,617 @@
+import sys
+import wx
+import wx.lib
+import numpy
+import copy
+
+
+from sans.guicomm.events import StatusEvent   
+(ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()
+_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"
+    
+    if high:
+        return "%-6.4g" % value
+    else:
+        return "%-5.3g" % value
+
+
+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"
+    
+    
+    def __init__(self, parent,model,name, *args, **kwargs):
+        wx.ScrolledWindow.__init__(self, parent, *args, **kwargs)
+        """ 
+            Initialization of the Panel
+        """
+        #self.scroll = wx.ScrolledWindow(self)
+        
+        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.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 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(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
+        self.vbox.Add(self.sizer10)
+        
+      
+        #------------------ sizer 4  draw------------------------   
+        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)
+        #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.SetFocus()
+        #----------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= 0.001
+        self.qmax= 0.1
+        self.num_points= 100
+        
+        
+        self.xmin    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
+        self.xmin.SetValue(format_number(self.qmin))
+        self.xmin.SetToolTipString("Minimun value of x in linear scale.")
+        self.xmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+        self.xmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
+        self.xmin.Disable()
+        
+        self.xmax    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
+        self.xmax.SetValue(format_number(self.qmax))
+        self.xmax.SetToolTipString("Maximum value of x in linear scale.")
+        self.xmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
+        self.xmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
+        self.xmax.Disable()
+
+        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()
+        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, 'x range'),(iy, ix),(1,1),\
+                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        ix += 1
+        self.sizer9.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        ix += 1
+        self.sizer9.Add(self.xmax,(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=[]
+        #contains link between a model and selected parameters to fit 
+        self.param_toFit=[]
+        # model on which the fit would be performed
+        self.model=None
+        #dictionary of model name and model class
+        self.model_list_box={}
+       
+        ## Q range
+        self.qmin= 0.001
+        self.qmax= 0.1
+       
+        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 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():
+            self.set_panel_dispers()
+        else:
+            self.sizer7.Clear(True)
+            self.sizer8.Clear(True)
+   
+    def set_range(self, qmin, qmax, 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 = qmin
+        self.qmax = qmax
+        self.num_points = npts
+        
+        # Set the controls
+        self.xmin.SetValue(format_number(self.qmin))
+        self.xmax.SetValue(format_number(self.qmax))
+        self.npts.SetValue(format_number(self.num_points))
+    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 onClose(self,event):
+        """ close the page associated with this panel"""
+        self.GrandParent.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()
+            
+        else:
+            print "enable is true:",self.enable2D
+            #self.manager.parent. show_panel(147)
+            self.manager.show_panel2D( id=None )
+            #self.manager.menu1.Append(event_id, new_panel.window_caption, 
+            #             "Show %s plot panel" % new_panel.window_caption)
+            
+    
+    def select_model(self, model, name):
+        """
+            Select a new model
+            @param model: model object 
+        """
+        self.model= model
+        print "select_model", model.__class__
+        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)):
+            print "model name",items[i],model.name, model.__class__.__name__
+            #if items[i]==model.__class__.__name__:
+            if items[i]==name:
+                self.modelbox.SetSelection(i)
+        
+    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
+        """
+       
+        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.manager.draw_model(model, name)
+                self.enable2D=False
+                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.model = model
+        keys = self.model.getParamList()
+        #print "fitpage1D : dispersion 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()
+        #Disable or enable fit button
+        
+        if not (len(self.param_toFit ) >0):
+            self.xmin.Disable()
+            self.xmax.Disable()
+        else:
+            self.xmin.Enable()
+            self.xmax.Enable()
+            
+        self.vbox.Layout()
+        self.SetScrollbars(20,20,55,40)
+        self.Layout()
+        self.GrandParent.GetSizer().Layout()
+        
+       
+    def  set_panel_dispers(self):
+        self.sizer7.Clear(True)
+        self.sizer8.Clear(True)
+        disp_list=self.model.getDispParamList()
+        ix=0
+        iy=1
+        if len(disp_list)>0:
+            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 
+            self.disp_box = wx.ComboBox(self, -1)
+            self.sizer7.Add(self.disp_box,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+            ix = 0 
+            iy = 1 
+            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 += 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.fixed
+            for item in disp_list:
+                if item in self.model.fixed:
+                    ix = 0
+                    iy += 1
+                    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.sizer7.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.sizer7.Add(ctl1, (iy,ix),(1,1), wx.EXPAND)
+                    
+                    self.parameters.append([cb,ctl1])
+                iy+= 1
+        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()
+        
+    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.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:
+                     wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
+                            "Model 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 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, qmax=self.qmax,
+                                qstep= self.num_points,
+                                enable2D=self.enable2D)
+        """
+            self.manager.draw_model(self.model, self.model.name, 
+                                    qmin=self.qmin, qmax=self.qmax,
+                                    qstep= self.num_points,
+                                    enable2D=self.enable2D)
+        """
+    def select_param(self,event):
+        pass
+    def select_all_param(self,event): 
+        pass
+        
+       
