Index: sansview/perspectives/fitting/AnnulusSlicer.py
===================================================================
--- sansview/perspectives/fitting/AnnulusSlicer.py	(revision 55e13ab144cc9c2543cb87c3ce551654d0aefb53)
+++ 	(revision )
@@ -1,347 +1,0 @@
-#TODO: the line slicer should listen to all 2DREFRESH events, get the data and slice it
-#      before pushing a new 1D data update.
-
-#
-#TODO: NEED MAJOR REFACTOR
-#
-
-
-# Debug printout
-from config import printEVT
-from BaseInteractor import _BaseInteractor
-from copy import deepcopy
-import math
-
-from Plotter1D import AddPlotEvent
-import SlicerParameters
-import wx
-
-class AnnulusInteractor(_BaseInteractor):
-    """
-         Select an annulus through a 2D plot
-    """
-    def __init__(self,base,axes,color='black', zorder=3):
-        
-        _BaseInteractor.__init__(self, base, axes, color=color)
-        self.markers = []
-        self.axes = axes
-        self.qmax = self.base.qmax
-        self.connect = self.base.connect
-        
-        ## Number of points on the plot
-        self.nbins = 20
-
-        # Inner circle
-        self.inner_circle = RingInteractor(self, self.base.subplot, zorder=zorder, r=self.qmax/2.0)
-        self.inner_circle.qmax = self.base.qmax
-        self.outer_circle = RingInteractor(self, self.base.subplot, zorder=zorder+1, r=self.qmax/1.8)
-        self.outer_circle.qmax = self.base.qmax*1.2
-        #self.outer_circle.set_cursor(self.base.qmax/1.8, 0)
-        
-                      
-        self.update()
-        self._post_data()
-        
-        # Bind to slice parameter events
-        self.base.parent.Bind(SlicerParameters.EVT_SLICER_PARS, self._onEVT_SLICER_PARS)
-
-
-    def _onEVT_SLICER_PARS(self, event):
-        printEVT("AnnulusSlicer._onEVT_SLICER_PARS")
-        event.Skip()
-        if event.type == self.__class__.__name__:
-            self.set_params(event.params)
-            self.base.update()
-
-    def update_and_post(self):
-        self.update()
-        self._post_data()
-
-    def save_data(self, path, image, x, y):
-        output = open(path, 'w')
-        
-        data_x, data_y = self.get_data(image, x, y)
-        
-        output.write("<phi>  <average>\n")
-        for i in range(len(data_x)):
-            output.write("%g  %g\n" % (data_x[i], data_y[i]))
-        output.close()
-
-    def set_layer(self, n):
-        self.layernum = n
-        self.update()
-        
-    def clear(self):
-        self.clear_markers()
-        self.outer_circle.clear()
-        self.inner_circle.clear()
-        #self.base.connect.disconnect()
-        self.base.parent.Unbind(SlicerParameters.EVT_SLICER_PARS)
-        
-    def update(self):
-        """
-        Respond to changes in the model by recalculating the profiles and
-        resetting the widgets.
-        """
-        # Update locations        
-        self.inner_circle.update()
-        self.outer_circle.update()
-        
-        
-    def get_data(self, image, x, y):
-        """ 
-            Return a 1D vector corresponding to the slice
-            @param image: data matrix
-            @param x: x matrix
-            @param y: y matrix
-        """
-        # If we have no data, just return
-        if image == None:
-            return        
-        
-        nbins = self.nbins
-        
-        data_x = nbins*[0]
-        data_y = nbins*[0]
-        counts = nbins*[0]
-        length = len(image)
-        
-        
-        for i_x in range(length):
-            for i_y in range(length):
-                        
-                q = math.sqrt(x[i_x]*x[i_x] + y[i_y]*y[i_y])
-                if (q>self.inner_circle._inner_mouse_x \
-                    and q<self.outer_circle._inner_mouse_x) \
-                    or (q<self.inner_circle._inner_mouse_x \
-                    and q>self.outer_circle._inner_mouse_x):
-                            
-                    i_bin = int(math.ceil(nbins*(math.atan2(y[i_y], x[i_x])+math.pi)/(2.0*math.pi)) - 1)
-                    
-                    
-                    #data_y[i_bin] += math.exp(image[i_x][i_y])
-                    data_y[i_bin] += image[i_y][i_x]
-                    counts[i_bin] += 1.0
-                    
-        for i in range(nbins):
-            data_x[i] = (1.0*i+0.5)*2.0*math.pi/nbins
-            if counts[i]>0:
-                data_y[i] = data_y[i]/counts[i]
-        
-        return data_x, data_y
-
-    def save(self, ev):
-        """
-        Remember the roughness for this layer and the next so that we
-        can restore on Esc.
-        """
-        self.base.freeze_axes()
-        self.inner_circle.save(ev)
-        self.outer_circle.save(ev)
-
-    def _post_data(self):
-        # Compute data
-        data = self.base.get_corrected_data()
-        # If we have no data, just return
-        if data == None:
-            return
-
-        data_x, data_y = self.get_data(data, self.base.x, self.base.y)
-        
-        name = "Ring"
-        if hasattr(self.base, "name"):
-            name += " %s" % self.base.name
-        
-        wx.PostEvent(self.base.parent, AddPlotEvent(name=name,
-                                               x = data_x,
-                                               y = data_y,
-                                               qmin = self.inner_circle._inner_mouse_x,
-                                               qmax = self.outer_circle._inner_mouse_x,
-                                               yscale = 'log',
-                                               variable = 'ANGLE',
-                                               ylabel = "\\rm{Intensity} ",
-                                               yunits = "cm^{-1}",
-                                               xlabel = "\\rm{\phi}",
-                                               xunits = "rad",
-                                               parent = self.base.__class__.__name__))
-                                               
-        
-    def moveend(self, ev):
-        self.base.thaw_axes()
-        
-        # Post paramters
-        event = SlicerParameters.SlicerParameterEvent()
-        event.type = self.__class__.__name__
-        event.params = self.get_params()
-        wx.PostEvent(self.base.parent, event)
-
-        self._post_data()
-            
-    def restore(self):
-        """
-        Restore the roughness for this layer.
-        """
-        self.inner_circle.restore()
-        self.outer_circle.restore()
-
-    def move(self, x, y, ev):
-        """
-        Process move to a new position, making sure that the move is allowed.
-        """
-        pass
-        
-    def set_cursor(self, x, y):
-        pass
-        
-    def get_params(self):
-        params = {}
-        params["inner_radius"] = self.inner_circle._inner_mouse_x
-        params["outer_radius"] = self.outer_circle._inner_mouse_x
-        params["nbins"] = self.nbins
-        return params
-    
-    def set_params(self, params):
-        
-        inner = params["inner_radius"] 
-        outer = params["outer_radius"] 
-        self.nbins = int(params["nbins"])
-        self.inner_circle.set_cursor(inner, self.inner_circle._inner_mouse_y)
-        self.outer_circle.set_cursor(outer, self.outer_circle._inner_mouse_y)
-        self._post_data()
-        
-    def freeze_axes(self):
-        self.base.freeze_axes()
-        
-    def thaw_axes(self):
-        self.base.thaw_axes()
-
-    def draw(self):
-        self.base.draw()
-
-        
-class RingInteractor(_BaseInteractor):
-    """
-         Select an annulus through a 2D plot
-    """
-    def __init__(self,base,axes,color='black', zorder=5, r=1.0):
-        
-        _BaseInteractor.__init__(self, base, axes, color=color)
-        self.markers = []
-        self.axes = axes
-        self._inner_mouse_x = r
-        self._inner_mouse_y = 0
-        self._inner_save_x  = r
-        self._inner_save_y  = 0
-        self.scale = 10.0
-        
-        try:
-            # Inner circle marker
-            self.inner_marker = self.axes.plot([self._inner_mouse_x],[0], linestyle='',
-                                          marker='s', markersize=10,
-                                          color=self.color, alpha=0.6,
-                                          pickradius=5, label="pick", 
-                                          zorder=zorder, # Prefer this to other lines
-                                          visible=True)[0]
-        except:
-            self.inner_marker = self.axes.plot([self._inner_mouse_x],[0], linestyle='',
-                                          marker='s', markersize=10,
-                                          color=self.color, alpha=0.6,
-                                          label="pick", 
-                                          visible=True)[0]
-            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n"
-            message += "Get the SVN version that is at least as recent as June 1, 2007"
-            
-            #raise "Version error", message
-            
-        # Inner circle
-
-           
-        [self.inner_circle] = self.axes.plot([],[],
-                                      linestyle='-', marker='',
-                                      color=self.color)
-        self.npts = 20
-            
-        self.connect_markers([self.inner_marker])
-        self.update()
-
-    def set_layer(self, n):
-        self.layernum = n
-        self.update()
-        
-    def clear(self):
-        self.clear_markers()
-        try:
-            self.inner_marker.remove()
-            self.inner_circle.remove()
-        except:
-            # Old version of matplotlib
-            for item in range(len(self.axes.lines)):
-                del self.axes.lines[0]
-        
-        
-        
-    def get_radius(self):
-        return self._inner_mouse_x
-        
-    def update(self):
-        """
-        Draw the new roughness on the graph.
-        """
-        # Plot inner circle
-        x = []
-        y = []
-        for i in range(self.npts):
-            phi = 2.0*math.pi/(self.npts-1)*i
-            
-            xval = 1.0*self._inner_mouse_x*math.cos(phi) 
-            yval = 1.0*self._inner_mouse_x*math.sin(phi) 
-            
-            x.append(xval)
-            y.append(yval)
-        
-        self.inner_marker.set(xdata=[self._inner_mouse_x],ydata=[0])
-        self.inner_circle.set_data(x, y)        
-
-    def save(self, ev):
-        """
-        Remember the roughness for this layer and the next so that we
-        can restore on Esc.
-        """
-        self._inner_save_x = self._inner_mouse_x
-        self._inner_save_y = self._inner_mouse_y
-        self.base.freeze_axes()
-
-    def moveend(self, ev):
-        self.base.moveend(ev)
-            
-    def restore(self):
-        """
-        Restore the roughness for this layer.
-        """
-        self._inner_mouse_x = self._inner_save_x
-        self._inner_mouse_y = self._inner_save_y
-
-    def move(self, x, y, ev):
-        """
-        Process move to a new position, making sure that the move is allowed.
-        """
-        self._inner_mouse_x = x
-        self._inner_mouse_y = y
-        self.base.base.update()
-        
-    def set_cursor(self, x, y):
-        self.move(x, y, None)
-        self.update()
-        
-        
-    def get_params(self):
-        params = {}
-        params["radius"] = self._inner_mouse_x
-        return params
-    
-    def set_params(self, params):
-
-        x = params["radius"] 
-        self.set_cursor(x, self._inner_mouse_y)
-        
-        
Index: sansview/perspectives/fitting/fitpage1D.py
===================================================================
--- sansview/perspectives/fitting/fitpage1D.py	(revision e191da5a0b9b6561ffc8982f24900292e285dd3b)
+++ sansview/perspectives/fitting/fitpage1D.py	(revision 10c43a589031ebfba8be2dfa4a95124ab9c0f6c4)
@@ -26,5 +26,5 @@
     ## Title to appear on top of the window
     window_caption = "Fit Page"
