Index: src/sas/perspectives/invariant/invariant_panel.py
===================================================================
--- src/sas/perspectives/invariant/invariant_panel.py	(revision d838715645ac898163603c42de5b97740d520c4b)
+++ src/sas/perspectives/invariant/invariant_panel.py	(revision 1128bd311afb104154567472e8421ba9258ce42d)
@@ -8,4 +8,5 @@
 import os
 import wx
+import logging
 from wx.lib.scrolledpanel import ScrolledPanel
 from sas.invariant import invariant
@@ -21,7 +22,7 @@
 from sas.guiframe.panel_base import PanelBase
 # The minimum q-value to be used when extrapolating
-Q_MINIMUM  = 1e-5
+Q_MINIMUM = 1e-5
 # The maximum q-value to be used when extrapolating
-Q_MAXIMUM  = 10
+Q_MAXIMUM = 10
 # the ratio of maximum q value/(qmax of data) to plot the theory data
 Q_MAXIMUM_PLOT = 3
@@ -36,5 +37,5 @@
 #default value of the power used for power law
 POWER = 4.0
-#Invariant panel size 
+#Invariant panel size
 _BOX_WIDTH = 76
 
@@ -42,5 +43,5 @@
 if sys.platform.count("win32") > 0:
     _STATICBOX_WIDTH = 450
-    PANEL_WIDTH = 500 
+    PANEL_WIDTH = 500
     PANEL_HEIGHT = 700
     FONT_VARIANT = 0
@@ -68,13 +69,13 @@
         PanelBase.__init__(self, parent)
         self.SetupScrolling()
-        #Font size 
+        #Font size
         self.SetWindowVariant(variant=FONT_VARIANT)
         #Object that receive status event
         self.parent = parent.parent
         #plug-in using this panel
-        self._manager = manager 
+        self._manager = manager
         #Data uses for computation
         self._data = data
-        self._scale = SCALE 
+        self._scale = SCALE
         self._background = BACKGROUND
         self._bmark = None
@@ -121,5 +122,5 @@
         self._reset_state_list()
         ## Default file location for save
-        self._default_save_location = os.getcwd()        
+        self._default_save_location = os.getcwd()
         if self.parent is not None:
             msg = ""
@@ -127,17 +128,17 @@
             self._default_save_location = \
                         self.parent.get_save_location()
-        
+
         self._set_bookmark_flag(False)
-    
+
     def get_data(self):
         """
         """
         return self._manager.get_data()
-    
+
     def get_state(self):
         """
         """
         return self.state
-    
+
     def set_data(self, data):
         """
@@ -150,6 +151,6 @@
             self.get_state_by_num(0)
             data_name = self._data.name
-            data_qmin = min (self._data.x)
-            data_qmax = max (self._data.x)
+            data_qmin = min(self._data.x)
+            data_qmax = max(self._data.x)
             self.data_name_tcl.SetValue(str(data_name))
             self.data_min_tcl.SetValue(str(data_qmin))
@@ -164,6 +165,6 @@
             self._reset_state_list()
             self._set_bookmark_flag(True)
-        return True  
-    
+        return True
+
     def _delete_bookmark_items(self):
         """
@@ -180,5 +181,5 @@
                 continue
             self.popUpMenu.DestroyItem(item)
-                
+
     def set_message(self):
         """
@@ -190,21 +191,21 @@
                 msg += "attention.\nPlease click on Details button."
                 self.hint_msg_txt.SetForegroundColour("red")
-    
+
                 wx.PostEvent(self.parent,
-                             StatusEvent(status=msg,info="warning"))
+                             StatusEvent(status=msg, info="warning"))
             else:
                 msg = "For more information, click on Details button."
                 self.hint_msg_txt.SetForegroundColour("black")
                 wx.PostEvent(self.parent,
-                             StatusEvent(status=msg,info="info"))
+                             StatusEvent(status=msg, info="info"))
             self.hint_msg_txt.SetLabel(msg)
         self.Layout()
-       
+
     def set_manager(self, manager):
         """
         set value for the manager
         """
-        self._manager = manager 
-        
+        self._manager = manager
+
     def save_project(self, doc=None):
         """
@@ -223,5 +224,5 @@
                 else:
                     doc = new_doc
-        return doc   
+        return doc
 
     def set_state(self, state=None, data=None):
@@ -229,8 +230,8 @@
         set state when loading it from a .inv/.svs file
         """
-        
+
         if state == None and data == None:
             self.state = IState()
-        elif state == None or data == None: 
+        elif state == None or data == None:
             return
         else:
@@ -240,13 +241,13 @@
                 return
 
-            self.state = new_state 
-            self.state.file = data.name   
+            self.state = new_state
+            self.state.file = data.name
 
             num = self.state.saved_state['state_num']
-            if num > 0 :
+            if num > 0:
                 self._set_undo_flag(True)
             if num < len(state.state_list) - 1:
                 self._set_redo_flag(True)
-                
+
             # get bookmarks
             self.bookmark_num = len(self.state.bookmark_list)
@@ -256,21 +257,22 @@
                 #bookmark_num = ind
                 value = self.state.bookmark_list[ind]
-                name = "%d] bookmarked at %s on %s"% (ind, value[0], value[1])
+                name = "%d] bookmarked at %s on %s" % (ind, value[0], value[1])
                 # append it to menu
                 id = wx.NewId()
                 self.popUpMenu.Append(id, name, str(''))
-                wx.EVT_MENU(self, id, self._back_to_bookmark) 
-                wx.PostEvent(self.parent, AppendBookmarkEvent(title=name, 
-                                          hint='', 
-                                          handler=self._back_to_bookmark))
+                wx.EVT_MENU(self, id, self._back_to_bookmark)
+                wx.PostEvent(self.parent,
+                             AppendBookmarkEvent(title=name,
+                                                 hint='',
+                                                 handler=self._back_to_bookmark))
 
             self.get_state_by_num(state_num=str(num))
-            
-            self._get_input_list() 
+
+            self._get_input_list()
             #make sure that the data is reset (especially
             # when loaded from a inv file)
             self.state.data = self._data
             self._set_preview_flag(False)
-            self.new_state = False 
+            self.new_state = False
             self.is_state_data = False
 
@@ -279,5 +281,5 @@
         Clear panel to defaults, used by set_state of manager
         """
-        
+
         self._data = None
         # default data testctrl
@@ -312,5 +314,5 @@
             msg = "Receive invalid value for background : %s" % (background)
             raise ValueError, msg
-    
+
     def get_scale(self):
         """
@@ -329,5 +331,5 @@
         else:
             raise ValueError, "Receive invalid value for scale : %s" % (scale)
-        
+
     def get_contrast(self):
         """
@@ -336,8 +338,8 @@
         par_str = self.contrast_tcl.GetValue().strip()
         contrast = None
-        if par_str !=" " and check_float(self.contrast_tcl):
+        if par_str != " " and check_float(self.contrast_tcl):
             contrast = float(par_str)
         return contrast
-    
+
     def get_extrapolation_type(self, low_q, high_q):
         """
@@ -352,5 +354,5 @@
             extrapolation = "both"
         return extrapolation
-            
+
     def get_porod_const(self):
         """
@@ -362,5 +364,5 @@
             porod_const = float(par_str)
         return porod_const
-    
+
     def get_volume(self, inv, contrast, extrapolation):
         """
@@ -369,6 +371,6 @@
         if contrast is not None:
             try:
-                v, dv = inv.get_volume_fraction_with_error(contrast=contrast, 
-                                                extrapolation=extrapolation)
+                v, dv = inv.get_volume_fraction_with_error(contrast=contrast,
+                                                           extrapolation=extrapolation)
                 self.volume_tcl.SetValue(format_number(v))
                 self.volume_err_tcl.SetValue(format_number(dv))
@@ -381,5 +383,5 @@
                                                       info="error",
                                                       type="stop"))
-               
+
     def get_surface(self, inv, contrast, porod_const, extrapolation):
         """
@@ -389,6 +391,6 @@
             try:
                 s, ds = inv.get_surface_with_error(contrast=contrast,
-                                        porod_const=porod_const,
-                                        extrapolation=extrapolation)
+                                                   porod_const=porod_const,
+                                                   extrapolation=extrapolation)
                 self.surface_tcl.SetValue(format_number(s))
                 self.surface_err_tcl.SetValue(format_number(ds))
