Index: src/sas/guiframe/gui_manager.py
===================================================================
--- src/sas/guiframe/gui_manager.py	(revision 064723bf3f830a2eca6b30a1ebfa1f5834e683b2)
+++ src/sas/guiframe/gui_manager.py	(revision 091e71a2c396c66b4a4d8a9536d715b2f2210daf)
@@ -5,5 +5,5 @@
 #This software was developed by the University of Tennessee as part of the
 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
-#project funded by the US National Science Foundation. 
+#project funded by the US National Science Foundation.
 #
 #See the license text in license.txtz
@@ -58,10 +58,10 @@
         logging.info("Using application path: %s", app_path)
         return app_path
-    
+
     # Next, try the current working directory
     if os.path.isfile(os.path.join(os.getcwd(), "custom_config.py")):
         logging.info("Using application path: %s", os.getcwd())
         return os.path.abspath(os.getcwd())
-    
+
     # Finally, try the directory of the sasview module
     #TODO: gui_manager will have to know about sasview until we
@@ -79,18 +79,18 @@
         Returns the user's home directory
     """
-    userdir = os.path.join(os.path.expanduser("~"),".sasview")
+    userdir = os.path.join(os.path.expanduser("~"), ".sasview")
     if not os.path.isdir(userdir):
         os.makedirs(userdir)
     return userdir
-    
+
 def _find_local_config(file, path):
     """
         Find configuration file for the current application
-    """    
+    """
     config_module = None
     fObj = None
     try:
         fObj, path_config, descr = imp.find_module(file, [path])
-        config_module = imp.load_module(file, fObj, path_config, descr) 
+        config_module = imp.load_module(file, fObj, path_config, descr)
     except:
         logging.error("Error loading %s/%s: %s" % (path, file, sys.exc_value))
@@ -102,8 +102,8 @@
 
 # Get APP folder
-PATH_APP = get_app_dir() 
+PATH_APP = get_app_dir()
 DATAPATH = PATH_APP
 
-# GUI always starts from the App folder 
+# GUI always starts from the App folder
 #os.chdir(PATH_APP)
 # Read in the local config, which can either be with the main
@@ -113,12 +113,12 @@
     config = _find_local_config('local_config', os.getcwd())
     if config is None:
-        # Didn't find local config, load the default 
+        # Didn't find local config, load the default
         import sas.guiframe.config as config
-        logging.info("using default local_config")        
+        logging.info("using default local_config")
     else:
-        logging.info("found local_config in %s" % os.getcwd())  
+        logging.info("found local_config in %s" % os.getcwd())
 else:
-    logging.info("found local_config in %s" % PATH_APP)     
-           
+    logging.info("found local_config in %s" % PATH_APP)
+
 from sas.guiframe.customdir  import SetupCustom
 c_conf_dir = SetupCustom().setup_dir(PATH_APP)
@@ -154,7 +154,7 @@
     PLOPANEL_WIDTH = custom_config.PLOPANEL_WIDTH
     DATAPANEL_WIDTH = custom_config.DATAPANEL_WIDTH
-    GUIFRAME_WIDTH = custom_config.GUIFRAME_WIDTH 
+    GUIFRAME_WIDTH = custom_config.GUIFRAME_WIDTH
     GUIFRAME_HEIGHT = custom_config.GUIFRAME_HEIGHT
-    CONTROL_WIDTH = custom_config.CONTROL_WIDTH 
+    CONTROL_WIDTH = custom_config.CONTROL_WIDTH
     CONTROL_HEIGHT = custom_config.CONTROL_HEIGHT
     DEFAULT_PERSPECTIVE = custom_config.DEFAULT_PERSPECTIVE
@@ -173,7 +173,7 @@
     PLOPANEL_WIDTH = config.PLOPANEL_WIDTH
     DATAPANEL_WIDTH = config.DATAPANEL_WIDTH
-    GUIFRAME_WIDTH = config.GUIFRAME_WIDTH 
+    GUIFRAME_WIDTH = config.GUIFRAME_WIDTH
     GUIFRAME_HEIGHT = config.GUIFRAME_HEIGHT
-    CONTROL_WIDTH = -1 
+    CONTROL_WIDTH = -1
     CONTROL_HEIGHT = -1
     DEFAULT_PERSPECTIVE = None
@@ -183,5 +183,5 @@
 DEFAULT_STYLE = config.DEFAULT_STYLE
 
-PLUGIN_STATE_EXTENSIONS =  config.PLUGIN_STATE_EXTENSIONS
+PLUGIN_STATE_EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS
 OPEN_SAVE_MENU = config.OPEN_SAVE_PROJECT_MENU
 VIEW_MENU = config.VIEW_MENU
@@ -214,13 +214,13 @@
         PARENT_FRAME = wx.Frame
         CHILD_FRAME = wx.Frame
-    
+
 class ViewerFrame(PARENT_FRAME):
     """
     Main application frame
     """
-    
-    def __init__(self, parent, title, 
+
+    def __init__(self, parent, title,
                  size=(GUIFRAME_WIDTH, GUIFRAME_HEIGHT),
-                 gui_style=DEFAULT_STYLE, 
+                 gui_style=DEFAULT_STYLE,
                  style=wx.DEFAULT_FRAME_STYLE,
                  pos=wx.DefaultPosition):
@@ -232,22 +232,22 @@
         # title
         self.title = title
-        self.__gui_style = gui_style       
+        self.__gui_style = gui_style
         path = os.path.dirname(__file__)
-        temp_path = os.path.join(path,'images')
-        ico_file = os.path.join(temp_path,'ball.ico')
+        temp_path = os.path.join(path, 'images')
+        ico_file = os.path.join(temp_path, 'ball.ico')
         if os.path.isfile(ico_file):
             self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO))
         else:
-            temp_path = os.path.join(os.getcwd(),'images')
-            ico_file = os.path.join(temp_path,'ball.ico')
+            temp_path = os.path.join(os.getcwd(), 'images')
+            ico_file = os.path.join(temp_path, 'ball.ico')
             if os.path.isfile(ico_file):
                 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO))
             else:
                 ico_file = os.path.join(os.path.dirname(os.path.sys.path[0]),
-                             'images', 'ball.ico')
+                                        'images', 'ball.ico')
                 if os.path.isfile(ico_file):
                     self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO))
         self.path = PATH_APP
-        self.application_name = APPLICATION_NAME 
+        self.application_name = APPLICATION_NAME
         ## Application manager
         self._input_file = None
@@ -294,5 +294,5 @@
 
         # Default locations
-        self._default_save_location = DEFAULT_OPEN_FOLDER       
+        self._default_save_location = DEFAULT_OPEN_FOLDER
         # Welcome panel
         self.defaultPanel = None
@@ -303,5 +303,5 @@
         self.cpanel_on_focus = None
 
-        self.loader = Loader()   
+        self.loader = Loader()
         #data manager
         self.batch_on = False
@@ -310,6 +310,5 @@
         self._data_panel = None#DataPanel(parent=self)
         if self.panel_on_focus is not None:
-            self._data_panel.set_panel_on_focus(
-                                self.panel_on_focus.window_caption)
+            self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption)
         # list of plot panels in schedule to full redraw
         self.schedule = False
@@ -318,10 +317,10 @@
         self.schedule_full_draw_list = []
         self.idletimer = wx.CallLater(TIME_FACTOR, self._onDrawIdle)
-        
+
         self.batch_frame = GridFrame(parent=self)
         self.batch_frame.Hide()
         self.on_batch_selection(event=None)
         self.add_icon()
-        
+
         # Register the close event so it calls our own method
         wx.EVT_CLOSE(self, self.WindowClose)
@@ -338,15 +337,15 @@
         # Preferred window size
         self._window_width, self._window_height = size
-        
+
     def add_icon(self):
         """
-        get list of child and attempt to add the default icon 
-        """
-        
-        list_children = self.GetChildren() 
+        get list of child and attempt to add the default icon
+        """
+
+        list_children = self.GetChildren()
         for frame in list_children:
             self.put_icon(frame)
-        
-    def put_icon(self, frame): 
+
+    def put_icon(self, frame):
         """
         Put icon on the tap of a panel
@@ -358,6 +357,6 @@
                     frame.SetIcon(icon)
                 except:
-                    pass  
-                
+                    pass
+
     def get_client_size(self):
         """
@@ -370,7 +369,7 @@
         if toolbar != None:
             _, tb_h = toolbar.GetSizeTuple()
-            height -= tb_h 
+            height -= tb_h
         return width, height
-    
+
     def on_change_categories(self, evt):
         # ILL
@@ -382,11 +381,9 @@
 
         if fitpanel != None:
-            for i in range(0,fitpanel.GetPageCount()):
+            for i in range(0, fitpanel.GetPageCount()):
                 fitpanel.GetPage(i)._populate_listbox()
 
-
-
     def on_set_batch_result(self, data_outputs, data_inputs=None,
-                             plugin_name=""):
+                            plugin_name=""):
         """
         Display data into a grid in batch mode and show the grid
@@ -395,16 +392,15 @@
         time_str = time.strftime("%b %d %H;%M of %Y", t)
         details = "File Generated by %s : %s" % (APPLICATION_NAME,
-                                                     str(plugin_name))
-        details += "on %s.\n" % time_str 
+                                                 str(plugin_name))
+        details += "on %s.\n" % time_str
         ext = ".csv"
-        file_name = "Batch_" + str(plugin_name)+ "_" + time_str + ext
+        file_name = "Batch_" + str(plugin_name) + "_" + time_str + ext
         file_name = self._default_save_location + str(file_name)
-        
+
         self.open_with_localapp(file_name=file_name,
                                 details=details,
                                 data_inputs=data_inputs,
-                                    data_outputs=data_outputs)
-     
-    
+                                data_outputs=data_outputs)
+
     def open_with_localapp(self, data_inputs=None, details="", file_name=None,
                            data_outputs=None):
@@ -413,10 +409,10 @@
         :param data: dictionary of string and list of items
         """
-        self.batch_frame.set_data(data_inputs=data_inputs, 
+        self.batch_frame.set_data(data_inputs=data_inputs,
                                   data_outputs=data_outputs,
                                   details=details,
                                   file_name=file_name)
         self.show_batch_frame(None)
-        
+
     def on_read_batch_tofile(self, base):
         """
@@ -428,8 +424,8 @@
             self._default_save_location = os.getcwd()
         wildcard = "(*.csv; *.txt)|*.csv; *.txt"
-        dlg = wx.FileDialog(base, 
-                            "Choose a file", 
+        dlg = wx.FileDialog(base,
+                            "Choose a file",
                             self._default_save_location, "",
-                             wildcard)
+                            wildcard)
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
@@ -440,9 +436,9 @@
             self.read_batch_tofile(file_name=path)
         except:
-            msg = "Error occurred when reading the file; %s\n"% path
-            msg += "%s\n"% sys.exc_value
+            msg = "Error occurred when reading the file; %s\n" % path
+            msg += "%s\n" % sys.exc_value
             wx.PostEvent(self, StatusEvent(status=msg,
-                                             info="error"))
-            
+                                           info="error"))
+
     def read_batch_tofile(self, file_name):
         """
@@ -457,8 +453,8 @@
         if ext.lower() == ".csv":
             separator = ","
-        buffer = fd.read()
-        lines = buffer.split('\n')
+        fd_buffer = fd.read()
+        lines = fd_buffer.split('\n')
         fd.close()
-        column_names_line  = ""
+        column_names_line = ""
         index = None
         details = ""
@@ -487,8 +483,8 @@
             if count >= 2:
                 column_names_line = line
-                break 
-           
+                break
+
         if column_names_line.strip() == "" or index is None:
-            return 
+            return
 
         col_name_toks = column_names_line.split(separator)
@@ -500,16 +496,16 @@
                 try:
                     float(c_name)
-                    col_name = "Column %s"% str(col_index + 1)
+                    col_name = "Column %s" % str(col_index + 1)
                     index_min = index
                 except:
                     col_name = c_name
                     index_min = index + 1
-                data[col_name] = [ lines[row].split(separator)[c_index]
-                                for row in range(index_min, len(lines)-1)]
+                data[col_name] = [lines[row].split(separator)[c_index]
+                                  for row in range(index_min, len(lines) - 1)]
                 c_index += 1
-                
+
         self.open_with_localapp(data_outputs=data, data_inputs=None,
                                 file_name=file_name, details=details)
-        
+
     def write_batch_tofile(self, data, file_name, details=""):
         """
