Index: sansview/perspectives/fitting/fitpage.py
===================================================================
--- sansview/perspectives/fitting/fitpage.py	(revision 6fdfc8fab90b8745b06ee22c6b8c7121258d54e1)
+++ sansview/perspectives/fitting/fitpage.py	(revision 2b63df09a5826d4b448bcf0aa71725f284eab711)
@@ -39,6 +39,6 @@
         ## fit page does not content npts txtcrtl
         self.npts=None
-        ## if no dispersity parameters is avaible 
-        #self.text_disp_1=None
+        ## thread for compute Chisqr
+        self.calc_Chisqr=None
         ## default fitengine type
         self.engine_type = None
@@ -53,5 +53,9 @@
                 self.enable_smearer.Disable()
                 self.disable_smearer.Disable()
-                
+        #try:
+            ##Calculate chi2
+        #    self.compute_chisqr(smearer= temp_smearer)  
+        #except:
+        #    raise              
         ## to update the panel according to the fit engine type selected
         self.Bind(EVT_FITTER_TYPE,self._on_engine_change)
@@ -145,5 +149,10 @@
         boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
         boxsizer1.SetMinSize((60,-1))
-        self.tcChi    =  wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT)        
+        temp_smearer = None
+        if self.enable_smearer.GetValue():
+            temp_smearer= self.smearer
+        
+        self.tcChi    =  wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT)
+         
         boxsizer1.Add( self.tcChi )   
         sizer_smearer.Add( boxsizer1 )
@@ -685,14 +694,58 @@
         ## set smearing value whether or not the data contain the smearing info
         self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x),
-                                      qmax= float(self.qmax_x)) 
+                                     qmax= float(self.qmax_x)) 
         ##Calculate chi2
         self.compute_chisqr(smearer= temp_smearer)  
         ## save the state enable smearing
-        self.save_current_state()
-       
-         
+        self.save_current_state() 
    