@@ -399,6 +401,6 @@
                 msg += "specific surface: %s" % sys.exc_value
                 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error",
-                                                       type="stop"))
-                
+                                                      type="stop"))
+
     def get_total_qstar(self, inv, extrapolation):
         """
@@ -420,6 +422,6 @@
             msg = "Error occurred computing invariant using"
             msg += " extrapolation: %s" % sys.exc_value
-            wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))  
-            
+            wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop"))
+
     def get_low_qstar(self, inv, npts_low, low_q=False):
         """
@@ -427,14 +429,14 @@
         """
         if low_q:
-            try: 
+            try:
                 qstar_low, qstar_low_err = inv.get_qstar_low()
                 self.inv_container.qstar_low = qstar_low
                 self.inv_container.qstar_low_err = qstar_low_err
-                extrapolated_data = inv.get_extra_data_low(npts_in=npts_low) 
-                power_low = inv.get_extrapolation_power(range='low')  
+                extrapolated_data = inv.get_extra_data_low(npts_in=npts_low)
+                power_low = inv.get_extrapolation_power(range='low')
                 if self.power_law_low.GetValue():
                     self.power_low_tcl.SetValue(format_number(power_low))
                 self._manager.plot_theory(data=extrapolated_data,
-                                           name="Low-Q extrapolation")
+                                          name="Low-Q extrapolation")
             except:
                 self.inv_container.qstar_low = "ERROR"
@@ -449,7 +451,7 @@
             try:
                 self._manager.plot_theory(name="Low-Q extrapolation")
-            except: 
-                pass
-            
+            except:
+                logging.error(sys.exc_value)
+
     def get_high_qstar(self, inv, high_q=False):
         """
@@ -457,17 +459,17 @@
         """
         if high_q:
-            try: 
+            try:
                 qmax_plot = Q_MAXIMUM_PLOT * max(self._data.x)
-                if qmax_plot > Q_MAXIMUM: 
+                if qmax_plot > Q_MAXIMUM:
                     qmax_plot = Q_MAXIMUM
                 qstar_high, qstar_high_err = inv.get_qstar_high()
                 self.inv_container.qstar_high = qstar_high
                 self.inv_container.qstar_high_err = qstar_high_err
-                power_high = inv.get_extrapolation_power(range='high') 
+                power_high = inv.get_extrapolation_power(range='high')
                 self.power_high_tcl.SetValue(format_number(power_high))
                 high_out_data = inv.get_extra_data_high(q_end=qmax_plot,
                                                         npts=500)
                 self._manager.plot_theory(data=high_out_data,
-                                           name="High-Q extrapolation")
+                                          name="High-Q extrapolation")
             except:
                 #raise
@@ -483,6 +485,6 @@
             try:
                 self._manager.plot_theory(name="High-Q extrapolation")
-            except: 
-                pass
+            except:
+                logging.error(sys.exc_value)
 
     def get_qstar(self, inv):
@@ -493,5 +495,5 @@
         self.inv_container.qstar = qstar
         self.inv_container.qstar_err = qstar_err
-             
+
     def set_extrapolation_low(self, inv, low_q=False):
         """
@@ -513,14 +515,15 @@
                     power_low = float(power_low)
                 else:
-                    if low_q :
+                    if low_q:
                         #Raise error only when qstar at low q is requested
                         msg = "Expect float for power at low q, "
                         msg += " got %s" % (power_low)
-                        wx.PostEvent(self.parent, StatusEvent(status=msg, 
-                                                  info="error",
-                                                  type="stop"))
-       
+                        wx.PostEvent(self.parent,
+                                     StatusEvent(status=msg,
+                                                 info="error",
+                                                 type="stop"))
+
         #Get the number of points to extrapolated
-        npts_low = self.npts_low_tcl.GetValue().lstrip().rstrip()   
+        npts_low = self.npts_low_tcl.GetValue().lstrip().rstrip()
         if check_float(self.npts_low_tcl):
             npts_low = float(npts_low)
@@ -529,12 +532,13 @@
                 msg = "Expect float for number of points at low q,"
                 msg += " got %s" % (npts_low)
-                wx.PostEvent(self.parent, StatusEvent(status=msg, 
-                                                  info="error",
-                                                  type="stop"))
+                wx.PostEvent(self.parent,
+                             StatusEvent(status=msg,
+                                         info="error",
+                                         type="stop"))
         #Set the invariant calculator
         inv.set_extrapolation(range="low", npts=npts_low,
-                                   function=function_low, power=power_low)    
-        return inv, npts_low  
-    
+                              function=function_low, power=power_low)
+        return inv, npts_low
+
 
     def set_extrapolation_high(self, inv, high_q=False):
@@ -557,9 +561,10 @@
                     msg = "Expect float for power at high q,"
                     msg += " got %s" % (power_high)
-                    wx.PostEvent(self.parent, StatusEvent(status=msg, 
-                                                  info="error",
-                                                  type="stop"))
-                          
-        npts_high = self.npts_high_tcl.GetValue().lstrip().rstrip()   
+                    wx.PostEvent(self.parent,
+                                 StatusEvent(status=msg,
+                                             info="error",
+                                             type="stop"))
+
+        npts_high = self.npts_high_tcl.GetValue().lstrip().rstrip()
         if check_float(self.npts_high_tcl):
             npts_high = float(npts_high)
@@ -568,24 +573,24 @@
                 msg = "Expect float for number of points at high q,"
                 msg += " got %s" % (npts_high)
-                wx.PostEvent(self.parent, StatusEvent(status=msg, 
-                                                  info="error",
-                                                  type="stop"))
+                wx.PostEvent(self.parent, StatusEvent(status=msg,
+                                                      info="error",
+                                                      type="stop"))
         inv.set_extrapolation(range="high", npts=npts_high,
-                                   function=function_high, power=power_high)
+                              function=function_high, power=power_high)
         return inv, npts_high
-    
+
     def display_details(self, event):
         """
         open another panel for more details on invariant calculation
         """
-        panel = InvariantDetailsPanel(parent=self, 
-                                           qstar_container=self.inv_container)
+        panel = InvariantDetailsPanel(parent=self,
+                                      qstar_container=self.inv_container)
         panel.ShowModal()
         panel.Destroy()
         self.button_calculate.SetFocus()
-        
+
     def compute_invariant(self, event=None):
         """
-        compute invariant 
+        compute invariant
         """
         if self._data == None:
@@ -594,15 +599,15 @@
             wx.PostEvent(self.parent, StatusEvent(status=msg))
         # set a state for this computation for saving
-        elif event != None: 
+        elif event != None:
             self._set_compute_state(state='compute')
             self._set_bookmark_flag(True)
-            msg = "\n\nStarting a new invariant computation..."            
+            msg = "\n\nStarting a new invariant computation..."
             wx.PostEvent(self.parent, StatusEvent(status=msg))
-            
+
 
         if self._data is None:
             return
         self.button_details.Enable()
-        #clear outputs textctrl 
+        #clear outputs textctrl
         self._reset_output()
         try:
@@ -613,10 +618,10 @@
             wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop"))
             return
-        
+
         low_q = self.enable_low_cbox.GetValue()
-        high_q = self.enable_high_cbox.GetValue() 
+        high_q = self.enable_high_cbox.GetValue()
         temp_data = copy.deepcopy(self._data)
-        
-        #set invariant calculator 
+
+        #set invariant calculator
         inv = invariant.InvariantCalculator(data=temp_data,
                                             background=background,
@@ -628,20 +633,15 @@
             msg = "Error occurred computing invariant: %s" % sys.exc_value
             wx.PostEvent(self.parent, StatusEvent(status=msg,
-                                                 info="warning", type="stop"))
+                                                  info="warning", type="stop"))
             return
         #check the type of extrapolation
         extrapolation = self.get_extrapolation_type(low_q=low_q, high_q=high_q)
-       
+
         #Compute invariant
-        bkg_changed = False
-        scale_changed = False
         try:
             self.get_qstar(inv=inv)
-            #if scale_changed or bkg_changed:
-            #self._manager.plot_data(data=inv.get_data())
-            
         except:
-            msg= "Error occurred computing invariant: %s" % sys.exc_value
-            wx.PostEvent(self.parent, StatusEvent(status=msg, 
+            msg = "Error occurred computing invariant: %s" % sys.exc_value
+            wx.PostEvent(self.parent, StatusEvent(status=msg,
                                                   info="warning",
                                                   type="stop"))
@@ -651,20 +651,20 @@
         try:
             r_msg = 'Low Q: '
-            #Compute qstar extrapolated to low q range 
+            #Compute qstar extrapolated to low q range
             self.get_low_qstar(inv=inv, npts_low=npts_low, low_q=low_q)
             r_msg = 'High Q: '
-            #Compute qstar extrapolated to high q range 
+            #Compute qstar extrapolated to high q range
             self.get_high_qstar(inv=inv, high_q=high_q)
             r_msg = ''
-            #Compute qstar extrapolated to total q range 
+            #Compute qstar extrapolated to total q range
             #and set value to txtcrtl
             self.get_total_qstar(inv=inv, extrapolation=extrapolation)
             # Parse additional parameters
-            porod_const = self.get_porod_const()        
+            porod_const = self.get_porod_const()
             contrast = self.get_contrast()
         except:
             msg = r_msg + "Error occurred computing invariant: %s" % \
                                                             sys.exc_value
-            wx.PostEvent(self.parent, StatusEvent(status=msg, 
+            wx.PostEvent(self.parent, StatusEvent(status=msg,
                                                   info="error",
                                                   type="stop"))
@@ -681,7 +681,7 @@
         try:
             self.get_surface(inv=inv, contrast=contrast,
-                                    porod_const=porod_const, 
-                                    extrapolation=extrapolation)
-            
+                             porod_const=porod_const,
+                             extrapolation=extrapolation)
+
         except:
             msg = "Error occurred computing invariant: %s" % sys.exc_value
@@ -689,8 +689,8 @@
                                                   info="warning",
                                                   type="stop"))
-            
+
         #compute percentage of each invariant
         self.inv_container.compute_percentage()
-        
+
         #display a message
         self.set_message()
@@ -703,21 +703,21 @@
             self.state.set_report_string()
             self.is_power_out = False
-            wx.PostEvent(self.parent, StatusEvent(status = msg ))
+            wx.PostEvent(self.parent, StatusEvent(status=msg))
 
         #enable the button_ok for more details
         self._set_preview_flag(True)
-        
-        if event != None: 
+
+        if event != None:
             self._set_preview_flag(True)
             self._set_save_flag(True)
             wx.PostEvent(self.parent,
-                StatusEvent(status='\nFinished invariant computation...'))
+                         StatusEvent(status='\nFinished invariant computation...'))
         #self.Show(True)
         self.Refresh()
-            
+
     def on_undo(self, event=None):
         """
         Go back to the previous state
-        
+
         : param event: undo button event
         """
@@ -729,5 +729,5 @@
 
         self.get_state_by_num(state_num=str(pre_state_num))
-        
+
         if float(pre_state_num) <= 0:
             self._set_undo_flag(False)
@@ -735,12 +735,12 @@
             self._set_undo_flag(True)
         self._set_redo_flag(True)
-        self.is_power_out = False  
+        self.is_power_out = False
         self._info_state_num()
 
-        
+
     def on_redo(self, event=None):
         """
         Go forward to the previous state
-        
+
         : param event: redo button event
         """
@@ -750,18 +750,18 @@
 
         self.get_state_by_num(state_num=str(next_state_num))
-        
-        if float(next_state_num)+2 > len(self.state.state_list):
+
+        if float(next_state_num) + 2 > len(self.state.state_list):
             self._set_redo_flag(False)
         else:
             self._set_redo_flag(True)
-    
+
         self._set_undo_flag(True)
         self.is_power_out = False
         self._info_state_num()
-        
+
     def on_preview(self, event=None):
         """
         Invoke report dialog panel
-        
+
         : param event: report button event
         """
@@ -775,26 +775,25 @@
         dialog = ReportDialog(report_list, None, -1, "")
         dialog.Show()
-        
+
     def get_state_by_num(self, state_num=None):
         """
         Get the state given by number
-        
+
         : param state_num: the given state number
-        """     
+        """
         if state_num == None:
             return
 
         backup_state_list = copy.deepcopy(self.state.state_list)
-        
+
         # get the previous state
         try:
             current_state = copy.deepcopy(self.state.state_list[str(state_num)])
-            # get the previously computed state number 
+            # get the previously computed state number
             #(computation before the state changes happened)
             current_compute_num = str(current_state['compute_num'])
-        except :
+        except:
             raise
-            #raise ValueError,  "No such state exists in history"
-        
+
         # get the state at pre_compute_num
         comp_state = copy.deepcopy(self.state.state_list[current_compute_num])
@@ -808,8 +807,8 @@
                 exec "self.%s.SetValue(%s)" % (key, value)
             except:
-                pass
-        
+                logging.error(sys.exc_value)
+
         self.compute_invariant(event=None)
-       
+
         # set the input params at the state at pre_state_num
         for key in current_state:
@@ -821,5 +820,5 @@
                 exec 'self.%s.SetValue(%s)' % (key, value)
             except:
-                pass
+                logging.error(sys.exc_value)
 
         self._enable_high_q_section(event=None)
@@ -829,11 +828,11 @@
         self.state.state_num = state_num
 
-        
+
     def get_bookmark_by_num(self, num=None):
         """
         Get the bookmark state given by number
-        
+
         : param num: the given bookmark number
-        
+
         """
         current_state = {}
@@ -843,7 +842,8 @@
         # get the previous state
         try:
-            _, _, current_state,comp_state = self.state.bookmark_list[int(num)] 
-        except :
-            raise ValueError,  "No such bookmark exists"
+            _, _, current_state, comp_state = self.state.bookmark_list[int(num)]
+        except:
+            logging.error(sys.exc_value)
+            raise ValueError, "No such bookmark exists"
 
         # set the parameters
@@ -855,5 +855,5 @@
                 exec "self.%s.SetValue(%s)" % (key, value)
             except:
-                pass
+                logging.error(sys.exc_value)
 
         self.compute_invariant(event=None)
@@ -866,7 +866,7 @@
                 exec 'self.%s.SetValue(%s)' % (key, value)
             except:
-                pass
+                logging.error(sys.exc_value)
         self.state.saved_state = copy.deepcopy(current_state)
-       
+
         self._enable_high_q_section(event=None)
         self._enable_low_q_section(event=None)
@@ -880,7 +880,7 @@
         """
         self.background_tcl.SetValue(str(BACKGROUND))
-        self.scale_tcl.SetValue(str(SCALE)) 
+        self.scale_tcl.SetValue(str(SCALE))
         self.contrast_tcl.SetValue(str(CONTRAST))
-        self.porod_constant_tcl.SetValue('') 
+        self.porod_constant_tcl.SetValue('')
         self.npts_low_tcl.SetValue(str(NPTS))
         self.enable_low_cbox.SetValue(False)
@@ -906,9 +906,9 @@
         self.button_calculate.SetFocus()
         #self.SetupScrolling()
-        
+
     def _set_state(self, event):
         """
         Set the state list
-        
+
         :param event: rb/cb event
         """
@@ -923,42 +923,42 @@
 
         try:
-            if value == None or value.lstrip().rstrip() =='':
+            if value == None or value.lstrip().rstrip() == '':
                 value = 'None'
             exec 'self.state.%s = %s' % (name, value)
-            exec "self.state.saved_state['%s'] = %s" %  (name, value)
-            
-            # set the count part of radio button clicked 
+            exec "self.state.saved_state['%s'] = %s" % (name, value)
+
+            # set the count part of radio button clicked
             #False for the saved_state
             for title, content in rb_list:
-                if name ==  title:
-                    name = content 
-                    value = False     
+                if name == title:
+                    name = content
+                    value = False
                 elif name == content:
                     name = title
-                    value = False 
-            exec "self.state.saved_state['%s'] = %s" %  (name, value)     
-            
+                    value = False
+            exec "self.state.saved_state['%s'] = %s" % (name, value)
+
             # Instead of changing the future, create a new future.
-            max_state_num = len(self.state.state_list) - 1   
-            self.state.saved_state['state_num'] = max_state_num   
-            
+            max_state_num = len(self.state.state_list) - 1
+            self.state.saved_state['state_num'] = max_state_num
+
             self.state.saved_state['state_num'] += 1
             self.state.state_num = self.state.saved_state['state_num']
             self.state.state_list[str(self.state.state_num)] = \
                     self.state.clone_state()