@@ -541,5 +537,5 @@
         max_index = max(max_list)
         index = 0
-        while(index < max_index):
+        while index < max_index:
             for value_list in data.values():
                 if index < len(value_list):
@@ -552,5 +548,5 @@
             index += 1
         fd.close()
-            
+
     def open_with_externalapp(self, data, file_name, details=""):
         """
@@ -559,9 +555,9 @@
         if not os.path.exists(file_name):
             self.write_batch_tofile(data=data, file_name=file_name,
-                                               details=details)
+                                    details=details)
         try:
             from win32com.client import Dispatch
-            excel_app = Dispatch('Excel.Application')     
-            wb = excel_app.Workbooks.Open(file_name) 
+            excel_app = Dispatch('Excel.Application')
+            excel_app.Workbooks.Open(file_name)
             excel_app.Visible = 1
         except:
@@ -570,7 +566,6 @@
             msg += "check that %s really exists.\n" % str(file_name)
             wx.PostEvent(self, StatusEvent(status=msg,
-                                             info="error"))
-            
-         
+                                           info="error"))
+
     def on_batch_selection(self, event=None):
         """
@@ -583,14 +578,13 @@
         for plug in self.plugins:
             plug.set_batch_selection(self.batch_on)
-            
+
     def on_color_selection(self, event):
         """
         :param event: contains parameters for id and color
-        """ 
-        color, id = event.color, event.id
+        """
+        color, event_id = event.color, event.id
         for plug in self.plugins:
-            plug.add_color(color, id)
-        
-        
+            plug.add_color(color, event_id)
+
     def setup_custom_conf(self):
         """
@@ -599,5 +593,5 @@
         if custom_config == None:
             return
-        
+
         if not FIXED_PANEL:
             self.__gui_style &= (~GUIFRAME.FIXED_PANEL)
@@ -611,6 +605,6 @@
 
         if WELCOME_PANEL_SHOW:
-            self.__gui_style |= GUIFRAME.WELCOME_PANEL_ON   
-             
+            self.__gui_style |= GUIFRAME.WELCOME_PANEL_ON
+
     def set_custom_default_perspective(self):
         """
@@ -622,5 +616,5 @@
             try:
                 if plugin.sub_menu == DEFAULT_PERSPECTIVE:
-                    
+
                     plugin.on_perspective(event=None)
                     frame = plugin.get_frame()
@@ -629,9 +623,9 @@
                 else:
                     frame = plugin.get_frame()
-                    frame.Show(False) 
+                    frame.Show(False)
             except:
-                pass  
-        return          
-                
+                pass
+        return
+
     def on_load_data(self, event):
         """
@@ -640,5 +634,5 @@
         if self._data_plugin is not None:
             self._data_plugin.load_data(event)
-            
+
     def get_current_perspective(self):
         """
@@ -652,5 +646,5 @@
         """
         return self._default_save_location
-    
+
     def set_input_file(self, input_file):
         """
@@ -658,5 +652,5 @@
         """
         self._input_file = input_file
-        
+
     def get_data_manager(self):
         """
@@ -664,5 +658,5 @@
         """
         return self._data_manager
-    
+
     def get_toolbar(self):
         """
@@ -670,5 +664,5 @@
         """
         return self._toolbar
-    
+
     def set_panel_on_focus(self, event):
         """
@@ -698,11 +692,11 @@
                 self.enable_edit_menu()
 
-    def disable_app_menu(self, p_panel=None):  
+    def disable_app_menu(self, p_panel=None):
         """
         Disables all menus in the menubar
         """
         return
-    
-    def send_focus_to_datapanel(self, name):  
+
+    def send_focus_to_datapanel(self, name):
         """
         Send focusing on ID to data explorer
@@ -710,5 +704,5 @@
         if self._data_panel != None:
             self._data_panel.set_panel_on_focus(name)
-            
+
     def set_panel_on_focus_helper(self):
         """
@@ -722,5 +716,5 @@
             combo_title = str(self.panel_on_focus.window_caption)
             combo.SetStringSelection(combo_title)
-            combo.SetToolTip( wx.ToolTip(combo_title )) 
+            combo.SetToolTip(wx.ToolTip(combo_title))
         elif self.panel_on_focus != self._data_panel:
             cpanel = self.panel_on_focus
@@ -728,9 +722,9 @@
                 cpanel.on_tap_focus()
                 self.cpanel_on_focus = self.panel_on_focus
-      
+
     def reset_bookmark_menu(self, panel):
         """
         Reset Bookmark menu list
-        
+
         : param panel: a control panel or tap where the bookmark is
         """
@@ -745,10 +739,10 @@
                 if pos < 3:
                     continue
-                id =  bitem.GetId()
+                id = bitem.GetId()
                 label = bitem.GetLabel()
                 self._toolbar.append_bookmark_item(id, label)
                 wx.EVT_MENU(self, id, cpanel._back_to_bookmark)
             self._toolbar.Realize()
-             
+
 
     def build_gui(self):
@@ -771,5 +765,5 @@
         self._setup_layout()
         self._add_menu_application()
-        
+
         # Set up the menu
         self._add_current_plugin_menu()
@@ -781,10 +775,10 @@
         if not wx.VERSION_STRING >= '3.0.0.0':
             self.SetMenuBar(self._menubar)
-        
+
         try:
             self.load_from_cmd(self._input_file)
         except:
-            msg = "%s Cannot load file %s\n" %(str(APPLICATION_NAME), 
-                                             str(self._input_file))
+            msg = "%s Cannot load file %s\n" % (str(APPLICATION_NAME),
+                                                str(self._input_file))
             msg += str(sys.exc_value) + '\n'
             logging.error(msg)
@@ -798,5 +792,5 @@
         self._check_update(None)
 
-    def _setup_extra_custom(self):  
+    def _setup_extra_custom(self):
         """
         Set up toolbar and welcome view if needed
@@ -804,11 +798,11 @@
         style = self.__gui_style & GUIFRAME.TOOLBAR_ON
         if (style == GUIFRAME.TOOLBAR_ON) & (not self._toolbar.IsShown()):
-            self._on_toggle_toolbar() 
-        
+            self._on_toggle_toolbar()
+
         # Set Custom deafult start page
         welcome_style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON
         if welcome_style == GUIFRAME.WELCOME_PANEL_ON:
             self.show_welcome_panel(None)
-      
+
     def _setup_layout(self):
         """
@@ -822,5 +816,5 @@
         self._load_panels()
         self.set_default_perspective()
-        
+
     def SetStatusText(self, *args, **kwds):
         """
@@ -828,5 +822,5 @@
         number = self.sb.get_msg_position()
         wx.Frame.SetStatusText(self, number=number, *args, **kwds)
-        
+
     def PopStatusText(self, *args, **kwds):
         """
@@ -834,12 +828,12 @@
         field = self.sb.get_msg_position()
         wx.Frame.PopStatusText(self, field=field)
-        
+
     def PushStatusText(self, *args, **kwds):
         """
-            FIXME: No message is passed. What is this supposed to do? 
+            FIXME: No message is passed. What is this supposed to do?
         """
         field = self.sb.get_msg_position()
-        wx.Frame.PushStatusText(self, field=field, 
-                        string="FIXME: PushStatusText called without text")
+        wx.Frame.PushStatusText(self, field=field,
+                                string="FIXME: PushStatusText called without text")
 
     def add_perspective(self, plugin):
@@ -855,13 +849,13 @@
                 msg = "Plugin %s already loaded" % plugin.sub_menu
                 logging.info(msg)
-                is_loaded = True  
+                is_loaded = True
         if not is_loaded:
-            self.plugins.append(plugin)  
+            self.plugins.append(plugin)
             msg = "Plugin %s appended" % plugin.sub_menu
             logging.info(msg)
-      
+
     def _get_local_plugins(self):
         """
-        get plugins local to guiframe and others 
+        get plugins local to guiframe and others
         """
         plugins = []
@@ -888,22 +882,22 @@
                 msg += "cannot import plotting plugin.\n %s" % sys.exc_value
                 logging.error(msg)
-     
+
         return plugins
-    
+
     def _find_plugins(self, dir="perspectives"):
         """
         Find available perspective plug-ins
-        
+
         :param dir: directory in which to look for plug-ins
-        
+
         :return: list of plug-ins
-        
+
         """
         plugins = []
         # Go through files in panels directory
         try:
-            list = os.listdir(dir)
+            file_list = os.listdir(dir)
             ## the default panel is the panel is the last plugin added
-            for item in list:
+            for item in file_list:
                 toks = os.path.splitext(os.path.basename(item))
                 name = ''
@@ -924,12 +918,12 @@
                         else:
                             (file, path, info) = imp.find_module(name, path)
-                            module = imp.load_module( name, file, item, info)
+                            module = imp.load_module(name, file, item, info)
                         if hasattr(module, "PLUGIN_ID"):
-                            try: 
+                            try:
                                 plug = module.Plugin()
                                 if plug.set_default_perspective():
                                     self._current_perspective = plug
                                 plugins.append(plug)
-                                
+
                                 msg = "Found plug-in: %s" % module.PLUGIN_ID
                                 logging.info(msg)
@@ -947,5 +941,5 @@
             # Should raise and catch at a higher level and 
             # display error on status bar
-            pass  
+            logging.error(sys.exc_value)
 
         return plugins
@@ -963,5 +957,4 @@
             panel_width = DATAPANEL_WIDTH
         panel_height = int(self._window_height)
-        style = self.__gui_style & (GUIFRAME.MANAGER_ON)
         if self._data_panel is not None  and (p == self._data_panel):
             return panel_width, panel_height
@@ -976,5 +969,5 @@
             return self._window_width, panel_height
         return panel_width, panel_height
-    
+
     def _load_panels(self):
         """
@@ -991,5 +984,5 @@
                 ps = item.get_panels(self)
                 panels.extend(ps)
-        
+
         # Set up welcome panel
         #TODO: this needs serious simplification
@@ -1000,5 +993,5 @@
             self.defaultPanel.set_frame(welcome_panel)
             welcome_panel.Show(False)
-        
+
         self.panels["default"] = self.defaultPanel
         size_t_bar = 70
@@ -1012,7 +1005,7 @@
                 frame.SetPosition((0, mac_pos_y + size_t_bar))
             frame.Show(True)
-        #add data panel 
+        #add data panel
         win = MDIFrame(self, None, 'None', (100, 200))
-        data_panel = DataPanel(parent=win,  id=-1)
+        data_panel = DataPanel(parent=win, id=-1)
         win.set_panel(data_panel)
         self.panels["data_panel"] = data_panel
@@ -1029,10 +1022,10 @@
         for panel_class in panels:
             frame = panel_class.get_frame()
-            id = wx.NewId()
+            wx_id = wx.NewId()
             # Check whether we need to put this panel in the center pane
             if hasattr(panel_class, "CENTER_PANE") and panel_class.CENTER_PANE:
                 w, h = self._get_panels_size(panel_class)
                 if panel_class.CENTER_PANE:
-                    self.panels[str(id)] = panel_class
+                    self.panels[str(wx_id)] = panel_class
                     _, pos_y = frame.GetPositionTuple()
                     frame.SetPosition((d_panel_width + 1, pos_y))
@@ -1043,5 +1036,5 @@
                 continue
             else:
-                self.panels[str(id)] = panel_class
+                self.panels[str(wx_id)] = panel_class
                 frame.SetSize((w, h))
                 frame.Show(False)
@@ -1061,24 +1054,24 @@
             else:
                 self.SetSize((self._window_width, win_height))
-        
+
     def update_data(self, prev_data, new_data):
         """
         Update the data.
         """