-    
+    name=None
     
     def __init__(self, parent,data, *args, **kwargs):
Index: sansview/perspectives/fitting/fitpanel.py
===================================================================
--- sansview/perspectives/fitting/fitpanel.py	(revision 888e62c7c7563fbd40a6aad40263e36508a6b2b7)
+++ sansview/perspectives/fitting/fitpanel.py	(revision 10c43a589031ebfba8be2dfa4a95124ab9c0f6c4)
@@ -43,5 +43,5 @@
         self.AddPage(self.sim_page,"Simultaneous Fit")
         
-        
+        self._mgr = wx.aui.AuiManager(self)
 
         
@@ -53,5 +53,5 @@
         #model page info
         self.model_page_number=None
-        self.page_name=None
+       
         self.model_page=None
         # increment number for model name
@@ -115,4 +115,5 @@
             from fitpage1D import FitPage1D
             panel = FitPage1D(self,data, -1)
+            panel.name=name
             m_name= "M"+str(self.count)  
             panel.set_manager(self.manager)
@@ -139,4 +140,5 @@
         self.AddPage(page=panel,caption="Model",select=True)
         panel.populate_box( self.model_list_box)
+        panel.name=page_title
         self.draw_model_name=page_title
         self.model_page_number=self.GetSelection()
@@ -166,9 +168,11 @@
             @param npts: number of Q points
         """
+        print "self.draw_model_name none",self.draw_model_name
         if  self.draw_model_name ==None:
+            print "self.draw_model_name none"
             self._help_add_model_page(model,description,page_title, qmin=qmin, qmax=qmax, npts=npts)
         elif topmenu==True:
             self.model_page.select_model(model, page_title)
-           
+          
     def get_current_page(self):
         """
