Index: src/sas/sasgui/perspectives/fitting/fitpanel.py
===================================================================
--- src/sas/sasgui/perspectives/fitting/fitpanel.py	(revision 998ca90ad87500d7d5fb3f4eb13105752a2f2952)
+++ src/sas/sasgui/perspectives/fitting/fitpanel.py	(revision e6de6b8b31744ebe652ab6206d60d0d20979c592)
@@ -10,6 +10,5 @@
 
 from sas.sasgui.guiframe.panel_base import PanelBase
-from sas.sasgui.guiframe.events import PanelOnFocusEvent
-from sas.sasgui.guiframe.events import StatusEvent
+from sas.sasgui.guiframe.events import PanelOnFocusEvent, StatusEvent
 from sas.sasgui.guiframe.dataFitting import check_data_validity
 from sas.sasgui.perspectives.fitting.simfitpage import SimultaneousFitPage
@@ -176,5 +175,5 @@
     def get_state(self):
         """
-         return the state of the current selected page
+        return the state of the current selected page
         """
         pos = self.GetSelection()
@@ -188,9 +187,9 @@
         """
 
-        #get number of pages
+        # get number of pages
         nop = self.GetPageCount()
-        #use while-loop, for-loop will not do the job well.
+        # use while-loop, for-loop will not do the job well.
         while (nop > 0):
-            #delete the first page until no page exists
+            # delete the first page until no page exists
             page = self.GetPage(0)
             if self._manager.parent.panel_on_focus == page:
@@ -198,9 +197,8 @@
             self._close_helper(selected_page=page)
             self.DeletePage(0)
-            nop = nop - 1
-
-        # save the title of the last page tab added
+            nop = self.GetPageCount()
+        # Clear list of names
         self.fit_page_name = {}
-        # list of existing fit page
+        # Clear list of opened pages
         self.opened_pages = {}
         self.fit_page_index = 0
@@ -214,5 +212,5 @@
         if state is not None:
             for uid, panel in self.opened_pages.iteritems():
-                #Don't return any panel is the exact same page is created
+                # Don't return any panel is the exact same page is created
                 if uid == panel.uid and panel.data == state.data:
                     # the page is still opened
@@ -222,8 +220,8 @@
             if not page_is_opened:
                 if state.data.__class__.__name__ != 'list':
-                    #To support older state file format
+                    # To support older state file format
                     list_data = [state.data]
                 else:
-                    #Todo: need new file format for the list
+                    # Todo: need new file format for the list
                     list_data = state.data
                 panel = self._manager.add_fit_page(data=list_data)
@@ -240,6 +238,5 @@
         Clear and close all panels, used by guimanager
         """
-
-        #close all panels only when svs file opened
+        # close all panels only when svs file opened
         self.close_all()
         self._manager.mypanels = []
@@ -254,5 +251,5 @@
         selected_page = self.GetPage(self.GetSelection())
         if nbr_page == 1:
-            if selected_page.get_data() == None:
+            if selected_page.get_data() is not None:
                 if event is not None:
                     event.Veto()
@@ -272,6 +269,6 @@
 
                 if data is None:
-                    #the fitpanel exists and only the initial fit page is open
-                    #with no selected data
+                    # the fitpanel exists and only the initial fit page is open
+                    # with no selected data
                     return
                 if data.id == deleted_data.id:
@@ -285,5 +282,4 @@
 
         :param manager: instance of plugin fitting
-
         """
         self._manager = manager
@@ -334,5 +330,5 @@
         else:
             self.batch_page = SimultaneousFitPage(self, batch_on=True,
-                                                   page_finder=page_finder)
+                                                  page_finder=page_finder)
             self.batch_page.window_caption = caption
             self.batch_page.window_name = caption
@@ -347,16 +343,6 @@
         add an empty page
         """
-        """
         if self.batch_on:
             from batchfitpage import BatchFitPage
-            panel = BatchFitPage(parent=self)
-            #Increment index of batch page
-            self.batch_page_index += 1
-            index = self.batch_page_index
-        else:
-        """
-        from fitpage import FitPage
-        from batchfitpage import BatchFitPage
-        if self.batch_on:
             panel = BatchFitPage(parent=self)
             self.batch_page_index += 1
@@ -365,4 +351,5 @@
         else:
             # Increment index of fit page
+            from fitpage import FitPage
             panel = FitPage(parent=self)
             self.fit_page_index += 1
@@ -442,9 +429,9 @@
         page = None
         for p in self.opened_pages.values():
-            #check if there is an empty page to fill up
+            # check if there is an empty page to fill up
             if not check_data_validity(p.get_data()) and p.batch_on:
 
