Index: src/sas/sasgui/perspectives/fitting/basepage.py
===================================================================
--- src/sas/sasgui/perspectives/fitting/basepage.py	(revision 81b35396fd691da758d9f5f478ee2725d48d171b)
+++ src/sas/sasgui/perspectives/fitting/basepage.py	(revision ba8d326f0f4ceb55c77296a9b5af8bd013c7dd92)
@@ -285,5 +285,5 @@
         """
         x = np.linspace(start=self.qmin_x, stop=self.qmax_x,
-                           num=self.npts_x, endpoint=True)
+                        num=self.npts_x, endpoint=True)
         self.data = Data1D(x=x)
         self.data.xaxis('\\rm{Q}', "A^{-1}")
@@ -311,5 +311,5 @@
 
         x = np.logspace(start=qmin, stop=qmax,
-                           num=self.npts_x, endpoint=True, base=10.0)
+                        num=self.npts_x, endpoint=True, base=10.0)
         self.data = Data1D(x=x)
         self.data.xaxis('\\rm{Q}', "A^{-1}")
@@ -904,5 +904,5 @@
         if len(self._disp_obj_dict) > 0:
             for k, v in self._disp_obj_dict.iteritems():
-                self.state._disp_obj_dict[k] = v.type
+                self.state.disp_obj_dict[k] = v.type
 
             self.state.values = copy.deepcopy(self.values)
@@ -922,5 +922,5 @@
                                     self.state.str_parameters)
         self._copy_parameters_state(self.orientation_params,
-                                     self.state.orientation_params)
+                                    self.state.orientation_params)
         self._copy_parameters_state(self.orientation_params_disp,
                                     self.state.orientation_params_disp)
@@ -976,9 +976,9 @@
                         try:
                             self.state.disp_cb_dict[k] = v.GetValue()
-                        except:
+                        except Exception:
                             self.state.disp_cb_dict[k] = None
             if len(self._disp_obj_dict) > 0:
                 for k, v in self._disp_obj_dict.iteritems():
-                    self.state._disp_obj_dict[k] = v.type
+                    self.state.disp_obj_dict[k] = v.type
 
             self.state.values = copy.deepcopy(self.values)
@@ -1022,5 +1022,5 @@
             # to support older version
             category_pos = int(state.categorycombobox)
-        except:
+        except Exception:
             category_pos = 0
             for ind_cat in range(self.categorybox.GetCount()):
@@ -1034,5 +1034,5 @@
             # to support older version
             formfactor_pos = int(state.formfactorcombobox)
-        except:
+        except Exception:
             formfactor_pos = 0
             for ind_form in range(self.formfactorbox.GetCount()):
@@ -1047,5 +1047,5 @@
             # to support older version
             structfactor_pos = int(state.structurecombobox)
-        except:
+        except Exception:
             structfactor_pos = 0
             for ind_struct in range(self.structurebox.GetCount()):
@@ -1284,5 +1284,5 @@
             self.dI_sqrdata.SetValue(state.dI_sqrdata)
             self.dI_idata.SetValue(state.dI_idata)
-        except:
+        except Exception:
             # to support older state file formats
             self.dI_noweight.SetValue(False)
@@ -1340,5 +1340,5 @@
         self.weights = copy.deepcopy(state.weights)
 
-        for key, disp_type in state._disp_obj_dict.iteritems():
+        for key, disp_type in state.disp_obj_dict.iteritems():
             # disp_model = disp
             disp_model = POLYDISPERSITY_MODELS[disp_type]()
@@ -1574,5 +1574,5 @@
                         try:
                             self.npts_x = float(self.Npts_total.GetValue())
-                        except:
+                        except Exception:
                             flag = False
                             return flag
@@ -1615,8 +1615,7 @@
             return
 
-        for j in range(len(listtorestore)):
+        for item_page in listtorestore:
             for param in statelist:
-                if param[1] == listtorestore[j][1]:
-                    item_page = listtorestore[j]
+                if param[1] == item_page[1]:
                     item_page_info = param
                     if (item_page_info[1] == "theta" or item_page_info[1] ==
@@ -1664,9 +1663,6 @@
         listtorestore = copy.deepcopy(statelist)
 
-        for j in range(len(listtorestore)):
-            item_page = listtorestore[j]
-            item_page_info = statelist[j]
+        for item_page, item_page_info in zip(listtorestore, statelist):
             # change the state of the check box for simple parameters
-
             if item_page[0] is not None:
                 item_page[0].SetValue(format_number(item_page_info[0], True))
@@ -1921,5 +1917,5 @@
                     wx.PostEvent(self.parent, StatusEvent(status=msg))
                     return
-            except:
+            except Exception:
                 tcrtl.SetBackgroundColour("pink")
                 msg = "Model Error: wrong value entered: %s" % sys.exc_info()[1]
@@ -1978,5 +1974,5 @@
                     wx.PostEvent(self._manager.parent, StatusEvent(status=msg))
                     return
-            except:
+            except Exception:
                 tcrtl.SetBackgroundColour("pink")
                 msg = "Model Error: wrong value entered: %s" % sys.exc_info()[1]
@@ -2156,5 +2152,5 @@
             # q value from qx and qy
             radius = np.sqrt(data.qx_data * data.qx_data +
-                                data.qy_data * data.qy_data)
+                             data.qy_data * data.qy_data)
             # get unmasked index
             index_data = (float(self.qmin.GetValue()) <= radius) & \
@@ -2385,5 +2381,5 @@
         put gaussian dispersity into current model
         """