-        
-  
+    def complete_chisqr(self, output, elapsed=None):  
+        """
+            print result chisqr
+        """
+        try:
+            self.tcChi.SetLabel(format_number(output))
+        except:
+            raise
+        
+        
+    def compute_chisqr1D(self, smearer=None):
+        """
+            Compute chisqr for 1D
+        """
+        from sans.guiframe.utils import check_value
+        flag = check_value( self.qmin, self.qmax)
+        
+        if not flag:
+            return 
+        
+        try:
+            self.qmin_x = float(self.qmin.GetValue())
+            self.qmax_x = float(self.qmax.GetValue())
+            ##return residuals within self.qmin_x and self.qmax_x
+            from gui_thread import CalcChisqr1D
+            ## If a thread is already started, stop it
+            if self.calc_Chisqr!= None and self.calc_Chisqr.isrunning():
+                self.calc_Chisqr.stop()
+                
+            self.calc_Chisqr= CalcChisqr1D( x= self.data.x,
+                                            y= self.data.y,
+                                            dy= self.data.dy,
+                                            model= self.model,
+                                            smearer=smearer,
+                                            qmin=self.qmin_x,
+                                            qmax=self.qmax_x,
+                                            completefn = self.complete_chisqr,
+                                            updatefn   = None)
+    
+            self.calc_Chisqr.queue()
+            
+        except:
+            raise ValueError," Could not compute Chisqr for %s Model 2D: "%self.model.name
+           
+            
+   
+        
+        
     def compute_chisqr2D(self):
         """ 
@@ -702,39 +755,33 @@
         from sans.guiframe.utils import check_value
         flag = check_value( self.qmin, self.qmax)
-        
-        err_image = copy.deepcopy(self.data.err_data)
-        if err_image==[] or err_image==None:
-            err_image= numpy.zeros(len(self.data.x_bins),len(self.data.y_bins))
-                       
-        err_image[err_image==0]=1
-       
-        res=[]
-        if flag== True:
-            try:
-                self.qmin_x = float(self.qmin.GetValue())
-                self.qmax_x = float(self.qmax.GetValue())
-                for i in range(len(self.data.x_bins)):
-                    for j in range(len(self.data.y_bins)):
-                        #Check the range containing data between self.qmin_x and self.qmax_x
-                        value =  math.pow(self.data.x_bins[i],2)+ math.pow(self.data.y_bins[j],2)
-                        if value >= math.pow(self.qmin_x,2) and value <= math.pow(self.qmax_x,2):
-                            
-                            temp = [self.data.x_bins[i],self.data.y_bins[j]]
-                            error= err_image[j][i]
-                            chisqrji = (self.data.data[j][i]- self.model.runXY(temp ))/error
-                            #Vector containing residuals
-                            res.append( math.pow(chisqrji,2) )
-
-                # compute sum of residual
-                sum=0
-                for item in res:
-                    if numpy.isfinite(item):
-                        sum +=item
-                self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
-            except:
-                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
-                            "Chisqr cannot be compute: %s"% sys.exc_value))
-                return
-    
+        if not flag:
+            return 
+      
+        try:
+            self.qmin_x = float(self.qmin.GetValue())
+            self.qmax_x = float(self.qmax.GetValue())
+           
+            ##return residuals within self.qmin_x and self.qmax_x
+            from gui_thread import CalcChisqr2D
+            ## If a thread is already started, stop it
+            if self.calc_Chisqr!= None and self.calc_Chisqr.isrunning():
+                self.calc_Chisqr.stop()
+                
+            self.calc_Chisqr= CalcChisqr2D( x_bins= self.data.x_bins,
+                                            y_bins= self.data.y_bins,
+                                            data= self.data.data,
+                                            err_data = self.data.err_data,
+                                            model= self.model,
+                                            qmin= self.qmin_x,
+                                            qmax = self.qmax_x,
+                                            completefn = self.complete_chisqr,
+                                            updatefn   = None)
+    
+            self.calc_Chisqr.queue()
+          
+        except:
+            raise ValueError," Could not compute Chisqr for %s Model 2D: "%self.model.name
+           
+
         
     def compute_chisqr(self , smearer=None):
@@ -751,38 +798,9 @@
                     return
                 else:
-                    self.qmin_x = float(self.qmin.GetValue())
-                    self.qmax_x = float(self.qmax.GetValue())
-                    # return residuals within self.qmin_x and self.qmax_x
-                    x,y = [numpy.asarray(v) for v in (self.data.x,self.data.y)]
-                    
-                    if self.data.dy==None:
-                        dy= numpy.zeros(len(y))
-                    else:
-                        dy= copy.deepcopy(self.data.dy)
-                        dy= numpy.asarray(dy)
-                    dy[dy==0]=1
-                   
-                    if self.qmin_x==None and self.qmax_x==None: 
-                        fx =numpy.asarray([self.model.run(v) for v in x])
-                        if smearer!=None:
-                            fx= smearer(fx)
-                        temp=(y - fx)/dy
-                        res= temp*temp
-                    else:
-                        idx = (x>= self.qmin_x) & (x <=self.qmax_x)
-                        fx = numpy.asarray([self.model.run(item)for item in x[idx ]])
-                        if smearer!=None:
-                            fx= smearer(fx)
-                        temp=(y[idx] - fx)/dy[idx]
-                        res= temp*temp
-                    #sum of residuals
-                    sum=0
-                    for item in res:
-                        if numpy.isfinite(item):
-                            sum +=item
-                    self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
+                    self.compute_chisqr1D(smearer=smearer)
+                    return
             except:
                 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
-                            "Chisqr cannot be compute: %s"% sys.exc_value))
+                            "Chisqr Error: %s"% sys.exc_value))
                 return 
             
Index: sansview/perspectives/fitting/fitting.py
===================================================================
--- sansview/perspectives/fitting/fitting.py	(revision 8b317804fa546988db2835755d5d71f3d97df9a6)
+++ sansview/perspectives/fitting/fitting.py	(revision 2b63df09a5826d4b448bcf0aa71725f284eab711)
@@ -3,10 +3,11 @@
 import string, numpy, math
 
-from danse.common.plottools.plottables import Data1D, Theory1D,Data2D
+from danse.common.plottools.plottables import Data2D,Theory1D
+from sans.guiframe import dataFitting 
 from danse.common.plottools.PlotPanel import PlotPanel
 from sans.guicomm.events import NewPlotEvent, StatusEvent  
 from sans.guicomm.events import EVT_SLICER_PANEL,ERR_DATA
 from sans.guiframe import dataFitting
-from sans.fit.AbstractFitEngine import Model,FitData1D,FitData2D
+from sans.fit.AbstractFitEngine import Model
 
 from fitproblem import FitProblem
@@ -266,5 +267,5 @@
             dx= item.dx
             
-        from sans.guiframe import dataFitting 
+        
         data= dataFitting.Data1D(x=item.x, y=item.y,dx=dx, dy=dy, dxl=dxl, dxw=dxw)
         
@@ -988,6 +989,6 @@
                 new_plot.is_data =False 
            
-            from DataLoader.data_info import Data1D
-            info= Data1D(x= new_plot.x, y=new_plot.y)
+            from DataLoader import data_info
+            info= data_info.Data1D(x= new_plot.x, y=new_plot.y)
             info.title= new_plot.name
             title= my_info.title
Index: sansview/perspectives/fitting/gui_thread.py
===================================================================
--- sansview/perspectives/fitting/gui_thread.py	(revision 413408601ab3e50cd9788992d4d404b3ff506ba9)
+++ sansview/perspectives/fitting/gui_thread.py	(revision 2b63df09a5826d4b448bcf0aa71725f284eab711)
@@ -2,4 +2,7 @@
 
 import time
+import numpy
+import copy
+import math
 import sys
 import wx
@@ -7,14 +10,12 @@
 from calcthread import CalcThread
 
-
-class SmearPlot(CalcThread):
+class CalcChisqr1D(CalcThread):
     """