@@ -179,23 +183,25 @@
   
     
-    def old_onClose(self, page=None,page_number=None):
+    def onClose(self, page=None,page_number=None):
         """
              close the current page except the simpage. remove each check box link to the model
              selected on that page. remove its reference into page_finder (fitting module)
         """
-        #print "model page", page_number, page
+        print "model page", page_number, page, self.draw_model_name
         if page!=None and page_number!=None:
-            
-            self.nb.RemovePage(page_number)
-            page.Destroy()
+            i=self.DeletePage(page_number)
+            #self.nb.RemovePage(page_number)
+            #page.Destroy()
             self.model_page_number=None
             self.model_page=None
             self.draw_model_name=None
+            print"self.draw_model_name",self.draw_model_name
             return 
         try:
-            sim_page = self.nb.GetPage(0)
-            selected_page = self.nb.GetPage(self.nb.GetSelection())
-            
+            sim_page = self.GetPage(1)
+            selected_page = self.GetPage(self.GetSelection())
+            print "sim_page ",sim_page ,selected_page
             if sim_page != selected_page:
+                print "sim_page ",sim_page ,selected_page
                 # remove the check box link to the model name of this page (selected_page)
                 sim_page.remove_model(selected_page)
@@ -207,12 +213,16 @@
                         break
                 #Delete the page from notebook