-        if len(self.param_toFit) > 0:
+        if self.param_toFit:
             for item in self.fittable_param:
                 if item in self.param_toFit:
@@ -2402,10 +2398,7 @@
         # from sas.models.dispersion_models import GaussianDispersion
         from sasmodels.weights import GaussianDispersion
-        if len(self.disp_cb_dict) == 0:
-            self.save_current_state()
+        if not self.disp_cb_dict:
             self.sizer4_4.Clear(True)
-            self.Layout()
-            return
-        if (len(self.disp_cb_dict) > 0):
+        else:
             for p in self.disp_cb_dict:
                 # The parameter was un-selected.
@@ -2480,5 +2473,5 @@
                 self._disp_obj_dict[name1] = disp_model
                 self.model.set_dispersion(param_name, disp_model)
-                self.state._disp_obj_dict[name1] = disp_model.type
+                self.state.disp_obj_dict[name1] = disp_model.type
 
                 value1 = str(format_number(self.model.getParam(name1), True))
@@ -2595,5 +2588,5 @@
         self._disp_obj_dict[name] = disp
         self.model.set_dispersion(name.split('.')[0], disp)
-        self.state._disp_obj_dict[name] = disp.type
+        self.state.disp_obj_dict[name] = disp.type
         self.values[name] = values
         self.weights[name] = weights
@@ -2953,20 +2946,20 @@
             # go through the parameters
             strings = self._get_copy_helper(self.parameters,
-                                           self.orientation_params)
+                                            self.orientation_params)
             content += strings
 
             # go through the fittables
             strings = self._get_copy_helper(self.fittable_param,
-                                           self.orientation_params_disp)
+                                            self.orientation_params_disp)
             content += strings
 
             # go through the fixed params
             strings = self._get_copy_helper(self.fixed_param,
-                                           self.orientation_params_disp)
+                                            self.orientation_params_disp)
             content += strings
 
             # go through the str params
             strings = self._get_copy_helper(self.str_parameters,
-                                           self.orientation_params)
+                                            self.orientation_params)
             content += strings
             return content