-        prev_id, data_state = self._data_manager.update_data(
+        prev_id, data_state = self._data_manager.update_data( \
                               prev_data=prev_data, new_data=new_data)
-        
+
         self._data_panel.remove_by_id(prev_id)
         self._data_panel.load_data_list(data_state)
-        
+
     def update_theory(self, data_id, theory, state=None):
         """
         Update the theory
-        """ 
-        data_state = self._data_manager.update_theory(data_id=data_id, 
-                                         theory=theory,
-                                         state=state)  
+        """
+        data_state = self._data_manager.update_theory(data_id=data_id,
+                                                      theory=theory,
+                                                      state=state)
         wx.CallAfter(self._data_panel.load_data_list, data_state)
-        
+
     def onfreeze(self, theory_id):
         """
@@ -1088,19 +1081,19 @@
         for data_state in data_state_list.values():
             new_plot = data_state.get_data()
-            
+
             wx.PostEvent(self, NewPlotEvent(plot=new_plot,
-                                             title=new_plot.title))
-        
+                                            title=new_plot.title))
+
     def freeze(self, data_id, theory_id):
         """
         """
-        data_state_list = self._data_manager.freeze_theory(data_id=data_id, 
-                                                theory_id=theory_id)
+        data_state_list = self._data_manager.freeze_theory(data_id=data_id,
+                                                           theory_id=theory_id)
         self._data_panel.load_data_list(list=data_state_list)
         for data_state in data_state_list.values():
             new_plot = data_state.get_data()
             wx.PostEvent(self, NewPlotEvent(plot=new_plot,
-                                             title=new_plot.title))
-        
+                                            title=new_plot.title))
+
     def delete_data(self, data):
         """
@@ -1108,10 +1101,10 @@
         """
         self._current_perspective.delete_data(data)
-        
-    
+
+
     def get_context_menu(self, plotpanel=None):
         """
-        Get the context menu items made available 
-        by the different plug-ins. 
+        Get the context menu items made available
+        by the different plug-ins.
         This function is used by the plotting module
         """
@@ -1122,9 +1115,9 @@
             menu_list.extend(item.get_context_menu(plotpanel=plotpanel))
         return menu_list
-        
+
     def get_current_context_menu(self, plotpanel=None):
         """
-        Get the context menu items made available 
-        by the current plug-in. 
+        Get the context menu items made available
+        by the current plug-in.
         This function is used by the plotting module
         """
@@ -1136,5 +1129,5 @@
             menu_list.extend(item.get_context_menu(plotpanel=plotpanel))
         return menu_list
-            
+
     def on_panel_close(self, event):
         """
@@ -1150,14 +1143,14 @@
                 break
         self.cpanel_on_focus.SetFocus()
-    
-    
+
+
     def popup_panel(self, p):
         """
         Add a panel object to the AUI manager
-        
+
         :param p: panel object to add to the AUI manager
-        
+
         :return: ID of the event associated with the new panel [int]
-        
+
         """
         ID = wx.NewId()
@@ -1179,6 +1172,7 @@
         # Append nummber
         captions = self._get_plotpanel_captions()
+        #FIXME: Fix this aweful loop
         while (1):
-            caption = windowcaption + '%s'% str(self.graph_num)
+            caption = windowcaption + '%s' % str(self.graph_num)
             if caption not in captions:
                 break
@@ -1188,7 +1182,7 @@
                 break
         if p.window_caption.split()[0] not in NOT_SO_GRAPH_LIST:
-            p.window_caption = caption 
+            p.window_caption = caption
         p.window_name = windowname + str(self.graph_num)
-        
+
         p.frame.SetTitle(p.window_caption)
         p.frame.name = p.window_name
@@ -1214,9 +1208,9 @@
                     self._data_panel.cb_plotpanel.Append(str(caption), p)
         return ID
-    
+
     def _get_plotpanel_captions(self):
         """
         Get all the plotpanel cations
-        
+
         : return: list of captions
         """
@@ -1224,7 +1218,7 @@
         for Id in self.plot_panels.keys():
             captions.append(self.plot_panels[Id].window_caption)
-        
+
         return captions
-        
+
     def _setup_tool_bar(self):
         """
@@ -1242,5 +1236,5 @@
         self._update_toolbar_helper()
         self._on_toggle_toolbar(event=None)
-    
+
     def _update_toolbar_helper(self):
         """
@@ -1249,5 +1243,5 @@
         application_name = 'No Selected Analysis'
         panel_name = 'No Panel on Focus'
-        c_panel = self.cpanel_on_focus        
+        c_panel = self.cpanel_on_focus
         if self._toolbar is  None:
             return
@@ -1262,8 +1256,8 @@
                 c_panel_state = None
         self._toolbar.update_toolbar(c_panel_state)
-        self._toolbar.update_button(application_name=application_name, 
-                                        panel_name=panel_name)
+        self._toolbar.update_button(application_name=application_name,
+                                    panel_name=panel_name)
         self._toolbar.Realize()
-        
+
     def _add_menu_tool(self):
         """
@@ -1287,16 +1281,16 @@
             if self._tool_menu is not None:
                 self._menubar.Append(self._tool_menu, '&Tool')
-                
+
     def _add_current_plugin_menu(self):
         """
         add current plugin menu
         Look for plug-in menus
-        Add available plug-in sub-menus. 
+        Add available plug-in sub-menus.
         """
         if self._menubar is None or self._current_perspective is None \
-            or self._menubar.GetMenuCount()==0:
+            or self._menubar.GetMenuCount() == 0:
             return
         #replace or add a new menu for the current plugin
-       
+
         pos = self._menubar.FindMenu(str(self._applications_menu_name))
         if pos != -1:
@@ -1304,13 +1298,12 @@
             if menu_list:
                 for (menu, name) in menu_list:
-                    hidden_menu = self._menubar.Replace(pos, menu, name) 
-                    self._applications_menu_name = name 
-                #self._applications_menu_pos = pos
+                    self._menubar.Replace(pos, menu, name)
+                    self._applications_menu_name = name
             else:
-                hidden_menu = self._menubar.Remove(pos)
+                self._menubar.Remove(pos)
                 self._applications_menu_name = None
             #get the position of the menu when it first added
-            self._applications_menu_pos = pos 
-            
+            self._applications_menu_pos = pos
+
         else:
             menu_list = self._current_perspective.populate_menu(self)
@@ -1320,12 +1313,12 @@
                         self._menubar.Append(menu, name)
                     else:
-                        self._menubar.Insert(self._applications_menu_pos, 
+                        self._menubar.Insert(self._applications_menu_pos,
                                              menu, name)
                     self._applications_menu_name = name
-                  
+
     def _add_help_menu(self):
         """
         add help menu to menu bar.  Includes welcome page, about page,
-        tutorial PDF and documentation pages. 
+        tutorial PDF and documentation pages.
         """
         # Help menu
@@ -1336,37 +1329,37 @@
             # add the welcome panel menu item
             if config.WELCOME_PANEL_ON and self.defaultPanel is not None:
-                id = wx.NewId()
-                self._help_menu.Append(id, '&Welcome', '')
-                wx.EVT_MENU(self, id, self.show_welcome_panel)
+                wx_id = wx.NewId()
+                self._help_menu.Append(wx_id, '&Welcome', '')
+                wx.EVT_MENU(self, wx_id, self.show_welcome_panel)
 
         self._help_menu.AppendSeparator()
-        id = wx.NewId()
-        self._help_menu.Append(id, '&Documentation', '')
-        wx.EVT_MENU(self, id, self._onSphinxDocs)
-
-        if config._do_tutorial and (IS_WIN or sys.platform =='darwin'):
+        wx_id = wx.NewId()
+        self._help_menu.Append(wx_id, '&Documentation', '')
+        wx.EVT_MENU(self, wx_id, self._onSphinxDocs)
+
+        if config._do_tutorial and (IS_WIN or sys.platform == 'darwin'):
             self._help_menu.AppendSeparator()
-            id = wx.NewId()
-            self._help_menu.Append(id, '&Tutorial', 'Software tutorial')
-            wx.EVT_MENU(self, id, self._onTutorial)
-            
+            wx_id = wx.NewId()
+            self._help_menu.Append(wx_id, '&Tutorial', 'Software tutorial')
+            wx.EVT_MENU(self, wx_id, self._onTutorial)
+
         if config._do_acknowledge:
             self._help_menu.AppendSeparator()
-            id = wx.NewId()
-            self._help_menu.Append(id, '&Acknowledge', 'Acknowledging SasView')
-            wx.EVT_MENU(self, id, self._onAcknowledge)
-        
+            wx_id = wx.NewId()
+            self._help_menu.Append(wx_id, '&Acknowledge', 'Acknowledging SasView')
+            wx.EVT_MENU(self, wx_id, self._onAcknowledge)
+
         if config._do_aboutbox:
             self._help_menu.AppendSeparator()
             self._help_menu.Append(wx.ID_ABOUT, '&About', 'Software information')
             wx.EVT_MENU(self, wx.ID_ABOUT, self._onAbout)
-        
+
         # Checking for updates
-        id = wx.NewId()
-        self._help_menu.Append(id,'&Check for update', 
-         'Check for the latest version of %s' % config.__appname__)
-        wx.EVT_MENU(self, id, self._check_update)
+        wx_id = wx.NewId()
+        self._help_menu.Append(wx_id, '&Check for update',
+                               'Check for the latest version of %s' % config.__appname__)
+        wx.EVT_MENU(self, wx_id, self._check_update)
         self._menubar.Append(self._help_menu, '&Help')
-            
+
     def _add_menu_view(self):
         """
@@ -1376,46 +1369,46 @@
             return
         self._view_menu = wx.Menu()
-        
-        id = wx.NewId()
+
+        wx_id = wx.NewId()
         hint = "Display the Grid Window for batch results etc."
-        self._view_menu.Append(id, '&Show Grid Window', hint) 
-        wx.EVT_MENU(self, id, self.show_batch_frame)
-        
+        self._view_menu.Append(wx_id, '&Show Grid Window', hint)
+        wx.EVT_MENU(self, wx_id, self.show_batch_frame)
+
         self._view_menu.AppendSeparator()
         style = self.__gui_style & GUIFRAME.MANAGER_ON
-        id = wx.NewId()
-        self._data_panel_menu = self._view_menu.Append(id,
-                                                '&Show Data Explorer', '')
-        wx.EVT_MENU(self, id, self.show_data_panel)
+        wx_id = wx.NewId()
+        self._data_panel_menu = self._view_menu.Append(wx_id,
+                                                       '&Show Data Explorer', '')
+        wx.EVT_MENU(self, wx_id, self.show_data_panel)
         if style == GUIFRAME.MANAGER_ON:
             self._data_panel_menu.SetText('Hide Data Explorer')
         else:
             self._data_panel_menu.SetText('Show Data Explorer')
-  
+
         self._view_menu.AppendSeparator()
-        id = wx.NewId()
+        wx_id = wx.NewId()
         style1 = self.__gui_style & GUIFRAME.TOOLBAR_ON
         if style1 == GUIFRAME.TOOLBAR_ON:
-            self._toolbar_menu = self._view_menu.Append(id, '&Hide Toolbar', '')
+            self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', '')
         else:
-            self._toolbar_menu = self._view_menu.Append(id, '&Show Toolbar', '')
-        wx.EVT_MENU(self, id, self._on_toggle_toolbar)
+            self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', '')
+        wx.EVT_MENU(self, wx_id, self._on_toggle_toolbar)
 
         if custom_config != None:
             self._view_menu.AppendSeparator()
-            id = wx.NewId()
+            wx_id = wx.NewId()
             hint_ss = "Select the current/default configuration "
             hint_ss += "as a startup setting"
-            preference_menu = self._view_menu.Append(id, 'Startup Setting', 
+            preference_menu = self._view_menu.Append(wx_id, 'Startup Setting',
                                                      hint_ss)
-            wx.EVT_MENU(self, id, self._on_preference_menu)
-            
-        id = wx.NewId()
+            wx.EVT_MENU(self, wx_id, self._on_preference_menu)
+
+        wx_id = wx.NewId()
         self._view_menu.AppendSeparator()
-        self._view_menu.Append(id, 'Category Manager', 'Edit model categories')
-        wx.EVT_MENU(self, id, self._on_category_manager)
-
-        self._menubar.Append(self._view_menu, '&View')   
-         
+        self._view_menu.Append(wx_id, 'Category Manager', 'Edit model categories')
+        wx.EVT_MENU(self, wx_id, self._on_category_manager)
+
+        self._menubar.Append(self._view_menu, '&View')
+
     def show_batch_frame(self, event=None):
         """
@@ -1425,11 +1418,11 @@
         self.batch_frame.Show(False)
         self.batch_frame.Show(True)
-    
-    def  on_category_panel(self, event):  
+
+    def  on_category_panel(self, event):
         """
         On cat panel
         """
         self._on_category_manager(event)
-          
+
     def _on_category_manager(self, event):
         """
@@ -1440,5 +1433,5 @@
         frame.SetIcon(icon)
 
-    def _on_preference_menu(self, event):     
+    def _on_preference_menu(self, event):
         """
         Build a panel to allow to edit Mask
@@ -1446,5 +1439,5 @@
         from sas.guiframe.startup_configuration \
         import StartupConfiguration as ConfDialog
-        
+
         dialog = ConfDialog(parent=self, gui=self.__gui_style)
         result = dialog.ShowModal()
@@ -1454,5 +1447,5 @@
             wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", info='info'))
         dialog.Destroy()
-        
+
     def _add_menu_application(self):
         """
@@ -1461,5 +1454,5 @@
         add menu application
         """
-        if self._num_perspectives  > 1:
+        if self._num_perspectives > 1:
             plug_data_count = False
             plug_no_data_count = False
@@ -1471,20 +1464,19 @@
                     id = wx.NewId()
                     if plug.use_data():
-                        
-                        self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu,
-                                      "Switch to analysis: %s" % plug.sub_menu)
+                        self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, \
+                            "Switch to analysis: %s" % plug.sub_menu)
                         plug_data_count = True
                         pos += 1
                     else:
                         plug_no_data_count = True