-                #make sure data get placed in 1D empty tab if data is 1D
-                #else data get place on 2D tab empty tab
+                # make sure data get placed in 1D empty tab if data is 1D
+                # else data get place on 2D tab empty tab
                 enable2D = p.get_view_mode()
                 if (data.__class__.__name__ == "Data2D" and enable2D)\
@@ -459,13 +446,13 @@
                 data_type = dlg.get_data()
                 dlg.Destroy()
-                if page  is None:
+                if page is None:
                     page = self.add_empty_page()
                 if data_type == 1:
-                    #user has selected only data1D
+                    # user has selected only data1D
                     page.fill_data_combobox(data_1d_list)
                 elif data_type == 2:
                     page.fill_data_combobox(data_2d_list)
             else:
-                #the batch analysis is canceled
+                # the batch analysis is canceled
                 dlg.Destroy()
                 return None
@@ -504,5 +491,5 @@
             try:
                 data = data_list[0]
-            except:
+            except Exception:
                 # for 'fitv' files
                 data_list = [data]
@@ -512,16 +499,16 @@
                 return None
         for page in self.opened_pages.values():
-            #check if the selected data existing in the fitpanel
+            # check if the selected data existing in the fitpanel
             pos = self.GetPageIndex(page)
             if not check_data_validity(page.get_data()) and not page.batch_on:
-                #make sure data get placed in 1D empty tab if data is 1D
-                #else data get place on 2D tab empty tab
+                # make sure data get placed in 1D empty tab if data is 1D
+                # else data get place on 2D tab empty tab
                 enable2D = page.get_view_mode()
                 if (data.__class__.__name__ == "Data2D" and enable2D)\
-                or (data.__class__.__name__ == "Data1D" and not enable2D):
+                   or (data.__class__.__name__ == "Data1D" and not enable2D):
                     page.batch_on = self.batch_on
                     page._set_save_flag(not page.batch_on)
                     page.fill_data_combobox(data_list)
-                    #caption = "FitPage" + str(self.fit_page_index)
+                    # caption = "FitPage" + str(self.fit_page_index)
                     self.SetPageText(pos, page.window_caption)
                     self.SetSelection(pos)
@@ -575,8 +562,8 @@
         Delete the given page from the notebook
         """
-        #remove hint page
-        #if selected_page == self.hint_page:
+        # remove hint page
+        # if selected_page == self.hint_page:
         #    return
-        ## removing sim_page
+        # removing sim_page
         if selected_page == self.sim_page:
             self._manager.sim_page = None
@@ -585,25 +572,17 @@
             self._manager.batch_page = None
             return
-        """
-        # The below is not working when delete #5 and still have #6.
-        if selected_page.__class__.__name__ == "FitPage":
-            self.fit_page_index -= 1
-        else:
-            self.batch_page_index -= 1
-        """
-        ## closing other pages
+        # closing other pages
         state = selected_page.createMemento()
         page_finder = self._manager.get_page_finder()
-        ## removing fit page
+        # removing fit page
         data = selected_page.get_data()
-        #Don' t remove plot for 2D
+        # Don' t remove plot for 2D
         flag = True
         if data.__class__.__name__ == 'Data2D':
             flag = False
         if selected_page in page_finder:
-            #Delete the name of the page into the list of open page
+            # Delete the name of the page into the list of open page
             for uid, list in self.opened_pages.iteritems():
-                #Don't return any panel is the exact same page is created
-
+                # Don't return any panel is the exact same page is created
                 if flag and selected_page.uid == uid:
                     self._manager.remove_plot(uid, theory=False)
@@ -611,21 +590,21 @@
             del page_finder[selected_page]
 
-        #Delete the name of the page into the list of open page
+        # Delete the name of the page into the list of open page
         for uid, list in self.opened_pages.iteritems():
-            #Don't return any panel is the exact same page is created
+            # Don't return any panel is the exact same page is created
             if selected_page.uid == uid:
                 del self.opened_pages[selected_page.uid]
                 break
-        ##remove the check box link to the model name of this page (selected_page)
+        # remove the check box link to the model name of the selected_page
         try:
             self.sim_page.draw_page()
         except:
-            ## that page is already deleted no need to remove check box on
-            ##non existing page
+            # that page is already deleted no need to remove check box on
+            # non existing page
             pass
         try:
             self.batch_page.draw_page()
         except:
-            ## that page is already deleted no need to remove check box on
-            ##non existing page
+            # that page is already deleted no need to remove check box on
+            # non existing page
             pass
