Index: sansview/perspectives/fitting/fitpanel.py
===================================================================
--- sansview/perspectives/fitting/fitpanel.py	(revision ef8b580e1d81d99a7c4cb6d0465ea7a27c2dfcbf)
+++ sansview/perspectives/fitting/fitpanel.py	(revision 2a8fac139d8cc1f41446e9eeb7178b18ec8186aa)
@@ -40,8 +40,8 @@
         #Creating a page for simultaneous fitting
         from simfitpage import SimultaneousFitPage
-        self.sim_page = SimultaneousFitPage(self, -1)
+        self.sim_page = SimultaneousFitPage(self, id=-1)
         self.AddPage(self.sim_page,"Simultaneous Fit")
         
-        self._mgr = wx.aui.AuiManager(self)
+        self._mgr = self.GetAuiManager()
 
         
@@ -60,4 +60,6 @@
         self.Update()
         self.Center()
+        
+        
     def onClosePage(self, event):
         self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
@@ -102,5 +104,5 @@
         except:
             name = 'Fit'
-        
+       
         if self.fit_page_name != name:
             #self.about_page.Disable()
Index: sansview/perspectives/fitting/fitproblem.py
===================================================================
--- sansview/perspectives/fitting/fitproblem.py	(revision 9e27de9d87e3595d153da904763a26129f58d987)
+++ sansview/perspectives/fitting/fitproblem.py	(revision 2a8fac139d8cc1f41446e9eeb7178b18ec8186aa)
@@ -16,5 +16,5 @@
             and its name assign example [lineModel, M0]
         """
-        self.data=None
+        self.fit_data=None
         self.theory_name=None
         self.model_list=[]
@@ -23,4 +23,5 @@
         self.name_per_page=None
         self.smearer= None
+        self.plotted_data=None
         
     def set_smearer(self, smearer):
@@ -46,10 +47,16 @@
 
   
-    def add_data(self,data):
+    def add_plotted_data(self,data):
         """ 
             save a copy of the data select to fit
             @param data: data selected
         """
-        self.data = data
+        self.plotted_data = data
+    def add_fit_data(self,data):
+        """ 
+            save a copy of the data select to fit
+            @param data: data selected
+        """
+        self.fit_data = data
             
     def get_model(self):
@@ -58,9 +65,13 @@
         return self.model_list
      
-    def get_data(self):
+    def get_plotted_data(self):
         """ @return:  list of data dList"""
-        return self.data
-      
-      
+        return self.plotted_data
+    
+    
+    def get_fit_data(self):
+        return self.fit_data
+    
+    
     def get_theory(self):
         """ @return the name of theory for plotting purpose"""
Index: sansview/perspectives/fitting/fitting.py
===================================================================
--- sansview/perspectives/fitting/fitting.py	(revision b5c537f1b7cd160d4bef4ae83b1be042d602ef73)
+++ sansview/perspectives/fitting/fitting.py	(revision 2a8fac139d8cc1f41446e9eeb7178b18ec8186aa)
@@ -7,5 +7,5 @@
 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.guicomm.events import EVT_SLICER_PANEL,EVT_MODEL2D_PANEL,ERR_DATA
 
 from sans.fit.AbstractFitEngine import Model,Data,FitData1D,FitData2D
@@ -49,10 +49,15 @@
         self._fit_engine = 'scipy'
         self.enable_model2D=False
-        
+        # list of selcted data
+        self.selected_data_list=[]
         # Log startup
         logging.info("Fitting plug-in started")   
         # model 2D view
         self.model2D_id=None
-
+        self.err_dy={}
+        
+    def _on_data_error(self, event):
+        self.err_dy= event.err_dy
+        
     def populate_menu(self, id, owner):
         """
@@ -117,6 +122,7 @@
                           "Dialog with fitting parameters ", self._onSelect]] 
             else:
-                if item.name==graph.selected_plottable and\
-                 item.__class__.__name__ is  "Data1D":
+                #if item.name==graph.selected_plottable and\
+                # item.__class__.__name__ is  "Data1D":
+                if item.name==graph.selected_plottable :
                     return [["Select data  for Fitting", \
                              "Dialog with fitting parameters ", self._onSelect]] 
@@ -142,5 +148,5 @@
         self.index_theory= 0
         self.parent.Bind(EVT_SLICER_PANEL, self._on_slicer_event)
-       
+        self.parent.Bind( ERR_DATA, self._on_data_error)
         
         #create the fitting panel
@@ -202,10 +208,28 @@
         self.panel = event.GetEventObject()
         for item in self.panel.graph.plottables:
+            if item.name == self.panel.graph.selected_plottable:
+                if len(self.err_dy)>0:
+                    if item.name in  self.err_dy.iterkeys():
+                        dy= self.err_dy[item.name]
+                        data= Data1D(x=item.x, y=item.y, dy=dy)
+                        data.name=item.name
+                else:
+                    if item.dy==None:
+                        dy= numpy.zeros(len(item.y))
+                        dy[dy==0]=1
+                        print "dy", dy
+                        data= Data1D(x=item.x, y=item.y, dy=dy)
+                        data.name=item.name
+                    else:
+                        data= Data1D(x=item.x, y=item.y, dy=item.dy)
+                        data.name=item.name
             if item.name == self.panel.graph.selected_plottable or\
                  item.__class__.__name__ is "Data2D":
                 #find a name for the page created for notebook