-        Compute 2D model
-        This calculation assumes a 2-fold symmetry of the model
-        where points are computed for one half of the detector
-        and I(qx, qy) = I(-qx, -qy) is assumed.
+       Compute chisqr
     """
-    
-    def __init__(self, enable_smearer=False,smearer=None,manager=None,
+    def __init__(self, x, y,dy, model,
+                 smearer=None,
+                 qmin=None,
+                 qmax=None,
                  completefn = None,
                  updatefn   = None,
@@ -26,8 +27,23 @@
                  yieldtime,
                  worktime)
-        self.enable_smearer = enable_smearer
+        self.smearer =smearer
+        self.y = numpy.array(y)
+        self.x = numpy.array(x)
+        self.dy= copy.deepcopy(dy)
+        self.model = model
+        self.qmin = qmin
+        self.qmax = qmax
         self.smearer = smearer
-        self.manager= manager
         self.starttime = 0  
+        
+    def isquit(self):
+        """
+             @raise KeyboardInterrupt: when the thread is interrupted
+        """
+        try:
+            CalcThread.isquit(self)
+        except KeyboardInterrupt:
+            raise KeyboardInterrupt   
+        
         
     def compute(self):
@@ -35,10 +51,131 @@
             Compute the data given a model function
         """
-        ## set smearing value whether or not the data contain the smearing info
-        self.manager.set_smearer(self.smearer, qmin= float(self.qmin_x),
-                                      qmax= float(self.qmax_x)) 
-        ##Calculate chi2
-        self.compute_chisqr(smearer= temp_smearer)  
-        elapsed = time.time()-self.starttime
-       
-
+        self.starttime = time.time()
+        x,y = [numpy.asarray(v) for v in (self.x,self.y)]
+        if self.dy==None or self.dy==[]:
+            self.dy= numpy.zeros(len(self.y))
+        self.dy[self.dy==0]=1
+        
+        if self.qmin==None:
+            self.qmin= min(self.x)
+        
+        if self.qmax==None:
+            self.qmax= max(self.x)
+            
+        fx = numpy.zeros(len(self.x)) 
+        
+        output= None
+        res=[]
+        try: 
+            
+            for i_x in range(len(self.x)):
+               
+                # Check whether we need to bail out
+                self.isquit()   
+                fx[i_x]=self.model.run(i_x)
+                
+            if self.smearer!=None:
+                fx= self.smearer(fx)
+            for i_y in range(len(fx)):
+                # Check whether we need to bail out
+                self.isquit()   
+                temp=(self.y[i_y] - fx[i_y])/self.dy[i_y]
+                res.append(temp*temp)
+            #sum of residuals
+            sum=0
+            for item in res:
+                # Check whether we need to bail out
+                self.isquit()  
+                if numpy.isfinite(item):
+                    sum +=item
+            output = sum/ len(res)
+            elapsed = time.time()-self.starttime
+            self.complete(output= output,  elapsed=elapsed)
+            
+        except KeyboardInterrupt:
+            # Thread was interrupted, just proceed and re-raise.
+            # Real code should not print, but this is an example...
+            raise
+        except:
+            raise
+        
+class CalcChisqr2D(CalcThread):
+    """
+       Compute chisqr
+    """
+    
+    def __init__(self, x_bins, y_bins,data,err_data, model,
+                 qmin,
+                 qmax,
+                 completefn = None,
+                 updatefn   = None,
+                 yieldtime  = 0.01,
+                 worktime   = 0.01
+                 ):
+        CalcThread.__init__(self,completefn,
+                 updatefn,
+                 yieldtime,
+                 worktime)
+      
+        self.y_bins = y_bins
+        self.x_bins = x_bins
+        self.data= data
+        self.err_data= copy.deepcopy(err_data)
+        self.model = model
+        self.qmin = qmin
+        self.qmax = qmax
+      
+        self.starttime = 0  
+        
+    def isquit(self):
+        """
+             @raise KeyboardInterrupt: when the thread is interrupted
+        """
+        try:
+            CalcThread.isquit(self)
+        except KeyboardInterrupt:
+            raise KeyboardInterrupt   
+        
+        
+    def compute(self):
+        """
+            Compute the data given a model function
+        """
+        self.starttime = time.time()
+        if self.err_data==None or self.err_data==[]:
+            self.err_data= numpy.zeros(len(self.x_bins),len(self.y_bins))
+            
+        self.err_data[self.err_data==0]=1
+            
+        output= None
+        res=[]
+        try:
+          
+            for i in range(len(self.x_bins)):
+                # Check whether we need to bail out
+                self.isquit()   
+                for j in range(len(self.y_bins)):
+                    #Check the range containing data between self.qmin_x and self.qmax_x
+                    value =  math.pow(self.x_bins[i],2)+ math.pow(self.y_bins[j],2)
+                    if value >= math.pow(self.qmin,2) and value <= math.pow(self.qmax,2):
+                        
+                        temp = [self.x_bins[i],self.y_bins[j]]
+                        error= self.err_data[j][i]
+                        chisqrji = (self.data[j][i]- self.model.runXY(temp ))/error
+                        #Vector containing residuals
+                        res.append( math.pow(chisqrji,2) )
+ 
+            sum=0
+            for item in res:
+                # Check whether we need to bail out
+                self.isquit()  
+                if numpy.isfinite(item):
+                    sum +=item
+            output = sum/ len(res)
+            elapsed = time.time()-self.starttime
+            self.complete(output= output,  elapsed=elapsed)
+            
+        except KeyboardInterrupt:
+            # Thread was interrupted, just proceed and re-raise.
+            # Real code should not print, but this is an example...
+            raise