-                        self._applications_menu.AppendCheckItem(id, plug.sub_menu,
-                                      "Switch to analysis: %s" % plug.sub_menu)
+                        self._applications_menu.AppendCheckItem(id, plug.sub_menu, \
+                            "Switch to analysis: %s" % plug.sub_menu)
                     wx.EVT_MENU(self, id, plug.on_perspective)
 
-            if (not plug_data_count or not plug_no_data_count):
+            if not plug_data_count or not plug_no_data_count:
                 self._applications_menu.RemoveItem(separator)
             self._menubar.Append(self._applications_menu, '&Analysis')
             self._check_applications_menu()
-            
+
     def _populate_file_menu(self):
         """
@@ -1499,13 +1491,12 @@
                     wx.EVT_MENU(self, id, m_handler)
                 self._file_menu.AppendSeparator()
-                
+
         style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS
         if OPEN_SAVE_MENU:
             id = wx.NewId()
             hint_load_file = "read all analysis states saved previously"
-            self._save_appl_menu = self._file_menu.Append(id, 
-                                    '&Open Project', hint_load_file)
+            self._save_appl_menu = self._file_menu.Append(id, '&Open Project', hint_load_file)
             wx.EVT_MENU(self, id, self._on_open_state_project)
-            
+
         if style1 == GUIFRAME.MULTIPLE_APPLICATIONS:
             # some menu of plugin to be seen under file menu
@@ -1513,25 +1504,24 @@
             hint_load_file += " them into the analysis"
             id = wx.NewId()
-            self._save_appl_menu = self._file_menu.Append(id, 
-                                    '&Open Analysis', hint_load_file)
+            self._save_appl_menu = self._file_menu.Append(id,
+                                                          '&Open Analysis', hint_load_file)
             wx.EVT_MENU(self, id, self._on_open_state_application)
-        if OPEN_SAVE_MENU:        
+        if OPEN_SAVE_MENU:
             self._file_menu.AppendSeparator()
             id = wx.NewId()
             self._file_menu.Append(id, '&Save Project',
-                                 'Save the state of the whole analysis')
+                                   'Save the state of the whole analysis')
             wx.EVT_MENU(self, id, self._on_save_project)
         if style1 == GUIFRAME.MULTIPLE_APPLICATIONS:
             id = wx.NewId()
-            self._save_appl_menu = self._file_menu.Append(id, 
-                                                      '&Save Analysis',
-                        'Save state of the current active analysis panel')
+            self._save_appl_menu = self._file_menu.Append(id, \
+                '&Save Analysis', 'Save state of the current active analysis panel')
             wx.EVT_MENU(self, id, self._on_save_application)
-        if not sys.platform =='darwin':
+        if not sys.platform == 'darwin':
             self._file_menu.AppendSeparator()
             id = wx.NewId()
-            self._file_menu.Append(id, '&Quit', 'Exit') 
+            self._file_menu.Append(id, '&Quit', 'Exit')
             wx.EVT_MENU(self, id, self.Close)
-        
+
     def _add_menu_file(self):
         """
@@ -1542,5 +1532,5 @@
         # Add sub menus
         self._menubar.Append(self._file_menu, '&File')
-        
+
     def _add_menu_edit(self):
         """
@@ -1551,15 +1541,15 @@
         # Edit Menu
         self._edit_menu = wx.Menu()
-        self._edit_menu.Append(GUIFRAME_ID.UNDO_ID, '&Undo', 
+        self._edit_menu.Append(GUIFRAME_ID.UNDO_ID, '&Undo',
                                'Undo the previous action')
         wx.EVT_MENU(self, GUIFRAME_ID.UNDO_ID, self.on_undo_panel)
-        self._edit_menu.Append(GUIFRAME_ID.REDO_ID, '&Redo', 
+        self._edit_menu.Append(GUIFRAME_ID.REDO_ID, '&Redo',
                                'Redo the previous action')
         wx.EVT_MENU(self, GUIFRAME_ID.REDO_ID, self.on_redo_panel)
         self._edit_menu.AppendSeparator()
-        self._edit_menu.Append(GUIFRAME_ID.COPY_ID, '&Copy Params', 
+        self._edit_menu.Append(GUIFRAME_ID.COPY_ID, '&Copy Params',
                                'Copy parameter values')
         wx.EVT_MENU(self, GUIFRAME_ID.COPY_ID, self.on_copy_panel)
-        self._edit_menu.Append(GUIFRAME_ID.PASTE_ID, '&Paste Params', 
+        self._edit_menu.Append(GUIFRAME_ID.PASTE_ID, '&Paste Params',
                                'Paste parameter values')
         wx.EVT_MENU(self, GUIFRAME_ID.PASTE_ID, self.on_paste_panel)
@@ -1570,29 +1560,29 @@
         #Sub menu for Copy As...
         self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 'Copy current tab to Excel',
-                               'Copy parameter values in tabular format')
+                                      'Copy parameter values in tabular format')
         wx.EVT_MENU(self, GUIFRAME_ID.COPYEX_ID, self.on_copy_panel)
 
         self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 'Copy current tab to LaTeX',
-                               'Copy parameter values in tabular format')
+                                      'Copy parameter values in tabular format')
         wx.EVT_MENU(self, GUIFRAME_ID.COPYLAT_ID, self.on_copy_panel)
 
 
-        self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...', self._edit_menu_copyas,
-                               'Copy parameter values in various formats')
-
+        self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...',
+                                   self._edit_menu_copyas,
+                                   'Copy parameter values in various formats')
 
         self._edit_menu.AppendSeparator()
-        
+
         self._edit_menu.Append(GUIFRAME_ID.PREVIEW_ID, '&Report Results',
                                'Preview current panel')
         wx.EVT_MENU(self, GUIFRAME_ID.PREVIEW_ID, self.on_preview_panel)
 
-        self._edit_menu.Append(GUIFRAME_ID.RESET_ID, '&Reset Page', 
+        self._edit_menu.Append(GUIFRAME_ID.RESET_ID, '&Reset Page',
                                'Reset current panel')
         wx.EVT_MENU(self, GUIFRAME_ID.RESET_ID, self.on_reset_panel)
-    
-        self._menubar.Append(self._edit_menu,  '&Edit')
+
+        self._menubar.Append(self._edit_menu, '&Edit')
         self.enable_edit_menu()
-        
+
     def get_style(self):
         """
@@ -1600,5 +1590,5 @@
         """
         return  self.__gui_style
-    
+
     def _add_menu_data(self):
         """
@@ -1610,6 +1600,5 @@
                 for (menu, name) in menu_list:
                     self._menubar.Append(menu, name)
-        
-                        
+
     def _on_toggle_toolbar(self, event=None):
         """
@@ -1627,5 +1616,5 @@
             self._toolbar.Show()
         self._toolbar.Realize()
-        
+
     def _on_status_event(self, evt):
         """
@@ -1634,24 +1623,24 @@
         # This CallAfter fixes many crashes on MAC.
         wx.CallAfter(self.sb.set_status, evt)
-       
+
     def on_view(self, evt):
         """
         A panel was selected to be shown. If it's not already
         shown, display it.
-        
+
         :param evt: menu event
-        
+
         """
         panel_id = str(evt.GetId())
         self.on_set_plot_focus(self.panels[panel_id])
-        wx.CallLater(5*TIME_FACTOR, self.set_schedule(True))
+        wx.CallLater(5 * TIME_FACTOR, self.set_schedule(True))
         self.set_plot_unfocus()
- 
+
     def show_welcome_panel(self, event):
-        """    
+        """
         Display the welcome panel
         """
         if self.defaultPanel is None:
-            return 
+            return
         frame = self.panels['default'].get_frame()
         if frame == None:
@@ -1660,5 +1649,5 @@
         if not frame.IsShown():
             frame.Show(True)
-            
+
     def on_close_welcome_panel(self):
         """
@@ -1666,9 +1655,9 @@
         """
         if self.defaultPanel is None:
-            return 
+            return
         default_panel = self.panels["default"].frame
         if default_panel.IsShown():
-            default_panel.Show(False) 
-                
+            default_panel.Show(False)
+
     def delete_panel(self, uid):
         """
@@ -1677,9 +1666,4 @@
         ID = str(uid)
         config.printEVT("delete_panel: %s" % ID)
-        try:
-            caption = self.panels[ID].window_caption
-        except:
-            logging.error("delete_panel: No such plot id as %s" % ID)
-            return
         if ID in self.panels.keys():
             self.panel_on_focus = None
@@ -1691,6 +1675,6 @@
 
             if panel in self.schedule_full_draw_list:
-                self.schedule_full_draw_list.remove(panel) 
-            
+                self.schedule_full_draw_list.remove(panel)
+
             #delete uid number not str(uid)
             if ID in self.plot_panels.keys():
@@ -1698,11 +1682,12 @@
             if ID in self.panels.keys():
                 del self.panels[ID]
-            return 
-            
+        else:
+            logging.error("delete_panel: No such plot id as %s" % ID)
+
     def create_gui_data(self, data, path=None):
         """
         """
         return self._data_manager.create_gui_data(data, path)
-    
+
     def get_data(self, path):
         """
@@ -1712,5 +1697,5 @@
         output = []
         error_message = ""
-        basename  = os.path.basename(path)
+        basename = os.path.basename(path)
         root, extension = os.path.splitext(basename)
         if extension.lower() not in EXTENSIONS:
@@ -1720,5 +1705,5 @@
             logging.error(log_msg)
             return
-        
+
         #reading a state file
         for plug in self.plugins:
@@ -1734,18 +1719,18 @@
                     except:
                         msg = "DataLoader Error: Encounted Non-ASCII character"
-                        msg += "\n(%s)"% sys.exc_value
-                        wx.PostEvent(self, StatusEvent(status=msg, 
-                                                info="error", type="stop"))
+                        msg += "\n(%s)" % sys.exc_value
+                        wx.PostEvent(self, StatusEvent(status=msg,
+                                                       info="error", type="stop"))
                         return
-        
+
         style = self.__gui_style & GUIFRAME.MANAGER_ON
         if style == GUIFRAME.MANAGER_ON:
             if self._data_panel is not None:
                 self._data_panel.frame.Show(True)
-      
-    def load_from_cmd(self,  path):   
+
+    def load_from_cmd(self, path):
         """
         load data from cmd or application