-        except:           
-            pass
-        
+        except:
+            logging.error(sys.exc_value)
+
         self._set_undo_flag(True)
         self._set_redo_flag(False)
         #event.Skip()
-                   
+
     def _set_compute_state(self, state=None):
         """
         Notify the compute_invariant state to self.state
-        
+
         : param state: set 'compute' when the computation is
         activated by the 'compute' button, else None
-        
+
         """
         # reset the default
@@ -969,6 +969,6 @@
             self.is_power_out = True
         # Instead of changing the future, create a new future.
-        max_state_num = len(self.state.state_list) - 1   
-        self.state.saved_state['state_num'] = max_state_num        
+        max_state_num = len(self.state.state_list) - 1
+        self.state.saved_state['state_num'] = max_state_num
         # A new computation is also A state
         #copy.deepcopy(self.state.saved_state)
@@ -977,6 +977,6 @@
         self.state.state_num = temp_saved_states['state_num']
 
-                
-        # set the state number of the computation 
+
+        # set the state number of the computation
         if state == 'compute':
             temp_saved_states['compute_num'] = self.state.state_num
@@ -985,16 +985,16 @@
         self.state.state_list[str(self.state.state_num)] = \
                                         self.state.clone_state()
-        
+
         # A computation is a new state, so delete the states with any higher
         # state numbers
-        for i in range(self.state.state_num+1, len(self.state.state_list)):
+        for i in range(self.state.state_num + 1, len(self.state.state_list)):
             try:
-                del (self.state.state_list[str(i)])
-            except: 
-                pass
+                del self.state.state_list[str(i)]
+            except:
+                logging.error(sys.exc_value)
         # Enable the undo button if it was not
         self._set_undo_flag(True)
         self._set_redo_flag(False)
-        
+
     def _reset_state_list(self, data=None):
         """
@@ -1005,5 +1005,5 @@
         #temp_state = self.state.clone_state()
         #copy.deepcopy(self.state.saved_state)
-        # Clear the list 
+        # Clear the list
         self.state.state_list.clear()
         self.state.bookmark_list.clear()
@@ -1030,13 +1030,13 @@
         self._set_save_flag(False)
 
-        
+
     def _on_text(self, event):
         """
         Catch text change event to add the state to the state_list
-        
+
         :param event: txtctr event ; assumes not None
-        
-        """
-        if self._data == None: 
+
+        """
+        if self._data == None:
             return
         # check if this event is from do/undo button
@@ -1044,5 +1044,5 @@
             #event.Skip()
             return
-        
+
         # get the object
         obj = event.GetEventObject()
@@ -1053,20 +1053,20 @@
         # text event is a new state, so delete the states with higher state_num
         # i.e., change the future
-        for i in range(int(state_num)+1, len(self.state.state_list)):
+        for i in range(int(state_num) + 1, len(self.state.state_list)):
             try:
-                del (self.state.state_list[str(i)])
-            except: 
-                pass
-        
+                del self.state.state_list[str(i)]
+            except:
+                logging.error(sys.exc_value)
+
         # Instead of changing the future, create a new future.
-        #max_state_num = len(self.state.state_list)-1   
+        #max_state_num = len(self.state.state_list)-1
         #self.state.saved_state['state_num'] = max_state_num
 
         # try to add new state of the text changes in the state_list
         try:
-            if value.strip() == None: 
+            if value.strip() == None:
                 value = ''
             exec "self.state.%s = '%s'" % (name, value)
-            exec "self.state.saved_state['%s'] = '%s'" %  (name, value)
+            exec "self.state.saved_state['%s'] = '%s'" % (name, value)
             exec "self.state.input_list['%s'] = '%s'" % (name, value)
             if not self.is_power_out:
@@ -1078,5 +1078,5 @@
                                         self.state.clone_state()
         except:
-            pass
+            logging.error(sys.exc_value)
 
         #event.Skip()
@@ -1085,12 +1085,12 @@
         self._set_bookmark_flag(True)
         self._set_preview_flag(False)
-       
-    def _on_out_text(self, event):     
-        """
-        Catch ouput text change to add the state 
-        
+
+    def _on_out_text(self, event):
+        """
+        Catch ouput text change to add the state
+
         :param event: txtctr event ; assumes not None
-        
-        """    
+
+        """
         # get the object
         obj = event.GetEventObject()
@@ -1098,24 +1098,24 @@
         value = str(obj.GetValue())
         try:
-            exec "self.state.saved_state['%s'] = '%s'" %  (name, value)
+            exec "self.state.saved_state['%s'] = '%s'" % (name, value)
             self.state.state_list[str(self.state.state_num)] = \
                                 self.state.clone_state()
         except:
-            pass
+            logging.error(sys.exc_value)
         #if event != None: event.Skip()
 
-    def _get_input_list(self):     
+    def _get_input_list(self):
         """
         get input_list; called by set_state
-        """    
+        """
         # get state num of the last compute state
         compute_num = self.state.saved_state['compute_num']
         # find values and put into the input list
-        for key1, value1 in self.state.state_list[str(compute_num)].iteritems(): 
-            for key, _ in self.state.input_list.iteritems(): 
+        for key1, value1 in self.state.state_list[str(compute_num)].iteritems():
+            for key, _ in self.state.input_list.iteritems():
                 if key == key1:
                     self.state.input_list[key] = value1
                     break
-        
+
     def _set_bookmark_menu(self):
         """
@@ -1132,13 +1132,13 @@
         self.popUpMenu.AppendSeparator()
         self.Bind(wx.EVT_CONTEXT_MENU, self._on_context_menu)
-        
+
     def on_bookmark(self, event):
         """
         Save the panel state in memory and add the list on
         the popup menu on bookmark context menu event
-        """ 
-        if self._data == None: 
+        """
+        if self._data == None:
             return
-        if event == None: 
+        if event == None:
             return
         self.bookmark_num += 1
@@ -1148,10 +1148,10 @@
         compute_num = self.state.saved_state['compute_num']
         # name and message of the bookmark list
-        msg =  "State saved at %s on %s"% (my_time, date)
-         ## post help message for the selected model 
+        msg = "State saved at %s on %s" % (my_time, date)
+        ## post help message for the selected model
         msg += " Right click on the panel to retrieve this state"
         #wx.PostEvent(self.parent.parent, StatusEvent(status = msg ))
-        name = "%d] bookmarked at %s on %s"% (self.bookmark_num, my_time, date)
-        
+        name = "%d] bookmarked at %s on %s" % (self.bookmark_num, my_time, date)
+
         # append it to menu
         id = wx.NewId()
@@ -1161,12 +1161,12 @@
         comp_state = copy.deepcopy(self.state.state_list[str(compute_num)])
         self.state.bookmark_list[self.bookmark_num] = [my_time, date,
-                                                       state,comp_state]
+                                                       state, comp_state]
         self.state.toXML(self, doc=None, entry_node=None)
-        
+
         wx.PostEvent(self.parent, StatusEvent(status=msg, info="info"))
-        wx.PostEvent(self.parent, 
-                     AppendBookmarkEvent(title=name, 
+        wx.PostEvent(self.parent,
+                     AppendBookmarkEvent(title=name,
                                          hint=str(msg),
-                                          handler=self._back_to_bookmark))
+                                         handler=self._back_to_bookmark))
 
     def _back_to_bookmark(self, event):
@@ -1178,31 +1178,31 @@
         self._manager.on_perspective(event)
         menu = event.GetEventObject()
-        ## post help message for the selected model 
+        ## post help message for the selected model
         msg = menu.GetHelpString(event.GetId())
         msg += " reloaded"
-        wx.PostEvent(self.parent, StatusEvent(status = msg ))
-        
+        wx.PostEvent(self.parent, StatusEvent(status=msg))
+
         name = menu.GetLabel(event.GetId())
-        
-        num, time = name.split(']')
-        current_state_num = self.state.state_num  
+
+        num, _ = name.split(']')
+        current_state_num = self.state.state_num
         self.get_bookmark_by_num(num)
         state_num = int(current_state_num) + 1
-        
+
         self.state.saved_state['state_num'] = state_num
         #copy.deepcopy(self.state.saved_state)
         self.state.state_list[str(state_num)] = self.state.clone_state()
         self.state.state_num = state_num
-       
+
         self._set_undo_flag(True)
         self._info_bookmark_num(event)
-        
+
     def _info_bookmark_num(self, event=None):
         """
         print the bookmark number in info