@@ -3027,6 +3020,6 @@
         Get the string copies of the param names and values in the tap
         """
-        content = '\\begin{table}'
-        content += '\\begin{tabular}[h]'
+        content = r'\begin{table}'
+        content += r'\begin{tabular}[h]'
 
         crlf = chr(13) + chr(10)
@@ -3039,14 +3032,14 @@
             for param in self.parameters:
                 content += 'l|l|'
-            content += '}\hline'
+            content += r'}\hline'
             content += crlf
 
             for index, param in enumerate(self.parameters):
-                content += param[1].replace('_', '\_')  # parameter name
+                content += param[1].replace('_', r'\_')  # parameter name
                 content += ' & '
-                content += param[1].replace('_', '\_') + "\_err"
+                content += param[1].replace('_', r'\_') + r'\_err'
                 if index < len(self.parameters) - 1:
                     content += ' & '
-            content += '\\\\ \\hline'
+            content += r'\\ \hline'
             content += crlf
 
@@ -3058,9 +3051,9 @@
                 if index < len(self.parameters) - 1:
                     content += ' & '
-            content += '\\\\ \\hline'
+            content += r'\\ \hline'
             content += crlf
 
-            content += '\\end{tabular}'
-            content += '\\end{table}'
+            content += r'\end{tabular}'
+            content += r'\end{table}'
             return content
         else:
@@ -3320,5 +3313,5 @@
                                 if name.endswith('.npts'):
                                     pd = int(pd)
-                            except:
+                            except Exception:
                                 # continue
                                 if not pd and pd != '':
@@ -3406,5 +3399,5 @@
                 self._disp_obj_dict[name] = disp_model
                 self.model.set_dispersion(param_name, disp_model)
-                self.state._disp_obj_dict[name] = disp_model.type
+                self.state.disp_obj_dict[name] = disp_model.type
                 # TODO: It's not an array, why update values and weights?
                 self.model._persistency_dict[param_name] = \
@@ -3512,7 +3505,7 @@
 
         else:
-            for (model, enabled) in sorted(self.master_category_dict[category],
-                                           key=lambda name: name[0]):
-                if(enabled):
+            for model, enabled in sorted(self.master_category_dict[category],
+                                         key=lambda name: name[0]):
+                if enabled:
                     self.model_box.Append(model)
 
@@ -3755,10 +3748,10 @@
         self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
         self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus
-        if kill_focus_callback is None else kill_focus_callback)
+                  if kill_focus_callback is None else kill_focus_callback)
         self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter
-        if text_enter_callback is None else text_enter_callback)
+                  if text_enter_callback is None else text_enter_callback)
         if not ON_MAC:
             self.Bind(wx.EVT_LEFT_UP, self._highlight_text
-            if mouse_up_callback is None else mouse_up_callback)
+                      if mouse_up_callback is None else mouse_up_callback)
 
     def _on_set_focus(self, event):
Index: src/sas/sasgui/perspectives/fitting/fit_thread.py
===================================================================
--- src/sas/sasgui/perspectives/fitting/fit_thread.py	(revision 959eb0181ad06828a748f04512f953aad5b31659)
+++ src/sas/sasgui/perspectives/fitting/fit_thread.py	(revision ba8d326f0f4ceb55c77296a9b5af8bd013c7dd92)
@@ -29,9 +29,5 @@
                  worktime=0.03,
                  reset_flag=False):
-        CalcThread.__init__(self,
-                 completefn,
-                 updatefn,
-                 yieldtime,
-                 worktime)
+        CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime)
         self.handler = handler
         self.fitter = fn
@@ -93,5 +89,5 @@
             # Real code should not print, but this is an example...
             #print "keyboard exception"
-            #Stop on exception during fitting. Todo: need to put 
+            #Stop on exception during fitting. Todo: need to put
             #some mssg and reset progress bar.
 
@@ -100,5 +96,5 @@
             if self.handler is not None:
                 self.handler.stop(msg=msg)
-        except:
+        except:  # catch-all: show every exception which stops the thread
             import traceback
             if self.handler is not None:
Index: src/sas/sasgui/perspectives/fitting/model_thread.py
===================================================================
--- src/sas/sasgui/perspectives/fitting/model_thread.py	(revision 7432acb919f4013119ca918a73350297e0d4c93f)
+++ src/sas/sasgui/perspectives/fitting/model_thread.py	(revision ba8d326f0f4ceb55c77296a9b5af8bd013c7dd92)
@@ -1,4 +1,4 @@
 """