-        """ 
+        """
         if path is None:
             return
@@ -1754,11 +1739,11 @@
             if not os.path.isfile(path) and not os.path.isdir(path):
                 return
-            
+
             if os.path.isdir(path):
                 self.load_folder(path)
                 return
 
-        basename  = os.path.basename(path)
-        root, extension = os.path.splitext(basename)
+        basename = os.path.basename(path)
+        _, extension = os.path.splitext(basename)
         if extension.lower() not in EXTENSIONS:
             self.load_data(path)
@@ -1767,11 +1752,11 @@
 
         self._default_save_location = os.path.dirname(path)
-        
-    def load_state(self, path, is_project=False):   
+
+    def load_state(self, path, is_project=False):
         """
         load data from command line or application
         """
         if path and (path is not None) and os.path.isfile(path):
-            basename  = os.path.basename(path)
+            basename = os.path.basename(path)
             if APPLICATION_STATE_EXTENSION is not None \
                 and basename.endswith(APPLICATION_STATE_EXTENSION):
@@ -1784,5 +1769,5 @@
         else:
             wx.PostEvent(self, StatusEvent(status=" "))
-            
+
     def load_data(self, path):
         """
@@ -1791,6 +1776,6 @@
         if not os.path.isfile(path):
             return
-        basename  = os.path.basename(path)
-        root, extension = os.path.splitext(basename)
+        basename = os.path.basename(path)
+        _, extension = os.path.splitext(basename)
         if extension.lower() in EXTENSIONS:
             log_msg = "Data Loader cannot "
@@ -1804,5 +1789,5 @@
         try:
             logging.info("Loading Data...:\n" + str(path) + "\n")
-            temp =  self.loader.load(path)
+            temp = self.loader.load(path)
             if temp.__class__.__name__ == "list":
                 for item in temp:
@@ -1812,5 +1797,5 @@
                 data = self.create_gui_data(temp, path)
                 output[data.id] = data
-            
+
             self.add_data(data_list=output)
         except:
@@ -1819,9 +1804,9 @@
             error_message += str(sys.exc_value) + "\n"
             logging.error(error_message)
- 
+
     def load_folder(self, path):
         """
         Load entire folder
-        """   
+        """
         if not os.path.isdir(path):
             return
@@ -1834,5 +1819,5 @@
                 self._data_plugin.get_data(file_list)
             else:
-                return 
+                return
         except:
             error_message = "Error while loading"
@@ -1840,5 +1825,5 @@
             error_message += str(sys.exc_value) + "\n"
             logging.error(error_message)
-            
+
     def _on_open_state_application(self, event):
         """
@@ -1849,6 +1834,6 @@
         wx.PostEvent(self, StatusEvent(status="Loading Analysis file..."))
         plug_wlist = self._on_open_state_app_helper()
-        dlg = wx.FileDialog(self, 
-                            "Choose a file", 
+        dlg = wx.FileDialog(self,
+                            "Choose a file",
                             self._default_save_location, "",
                             plug_wlist)
@@ -1858,16 +1843,16 @@
                 self._default_save_location = os.path.dirname(path)
         dlg.Destroy()
-        self.load_state(path=path)  
-    
+        self.load_state(path=path)
+
     def _on_open_state_app_helper(self):
         """
-        Helps '_on_open_state_application()' to find the extension of 
+        Helps '_on_open_state_application()' to find the extension of
         the current perspective/application
         """
         # No current perspective or no extension attr
         if self._current_perspective is None:
-            return PLUGINS_WLIST 
+            return PLUGINS_WLIST
         try:
-            # Find the extension of the perspective 
+            # Find the extension of the perspective
             # and get that as 1st item in list
             ind = None
@@ -1888,8 +1873,8 @@
 
         except:
-            plug_wlist = PLUGINS_WLIST 
-            
+            plug_wlist = PLUGINS_WLIST
+
         return plug_wlist
-            
+
     def _on_open_state_project(self, event):
         """
@@ -1899,8 +1884,8 @@
             self._default_save_location = os.getcwd()
         wx.PostEvent(self, StatusEvent(status="Loading Project file..."))
-        dlg = wx.FileDialog(self, 
-                            "Choose a file", 
+        dlg = wx.FileDialog(self,
+                            "Choose a file",
                             self._default_save_location, "",
-                             APPLICATION_WLIST)
+                            APPLICATION_WLIST)
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
@@ -1908,7 +1893,7 @@
                 self._default_save_location = os.path.dirname(path)
         dlg.Destroy()
-        
+
         self.load_state(path=path, is_project=True)
-        
+
     def _on_save_application(self, event):
         """
@@ -1917,14 +1902,14 @@
         if self.cpanel_on_focus is not None:
             try:
-                wx.PostEvent(self, 
+                wx.PostEvent(self,
                              StatusEvent(status="Saving Analysis file..."))
                 self.cpanel_on_focus.on_save(event)
-                wx.PostEvent(self, 
+                wx.PostEvent(self,
                              StatusEvent(status="Completed saving."))
             except:
                 msg = "Error occurred while saving: "
                 msg += "To save, the application panel should have a data set.."
-                wx.PostEvent(self, StatusEvent(status=msg))  
-            
+                wx.PostEvent(self, StatusEvent(status=msg))
+
     def _on_save_project(self, event):
         """
@@ -1934,11 +1919,10 @@
             return
         wx.PostEvent(self, StatusEvent(status="Saving Project file..."))
-        reader, ext = self._current_perspective.get_extensions()
         path = None
         extension = '*' + APPLICATION_STATE_EXTENSION
         dlg = wx.FileDialog(self, "Save Project file",
                             self._default_save_location, "sasview_proj",
-                             extension, 
-                             wx.SAVE)
+                            extension,
+                            wx.SAVE)
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
@@ -1956,5 +1940,5 @@
                 if temp is not None:
                     doc = temp
-            
+
             # Write the XML document
             extens = APPLICATION_STATE_EXTENSION
@@ -1972,45 +1956,40 @@
                 msg += "No project was saved to %s" % (str(path))
                 logging.error(msg)
-                wx.PostEvent(self,StatusEvent(status=msg))
+                wx.PostEvent(self, StatusEvent(status=msg))
         except:
             msg = "Error occurred while saving: "
             msg += "To save, at least one application panel "
             msg += "should have a data set.."
-            wx.PostEvent(self, StatusEvent(status=msg))    
-                    
+            wx.PostEvent(self, StatusEvent(status=msg))
+
     def on_save_helper(self, doc, reader, panel, path):
         """
         Save state into a file
         """
-        try:
-            if reader is not None:
-                # case of a panel with multi-pages
-                if hasattr(panel, "opened_pages"):
-                    for uid, page in panel.opened_pages.iteritems():
-                        data = page.get_data()
-                        # state must be cloned
-                        state = page.get_state().clone()
-                        if data is not None:
-                            new_doc = reader.write_toXML(data, state)
-                            if doc != None and hasattr(doc, "firstChild"):
-                                child = new_doc.firstChild.firstChild
-                                doc.firstChild.appendChild(child)  
-                            else:
-                                doc = new_doc 
-                # case of only a panel
-                else:
-                    data = panel.get_data()
-                    state = panel.get_state()
+        if reader is not None:
+            # case of a panel with multi-pages
+            if hasattr(panel, "opened_pages"):
+                for _, page in panel.opened_pages.iteritems():
+                    data = page.get_data()
+                    # state must be cloned
+                    state = page.get_state().clone()
                     if data is not None:
                         new_doc = reader.write_toXML(data, state)
                         if doc != None and hasattr(doc, "firstChild"):
                             child = new_doc.firstChild.firstChild
-                            doc.firstChild.appendChild(child)  
+                            doc.firstChild.appendChild(child)
                         else:
-                            doc = new_doc 
-        except: 
-            raise
-            #pass
-
+                            doc = new_doc
+            # case of only a panel
+            else:
+                data = panel.get_data()
+                state = panel.get_state()
+                if data is not None:
+                    new_doc = reader.write_toXML(data, state)
+                    if doc != None and hasattr(doc, "firstChild"):
+                        child = new_doc.firstChild.firstChild
+                        doc.firstChild.appendChild(child)
+                    else:
+                        doc = new_doc
         return doc
 