-        
+
         : event: popUpMenu event
         """
-        if event == None: 
+        if event == None:
             return
         # get the object
@@ -1211,8 +1211,8 @@
         text = item.GetText()
         num = text.split(']')[0]
-        msg = "bookmark num = %s "% num
-        
-        wx.PostEvent(self.parent, StatusEvent(status = msg ))
-        
+        msg = "bookmark num = %s " % num
+
+        wx.PostEvent(self.parent, StatusEvent(status=msg))
+
     def _info_state_num(self):
         """
@@ -1221,20 +1221,20 @@
         msg = "state num = "
         msg += self.state.state_num
-        
-        wx.PostEvent(self.parent, StatusEvent(status = msg))
-                         
+
+        wx.PostEvent(self.parent, StatusEvent(status=msg))
+
     def _get_time_stamp(self):
         """
         return time and date stings
         """
-        # date and time 
+        # date and time
         year, month, day, hour, minute, second, _, _, _ = \
                                     time.localtime()
         my_time = str(hour) + ":" + str(minute) + ":" + str(second)
-        date = str( month) + "/" + str(day) + "/" + str(year)
+        date = str(month) + "/" + str(day) + "/" + str(year)
         return my_time, date
-   
-            
-    def on_save(self, evt=None): 
+
+
+    def on_save(self, evt=None):
         """
         Save invariant state into a file
@@ -1257,5 +1257,5 @@
         else:
             return None
-        
+
         dlg.Destroy()
         # MAC always needs the extension for saving
@@ -1264,5 +1264,5 @@
         fName = os.path.splitext(path)[0] + extens
         self._manager.save_file(filepath=fName, state=self.state)
-        
+
     def _show_message(self, mssg='', msg='Warning'):
         """
@@ -1271,5 +1271,5 @@
         # no message for now
         return True
-        
+
     def _reset_output(self):
         """
@@ -1285,5 +1285,5 @@
         self.inv_container = InvariantContainer()
 
-    
+
     def _on_context_menu(self, event):
         """
@@ -1292,12 +1292,12 @@
         pos = event.GetPosition()
         pos = self.ScreenToClient(pos)
-       
-        self.PopupMenu(self.popUpMenu, pos) 
-      
+
+        self.PopupMenu(self.popUpMenu, pos)
+
     def _define_structure(self):
         """
         Define main sizers needed for this panel
         """
-        ## Box sizers must be defined first before 
+        ## Box sizers must be defined first before
         #defining buttons/textctrls (MAC).
         self.main_sizer = wx.BoxSizer(wx.VERTICAL)
@@ -1309,11 +1309,11 @@
         data_name_box = wx.StaticBox(self, -1, "I(q) Data Source")
         self.data_name_boxsizer = wx.StaticBoxSizer(data_name_box, wx.VERTICAL)
-        self.data_name_boxsizer.SetMinSize((_STATICBOX_WIDTH,-1))
+        self.data_name_boxsizer.SetMinSize((_STATICBOX_WIDTH, -1))
         self.hint_msg_sizer = wx.BoxSizer(wx.HORIZONTAL)
         self.data_name_sizer = wx.BoxSizer(wx.HORIZONTAL)
-       
+
         self.data_range_sizer = wx.BoxSizer(wx.HORIZONTAL)
         #Sizer related to inputs
-        self.sizer_input =  wx.FlexGridSizer(2, 6, 0, 0)
+        self.sizer_input = wx.FlexGridSizer(2, 6, 0, 0)
         #Sizer related to inputs
         inputs_box = wx.StaticBox(self, -1, "Customized Inputs")
@@ -1323,5 +1323,5 @@
         extrapolation_box = wx.StaticBox(self, -1, "Extrapolation")
         self.extrapolation_sizer = wx.StaticBoxSizer(extrapolation_box,
-                                                        wx.VERTICAL)
+                                                     wx.VERTICAL)
         self.extrapolation_sizer.SetMinSize((_STATICBOX_WIDTH, -1))
         self.extrapolation_range_sizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -1330,5 +1330,5 @@
         low_q_box = wx.StaticBox(self, -1, "Low Q")
         self.low_extrapolation_sizer = wx.StaticBoxSizer(low_q_box, wx.VERTICAL)
-      
+
         self.low_q_sizer = wx.GridBagSizer(5, 5)
         #Sizer related to extrapolation at low q range
@@ -1346,13 +1346,13 @@
         #Sizer related to save button
         self.save_button_sizer = wx.BoxSizer(wx.HORIZONTAL)
-        
+
     def _layout_data_name(self):
         """
         Draw widgets related to data's name
         """
-        #Sizer hint 
+        #Sizer hint
         hint_msg = ""
-        
-        self.hint_msg_txt = wx.StaticText(self, -1, hint_msg)  
+
+        self.hint_msg_txt = wx.StaticText(self, -1, hint_msg)
         self.hint_msg_txt.SetForegroundColour("red")
         msg = "Highlight = mouse the mouse's cursor on the data until"
@@ -1361,20 +1361,20 @@
         self.hint_msg_sizer.Add(self.hint_msg_txt)
         #Data name [string]
-        data_name_txt = wx.StaticText(self, -1, 'Name:')  
-       
-        self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*4, 20),
-                                            style=0) 
+        data_name_txt = wx.StaticText(self, -1, 'Name:')
+
+        self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH * 4, 20),
+                                            style=0)
         self.data_name_tcl.SetToolTipString("Data's name.")
-        self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT|wx.RIGHT, 10),
-                                       (self.data_name_tcl, 0, wx.EXPAND)])
+        self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT | wx.RIGHT, 10),
+                                      (self.data_name_tcl, 0, wx.EXPAND)])
         #Data range [string]
-        data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ') 
-        data_min_txt = wx.StaticText(self, -1, 'Min : ')  
+        data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ')
+        data_min_txt = wx.StaticText(self, -1, 'Min : ')
         self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20),
                                            style=0, name='data_min_tcl')
         self.data_min_tcl.SetToolTipString("The minimum value of q range.")
-        data_max_txt = wx.StaticText(self, -1, 'Max : ') 
+        data_max_txt = wx.StaticText(self, -1, 'Max : ')
         self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20),
-                                           style=0, name='data_max_tcl') 
+                                           style=0, name='data_max_tcl')
         self.data_max_tcl.SetToolTipString("The maximum value of q range.")
         self.data_range_sizer.AddMany([(data_range_txt, 0, wx.RIGHT, 5),
@@ -1383,18 +1383,18 @@
                                        (data_max_txt, 0, wx.RIGHT, 5),
                                        (self.data_max_tcl, 0, wx.RIGHT, 10)])
-        self.data_name_boxsizer.AddMany([(self.hint_msg_sizer, 0 , wx.ALL, 5),
-                            (self.data_name_sizer, 0 , wx.ALL, 10),
-                                     (self.data_range_sizer, 0 , wx.ALL, 10)])
-    
+        self.data_name_boxsizer.AddMany([(self.hint_msg_sizer, 0, wx.ALL, 5),
+                                         (self.data_name_sizer, 0, wx.ALL, 10),
+                                         (self.data_range_sizer, 0, wx.ALL, 10)])
+
     def _enable_fit_power_law_low(self, event=None):
         """
         Enable and disable the power value editing
         """
-        if event != None: 
+        if event != None:
             self._set_bookmark_flag(True)
             self._set_preview_flag(False)
-    
+
         if self.fix_enable_low.IsEnabled():
-            
+
             if self.fix_enable_low.GetValue():
                 self.fit_enable_low.SetValue(False)
@@ -1404,13 +1404,13 @@
                 self.power_low_tcl.Disable()
         self._set_state(event=event)
-           
+
     def _enable_low_q_section(self, event=None):
         """
         Disable or enable some button if the user enable low q extrapolation
         """
-        if event != None: 
+        if event != None:
             self._set_bookmark_flag(True)
             self._set_preview_flag(False)
-            
+
         if self.enable_low_cbox.GetValue():
             self.npts_low_tcl.Enable()
@@ -1426,15 +1426,15 @@
             self.guinier.Disable()
             self.power_law_low.Disable()
-        
+
         self._enable_power_law_low()
         self._enable_fit_power_law_low()
         self._set_state(event=event)
         self.button_calculate.SetFocus()
-        
+
     def _enable_power_law_low(self, event=None):
         """
         Enable editing power law section at low q range
         """