-                page_number = self.nb.GetSelection()
-                if self.nb.GetPageText(page_number)== self.page_name:
+                page_number = self.GetSelection()
+                print selected_page.name,self.GetPageText(page_number),self.draw_model_name
+                if selected_page.name== self.draw_model_name:
+                    print "went here"
                     self.draw_model_name=None
+                    self.model_page=None
                 if  page_number == 1:
                     self.model_page=None
                     self.draw_model_name=None
-                selected_page.Destroy()
-                self.nb.RemovePage(page_number)
+                #selected_page.Destroy()
+                #self.RemovePage(page_number)
+                i=self.DeletePage(page_number)
                 #self.count =self.count -1 
                 self.fit_page_name=None
Index: sansview/perspectives/fitting/modelpage.py
===================================================================
--- sansview/perspectives/fitting/modelpage.py	(revision 888e62c7c7563fbd40a6aad40263e36508a6b2b7)
+++ sansview/perspectives/fitting/modelpage.py	(revision 10c43a589031ebfba8be2dfa4a95124ab9c0f6c4)
@@ -26,6 +26,5 @@
     ## Title to appear on top of the window
     window_caption = "Fit Page"
-    
-    
+    name=""
     def __init__(self, parent,model,name, *args, **kwargs):
         wx.ScrolledWindow.__init__(self, parent, *args, **kwargs)