@@ -2021,10 +2000,10 @@
         message = "\nDo you really want to exit this application?        \n\n"
         dial = wx.MessageDialog(self, message, 'Confirm Exit',
-                           wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
+                                wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
         if dial.ShowModal() == wx.ID_YES:
             return True
         else:
-            return False    
-        
+            return False
+
     def WindowClose(self, event=None):
         """
@@ -2035,5 +2014,5 @@
             _pylab_helpers.Gcf.figs = {}
             self.Close()
-            
+
     def Close(self, event=None):
         """
@@ -2042,6 +2021,6 @@
         wx.Exit()
         sys.exit()
-            
-    def _check_update(self, event=None): 
+
+    def _check_update(self, event=None):
         """
         Check with the deployment server whether a new version
@@ -2051,6 +2030,6 @@
         """
         try:
-            conn = httplib.HTTPConnection(config.__update_URL__[0], 
-                              timeout=3.0)
+            conn = httplib.HTTPConnection(config.__update_URL__[0],
+                                          timeout=3.0)
             conn.request("GET", config.__update_URL__[1])
             res = conn.getresponse()
@@ -2059,10 +2038,10 @@
         except:
             content = "0.0.0"
-       
+
         version = content.strip()
         if len(re.findall('\d+\.\d+\.\d+$', version)) < 0:
             content = "0.0.0"
-        self._process_version(content, standalone=event==None)
-    
+        self._process_version(content, standalone=event == None)
+
     def _process_version(self, version, standalone=True):
         """
@@ -2071,9 +2050,9 @@
         version number has been obtained. If the check is being done in the
         background, the user will not be notified unless there's an update.
-        
+
         :param version: version string
-        :param standalone: True of the update is being checked in 
+        :param standalone: True of the update is being checked in
            the background, False otherwise.
-           
+
         """
         try:
@@ -2088,5 +2067,5 @@
                     webbrowser.open(config.__download_page__)
                 else:
-                    msg +=  "See the help menu to download it." 
+                    msg += "See the help menu to download it."
                 self.SetStatusText(msg)
             else:
@@ -2103,11 +2082,11 @@
                 msg += " Please try again later."
                 self.SetStatusText(msg)
-                    
+
     def _onAcknowledge(self, evt):
         """
         Pop up the acknowledge dialog
-        
+
         :param evt: menu event
-        
+
         """
         if config._do_acknowledge:
@@ -2115,25 +2094,25 @@
             dialog = AcknowledgeBox.DialogAcknowledge(None, -1, "")
             dialog.ShowModal()
-                     
+
     def _onAbout(self, evt):
         """
         Pop up the about dialog
-        
+
         :param evt: menu event
-        
+
         """
         if config._do_aboutbox:
             import sas.guiframe.aboutbox as AboutBox
             dialog = AboutBox.DialogAbout(None, -1, "")
-            dialog.ShowModal()   
-                     
+            dialog.ShowModal()
+
     def _onTutorial(self, evt):
         """
         Pop up the tutorial dialog
-        
+
         :param evt: menu event
-        
-        """
-        if config._do_tutorial:   
+
+        """
+        if config._do_tutorial:
             path = config.TUTORIAL_PATH
             if IS_WIN:
@@ -2142,6 +2121,6 @@
                     dialog = PDFFrame(None, -1, "Tutorial", path)
                     # put icon
-                    self.put_icon(dialog)  
-                    dialog.Show(True) 
+                    self.put_icon(dialog)
+                    dialog.Show(True)
                 except:
                     logging.error("Error in _onTutorial: %s" % sys.exc_value)
@@ -2175,5 +2154,5 @@
         'documentation' is clicked. Calls DocumentationWindow with the top
         level path of "index.html"
-        
+
         :param evt: menu event
         """
@@ -2181,19 +2160,17 @@
         # different place than they would otherwise.
         from documentation_window import DocumentationWindow
-        
-        sphinx_doc_viewer = DocumentationWindow(self, -1, "index.html", \
-                                                "General Help")
+        DocumentationWindow(self, -1, "index.html", "General Help")
 
     def set_manager(self, manager):
         """
         Sets the application manager for this frame
-        
+
         :param manager: frame manager
         """
         self.app_manager = manager
-        
+
     def post_init(self):
         """
-        This initialization method is called after the GUI 
+        This initialization method is called after the GUI
         has been created and all plug-ins loaded. It calls
         the post_init() method of each plug-in (if it exists)
@@ -2203,8 +2180,8 @@
             if hasattr(item, "post_init"):
                 item.post_init()
-        
+
     def set_default_perspective(self):
         """
-        Choose among the plugin the first plug-in that has 
+        Choose among the plugin the first plug-in that has
         "set_default_perspective" method and its return value is True will be
         as a default perspective when the welcome page is closed
@@ -2214,6 +2191,6 @@
                 if item.set_default_perspective():
                     item.on_perspective(event=None)
-                    return 
-        
+                    return
+
     def set_perspective(self, panels):
         """
@@ -2221,5 +2198,5 @@
         Opens all the panels in the list, and closes
         all the others.
-        
+
         :param panels: list of panels
         """
@@ -2228,5 +2205,5 @@
             if hasattr(self.panels[item], "ALWAYS_ON"):
                 if self.panels[item].ALWAYS_ON:
-                    continue 
+                    continue
             if self.panels[item] == None:
                 continue
@@ -2252,5 +2229,5 @@
                     if frame.IsShown():
                         frame.Show(False)
-        
+
     def show_data_panel(self, event=None, action=True):
         """
@@ -2263,5 +2240,5 @@
         frame = pane.get_frame()
         if label == 'Show Data Explorer':
-            if action: 
+            if action:
                 frame.Show(True)
             self.__gui_style = self.__gui_style | GUIFRAME.MANAGER_ON
@@ -2278,11 +2255,11 @@
         if self._data_manager is not None:
             self._data_manager.add_data(data_list)
-        
+
     def add_data(self, data_list):
         """
         receive a dictionary of data from loader
         store them its data manager if possible
-        send to data the current active perspective if the data panel 
-        is not active. 
+        send to data the current active perspective if the data panel
+        is not active.
         :param data_list: dictionary of data's ID and value Data
         """
@@ -2293,10 +2270,10 @@
             data_state = self._data_manager.get_data_state(data_list.keys())
             self._data_panel.load_data_list(data_state)
-        #if the data panel is shown wait for the user to press a button 
+        #if the data panel is shown wait for the user to press a button
         #to send data to the current perspective. if the panel is not
         #show  automatically send the data to the current perspective
         style = self.__gui_style & GUIFRAME.MANAGER_ON
         if style == GUIFRAME.MANAGER_ON:
-            #wait for button press from the data panel to set_data 
+            #wait for button press from the data panel to set_data
             if self._data_panel is not None:
                 self._data_panel.frame.Show(True)
@@ -2304,6 +2281,6 @@
             #automatically send that to the current perspective
             self.set_data(data_id=data_list.keys())
-       
-    def set_data(self, data_id, theory_id=None): 
+
+    def set_data(self, data_id, theory_id=None):
         """
         set data to current perspective
@@ -2316,5 +2293,5 @@
             msg = "Guiframe does not have a current perspective"
             logging.info(msg)
-            
+
     def set_theory(self, state_id, theory_id=None):
         """
@@ -2331,11 +2308,10 @@
             msg = "Guiframe does not have a current perspective"
             logging.info(msg)
-            
-    def plot_data(self,  state_id, data_id=None,
+
+    def plot_data(self, state_id, data_id=None,
                   theory_id=None, append=False):
         """
         send a list of data to plot
         """
-        total_plot_list = []
         data_list, _ = self._data_manager.get_by_id(data_id)
         _, temp_list_theory = self._data_manager.get_by_id(theory_id)
@@ -2350,7 +2326,7 @@
                     message = "cannot append plot. No plot panel on focus!"
                     message += "please click on any available plot to set focus"
-                    wx.PostEvent(self, StatusEvent(status=message, 
+                    wx.PostEvent(self, StatusEvent(status=message,
                                                    info='warning'))
-                    return 
+                    return
                 else:
                     if self.enable_add_data(new_plot):
@@ -2359,8 +2335,8 @@
                         message = "Only 1D Data can be append to"
                         message += " plot panel containing 1D data.\n"
-                        message += "%s not be appended.\n" %str(new_plot.name)
+                        message += "%s not be appended.\n" % str(new_plot.name)
                         message += "try new plot option.\n"
-                        wx.PostEvent(self, StatusEvent(status=message, 
-                                                   info='warning'))
+                        wx.PostEvent(self, StatusEvent(status=message,
+                                                       info='warning'))
             else:
                 #if not append then new plot
@@ -2374,7 +2350,7 @@
             title = "PLOT " + str(new_plot.title)
             wx.PostEvent(self, NewPlotEvent(plot=new_plot,
-                                                  title=title,
-                                                  group_id = new_plot.group_id))
-            
+                                            title=title,
+                                            group_id=new_plot.group_id))
+
     def remove_data(self, data_id, theory_id=None):
         """
@@ -2387,5 +2363,4 @@
         for plug in self.plugins:
             plug.delete_data(temp)
-        total_plot_list = []
         data_list, _ = self._data_manager.get_by_id(data_id)
         _, temp_list_theory = self._data_manager.get_by_id(theory_id)
@@ -2398,24 +2373,24 @@
             for group_id in new_plot.list_group_id:
                 wx.PostEvent(self, NewPlotEvent(id=id,
-                                                   group_id=group_id,
-                                                   action='remove'))
+                                                group_id=group_id,
+                                                action='remove'))
                 #remove res plot: Todo: improve
                 wx.CallAfter(self._remove_res_plot, id)
-        self._data_manager.delete_data(data_id=data_id, 
+        self._data_manager.delete_data(data_id=data_id,
                                        theory_id=theory_id)
-        
+
     def _remove_res_plot(self, id):
         """
         Try to remove corresponding res plot
-        
+
         : param id: id of the data
         """
         try:
-            wx.PostEvent(self, NewPlotEvent(id=("res"+str(id)),
-                                           group_id=("res"+str(id)),
-                                           action='remove'))
+            wx.PostEvent(self, NewPlotEvent(id=("res" + str(id)),
+                                            group_id=("res" + str(id)),
+                                            action='remove'))
         except:
-            pass
-    
+            logging.error(sys.exc_value)
+
     def save_data1d(self, data, fname):
         """
@@ -2424,10 +2399,10 @@
         default_name = fname
         wildcard = "Text files (*.txt)|*.txt|"\
-                    "CanSAS 1D files(*.xml)|*.xml" 
+                    "CanSAS 1D files(*.xml)|*.xml"
         path = None
         dlg = wx.FileDialog(self, "Choose a file",
                             self._default_save_location,
-                            default_name, wildcard , wx.SAVE)
-       
+                            default_name, wildcard, wx.SAVE)
+
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
@@ -2441,13 +2416,7 @@
             path = os.path.splitext(path)[0] + format
             mypath = os.path.basename(path)
-            
-            #TODO: This is bad design. The DataLoader is designed 
-            #to recognize extensions.
-            # It should be a simple matter of calling the .
-            #save(file, data, '.xml') method
-            # of the sas.dataloader.loader.Loader class.
-            from sas.dataloader.loader import  Loader
-            #Instantiate a loader 
-            loader = Loader() 
+
+            #Instantiate a loader
+            loader = Loader()
             format = ".txt"
             if os.path.splitext(mypath)[1].lower() == format:
@@ -2465,11 +2434,11 @@
                 self._default_save_location = os.path.dirname(path)
             except:
-                pass    
+                pass
         dlg.Destroy()
-        
-        
+
+
     def _onsaveTXT(self, data, path):
         """
-        Save file as txt  
+        Save file as txt
         :TODO: Refactor and remove this method. See TODO in _onSave.
         """
@@ -2493,46 +2462,46 @@
             else:
                 out.write("<X>   <Y>\n")
-                
+
             for i in range(len(data.x)):
                 if has_errors:
                     if data.dx != None and data.dx != []:
                         if  data.dx[i] != None:
-                            out.write("%g  %g  %g  %g\n" % (data.x[i], 
-                                                        data.y[i],
-                                                        data.dy[i],
-                                                        data.dx[i]))
+                            out.write("%g  %g  %g  %g\n" % (data.x[i],
+                                                            data.y[i],
+                                                            data.dy[i],
+                                                            data.dx[i]))
                         else:
-                            out.write("%g  %g  %g\n" % (data.x[i], 
+                            out.write("%g  %g  %g\n" % (data.x[i],
                                                         data.y[i],
                                                         data.dy[i]))
                     else:
-                        out.write("%g  %g  %g\n" % (data.x[i], 
+                        out.write("%g  %g  %g\n" % (data.x[i],
                                                     data.y[i],
                                                     data.dy[i]))
                 else:
-                    out.write("%g  %g\n" % (data.x[i], 
+                    out.write("%g  %g\n" % (data.x[i],
                                             data.y[i]))
-            out.close()  
-                             
+            out.close()
+
     def show_data1d(self, data, name):
         """
         Show data dialog
-        """   
+        """
         try:
             xmin = min(data.x)
             ymin = min(data.y)
         except:
-            msg = "Unable to find min/max of \n data named %s"% \
-                        data.filename  
+            msg = "Unable to find min/max of \n data named %s" % \
+                        data.filename
             wx.PostEvent(self, StatusEvent(status=msg,
-                                       info="error"))
+                                           info="error"))
             raise ValueError, msg
         ## text = str(data)
         text = data.__str__()
         text += 'Data Min Max:\n'
-        text += 'X_min = %s:  X_max = %s\n'% (xmin, max(data.x))
-        text += 'Y_min = %s:  Y_max = %s\n'% (ymin, max(data.y))
+        text += 'X_min = %s:  X_max = %s\n' % (xmin, max(data.x))
+        text += 'Y_min = %s:  Y_max = %s\n' % (ymin, max(data.y))
         if data.dy != None:
-            text += 'dY_min = %s:  dY_max = %s\n'% (min(data.dy), max(data.dy))
+            text += 'dY_min = %s:  dY_max = %s\n' % (min(data.dy), max(data.dy))
         text += '\nData Points:\n'
         x_st = "X"
@@ -2547,26 +2516,26 @@
                 dx_val = 0.0
             if data.dxl != None and len(data.dxl) > index:
-                if index == 0: 
+                if index == 0:
                     x_st = "Xl"
                 dx_val = data.dxl[index]
             elif data.dxw != None and len(data.dxw) > index:
-                if index == 0: 
+                if index == 0:
                     x_st = "Xw"
                 dx_val = data.dxw[index]
-            
+
             if index == 0:
-                text += "<index> \t<X> \t<Y> \t<dY> \t<d%s>\n"% x_st
+                text += "<index> \t<X> \t<Y> \t<dY> \t<d%s>\n" % x_st
             text += "%s \t%s \t%s \t%s \t%s\n" % (index,
-                                            data.x[index], 
-                                            data.y[index],
-                                            dy_val,
-                                            dx_val)
+                                                  data.x[index],
+                                                  data.y[index],
+                                                  dy_val,
+                                                  dx_val)
         from pdfview import TextFrame
-        frame = TextFrame(None, -1, "Data Info: %s"% data.name, text) 
+        frame = TextFrame(None, -1, "Data Info: %s" % data.name, text)
         # put icon