-        if event != None: 
+        if event != None:
             self._set_bookmark_flag(True)
             self._set_preview_flag(False)
@@ -1451,5 +1451,5 @@
         self._enable_fit_power_law_low()
         self._set_state(event=event)
-            
+
     def _layout_extrapolation_low(self):
         """
@@ -1460,27 +1460,27 @@
                                            name='enable_low_cbox')
         wx.EVT_CHECKBOX(self, self.enable_low_cbox.GetId(),
-                                         self._enable_low_q_section)
+                        self._enable_low_q_section)
         self.fix_enable_low = wx.RadioButton(self, -1, 'Fix',
-                                         (10, 10), style=wx.RB_GROUP,
-                                         name='fix_enable_low')
+                                             (10, 10), style=wx.RB_GROUP,
+                                             name='fix_enable_low')
         self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low,
-                                     id=self.fix_enable_low.GetId())
+                  id=self.fix_enable_low.GetId())
         self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10),
                                              name='fit_enable_low')
-        self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, 
-                                        id=self.fit_enable_low.GetId())
+        self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low,
+                  id=self.fit_enable_low.GetId())
         self.guinier = wx.RadioButton(self, -1, 'Guinier',
-                                         (10, 10), style=wx.RB_GROUP,
-                                         name='guinier')
+                                      (10, 10), style=wx.RB_GROUP,
+                                      name='guinier')
         self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low,
-                                     id=self.guinier.GetId())        
+                  id=self.guinier.GetId())
         self.power_law_low = wx.RadioButton(self, -1, 'Power Law',
                                             (10, 10), name='power_law_low')
-        self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, 
-                                        id=self.power_law_low.GetId())
-        
+        self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low,
+                  id=self.power_law_low.GetId())
+
         npts_low_txt = wx.StaticText(self, -1, 'Npts')
         self.npts_low_tcl = InvTextCtrl(self, -1,
-                                        size=(_BOX_WIDTH*2/3, -1),
+                                        size=(_BOX_WIDTH * 2 / 3, -1),
                                         name='npts_low_tcl')
         wx.EVT_TEXT(self, self.npts_low_tcl.GetId(), self._on_text)
@@ -1489,8 +1489,8 @@
         self.npts_low_tcl.SetToolTipString(msg_hint)
         power_txt = wx.StaticText(self, -1, 'Power')
-        self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),
+        self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH * 2 / 3, -1),
                                          name='power_low_tcl')
         wx.EVT_TEXT(self, self.power_low_tcl.GetId(), self._on_text)
-       
+
         power_hint_txt = "Exponent to apply to the Power_law function."
         self.power_low_tcl.SetToolTipString(power_hint_txt)
@@ -1498,44 +1498,44 @@
         ix = 0
         self.low_q_sizer.Add(self.enable_low_cbox, (iy, ix), (1, 5),
-                            wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+                             wx.TOP | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
         iy += 1
         ix = 0
         self.low_q_sizer.Add(npts_low_txt, (iy, ix), (1, 1),
-                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
         ix += 1
-        self.low_q_sizer.Add(self.npts_low_tcl, (iy, ix), (1,1),
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        self.low_q_sizer.Add(self.npts_low_tcl, (iy, ix), (1, 1),
+                             wx.EXPAND | wx.ADJUST_MINSIZE, 0)
         iy += 1
         ix = 0
-        self.low_q_sizer.Add(self.guinier, (iy, ix), (1,2),
-                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        self.low_q_sizer.Add(self.guinier, (iy, ix), (1, 2),
+                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
         iy += 1
         ix = 0
         self.low_q_sizer.Add(self.power_law_low, (iy, ix), (1, 2),
-                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
         # Parameter controls for power law
         ix = 1
         iy += 1
         self.low_q_sizer.Add(self.fix_enable_low, (iy, ix), (1, 1),
-                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0)
         ix += 1
-        self.low_q_sizer.Add(self.fit_enable_low, (iy, ix),(1,1),
-                           wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        self.low_q_sizer.Add(self.fit_enable_low, (iy, ix), (1, 1),
+                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0)
         ix = 1
         iy += 1
         self.low_q_sizer.Add(power_txt, (iy, ix), (1, 1),
-                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0)
         ix += 1
         self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1, 1),
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+                             wx.EXPAND | wx.ADJUST_MINSIZE, 0)
         self.low_extrapolation_sizer.Add(self.low_q_sizer)
-        
+
     def _enable_fit_power_law_high(self, event=None):
         """
         Enable and disable the power value editing
         """
-        if event != None: 
+        if event != None:
             self._set_bookmark_flag(True)
-    
+
             self._set_preview_flag(False)
         if self.fix_enable_high.IsEnabled():
@@ -1547,10 +1547,10 @@
                 self.power_high_tcl.Disable()
         self._set_state(event=event)
-        
+
     def _enable_high_q_section(self, event=None):
         """
         Disable or enable some button if the user enable high q extrapolation
         """
-        if event != None: 
+        if event != None:
             self._set_bookmark_flag(True)
             self._set_preview_flag(False)
@@ -1570,5 +1570,5 @@
         self._set_state(event=event)
         self.button_calculate.SetFocus()
- 
+
     def _layout_extrapolation_high(self):
         """
@@ -1579,20 +1579,20 @@
                                             name='enable_high_cbox')
         wx.EVT_CHECKBOX(self, self.enable_high_cbox.GetId(),
-                                         self._enable_high_q_section)
+                        self._enable_high_q_section)
         self.fix_enable_high = wx.RadioButton(self, -1, 'Fix',
-                                         (10, 10), style=wx.RB_GROUP,
-                                         name='fix_enable_high')
+                                              (10, 10), style=wx.RB_GROUP,
+                                              name='fix_enable_high')
         self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high,
-                                     id=self.fix_enable_high.GetId())
+                  id=self.fix_enable_high.GetId())
         self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10),
-                                              name='fit_enable_high')     
-        self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, 
-                                        id=self.fit_enable_high.GetId())
-        
+                                              name='fit_enable_high')
+        self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high,
+                  id=self.fit_enable_high.GetId())
+
         self.power_law_high = wx.StaticText(self, -1, 'Power Law')
         msg_hint = "Check to extrapolate data at high-Q"
         self.power_law_high.SetToolTipString(msg_hint)
         npts_high_txt = wx.StaticText(self, -1, 'Npts')
-        self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),
+        self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH * 2 / 3, -1),
                                          name='npts_high_tcl')
         wx.EVT_TEXT(self, self.npts_high_tcl.GetId(), self._on_text)
@@ -1601,5 +1601,5 @@
         self.npts_high_tcl.SetToolTipString(msg_hint)
         power_txt = wx.StaticText(self, -1, 'Power')
-        self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),
+        self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH * 2 / 3, -1),
                                           name='power_high_tcl')
         wx.EVT_TEXT(self, self.power_high_tcl.GetId(), self._on_text)
@@ -1609,35 +1609,35 @@
         ix = 0
         self.high_q_sizer.Add(self.enable_high_cbox, (iy, ix), (1, 5),
-                            wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+                              wx.TOP | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
         iy += 1
         ix = 0
         self.high_q_sizer.Add(npts_high_txt, (iy, ix), (1, 1),
-                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
         ix += 1
         self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1, 1),
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+                              wx.EXPAND | wx.ADJUST_MINSIZE, 0)
         iy += 1
         ix = 0