-    Calculation thread for modeling
+Calculation thread for modeling
 """
 
@@ -28,5 +28,5 @@
                  worktime=0.04,
                  exception_handler=None,
-                 ):
+                ):
         CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime,
                             exception_handler=exception_handler)
@@ -57,9 +57,7 @@
         if self.qmax is None:
             if self.data is not None:
-                newx = math.pow(max(math.fabs(self.data.xmax),
-                                   math.fabs(self.data.xmin)), 2)
-                newy = math.pow(max(math.fabs(self.data.ymax),
-                                   math.fabs(self.data.ymin)), 2)
-                self.qmax = math.sqrt(newx + newy)
+                newx = max(math.fabs(self.data.xmax), math.fabs(self.data.xmin))
+                newy = max(math.fabs(self.data.ymax), math.fabs(self.data.ymin))
+                self.qmax = math.sqrt(newx**2 + newy**2)
 
         if self.data is None:
@@ -68,12 +66,11 @@
 
         # Define matrix where data will be plotted
-        radius = np.sqrt((self.data.qx_data * self.data.qx_data) + \
-                    (self.data.qy_data * self.data.qy_data))
-
-        # For theory, qmax is based on 1d qmax 
+        radius = np.sqrt(self.data.qx_data**2 + self.data.qy_data**2)
+
+        # For theory, qmax is based on 1d qmax
         # so that must be mulitified by sqrt(2) to get actual max for 2d
         index_model = (self.qmin <= radius) & (radius <= self.qmax)
-        index_model = index_model & self.data.mask
-        index_model = index_model & np.isfinite(self.data.data)
+        index_model &= self.data.mask
+        index_model &= np.isfinite(self.data.data)
 
         if self.smearer is not None:
@@ -100,18 +97,18 @@
         elapsed = time.time() - self.starttime
         self.complete(image=output,
-                       data=self.data,
-                       page_id=self.page_id,
-                       model=self.model,
-                       state=self.state,
-                       toggle_mode_on=self.toggle_mode_on,
-                       elapsed=elapsed,
-                       index=index_model,
-                       fid=self.fid,
-                       qmin=self.qmin,
-                       qmax=self.qmax,
-                       weight=self.weight,
-                       #qstep=self.qstep,
-                       update_chisqr=self.update_chisqr,
-                       source=self.source)
+                      data=self.data,
+                      page_id=self.page_id,
+                      model=self.model,
+                      state=self.state,
+                      toggle_mode_on=self.toggle_mode_on,
+                      elapsed=elapsed,
+                      index=index_model,
+                      fid=self.fid,
+                      qmin=self.qmin,
+                      qmax=self.qmax,
+                      weight=self.weight,
+                      #qstep=self.qstep,
+                      update_chisqr=self.update_chisqr,
+                      source=self.source)
 
 
@@ -137,5 +134,5 @@
                  worktime=0.01,
                  exception_handler=None,
-                 ):
+                ):
         """
         """
@@ -192,7 +189,7 @@
                                                         * unsmeared_output[first_bin:last_bin+1]\
                                                         / output[first_bin:last_bin+1]
-                unsmeared_output=unsmeared_output[index]
-                unsmeared_data=unsmeared_data[index]
-                unsmeared_error=unsmeared_error
+                unsmeared_output = unsmeared_output[index]
+                unsmeared_data = unsmeared_data[index]
+                unsmeared_error = unsmeared_error
         else:
             output[index] = self.model.evalDistribution(self.data.x[index])
Index: src/sas/sasgui/perspectives/fitting/models.py
===================================================================
--- src/sas/sasgui/perspectives/fitting/models.py	(revision 56a282cafe4912b6aaa6e88b2b92225eb5a897fa)
+++ src/sas/sasgui/perspectives/fitting/models.py	(revision ba8d326f0f4ceb55c77296a9b5af8bd013c7dd92)
@@ -68,5 +68,5 @@
     try:
         new_instance = model()
-    except:
+    except Exception:
         msg = "Plugin %s error in __init__ \n\t: %s %s\n" % (str(name),
                                                              str(sys.exc_type),
@@ -78,5 +78,5 @@
         try:
             value = new_instance.function()
-        except:
+        except Exception:
             msg = "Plugin %s: error writing function \n\t :%s %s\n " % \
                     (str(name), str(sys.exc_type), sys.exc_info()[1])
@@ -102,4 +102,5 @@
 
     # Find paths needed
+    # TODO: remove unneeded try/except block
     try:
         # For source
@@ -108,5 +109,5 @@
         else:
             raise
-    except:
+    except Exception:
         # Check for data path next to exe/zip file.
         #Look for maximum n_dir up of the current dir to find plugins dir
@@ -158,5 +159,5 @@
         compileall.compile_dir(dir=dir, ddir=dir, force=0,
                                quiet=report_problem)
-    except:
+    except Exception:
         return sys.exc_info()[1]
     return None
@@ -177,5 +178,5 @@
     plugin_log("looking for models in: %s" % str(directory))
     # compile_file(directory)  #always recompile the folder plugin
-    logger.info("plugin model dir: %s" % str(directory))
+    logger.info("plugin model dir: %s", str(directory))
 
     plugins = {}
@@ -192,6 +193,6 @@
                 msg += "\nwhile accessing model in %r" % path
                 plugin_log(msg)
-                logger.warning("Failed to load plugin %r. See %s for details"
-                               % (path, PLUGIN_LOG))
+                logger.warning("Failed to load plugin %r. See %s for details",
+                               path, PLUGIN_LOG)
 
     return plugins
@@ -230,5 +231,5 @@
 
 
-class ModelManagerBase:
+class ModelManagerBase(object):
     """
     Base class for the model manager
@@ -265,5 +266,5 @@
         if self.is_changed():
             return  _find_models()
-        logger.info("plugin model : %s" % str(temp))
+        logger.info("plugin model : %s", str(temp))
         return temp
 
@@ -297,5 +298,5 @@
         for name, plug in self.stored_plugins.iteritems():
             self.model_dictionary[name] = plug
-        
+
         self._get_multifunc_models()
 