-        self.put_icon(frame) 
-        frame.Show(True) 
-            
-    def save_data2d(self, data, fname):    
+        self.put_icon(frame)
+        frame.Show(True)
+
+    def save_data2d(self, data, fname):
         """
         Save data2d dialog
@@ -2576,6 +2545,6 @@
         dlg = wx.FileDialog(self, "Choose a file",
                             self._default_save_location,
-                            default_name, wildcard , wx.SAVE)
-       
+                            default_name, wildcard, wx.SAVE)
+
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
@@ -2589,13 +2558,7 @@
             path = os.path.splitext(path)[0] + format
             mypath = os.path.basename(path)
-            
-            #TODO: This is bad design. The DataLoader is designed 
-            #to recognize extensions.
-            # It should be a simple matter of calling the .
-            #save(file, data, '.xml') method
-            # of the DataLoader.loader.Loader class.
-            from sas.dataloader.loader import  Loader
-            #Instantiate a loader 
-            loader = Loader() 
+
+            #Instantiate a loader
+            loader = Loader()
 
             format = ".dat"
@@ -2608,18 +2571,17 @@
                 self._default_save_location = os.path.dirname(path)
             except:
-                pass    
-        dlg.Destroy() 
-                             
+                pass
+        dlg.Destroy()
+
     def show_data2d(self, data, name):
         """
         Show data dialog
-        """   
-
-        wx.PostEvent(self, StatusEvent(status = "Gathering Data2D Info.", 
-                                       type = 'start' ))
-        text = data.__str__() 
+        """
+        wx.PostEvent(self, StatusEvent(status="Gathering Data2D Info.",
+                                       type='start'))
+        text = data.__str__()
         text += 'Data Min Max:\n'
-        text += 'I_min = %s\n'% min(data.data)
-        text += 'I_max = %s\n\n'% max(data.data)
+        text += 'I_min = %s\n' % min(data.data)
+        text += 'I_max = %s\n\n' % max(data.data)
         text += 'Data (First 2501) Points:\n'
         text += 'Data columns include err(I).\n'
@@ -2629,5 +2591,4 @@
         dx_val = 0.0
         dy_val = 0.0
-        #mask_val = True
         len_data = len(data.qx_data)
         for index in xrange(0, len_data):
@@ -2635,18 +2596,18 @@
             y_val = data.qy_data[index]
             i_val = data.data[index]
-            if data.err_data != None: 
+            if data.err_data != None:
                 di_val = data.err_data[index]
-            if data.dqx_data != None: 
+            if data.dqx_data != None:
                 dx_val = data.dqx_data[index]
-            if data.dqy_data != None: 
+            if data.dqy_data != None:
                 dy_val = data.dqy_data[index]
-  
+
             text += "%s \t%s \t%s \t%s \t%s \t%s \t%s\n" % (index,
-                                            x_val, 
-                                            y_val,
-                                            i_val,
-                                            di_val,
-                                            dx_val,
-                                            dy_val)
+                                                            x_val,
+                                                            y_val,
+                                                            i_val,
+                                                            di_val,
+                                                            dx_val,
+                                                            dy_val)
             # Takes too long time for typical data2d: Break here
             if index >= 2500:
@@ -2655,14 +2616,14 @@
 
         from pdfview import TextFrame
-        frame = TextFrame(None, -1, "Data Info: %s"% data.name, text) 
+        frame = TextFrame(None, -1, "Data Info: %s" % data.name, text)
         # put icon
         self.put_icon(frame)
-        frame.Show(True) 
-        wx.PostEvent(self, StatusEvent(status = "Data2D Info Displayed", 
-                                       type = 'stop' ))
-                                  
+        frame.Show(True)
+        wx.PostEvent(self, StatusEvent(status="Data2D Info Displayed",
+                                       type='stop'))
+
     def set_current_perspective(self, perspective):
         """
-        set the current active perspective 
+        set the current active perspective
         """
         self._current_perspective = perspective
@@ -2680,5 +2641,4 @@
                             else:
                                 frame.Show(False)
-                            #break               
             name = self._current_perspective.sub_menu
             if self._data_panel is not None:
@@ -2687,9 +2647,9 @@
             #Set the SasView title
             self._set_title_name(name)
-            
+
     def _set_title_name(self, name):
         """
         Set the SasView title w/ the current application name
-        
+
         : param name: application name [string]
         """
@@ -2697,5 +2657,5 @@
         title = self.title + "  - " + name + " -"
         self.SetTitle(title)
-            
+
     def _check_applications_menu(self):
         """
@@ -2710,6 +2670,6 @@
                             menu.Check(True)
                         else:
-                            menu.Check(False) 
-            
+                            menu.Check(False)
+
     def enable_add_data(self, new_plot):
         """
@@ -2721,23 +2681,23 @@
         is_theory = len(self.panel_on_focus.plots) <= 1 and \
             self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D"
-            
+
         is_data2d = hasattr(new_plot, 'data')
-        
+
         is_data1d = self.panel_on_focus.__class__.__name__ == "ModelPanel1D"\
             and self.panel_on_focus.group_id is not None
         has_meta_data = hasattr(new_plot, 'meta_data')
-        
+
         #disable_add_data if the data is being recovered from  a saved state file.
         is_state_data = False
         if has_meta_data:
-            if 'invstate' in new_plot.meta_data: 
+            if 'invstate' in new_plot.meta_data:
                 is_state_data = True
-            if  'prstate' in new_plot.meta_data: 
+            if  'prstate' in new_plot.meta_data:
                 is_state_data = True
-            if  'fitstate' in new_plot.meta_data: 
+            if  'fitstate' in new_plot.meta_data:
                 is_state_data = True
-    
+
         return is_data1d and not is_data2d and not is_theory and not is_state_data
-    
+
     def check_multimode(self, perspective=None):
         """
@@ -2756,7 +2716,5 @@
         self._data_panel.rb_single_mode.Enable(flag)
         self._data_panel.rb_batch_mode.Enable(flag)
-                
-
-    
+
     def enable_edit_menu(self):
         """
@@ -2775,5 +2733,4 @@
             #Copy menu
             flag = self.cpanel_on_focus.get_copy_flag()
-            #self._edit_menu.ENABLE(GUIFRAME_ID.COPYAS_ID,flag)
             self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYEX_ID, flag)
             self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYLAT_ID, flag)
@@ -2789,10 +2746,7 @@
             self._edit_menu.Enable(GUIFRAME_ID.COPY_ID, flag)
             self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag)
-            #self._edit_menu.Enable(GUIFRAME_ID.COPYEX_ID, flag)
-            #self._edit_menu.Enable(GUIFRAME_ID.COPYLAT_ID, flag)
-            #self._edit_menu.Enable(GUIFRAME_ID.COPYAS_ID, flag)
             self._edit_menu.Enable(GUIFRAME_ID.PREVIEW_ID, flag)
             self._edit_menu.Enable(GUIFRAME_ID.RESET_ID, flag)
-            
+
     def on_undo_panel(self, event=None):
         """
@@ -2801,5 +2755,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_undo(event)
-            
+
     def on_redo_panel(self, event=None):
         """
@@ -2808,5 +2762,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_redo(event)
-            
+
     def on_copy_panel(self, event=None):
         """
@@ -2815,5 +2769,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_copy(event)
-            
+
     def on_paste_panel(self, event=None):
         """
@@ -2822,5 +2776,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_paste(event)
-                    
+
     def on_bookmark_panel(self, event=None):
         """
@@ -2829,5 +2783,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_bookmark(event)
-            
+
     def append_bookmark(self, event=None):
         """
@@ -2835,5 +2789,5 @@
         """
         self._toolbar.append_bookmark(event)
-            
+
     def on_save_panel(self, event=None):
         """
@@ -2842,5 +2796,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_save(event)
-            
+
     def on_preview_panel(self, event=None):
         """
@@ -2849,5 +2803,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_preview(event)
-            
+
     def on_print_panel(self, event=None):
         """
@@ -2856,5 +2810,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_print(event)
-            
+
     def on_zoom_panel(self, event=None):
         """
@@ -2863,5 +2817,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_zoom(event)
-            
+
     def on_zoom_in_panel(self, event=None):
         """
@@ -2870,5 +2824,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_zoom_in(event)
-            
+
     def on_zoom_out_panel(self, event=None):
         """
@@ -2877,5 +2831,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_zoom_out(event)
-            
+
     def on_drag_panel(self, event=None):
         """
@@ -2884,5 +2838,5 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_drag(event)
-            
+
     def on_reset_panel(self, event=None):
         """
@@ -2891,9 +2845,9 @@
         if self.cpanel_on_focus is not None:
             self.cpanel_on_focus.on_reset(event)
-            
-    def on_change_caption(self, name, old_caption, new_caption):     
+
+    def on_change_caption(self, name, old_caption, new_caption):
         """
         Change the panel caption
-        
+
         :param name: window_name of the pane
         :param old_caption: current caption [string]
@@ -2901,5 +2855,5 @@
         """
         # wx.aui.AuiPaneInfo
-        pane_info = self.get_paneinfo(old_caption) 
+        pane_info = self.get_paneinfo(old_caption)
         # update the data_panel.cb_plotpanel
         if 'data_panel' in self.panels.keys():
@@ -2909,5 +2863,5 @@
                 # Check if any panel has the same caption
                 has_newstring = data_panel.cb_plotpanel.FindString\
-                                                            (str(new_caption)) 
+                                                            (str(new_caption))
                 caption = new_caption
                 if has_newstring != wx.NOT_FOUND:
@@ -2915,14 +2869,15 @@
                     # Append nummber
                     inc = 1
+                    #FIXME: fix this terrible loop
                     while (1):
-                        caption = new_caption + '_%s'% str(inc)
+                        caption = new_caption + '_%s' % str(inc)
                         if caption not in captions:
                             break
                         inc += 1
                     # notify to users
-                    msg = "Found Same Title: Added '_%s'"% str(inc)
+                    msg = "Found Same Title: Added '_%s'" % str(inc)
                     wx.PostEvent(self, StatusEvent(status=msg))
                 # update data_panel cb
-                pos = data_panel.cb_plotpanel.FindString(str(old_caption)) 
+                pos = data_panel.cb_plotpanel.FindString(str(old_caption))
                 if pos != wx.NOT_FOUND:
                     data_panel.cb_plotpanel.SetString(pos, caption)
@@ -2931,9 +2886,9 @@
         pane_info.SetTitle(caption)
         return caption
-        
+
     def get_paneinfo(self, name):
         """
         Get pane Caption from window_name
-        
+
         :param name: window_name in AuiPaneInfo
         : return: AuiPaneInfo of the name
@@ -2943,5 +2898,5 @@
                 return panel.frame
         return None
-    
+
     def enable_undo(self):
         """
@@ -2950,12 +2905,12 @@
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_undo(self.cpanel_on_focus)
-            
+
     def enable_redo(self):
         """
-        enable redo 
+        enable redo
         """
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_redo(self.cpanel_on_focus)
-            
+
     def enable_copy(self):
         """
@@ -2964,67 +2919,67 @@
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_copy(self.cpanel_on_focus)
-            
+
     def enable_paste(self):
         """
-        enable paste 
+        enable paste
         """
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_paste(self.cpanel_on_focus)
-                       
+
     def enable_bookmark(self):
         """
-        Bookmark 
+        Bookmark
         """
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_bookmark(self.cpanel_on_focus)
-            
+
     def enable_save(self):
         """
-        save 
+        save
         """
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_save(self.cpanel_on_focus)
-            
+
     def enable_preview(self):
         """
-        preview 
+        preview
         """
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_preview(self.cpanel_on_focus)
-            
+
     def enable_print(self):
         """
-        print 
+        print
         """
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_print(self.cpanel_on_focus)
-            
+
     def enable_zoom(self):
         """
-        zoom 
+        zoom
         """
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_zoom(self.panel_on_focus)
-            
+
     def enable_zoom_in(self):
         """
-        zoom in 
+        zoom in
         """
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_zoom_in(self.panel_on_focus)
-            
+
     def enable_zoom_out(self):
         """
-        zoom out 
+        zoom out
         """
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_zoom_out(self.panel_on_focus)
-            
+
     def enable_drag(self, event=None):
         """
-        drag 
+        drag
         """
         #Not implemeted