+                print "fitting", self.panel
                 try:
                    
-                    page = self.fit_panel.add_fit_page(item)
+                    #page = self.fit_panel.add_fit_page(item)
+                    page = self.fit_panel.add_fit_page(data)
                     #page, model_name = self.fit_panel.add_fit_page(item)
                     # add data associated to the page created
@@ -215,12 +239,17 @@
                         self.page_finder[page]= FitProblem()
                         #self.page_finder[page].save_model_name(model_name)  
-                        self.page_finder[page].add_data(item)
+                        self.page_finder[page].add_plotted_data(item)
+                        self.page_finder[page].add_fit_data(data)
+                       
+                            
                         wx.PostEvent(self.parent, StatusEvent(status="Page Created"))
                     else:
                         wx.PostEvent(self.parent, StatusEvent(status="Page was already Created"))
                 except:
-                    #raise
-                    wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\
-                    %sys.exc_value))
+                    raise
+                    #wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\
+                    #%sys.exc_value))
+                    
+                    
     def schedule_for_fit(self,value=0,fitproblem =None):  
         """
@@ -400,5 +429,5 @@
         #    if  value.get_scheduled() ==1 :
             value = self.page_finder[current_pg]
-            metadata =  value.get_data()
+            metadata =  value.get_fit_data()
             list = value.get_model()
             model = list[0]
@@ -477,5 +506,5 @@
             try:
                 if value.get_scheduled()==1:
-                    metadata = value.get_data()
+                    metadata = value.get_fit_data()
                     list = value.get_model()
                     model= list[0]
@@ -629,5 +658,5 @@
             for page in self.page_finder.iterkeys():
                 if  page==currpage :  
-                    data=self.page_finder[page].get_data()
+                    data=self.page_finder[page].get_plotted_data()
                     list=self.page_finder[page].get_model()
                     model=list[0]
@@ -766,4 +795,5 @@
             self.redraw_model(qmin,qmax)
             return 
+        self._draw_model1D(model,name,model.description, enable1D,qmin,qmax, qstep)
         self._draw_model2D(model=model,
                            description=model.description,
@@ -772,5 +802,5 @@
                            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,
@@ -803,6 +833,5 @@
             else:
                 for i in range(xlen):
-                    y[i] = model.run(x[i])
-                #print x, y   
+                    y[i] = model.run(x[i]) 
                 try:
                     new_plot = Theory1D(x, y)
@@ -828,5 +857,5 @@
        
         wx.PostEvent(self.parent, StatusEvent(status="Calc \
-        complete in %g sec" % elapsed, type="stop"))
+        complete !" , type="stop"))
         #print "complete",output, model,qmin, qmax
         data = output
@@ -890,5 +919,5 @@
         theory.ymax= qmax#/math.sqrt(2)
         
-        print "model draw comptele xmax",theory.xmax,model.name
+        #print "model draw comptele xmax",theory.xmax,model.name
         wx.PostEvent(self.parent, NewPlotEvent(plot=theory,
                          title="Analytical model 2D ", reset=True ))
@@ -898,5 +927,5 @@
     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,
@@ -910,17 +939,21 @@
         lx = len(x)
         #print x
-        data=numpy.zeros([len(x),len(y)])
+        #data=numpy.zeros([len(x),len(y)])
         self.model= model
         if enable2D:
-            from sans.guiframe.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)
+            try:
+                from sans.guiframe.model_thread import Calc2D
+                print "in draw model 2d ",self.model
+                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)
+            except:
+                raise
             
     def show_panel2D(self, id=None ):
Index: sansview/perspectives/fitting/old_fitpanel.py
===================================================================
--- sansview/perspectives/fitting/old_fitpanel.py	(revision 2a8fac139d8cc1f41446e9eeb7178b18ec8186aa)
+++ sansview/perspectives/fitting/old_fitpanel.py	(revision 2a8fac139d8cc1f41446e9eeb7178b18ec8186aa)
@@ -0,0 +1,240 @@
+import wx
+import wx.aui
+import wx.lib
+import numpy
+import string ,re
+#import models
+_BOX_WIDTH = 80
+
+(FitPageEvent, EVT_FIT_PAGE)   = wx.lib.newevent.NewEvent()
+class FitPanel(wx.aui.AuiNotebook):    
+#class FitPanel(wx.aui.AuiNotebook,wx.panel):
+    """
+        FitPanel class contains fields allowing to fit  models and  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 panel"
+    ## Title to appear on top of the window
+    window_caption = "Fit Panel "
+    CENTER_PANE = True
+    def __init__(self, parent, *args, **kwargs):
+        
+        wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_SCROLL_BUTTONS )
+        #wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_DEFAULT_STYLE  )
+        
+        
+        self.manager=None
+        self.parent=parent
+        self.event_owner=None
+        
+        pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE
+        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)
+        #Creating the default page --welcomed page
+        from sans.guiframe.welcome_panel import PanelAbout
+        self.about_page = PanelAbout(self, -1)
+        self.AddPage(self.about_page,"welcome!")
+        #self.about_page.Disable()
+        #Creating a page for simultaneous fitting
+        from simfitpage import SimultaneousFitPage
+        self.sim_page = SimultaneousFitPage(self, id=-1)
+        self.AddPage(self.sim_page,"Simultaneous Fit")
+        
+        self._mgr = wx.aui.AuiManager(self)
+
+        
+        #dictionary of miodel {model class name, model class}
+        self.model_list_box={}
+        # save the title of the last page tab added
+        self.fit_page_name=None
+        self.draw_model_name=None
+        #model page info
+        self.model_page_number=None
+       
+        self.model_page=None
+        # increment number for model name
+        self.count=0
+        #updating the panel
+        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)
+            
+
+   
+
+
+        
+    def set_manager(self, manager):
+        """
+             set panel manager
+             @param manager: instance of plugin fitting
+        """
+        self.manager = manager
+        self.sim_page.set_manager(manager)
+        
+    def set_owner(self,owner):
+        """ 
+            set and owner for fitpanel
+            @param owner: the class responsible of plotting
+        """
+        self.event_owner=owner
+      
+        
+    def add_fit_page( self,data ):
+        """ 
+            Add a fitting page on the notebook contained by fitpanel
+            @param panel: contains in the page to add
+            @param name: title of the page tab
+            @return panel : page just added for futher used. is used by fitting module
+        """     
+        try:
+            name = data.name # item in Data1D
+        except:
+            name = 'Fit'
+        
+        if self.fit_page_name != name:
+            #self.about_page.Disable()
+            from fitpage1D import FitPage1D
+            panel = FitPage1D(self,data, -1)
+            panel.name=name
+            #m_name= "M"+str(self.count)  
+            panel.set_manager(self.manager)
+            panel.set_owner(self.event_owner)
+            
+            self.AddPage(page=panel,caption=name,select=True)
+            panel.populate_box( self.model_list_box)
+            self.fit_page_name = name
+            EVT_FIT_PAGE
+            return panel #,m_name
+        else:
+            return None #, None
+        
+    def _help_add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50):
+        """
+            #TODO: fill in description
+            
+            @param qmin: mimimum Q
+            @param qmax: maximum Q
+            @param npts: number of Q points
+        """
+        from modelpage import ModelPage
+        #print "fitpanel model", model
+        panel = ModelPage(self,model,page_title, -1)
+        panel.set_manager(self.manager)
+        panel.set_owner(self.event_owner)
+        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()
+        self.model_page=self.GetPage(self.GetSelection())
+        
+        
+        # Set the range used to plot models
+        self.model_page.set_range(qmin, qmax, npts)
+        
+        # We just created a model page, we are ready to plot the model
+        #self.manager.draw_model(model, model.name)
+        #FOR PLUGIN  for somereason model.name is = BASEcomponent
+        self.manager.draw_model(model, page_title)
+        
+        
+    def add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50, topmenu=False):
+        """
+            Add a model page only one  to display any model selected from the menu or the page combo box.
+            when this page is closed than the user will be able to open a new one
+            
+            @param model: the model for which paramters will be changed
+            @param page_title: the name of the page
+            @param description: [Coder: fill your description!]
+            @param page_title: [Coder: fill your description!]
+            @param qmin: mimimum Q
+            @param qmax: maximum Q
+            @param npts: number of Q points
+        """
+        print "self.draw_model_name none",self.draw_model_name
+        if topmenu==True:
+            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)
+            else:
+                #self.model_page.name=page_title
+                #self.draw_model_name=page_title
+                #print "wnent here self.draw_model_name ",self.draw_model_name,self.model_page.name,self.model_page
+                
+                self.model_page.select_model(model, page_title)
+          
+    def get_current_page(self):
+        """
+            @return the current page selected
+        """
+        #return self.nb.GetCurrentPage()
+        return self.GetPage(self.GetSelection() )
+  
+    
+    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, self.draw_model_name
+        if page!=None and page_number!=None:
+            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.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)
+                #remove that page from page_finder of fitting module
+                page_finder=self.manager.get_page_finder() 
+                for page, value in page_finder.iteritems():
+                    if page==selected_page:
+                        del page_finder[page]
+                        break
+                #Delete the page from notebook
+                page_number = self.GetSelection()
+                print "on close",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.RemovePage(page_number)
+                i=self.DeletePage(page_number)
+                #self.count =self.count -1 
+                self.fit_page_name=None
+        except:
+            raise
+        #print "fitpanel", self.draw_model_name 
+        
+    def set_model_list(self,dict):
+         """ 
+             copy a dictionary of model into its own dictionary
+             @param dict: dictionnary made of model name as key and model class
+             as value
+         """
+         self.model_list_box = dict
+  