Index: sansview/perspectives/fitting/scroll_fitpage1D.py
===================================================================
--- sansview/perspectives/fitting/scroll_fitpage1D.py	(revision b5847bd86a432a691bb05ed54af212f79ff5db1b)
+++ 	(revision )
@@ -1,627 +1,0 @@
-import sys
-import wx
-import wx.lib
-import numpy,math
-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 FitPage1D(wx.Panel):
-    """
-        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,data, *args, **kwargs):
-        wx.Panel.__init__(self, parent, *args, **kwargs)
-        """ 
-            Initialization of the Panel
-        """
-        self.scroll = wx.ScrolledWindow(self,-1)
-        
-        self.manager = None
-        self.parent  = parent
-        self.event_owner=None
-        #panel interface
-        self.vbox  = wx.BoxSizer(wx.VERTICAL)
-        self.sizer5 = wx.GridBagSizer(5,5)
-        self.sizer4 = wx.GridBagSizer(5,5)
-        self.sizer3 = wx.GridBagSizer(5,5)
-        self.sizer2 = wx.GridBagSizer(5,5)
-        self.sizer1 = wx.GridBagSizer(5,5)
-        
-        
-        self.DataSource  =wx.StaticText(self.scroll, -1,str(data.name))
-        
-        self.modelbox = wx.ComboBox(self.scroll, -1)
-        id = wx.NewId()
-        self.btFit =wx.Button(self.scroll,id,'Fit')
-        self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id=id)
-        self.btFit.SetToolTipString("Perform fit.")
-        self.static_line_1 = wx.StaticLine(self.scroll, -1)
-       
-        self.vbox.Add(self.sizer3)
-        
-        self.vbox.Add(self.sizer2)
-        self.vbox.Add(self.static_line_1, 0, wx.EXPAND, 0)
-        self.vbox.Add(self.sizer5)
-        
-        self.vbox.Add(self.sizer4)
-        self.vbox.Add(self.sizer1)
-        
-        id = wx.NewId()
-        self.btClose =wx.Button(self.scroll,id,'Close')
-        self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id)
-        self.btClose.SetToolTipString("Close page.")
-        ix = 0
-        iy = 1
-        self.sizer3.Add(wx.StaticText(self.scroll, -1, 'Data Source Name : '),(iy,ix),\
-                 (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        ix += 1
-        self.sizer3.Add(self.DataSource,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        ix += 1
-        self.sizer3.Add((20,20),(iy,ix),(1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE,0)
-        ix = 0
-        iy += 1
-        self.sizer3.Add(wx.StaticText(self.scroll,-1,'Model'),(iy,ix),(1,1)\
-                  , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        ix += 1
-        self.sizer3.Add(self.modelbox,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        
-        ix = 0
-        iy = 1
-        #set maximum range for x in linear scale
-        self.text4_3 = wx.StaticText(self.scroll, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT)
-        self.sizer4.Add(self.text4_3,(iy,ix),(1,1),\
-                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        ix += 1
-        self.sizer4.Add(wx.StaticText(self.scroll, -1, 'Min'),(iy, ix),(1,1),\
-                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        ix += 2
-        self.sizer4.Add(wx.StaticText(self.scroll, -1, 'Max'),(iy, ix),(1,1),\
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        ix = 0
-        iy += 1
-        self.sizer4.Add(wx.StaticText(self.scroll, -1, 'x range'),(iy, ix),(1,1),\
-                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        ix += 1
-        self.xmin    = wx.TextCtrl(self.scroll, -1,size=(_BOX_WIDTH,20))
-        self.xmin.SetValue(format_number(numpy.min(data.x)))
-        self.xmin.SetToolTipString("Minimun value of x in linear scale.")
-        self.xmin.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
-        self.xmin.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)
-        self.xmin.Disable()
-        self.sizer4.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        
-       
-        ix += 2
-        self.xmax    = wx.TextCtrl(self.scroll, -1,size=(_BOX_WIDTH,20))
-        self.xmax.SetValue(format_number(numpy.max(data.x)))
-        self.xmax.SetToolTipString("Maximum value of x in linear scale.")
-        self.xmax.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
-        self.xmax.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)
-        self.xmax.Disable()
-        self.sizer4.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        ix =0
-        iy+=1
-        self.sizer4.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        #Set chisqr  result into TextCtrl
-        ix = 0
-        iy = 1
-        self.smear= wx.CheckBox(self.scroll, -1, "Fit with Smear", (10, 10))
-        wx.EVT_CHECKBOX(self.scroll, self.smear.GetId(), self.onSmear)
-        self.sizer1.Add(self.smear,(iy,ix),(1,1),\
-                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        iy+=1
-        self.text1_1 = wx.StaticText(self.scroll, -1, 'Chi2/dof', style=wx.ALIGN_LEFT)
-        #self.sizer1.Add(self.text1_1,1)
-        self.sizer1.Add(self.text1_1,(iy,ix),(1,1),\
-                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-        ix += 1
-        self.tcChi    = wx.TextCtrl(self.scroll, -1,size=(_BOX_WIDTH,20))
-        self.tcChi.SetToolTipString("Chi^2 over degrees of freedom.")
-        #self.sizer1.Add(self.tcChi, 1, wx.R | wx.BOTTOM , 5)
-        self.sizer1.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        ix +=2
-        #self.sizer1.Add(self.btFit, 1, wx.LEFT | wx.BOTTOM , 5)
-        self.sizer1.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        ix+= 2
-        self.sizer1.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        #self.sizer1.Add( self.btClose,1, wx.LEFT | wx.BOTTOM , 5)
-
-        ix= 0
-        iy+=1
-        self.sizer1.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        #self.sizer1.Add((20,20), 0)
-        # contains link between  model ,all its parameters, and panel organization
-        self.parameters=[]
-        #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={}
-        self.data = data
-        self.vbox.Layout()
-        
-        bs = wx.BoxSizer(wx.VERTICAL)
-        bs.Add(self.scroll, 1, wx.EXPAND)
-        self.SetSizer(bs)
-        
-        
-        self.GrandParent.GetSizer().Layout()
-        self.vbox.Fit(self) 
-        self.SetSizer(self.vbox)
-        
-        self.Centre()
-       
-        #self.scrollbar= wx.ScrollBar(self, -1,pos = wx.DefaultPosition,style = wx.VERTICAL)
-        
-        unit = 20
-        width,height = self.GetSize()
-        self.scroll.SetVirtualSize((width+unit, height+unit))
-        self.scroll.SetScrollRate(unit, unit)
-
-        print self.GetSize()
-        print self.scroll.GetSize()
-
-        
-        
-        
-        
-        
-        
-    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):
-        """ @param fn: function that return model value
-            @return residuals
-        """
-        
-        flag=self.checkFitRange()
-        if flag== True:
-            try:
-                qmin = float(self.xmin.GetValue())
-                qmax = float(self.xmax.GetValue())
-                x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)]
-                if qmin==None and qmax==None: 
-                    fx =numpy.asarray([self.model.run(v) for v in x])
-                    res=(y - fx)/dy
-                else:
-                    idx = (x>= qmin) & (x <=qmax)
-                    fx = numpy.asarray([self.model.run(item)for item in x[idx ]])
-                    res= (y[idx] - fx)/dy[idx]  
-                
-               
-                sum=0
-                for item in res:
-                    if numpy.isfinite(item):
-                        sum +=item
-                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.scroll, -1, 'Dispersion')
-            self.sizer5.Add(disp,( iq, ip),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-            ip += 1 
-            values = wx.StaticText(self.scroll, -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.scroll, -1,'Parameters', (10, 10))
-        wx.EVT_CHECKBOX(self.scroll, 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.scroll, -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.scroll, -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.scroll, -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.scroll, -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.scroll, cb.GetId(), self.select_param)
-                
-                ix += 1
-                value= self.model.getParam(item)
-                ctl1 = wx.TextCtrl(self.scroll, -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.scroll, -1, '+/-')
-                self.sizer2.Add(text2,(iy, ix),(1,1),\
-                                wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
-                text2.Hide()  
-                ix += 1
-                ctl2 = wx.TextCtrl(self.scroll, -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.scroll, -1, self.model.details[item][0], style=wx.ALIGN_LEFT)
-                except:
-                    units = wx.StaticText(self.scroll, -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.scroll, -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.scroll, cb.GetId(), self.select_param)
-                
-                ip += 1
-                value= self.model.getParam(item)
-                ctl1 = wx.TextCtrl(self.scroll, -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()
-        else:
-            self.xmin.Enable()
-            self.xmax.Enable()
-       
-        self.compute_chisqr()
-        self.vbox.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
-        """
-        if len(self.parameters) !=0 and self.model !=None:
-            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())
-                    self.model.setParam(name,value) 
-                except:
-                     wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
-                            "Drawing  Error:wrong value entered : %s"% sys.exc_value))
-           
-            self.manager.redraw_model(float(self.xmin.GetValue())\
-                                               ,float(self.xmax.GetValue()))      
-                     
-    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()
-                else:
-                    self.xmin.Enable()
-                    self.xmax.Enable()
-            else:
-                for item in self.parameters:
-                    item[0].SetValue(False)
-                self.param_toFit=[]
-              
-                self.xmin.Disable()
-                self.xmax.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()
-        else:
-            self.xmin.Enable()
-            self.xmax.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.GrandParent.GetSizer().Layout()
-    def onSmear(self, event):
-        if self.smear.GetValue()==True:
-            from DataLoader.qsmearing import smear_selection
-            smear =smear_selection( self.data )
-            self.data.smearer= smear
-            #print "on smearing", self.data.smearer._compute_matrix()
-        else:
-            self.data.smearer=None
-        