-            
+
     def enable_reset(self):
         """
@@ -3033,5 +2988,5 @@
         if self.cpanel_on_focus is not None:
             self._toolbar.enable_reset(self.panel_on_focus)
-            
+
     def get_toolbar_height(self):
         """
@@ -3042,9 +2997,9 @@
                 _, size_y = self.GetToolBar().GetSizeTuple()
         return size_y
-    
+
     def set_schedule_full_draw(self, panel=None, func='del'):
         """
         Add/subtract the schedule full draw list with the panel given
-        
+
         :param panel: plot panel
         :param func: append or del [string]
@@ -3054,5 +3009,5 @@
         if func == 'append':
             if not panel in self.schedule_full_draw_list:
-                self.schedule_full_draw_list.append(panel) 
+                self.schedule_full_draw_list.append(panel)
         # remove this panel from schedule list
         elif func == 'del':
@@ -3065,11 +3020,11 @@
             self.schedule = False
         else:
-            self.schedule = True    
-        
+            self.schedule = True
+
     def full_draw(self):
         """
         Draw the panels with axes in the schedule to full dwar list
         """
-        
+
         count = len(self.schedule_full_draw_list)
         #if not self.schedule:
@@ -3097,5 +3052,5 @@
                 # while any panel is capture.
                 frame = panel.frame
-                
+
                 if not frame.GetCapture():
                     # draw if possible
@@ -3105,11 +3060,11 @@
                 # Check if the panel is not shown
                 flag = frame.IsShown()
-                frame.Show(flag)  
+                frame.Show(flag)
             except:
                 pass
-     
+
         # Draw all panels 
         if count == 1:
-            f_draw(self.schedule_full_draw_list[0])  
+            f_draw(self.schedule_full_draw_list[0])
         else:
             map(f_draw, self.schedule_full_draw_list)
@@ -3119,17 +3074,17 @@
         else:
             self.set_schedule(True)
-        
-    def set_schedule(self, schedule=False):  
+
+    def set_schedule(self, schedule=False):
         """
         Set schedule
         """
         self.schedule = schedule
-                
-    def get_schedule(self):  
+
+    def get_schedule(self):
         """
         Get schedule
         """
         return self.schedule
-    
+
     def on_set_plot_focus(self, panel):
         """
@@ -3139,10 +3094,10 @@
             return
         #self.set_plot_unfocus()
-        panel.on_set_focus(None)  
+        panel.on_set_focus(None)
         # set focusing panel
-        self.panel_on_focus = panel  
+        self.panel_on_focus = panel
         self.set_panel_on_focus(None)
 
-    def set_plot_unfocus(self): 
+    def set_plot_unfocus(self):
         """
         Un focus all plot panels
@@ -3150,9 +3105,9 @@
         for plot in self.plot_panels.values():
             plot.on_kill_focus(None)
-    
+
     def get_window_size(self):
         """
-        Get window size 
-        
+        Get window size
+
         :return size: tuple
         """
@@ -3163,5 +3118,5 @@
                 height -= 45
         return (width, height)
-            
+
     def _onDrawIdle(self, *args, **kwargs):
         """
@@ -3175,9 +3130,9 @@
         except:
             pass
-            
+
         # restart idle        
         self._redraw_idle(*args, **kwargs)
 
-            
+
     def _redraw_idle(self, *args, **kwargs):
         """
@@ -3185,7 +3140,7 @@
         """
         # restart idle   
-        self.idletimer.Restart(100*TIME_FACTOR, *args, **kwargs)
-
-        
+        self.idletimer.Restart(100 * TIME_FACTOR, *args, **kwargs)
+
+
 class DefaultPanel(wx.Panel, PanelBase):
     """
@@ -3202,5 +3157,5 @@
         wx.Panel.__init__(self, parent, *args, **kwds)
         PanelBase.__init__(self, parent)
-    
+
 
 
@@ -3213,11 +3168,11 @@
         When initialised
         """
-        pos, size, self.is_max = self.window_placement((GUIFRAME_WIDTH, 
-                                           GUIFRAME_HEIGHT))     
-        self.frame = ViewerFrame(parent=None, 
-                             title=APPLICATION_NAME, 
-                             pos=pos, 
-                             gui_style = DEFAULT_STYLE,
-                             size=size)
+        pos, size, self.is_max = self.window_placement((GUIFRAME_WIDTH,
+                                                        GUIFRAME_HEIGHT))
+        self.frame = ViewerFrame(parent=None,
+                                 title=APPLICATION_NAME,
+                                 pos=pos,
+                                 gui_style=DEFAULT_STYLE,
+                                 size=size)
         self.frame.Hide()
         if not IS_WIN:
@@ -3234,20 +3189,20 @@
         try:
             if os.path.isfile(SPLASH_SCREEN_PATH):
-                self.s_screen = self.display_splash_screen(parent=self.frame, 
-                                        path=SPLASH_SCREEN_PATH)
+                self.s_screen = self.display_splash_screen(parent=self.frame,
+                                                           path=SPLASH_SCREEN_PATH)
             else:
-                self.frame.Show()   
+                self.frame.Show()
         except:
             if self.s_screen is not None:
                 self.s_screen.Close()
             msg = "Cannot display splash screen\n"
-            msg += str (sys.exc_value)
+            msg += str(sys.exc_value)
             logging.error(msg)
             self.frame.Show()
 
         self.SetTopWindow(self.frame)
-  
+
         return True
-    
+
     def maximize_win(self):
         """
@@ -3266,5 +3221,5 @@
         if len(sys.argv) >= 2:
             cmd = sys.argv[0].lower()
-            basename  = os.path.basename(cmd)
+            basename = os.path.basename(cmd)
             app_base = str(APPLICATION_NAME).lower()
             if os.path.isfile(cmd) or basename.lower() == app_base:
@@ -3274,5 +3229,5 @@
                 if basename.lower() in [app_py, app_exe, app_app, app_base]:
                     data_base = sys.argv[1]
-                    input_file = os.path.normpath(os.path.join(DATAPATH, 
+                    input_file = os.path.normpath(os.path.join(DATAPATH,
                                                                data_base))
         if input_file is None:
@@ -3280,13 +3235,13 @@
         if self.frame is not None:
             self.frame.set_input_file(input_file=input_file)
-         
-    def clean_plugin_models(self, path): 
+
+    def clean_plugin_models(self, path):
         """
         Delete plugin models  in app folder
-        
+
         :param path: path of the plugin_models folder in app
         """
         # do it only the first time app loaded
-        # delete unused model folder    
+        # delete unused model folder
         model_folder = os.path.join(PATH_APP, path)
         if os.path.exists(model_folder) and os.path.isdir(model_folder):
@@ -3300,12 +3255,12 @@
                     logging.error("gui_manager.clean_plugin_models:\n  %s" \
                                   % sys.exc_value)
-              
+
     def set_manager(self, manager):
         """
         Sets a reference to the application manager
-        of the GUI manager (Frame) 
+        of the GUI manager (Frame)
         """
         self.frame.set_manager(manager)
-        
+
     def build_gui(self):
         """
@@ -3318,14 +3273,14 @@
             raise
         self.frame.build_gui()
-        
+
     def set_welcome_panel(self, panel_class):
         """
         Set the welcome panel
-        
+
         :param panel_class: class of the welcome panel to be instantiated
-        
+
         """
         self.frame.welcome_panel_class = panel_class
-        
+
     def add_perspective(self, perspective):
         """
@@ -3333,5 +3288,5 @@
         """
         self.frame.add_perspective(perspective)
-    
+
     def window_placement(self, size):
         """
@@ -3350,8 +3305,8 @@
                 displayRect = screen.GetClientArea()
                 break
-        
-        posX, posY, displayWidth, displayHeight = displayRect        
+
+        posX, posY, displayWidth, displayHeight = displayRect
         customWidth, customHeight = size
-        
+
         # If the custom size is default, set 90% of the screen size
         if customWidth <= 0 and customHeight <= 0:
@@ -3367,5 +3322,5 @@
             if customHeight > displayHeight:
                 customHeight = displayHeight
-            
+
         # Note that when running Linux and using an Xming (X11) server on a PC
         # with a dual  monitor configuration, the reported display size may be
@@ -3374,30 +3329,30 @@
         # screen 'too big'.  If so, we assume a smaller width which means the
         # application will be placed towards the left hand side of the screen.
-        
+
         # If dual screen registered as 1 screen. Make width half.
         # MAC just follows the default behavior of pos
         if IS_WIN:
-            if displayWidth > (displayHeight*2):
-                if (customWidth == displayWidth):
-                    customWidth = displayWidth/2
+            if displayWidth > (displayHeight * 2):
+                if customWidth == displayWidth:
+                    customWidth = displayWidth / 2
                 # and set the position to be the corner of the screen.
                 posX = 0
                 posY = 0
-                
+
             # Make the position the middle of the screen. (Not 0,0)
             else:
-                posX = (displayWidth - customWidth)/2
-                posY = (displayHeight - customHeight)/2
-        # Return the suggested position and size for the application frame.    
+                posX = (displayWidth - customWidth) / 2
+                posY = (displayHeight - customHeight) / 2
+        # Return the suggested position and size for the application frame.
         return (posX, posY), (customWidth, customHeight), is_maximized
 
-    
-    def display_splash_screen(self, parent, 
+
+    def display_splash_screen(self, parent,
                               path=SPLASH_SCREEN_PATH):
         """Displays the splash screen.  It will exactly cover the main frame."""
-       
+
         # Prepare the picture.  On a 2GHz intel cpu, this takes about a second.
         image = wx.Image(path, wx.BITMAP_TYPE_PNG)
-        image.Rescale(SPLASH_SCREEN_WIDTH, 
+        image.Rescale(SPLASH_SCREEN_WIDTH,
                       SPLASH_SCREEN_HEIGHT, wx.IMAGE_QUALITY_HIGH)
         bm = image.ConvertToBitmap()
@@ -3413,8 +3368,8 @@
         # case the splash screen disappears upon entering the event loop.
         s_screen = wx.SplashScreen(bitmap=bm,
-                                   splashStyle=(wx.SPLASH_TIMEOUT|
+                                   splashStyle=(wx.SPLASH_TIMEOUT |
                                                 wx.SPLASH_CENTRE_ON_SCREEN),
-                                   style=(wx.SIMPLE_BORDER|
-                                          wx.FRAME_NO_TASKBAR|
+                                   style=(wx.SIMPLE_BORDER |
+                                          wx.FRAME_NO_TASKBAR |
                                           wx.FRAME_FLOAT_ON_PARENT),
                                    milliseconds=SS_MAX_DISPLAY_TIME,
@@ -3427,6 +3382,6 @@
         s_screen.Show()
         return s_screen
-        
-        
+
+
     def on_close_splash_screen(self, event):
         """
@@ -3442,5 +3397,5 @@
     Frame for panels
     """
-    def __init__(self, parent, panel, title="Untitled", size=(300,200)):
+    def __init__(self, parent, panel, title="Untitled", size=(300, 200)):
         """
         comment
@@ -3456,10 +3411,10 @@
             self.set_panel(panel)
         self.Show(False)
-    
+
     def show_data_panel(self, action):
         """
         """
         self.parent.show_data_panel(action)
-        
+
     def set_panel(self, panel):
         """
@@ -3471,5 +3426,5 @@
         width, height = self.parent._get_panels_size(panel)
         if hasattr(panel, "CENTER_PANE") and panel.CENTER_PANE:
-            width *= 0.6  
+            width *= 0.6
         self.SetSize((width, height))
         self.parent.put_icon(self)
@@ -3477,5 +3432,5 @@
         self.Bind(wx.EVT_CLOSE, self.OnClose)
         self.Show(False)
-    
+
     def set_panel_focus(self, event):
         """
@@ -3484,5 +3439,5 @@
             self.panel.SetFocus()
             self.parent.panel_on_focus = self.panel
-        
+
     def OnClose(self, event):
         """
@@ -3490,6 +3445,6 @@
         """
         self.panel.on_close(event)
-        
-if __name__ == "__main__": 
+
+if __name__ == "__main__":
     app = ViewApp(0)
     app.MainLoop()