-        self.high_q_sizer.Add(self.power_law_high, (iy, ix),(1, 2),
-                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-       
+        self.high_q_sizer.Add(self.power_law_high, (iy, ix), (1, 2),
+                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
+
         # Parameter controls for power law
         ix = 1
         iy += 1
-        self.high_q_sizer.Add(self.fix_enable_high,(iy, ix), (1, 1),
-                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        self.high_q_sizer.Add(self.fix_enable_high, (iy, ix), (1, 1),
+                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0)
         ix += 1
-        self.high_q_sizer.Add(self.fit_enable_high,(iy, ix), (1, 1),
-                           wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
+        self.high_q_sizer.Add(self.fit_enable_high, (iy, ix), (1, 1),
+                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0)
         ix = 1
         iy += 1
-        self.high_q_sizer.Add(power_txt,(iy, ix), (1, 1),
-                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+        self.high_q_sizer.Add(power_txt, (iy, ix), (1, 1),
+                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
         ix += 1
-        self.high_q_sizer.Add(self.power_high_tcl, (iy, ix),  (1, 1),
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        self.high_extrapolation_sizer.Add(self.high_q_sizer, 0, 
-                                                wx.BOTTOM, 20)
-        
+        self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1, 1),
+                              wx.EXPAND | wx.ADJUST_MINSIZE, 0)
+        self.high_extrapolation_sizer.Add(self.high_q_sizer, 0,
+                                          wx.BOTTOM, 20)
+
     def _layout_extrapolation(self):
         """
@@ -1647,39 +1647,38 @@
         extra_hint_txt = wx.StaticText(self, -1, extra_hint)
         #Extrapolation range [string]
-        extrapolation_min_txt = wx.StaticText(self, -1, 'Min:')  
-        self.extrapolation_min_tcl = OutputTextCtrl(self, -1, 
-                                                size=(_BOX_WIDTH, 20), style=0,
-                                                name='extrapolation_min_tcl')
+        extrapolation_min_txt = wx.StaticText(self, -1, 'Min:')
+        self.extrapolation_min_tcl = OutputTextCtrl(self, -1,
+                                                    size=(_BOX_WIDTH, 20), style=0,
+                                                    name='extrapolation_min_tcl')
         self.extrapolation_min_tcl.SetValue(str(Q_MINIMUM))
         hint_msg = "The minimum extrapolated q value."
         self.extrapolation_min_tcl.SetToolTipString(hint_msg)
-        extrapolation_max_txt = wx.StaticText(self, -1, 'Max:') 
+        extrapolation_max_txt = wx.StaticText(self, -1, 'Max:')
         self.extrapolation_max_tcl = OutputTextCtrl(self, -1,
-                                                  size=(_BOX_WIDTH, 20),
-                                                  style=0,
-                                                  name='extrapolation_max_tcl') 
+                                                    size=(_BOX_WIDTH, 20),
+                                                    style=0,
+                                                    name='extrapolation_max_tcl')
         self.extrapolation_max_tcl.SetValue(str(Q_MAXIMUM))
         hint_msg = "The maximum extrapolated q value."
         self.extrapolation_max_tcl.SetToolTipString(hint_msg)
-        self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0, 
+        self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0,
                                                  wx.LEFT, 5),
                                                 (extrapolation_min_txt, 0,
                                                  wx.LEFT, 10),
                                                 (self.extrapolation_min_tcl,
-                                                            0, wx.LEFT, 5),
+                                                 0, wx.LEFT, 5),
                                                 (extrapolation_max_txt, 0,
                                                  wx.LEFT, 20),
                                                 (self.extrapolation_max_tcl,
-                                                            0, wx.LEFT, 5)])
+                                                 0, wx.LEFT, 5)])
         self._layout_extrapolation_low()
         self._layout_extrapolation_high()
-        self.extrapolation_low_high_sizer.AddMany(\
-                                            [(self.low_extrapolation_sizer,
-                                            0, wx.LEFT|wx.BOTTOM|wx.TOP, 5),
-                                            (self.high_extrapolation_sizer,
-                                             0, wx.LEFT|wx.BOTTOM|wx.TOP, 5)])
+        self.extrapolation_low_high_sizer.AddMany([(self.low_extrapolation_sizer,
+                                                    0, wx.LEFT | wx.BOTTOM | wx.TOP, 5),
+                                                   (self.high_extrapolation_sizer,
+                                                    0, wx.LEFT | wx.BOTTOM | wx.TOP, 5)])
         self.extrapolation_sizer.AddMany([(self.extrapolation_range_sizer),
-                                        (self.extrapolation_low_high_sizer)])
-        
+                                          (self.extrapolation_low_high_sizer)])
+
     def _layout_volume_surface_sizer(self):
         """
@@ -1688,5 +1687,5 @@
         unit_volume = ''
         unit_surface = '[1/A]'
-        uncertainty = "+/-" 
+        uncertainty = "+/-"
         volume_txt = wx.StaticText(self, -1, 'Volume Fraction')
         self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1),
@@ -1700,5 +1699,5 @@
         self.volume_err_tcl.SetToolTipString(hint_msg)
         volume_units_txt = wx.StaticText(self, -1, unit_volume)
-        
+
         surface_txt = wx.StaticText(self, -1, 'Specific Surface')
         self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1),
@@ -1715,42 +1714,42 @@
         ix = 0
         self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1, 1),
-                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+                                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
         ix += 1
         self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1, 1),
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 20)
+                                      wx.EXPAND | wx.ADJUST_MINSIZE, 20)
         ix += 1
         self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty),
-                         (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
+                                      (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 10)
         ix += 1
         self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1, 1),
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
+                                      wx.EXPAND | wx.ADJUST_MINSIZE, 10)
         ix += 1
         self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1, 1),
-                             wx.EXPAND|wx.ADJUST_MINSIZE, 10)
+                                      wx.EXPAND | wx.ADJUST_MINSIZE, 10)
         iy += 1
         ix = 0
         self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1, 1),
-                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+                                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
         ix += 1
         self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1, 1),
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 20)
+                                      wx.EXPAND | wx.ADJUST_MINSIZE, 20)
         ix += 1
         self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty),
-                         (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
+                                      (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 10)
         ix += 1
         self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1, 1),
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
+                                      wx.EXPAND | wx.ADJUST_MINSIZE, 10)
         ix += 1
         self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1, 1),
-                            wx.EXPAND|wx.ADJUST_MINSIZE, 10)
+                                      wx.EXPAND | wx.ADJUST_MINSIZE, 10)
         static_line = wx.StaticLine(self, -1)
         iy += 1
         ix = 0
-        
+
     def _layout_invariant_sizer(self):
         """
         Draw widgets related to invariant
         """
-        uncertainty = "+/-" 
+        uncertainty = "+/-"
         unit_invariant = '[1/(cm*A^3)]'
         invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total [Q*]')
@@ -1762,33 +1761,33 @@
         self.invariant_total_err_tcl = OutputTextCtrl(self, -1,
                                                       size=(_BOX_WIDTH, -1),
-                                                name='invariant_total_err_tcl')
+                                                      name='invariant_total_err_tcl')
         hint_msg = "Uncertainty on invariant."
         self.invariant_total_err_tcl.SetToolTipString(hint_msg)
-        invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant, 
-                                                  size=(80,-1))
-    
+        invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant,
+                                                  size=(80, -1))
+
         #Invariant total
         iy = 0
         ix = 0
         self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1, 1),
-                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
+                                 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)
         ix += 1
         self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1, 1),
-                          wx.EXPAND|wx.ADJUST_MINSIZE, 10)
+                                 wx.EXPAND | wx.ADJUST_MINSIZE, 10)
         ix += 1
-        self.invariant_sizer.Add( wx.StaticText(self, -1, uncertainty),
-                         (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) 
+        self.invariant_sizer.Add(wx.StaticText(self, -1, uncertainty),
+                                 (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 10)
         ix += 1
         self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1, 1),
-                             wx.EXPAND|wx.ADJUST_MINSIZE, 10)
+                                 wx.EXPAND | wx.ADJUST_MINSIZE, 10)
         ix += 1
-        self.invariant_sizer.Add(invariant_total_units_txt,(iy, ix), (1, 1),
-                          wx.EXPAND|wx.ADJUST_MINSIZE, 10)
- 
+        self.invariant_sizer.Add(invariant_total_units_txt, (iy, ix), (1, 1),
+                                 wx.EXPAND | wx.ADJUST_MINSIZE, 10)
+
     def _layout_inputs_sizer(self):
         """
         Draw widgets related to inputs
         """
-        contrast_txt = wx.StaticText(self, -1, 'Contrast:')  
+        contrast_txt = wx.StaticText(self, -1, 'Contrast:')
         self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20),
                                         style=0, name='contrast_tcl')
@@ -1796,23 +1795,23 @@
         contrast_hint_txt = "Contrast"
         self.contrast_tcl.SetToolTipString(contrast_hint_txt)
-        contrast_unit_txt = wx.StaticText(self, -1, '[1/A^2]', size=(40,-1))  
-        porod_const_txt = wx.StaticText(self, -1, 
-                                        'Porod\nConstant:\n(optional)\n')  
-        porod_unit_txt = wx.StaticText(self, -1, '[1/(cm*A^4)]', size=(80,-1)) 
-        self.porod_constant_tcl = InvTextCtrl(self, -1, 
+        contrast_unit_txt = wx.StaticText(self, -1, '[1/A^2]', size=(40, -1))
+        porod_const_txt = wx.StaticText(self, -1,
+                                        'Porod\nConstant:\n(optional)\n')
+        porod_unit_txt = wx.StaticText(self, -1, '[1/(cm*A^4)]', size=(80, -1))
+        self.porod_constant_tcl = InvTextCtrl(self, -1,
                                               size=(_BOX_WIDTH, 20), style=0,
-                                              name='porod_constant_tcl') 
+                                              name='porod_constant_tcl')
         wx.EVT_TEXT(self, self.porod_constant_tcl.GetId(), self._on_text)
         porod_const_hint_txt = "Porod Constant"
         self.porod_constant_tcl.SetToolTipString(porod_const_hint_txt)
-        
-        background_txt = wx.StaticText(self, -1, 'Background:')  
+
+        background_txt = wx.StaticText(self, -1, 'Background:')
         self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20),
-                                          style=0, name='background_tcl') 
+                                          style=0, name='background_tcl')
         wx.EVT_TEXT(self, self.background_tcl.GetId(), self._on_text)
         background_hint_txt = "Background"
         self.background_tcl.SetToolTipString(background_hint_txt)
-        background_unit_txt = wx.StaticText(self, -1, '[1/cm]')  
-        scale_txt = wx.StaticText(self, -1, 'Scale:')  
+        background_unit_txt = wx.StaticText(self, -1, '[1/cm]')
+        scale_txt = wx.StaticText(self, -1, 'Scale:')
         self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0,
                                      name='scale_tcl')
@@ -1820,18 +1819,18 @@
         scale_hint_txt = "Scale"
         self.scale_tcl.SetToolTipString(scale_hint_txt)
-        self.sizer_input.AddMany([(background_txt, 0, wx.LEFT|wx.BOTTOM, 5),
-                            (self.background_tcl, 0, wx.LEFT|wx.BOTTOM, 5),
-                            (background_unit_txt, 0, wx.LEFT|wx.BOTTOM, 5),
-                            (scale_txt, 0, wx.LEFT|wx.BOTTOM, 10),
-                            (self.scale_tcl, 0, wx.LEFT|wx.BOTTOM|wx.RIGHT, 5),
-                            (10, 10),
-                            (contrast_txt, 0, wx.LEFT|wx.BOTTOM, 5),
-                            (self.contrast_tcl, 0, wx.LEFT|wx.BOTTOM, 5),
-                            (contrast_unit_txt, 0, wx.LEFT|wx.BOTTOM, 5),
-                            (porod_const_txt, 0, wx.LEFT, 10),
-                (self.porod_constant_tcl, 0, wx.LEFT|wx.BOTTOM|wx.RIGHT, 5),
-                (porod_unit_txt, 0, wx.LEFT|wx.BOTTOM, 5)])
+        self.sizer_input.AddMany([(background_txt, 0, wx.LEFT | wx.BOTTOM, 5),
+                                  (self.background_tcl, 0, wx.LEFT | wx.BOTTOM, 5),
+                                  (background_unit_txt, 0, wx.LEFT | wx.BOTTOM, 5),
+                                  (scale_txt, 0, wx.LEFT | wx.BOTTOM, 10),
+                                  (self.scale_tcl, 0, wx.LEFT | wx.BOTTOM | wx.RIGHT, 5),
+                                  (10, 10),
+                                  (contrast_txt, 0, wx.LEFT | wx.BOTTOM, 5),
+                                  (self.contrast_tcl, 0, wx.LEFT | wx.BOTTOM, 5),
+                                  (contrast_unit_txt, 0, wx.LEFT | wx.BOTTOM, 5),
+                                  (porod_const_txt, 0, wx.LEFT, 10),
+                                  (self.porod_constant_tcl, 0, wx.LEFT | wx.BOTTOM | wx.RIGHT, 5),
+                                  (porod_unit_txt, 0, wx.LEFT | wx.BOTTOM, 5)])
         self.inputs_sizer.Add(self.sizer_input)
-       
+
     def _layout_outputs_sizer(self):
         """
@@ -1842,11 +1841,11 @@
         static_line = wx.StaticLine(self, -1)
         self.outputs_sizer.AddMany([(self.volume_surface_sizer,
-                                      0, wx.TOP|wx.BOTTOM, 10),
+                                     0, wx.TOP | wx.BOTTOM, 10),
                                     (static_line, 0, wx.EXPAND, 0),
-                         (self.invariant_sizer, 0, wx.TOP|wx.BOTTOM, 10)])
-    def _layout_button(self):  
+                                    (self.invariant_sizer, 0, wx.TOP | wx.BOTTOM, 10)])
+    def _layout_button(self):
         """
         Do the layout for the button widgets
-        """ 
+        """
         #compute button
         id = wx.NewId()
@@ -1854,5 +1853,5 @@
                                           name='compute_invariant')
         self.button_calculate.SetToolTipString("Compute invariant")
-        self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id)   
+        self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id)
         #detail button
         id = wx.NewId()
@@ -1863,9 +1862,9 @@
         details = "Details on Invariant Total Calculations"
         details_txt = wx.StaticText(self, -1, details)
-        self.button_sizer.AddMany([(details_txt, 0 , 
-                                    wx.RIGHT|wx.BOTTOM|wx.TOP, 10),
-                                   (self.button_details, 0 , wx.ALL, 10),
-                        (self.button_calculate, 0 ,
-                         wx.RIGHT|wx.TOP|wx.BOTTOM, 10)])
+        self.button_sizer.AddMany([(details_txt, 0,
+                                    wx.RIGHT | wx.BOTTOM | wx.TOP, 10),
+                                   (self.button_details, 0, wx.ALL, 10),
+                                   (self.button_calculate, 0,
+                                    wx.RIGHT | wx.TOP | wx.BOTTOM, 10)])
     def _do_layout(self):
         """
@@ -1879,15 +1878,15 @@
         self._layout_button()
         self.main_sizer.AddMany([(self.data_name_boxsizer, 0, wx.ALL, 10),
-                                  (self.outputs_sizer, 0,
-                                  wx.LEFT|wx.RIGHT|wx.BOTTOM, 10),
-                                  (self.button_sizer, 0, wx.LEFT|wx.RIGHT, 15),
+                                 (self.outputs_sizer, 0,
+                                  wx.LEFT | wx.RIGHT | wx.BOTTOM, 10),
+                                 (self.button_sizer, 0, wx.LEFT | wx.RIGHT, 15),
                                  (self.inputs_sizer, 0,
-                                  wx.LEFT|wx.RIGHT|wx.BOTTOM, 10),
-                                  (self.extrapolation_sizer, 0,
-                                  wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)])
+                                  wx.LEFT | wx.RIGHT | wx.BOTTOM, 10),
+                                 (self.extrapolation_sizer, 0,
+                                  wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)])
         self.SetSizer(self.main_sizer)
         self.SetAutoLayout(True)
-        
-        
+
+
 class InvariantDialog(wx.Dialog):
     """
@@ -1897,21 +1896,20 @@
                  data=None, title="Invariant", base=None):
         wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH,
-                                                             PANEL_HEIGHT))
+                                                          PANEL_HEIGHT))
         self.panel = InvariantPanel(self)
         self.Centre()
         self.Show(True)
-        
+
 class InvariantWindow(wx.Frame):
     """
     Invariant Window
     """
-    def __init__(self, parent=None, id=1, graph=None, 
+    def __init__(self, parent=None, id=1, graph=None,
                  data=None, title="Invariant", base=None):
-        
-        wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH +100,
-                                                             PANEL_HEIGHT+100))
+
+        wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH + 100,
+                                                         PANEL_HEIGHT + 100))
         from sas.dataloader.loader import  Loader
         self.loader = Loader()
-        import invariant
         path = "C:/ECLPS/workspace/trunk/sasdataloader/test/ascii_test_3.txt"
         data = self.loader.load(path)
@@ -1922,5 +1920,5 @@
         self.Centre()
         self.Show(True)
-        
+
 class MyApp(wx.App):
     """
@@ -1935,7 +1933,7 @@
         frame.Show(True)
         self.SetTopWindow(frame)
-        
+
         return True
-      
+
 # end of class MyApp
 
