source: sasview/src/sas/perspectives/fitting/fitpanel.py @ 573e7034

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 573e7034 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 23.9 KB
RevLine 
[f32d144]1"""
2FitPanel class contains fields allowing to fit  models and  data
[e2f1023]3
[f32d144]4:note: For Fit to be performed the user should check at least one parameter
5    on fit Panel window.
6   
7"""
[d89f09b]8import wx
[1b1bbf9]9from wx.aui import AuiNotebook as nb
[a93f525]10
[79492222]11from sas.guiframe.panel_base import PanelBase
12from sas.guiframe.events import PanelOnFocusEvent
13from sas.guiframe.events import StatusEvent
14from sas.guiframe.dataFitting import check_data_validity
[66ff250]15
[cfc0913]16import basepage
[6bbeacd4]17import models
[330573d]18_BOX_WIDTH = 80
19
20
[f32d144]21class FitPanel(nb, PanelBase):
[d89f09b]22    """
[5062bbf]23    FitPanel class contains fields allowing to fit  models and  data
24   
25    :note: For Fit to be performed the user should check at least one parameter
[d89f09b]26        on fit Panel window.
27       
28    """
29    ## Internal name for the AUI manager
30    window_name = "Fit panel"
31    ## Title to appear on top of the window
32    window_caption = "Fit Panel "
[2139c3f]33    CENTER_PANE = True
[7437880]34   
[6bbeacd4]35    def __init__(self, parent, manager=None, *args, **kwargs):
[5062bbf]36        """
37        """
[1b1bbf9]38        nb.__init__(self, parent, -1,
[f32d144]39                    style=wx.aui.AUI_NB_WINDOWLIST_BUTTON|
[3244cbe1]40                    wx.aui.AUI_NB_DEFAULT_STYLE|
41                    wx.CLIP_CHILDREN)
[3cd5806]42        PanelBase.__init__(self, parent)
[1b1bbf9]43        #self.SetWindowStyleFlag(style=nb.FNB_FANCY_TABS)
[6bbeacd4]44        self._manager = manager
[340c2b3]45        self.parent = parent
46        self.event_owner = None
[d89f09b]47        #dictionary of miodel {model class name, model class}
[6bbeacd4]48        self.menu_mng = models.ModelManager()
[b2d9826]49        self.model_list_box = self.menu_mng.get_model_list()
[f32d144]50        #pageClosedEvent = nb.EVT_FLATNOTEBOOK_PAGE_CLOSING
[ea5fa58]51        self.model_dictionary = self.menu_mng.get_model_dictionary()
[f22e626]52        self.pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE
[1b1bbf9]53       
[f22e626]54        self.Bind(self.pageClosedEvent, self.on_close_page)
[f32d144]55        ## save the title of the last page tab added
[2f189dc]56        self.fit_page_name = {}
[cfc0913]57        ## list of existing fit page
[2f189dc]58        self.opened_pages = {}
[f32d144]59        #index of fit page
[cc31608]60        self.fit_page_index = 0
61        #index of batch page
62        self.batch_page_index = 0
[f32d144]63        #page of simultaneous fit
[ffa69b6]64        self.sim_page = None
[fa02d95]65        self.batch_page = None
[eff93b8]66        self.fit_engine_type = "bumps"
[cfc0913]67        ## get the state of a page
68        self.Bind(basepage.EVT_PAGE_INFO, self._onGetstate)
[330573d]69        self.Bind(basepage.EVT_PREVIOUS_STATE, self._onUndo)
[fe496eeb]70        self.Bind(basepage.EVT_NEXT_STATE, self._onRedo)
[90a7bbd]71        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.on_page_changing)
[f22e626]72        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED, self.on_closed)
[ae84427]73       
[f22e626]74    def on_closed(self, event):
75        """
76        """
[394ffa7]77        if self.GetPageCount() == 0:
78            self.add_empty_page()
79            self.enable_close_button()
[f22e626]80       
[4e78f56]81    def save_project(self, doc=None):
82        """
83        return an xml node containing state of the panel
84         that guiframe can write to file
85        """
[72bd8e7]86        msg = ""
[4e78f56]87        for uid, page in self.opened_pages.iteritems():
[72bd8e7]88            if page.batch_on:
89                pos = self.GetPageIndex(page)
[fa02d95]90                if pos != -1 and page not in [self.sim_page, self.batch_page]:
[72bd8e7]91                    msg += "%s .\n" % str(self.GetPageText(pos))
92            else:
93                data = page.get_data()
94                # state must be cloned
95                state = page.get_state().clone()
[3b148c3]96                if data is not None and page.model is not None:
[f32d144]97                    new_doc = self._manager.state_reader.write_toXML(data,
98                                                                     state)
[72bd8e7]99                    if doc != None and hasattr(doc, "firstChild"):
100                        child = new_doc.firstChild.firstChild
[f32d144]101                        doc.firstChild.appendChild(child)
[72bd8e7]102                    else:
[f32d144]103                        doc = new_doc
[72bd8e7]104        if msg.strip() != "":
105            temp = "Save Project is not supported for Batch page.\n"
106            temp += "The following pages will not be save:\n"
107            message = temp + msg
108            wx.PostEvent(self._manager.parent, StatusEvent(status=message,
109                                                            info="warning"))
[f32d144]110        return doc
[6bbeacd4]111   
[66ff250]112    def _on_engine_change(self, name='scipy'):
113        """
114        """
115        for panel in self.opened_pages.values():
116            self.set_engine_helper(panel=panel, name=name)
117           
118    def set_engine_helper(self, panel, name='scipy'):
119        """
120        """
121        self.fit_engine_type = name
[fa02d95]122        if panel not in[self.batch_page, self.sim_page]:
[66ff250]123            panel._on_engine_change(name=self.fit_engine_type)
124               
[b2d9826]125    def update_model_list(self):
126        """
127        """
[9466f2d6]128        temp = self.menu_mng.update()
129        if len(temp):
130            self.model_list_box = temp
131        return temp
[916f5c0]132   
133    def reset_pmodel_list(self):
134        """
135        """
136        temp = self.menu_mng.pulgins_reset()
137        if len(temp):
138            self.model_list_box = temp
139        return temp
140   
[f32d144]141    def get_page_by_id(self, uid):
[6bbeacd4]142        """
143        """
[66ff250]144        if uid not in self.opened_pages:
145            msg = "Fitpanel cannot find ID: %s in self.opened_pages" % str(uid)
[6bbeacd4]146            raise ValueError, msg
147        else:
[66ff250]148            return self.opened_pages[uid]
[31b0c47]149       
[90a7bbd]150    def on_page_changing(self, event):
[6bbeacd4]151        """
[f22e626]152        calls the function when the current event handler has exited. avoiding
153        to call panel on focus on a panel that is currently deleted
154        """
155        wx.CallAfter(self.helper_on_page_change)
156       
157    def helper_on_page_change(self):
158        """
[6bbeacd4]159        """
[90a7bbd]160        pos = self.GetSelection()
161        if pos != -1:
162            selected_page = self.GetPage(pos)
[ae84427]163            wx.PostEvent(self._manager.parent, 
164                         PanelOnFocusEvent(panel=selected_page))
[e4c9030]165        self.enable_close_button()
[f22e626]166       
[3cd5806]167    def on_set_focus(self, event):
168        """
169        """
170        pos = self.GetSelection()
[90a7bbd]171        if pos != -1:
172            selected_page = self.GetPage(pos)
[ae84427]173            wx.PostEvent(self._manager.parent, 
174                         PanelOnFocusEvent(panel=selected_page))
[3cd5806]175       
[c8deee5]176    def get_data(self):
177        """
178        get the data in the current page
179        """
180        pos = self.GetSelection()
[90a7bbd]181        if pos != -1:
182            selected_page = self.GetPage(pos)
183            return selected_page.get_data()
[c8deee5]184   
[6d8bad4]185    def set_model_state(self, state):
[e88ebfd]186        """
187        receive a state to reset the model in the current page
188        """
189        pos = self.GetSelection()
190        if pos != -1:
191            selected_page = self.GetPage(pos)
192            selected_page.set_model_state(state)
193           
[c8deee5]194    def get_state(self):
195        """
196         return the state of the current selected page
197        """
198        pos = self.GetSelection()
[90a7bbd]199        if pos != -1:
200            selected_page = self.GetPage(pos)
201            return selected_page.get_state()
[c8deee5]202   
[ac2dc0e]203    def close_all(self):
204        """
[8897d66]205        remove all pages, used when a svs file is opened
206        """
[90a7bbd]207       
[8897d66]208        #get number of pages
209        nop = self.GetPageCount()
210        #use while-loop, for-loop will not do the job well.
[f32d144]211        while (nop > 0):
[8897d66]212            #delete the first page until no page exists
213            page = self.GetPage(0)
[90a7bbd]214            if self._manager.parent.panel_on_focus == page:
215                self._manager.parent.panel_on_focus = None
[8897d66]216            self._close_helper(selected_page=page)
217            self.DeletePage(0)
218            nop = nop - 1
[90a7bbd]219           
[ac2dc0e]220        ## save the title of the last page tab added
221        self.fit_page_name = {}
222        ## list of existing fit page
[f32d144]223        self.opened_pages = {}
[ac2dc0e]224         
[31b0c47]225    def set_state(self, state):
226        """
[5062bbf]227        Restore state of the panel
[31b0c47]228        """
229        page_is_opened = False
230        if state is not None:
[66ff250]231            for uid, panel in self.opened_pages.iteritems():
[31b0c47]232                #Don't return any panel is the exact same page is created
[4bee68d]233                if uid == panel.uid and panel.data == state.data:
[31b0c47]234                    # the page is still opened
235                    panel.reset_page(state=state)
[f32d144]236                    panel.save_current_state()
[31b0c47]237                    page_is_opened = True
238            if not page_is_opened:
[ea8283d]239                if state.data.__class__.__name__ != 'list':
240                    #To support older state file format
241                    list_data = [state.data]
242                else:
243                    #Todo: need new file format for the list
244                    list_data = state.data
245                panel = self._manager.add_fit_page(data=list_data)
[31b0c47]246                # add data associated to the page created
[f32d144]247                if panel is not None:
248                    self._manager.store_data(uid=panel.uid,
[ea8283d]249                                             data_list=list_data,
[4bee68d]250                                             caption=panel.window_caption)
[31b0c47]251                    panel.reset_page(state=state)
[645f9b6]252                    panel.save_current_state()
[31b0c47]253                   
[90a7bbd]254    def clear_panel(self):
[9b18735]255        """
256        Clear and close all panels, used by guimanager
257        """
[90a7bbd]258       
259        #close all panels only when svs file opened
260        self.close_all()
261        self._manager.mypanels = []
262       
[ac2dc0e]263    def on_close_page(self, event=None):
[51d47b5]264        """
[5062bbf]265        close page and remove all references to the closed page
[51d47b5]266        """
[d361b462]267        nbr_page = self.GetPageCount()
[51d47b5]268        selected_page = self.GetPage(self.GetSelection())
[f22e626]269        if nbr_page == 1:
270            if selected_page.get_data() == None:
271                if event is not None:
272                    event.Veto()
[f32d144]273                return
[2f189dc]274        self._close_helper(selected_page=selected_page)
[9853ad0]275       
[2f189dc]276    def close_page_with_data(self, deleted_data):
277        """
[5062bbf]278        close a fit page when its data is completely remove from the graph
[2f189dc]279        """
[784e2fa]280        if deleted_data is None:
281            return
[2f189dc]282        for index in range(self.GetPageCount()):
[f32d144]283            selected_page = self.GetPage(index)
284            if hasattr(selected_page, "get_data"):
[2f189dc]285                data = selected_page.get_data()
[ac2dc0e]286               
[784e2fa]287                if data is None:
[f32d144]288                    #the fitpanel exists and only the initial fit page is open
[784e2fa]289                    #with no selected data
290                    return
[f22e626]291                if data.id == deleted_data.id:
[2f189dc]292                    self._close_helper(selected_page)
293                    self.DeletePage(index)
294                    break
[d89f09b]295       
296    def set_manager(self, manager):
297        """
[5062bbf]298        set panel manager
299       
300        :param manager: instance of plugin fitting
301       
[d89f09b]302        """
[c8deee5]303        self._manager = manager
[3cd5806]304        for pos in range(self.GetPageCount()):
305            page = self.GetPage(pos)
306            if page is not None:
307                page.set_manager(self._manager)
[a93f525]308
[ea5fa58]309    def set_model_list(self, dict):
[f32d144]310        """
311        copy a dictionary of model into its own dictionary
312       
[df7a7e3]313        :param m_dict: dictionnary made of model name as key and model class
[f32d144]314        as value
315        """
[ea5fa58]316        self.model_list_box = dict
[51d47b5]317       
[df7a7e3]318    def set_model_dict(self, m_dict):
319        """
320        copy a dictionary of model name -> model object
321
322        :param m_dict: dictionary linking model name -> model object
323        """
324
[c77d859]325    def get_current_page(self):
326        """
[5062bbf]327        :return: the current page selected
328       
[c77d859]329        """
[6bbeacd4]330        return self.GetPage(self.GetSelection())
[c77d859]331   
[b6a181b]332    def add_sim_page(self, caption="Const & Simul Fit"):
[925a30e]333        """
[5062bbf]334        Add the simultaneous fit page
[925a30e]335        """
[51d47b5]336        from simfitpage import SimultaneousFitPage
[fa02d95]337        page_finder = self._manager.get_page_finder()
[b6a181b]338        if caption == "Const & Simul Fit":
[f32d144]339            self.sim_page = SimultaneousFitPage(self, page_finder=page_finder,
[fa02d95]340                                                 id=-1, batch_on=False)
341            self.sim_page.window_caption = caption
342            self.sim_page.window_name = caption
343            self.sim_page.uid = wx.NewId()
344            self.AddPage(self.sim_page, caption, True)
345            self.sim_page.set_manager(self._manager)
346            self.enable_close_button()
347            return self.sim_page
348        else:
349            self.batch_page = SimultaneousFitPage(self, batch_on=True,
350                                                   page_finder=page_finder)
351            self.batch_page.window_caption = caption
352            self.batch_page.window_name = caption
353            self.batch_page.uid = wx.NewId()
354            self.AddPage(self.batch_page, caption, True)
355            self.batch_page.set_manager(self._manager)
356            self.enable_close_button()
357            return self.batch_page
[6bbeacd4]358 
[2f189dc]359    def add_empty_page(self):
[9853ad0]360        """
[5062bbf]361        add an empty page
[9853ad0]362        """
[3f36675]363        """
[cc31608]364        if self.batch_on:
365            from batchfitpage import BatchFitPage
366            panel = BatchFitPage(parent=self)
367            #Increment index of batch page
368            self.batch_page_index += 1
369            index = self.batch_page_index
370        else:
[3f36675]371        """
372        from fitpage import FitPage
[ea5fa58]373        panel = FitPage(parent=self)
[aefc09f]374        if self.batch_on:
375            self.batch_page_index += 1
[55bb249c]376            caption = "BatchPage" + str(self.batch_page_index)
[aefc09f]377            panel.set_index_model(self.batch_page_index)
378        else:
379            #Increment index of fit page
380            self.fit_page_index += 1
[55bb249c]381            caption = "FitPage" + str(self.fit_page_index)
[aefc09f]382            panel.set_index_model(self.fit_page_index)
[22ce7e2]383        panel.batch_on = self.batch_on
[61523e2]384        panel._set_save_flag(not panel.batch_on)
[df7a7e3]385        panel.set_model_dictionary(self.model_dictionary)
[eddb6ec]386        panel.populate_box(model_dict=self.model_list_box)
[ea5fa58]387        panel.formfactor_combo_init()
[c8deee5]388        panel.set_manager(self._manager)
[aefc09f]389        panel.window_caption = caption
390        panel.window_name = caption
[ae4ade7]391        self.AddPage(panel, caption, select=True)
[66ff250]392        self.opened_pages[panel.uid] = panel
393        self.set_engine_helper(panel=panel)
[aefc09f]394        self._manager.create_fit_problem(panel.uid)
395        self._manager.page_finder[panel.uid].add_data(panel.get_data())
[f22e626]396        self.enable_close_button()
[dafc36f]397        panel.on_set_focus(None)
[f32d144]398        return panel
[2f189dc]399   
[f22e626]400    def enable_close_button(self):
401        """
[f32d144]402        display the close button on tab for more than 1 tabs else remove the
[f22e626]403        close button
404        """
405        if self.GetPageCount() <= 1:
[f32d144]406            style = self.GetWindowStyleFlag()
[3f36675]407            flag = wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
408            if style & wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB == flag:
[f22e626]409                style = style & ~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
410                self.SetWindowStyle(style)
411        else:
412            style = self.GetWindowStyleFlag()
[3f36675]413            flag = wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
414            if style & wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB != flag:
[f22e626]415                style |= wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
416                self.SetWindowStyle(style)
417           
[8ee56a9]418    def delete_data(self, data):
419        """
420        Delete the given data
421        """
[f22e626]422        if data.__class__.__name__ != "list":
423            raise ValueError, "Fitpanel delete_data expect list of id"
424        else:
425            n = self.GetPageCount()
426            for page in self.opened_pages.values():
427                pos = self.GetPageIndex(page)
428                temp_data = page.get_data()
429                if temp_data is not None and temp_data.id in data:
430                    self.SetSelection(pos)
431                    self.on_close_page(event=None)
432                    temp = self.GetSelection()
433                    self.DeletePage(temp)
[f32d144]434            if self.GetPageCount() == 0:
[e4c9030]435                self._manager.on_add_new_page(event=None)
[f22e626]436       
[3f36675]437    def set_data_on_batch_mode(self, data_list):
438        """
439        Add all data to a single tab when the application is on Batch mode.
440        However all data in the set of data must be either 1D or 2D type.
441        This method presents option to select the data type before creating a
[f32d144]442        tab.
[3f36675]443        """
444        data_1d_list = []
445        data_2d_list = []
[2e643a8]446        group_id_1d = wx.NewId()
[4225aed]447        # separate data into data1d and data2d list
[3f36675]448        for data in data_list:
449            if data.__class__.__name__ == "Data1D":
[2e643a8]450                data.group_id = group_id_1d
[3f36675]451                data_1d_list.append(data)
452            if data.__class__.__name__ == "Data2D":
[017e0390]453                data.group_id = wx.NewId()
[3f36675]454                data_2d_list.append(data)
455        page = None
456        for p in self.opened_pages.values():
[f32d144]457            #check if there is an empty page to fill up
[dafc36f]458            if not check_data_validity(p.get_data()) and p.batch_on:
[f3f6746]459               
460                #make sure data get placed in 1D empty tab if data is 1D
461                #else data get place on 2D tab empty tab
462                enable2D = p.get_view_mode()
463                if (data.__class__.__name__ == "Data2D" and enable2D)\
464                or (data.__class__.__name__ == "Data1D" and not enable2D):
465                    page = p
466                    break
[3f36675]467        if data_1d_list and data_2d_list:
468            # need to warning the user that this batch is a special case
[79492222]469            from sas import BatchDataDialog
[3f36675]470            dlg = BatchDataDialog(self)
471            if dlg.ShowModal() == wx.ID_OK:
472                data_type = dlg.get_data()
473                dlg.Destroy()
474                if page  is None:
475                    page = self.add_empty_page()
476                if data_type == 1:
477                    #user has selected only data1D
478                    page.fill_data_combobox(data_1d_list)
479                elif data_type == 2:
480                    page.fill_data_combobox(data_2d_list)
481            else:
482                #the batch analysis is canceled
[f32d144]483                dlg.Destroy()
484                return None
[3f36675]485        else:
486            if page is None:
487                page = self.add_empty_page()
488            if data_1d_list and not data_2d_list:
[f32d144]489                #only on type of data
[3f36675]490                page.fill_data_combobox(data_1d_list)
491            elif not data_1d_list and data_2d_list:
492                page.fill_data_combobox(data_2d_list)
[72bd8e7]493               
[aefc09f]494        pos = self.GetPageIndex(page)
[05efe88]495        page.batch_on = self.batch_on
[61523e2]496        page._set_save_flag(not page.batch_on)
[72bd8e7]497        self.SetSelection(pos)
[3f36675]498        self.opened_pages[page.uid] = page
499        return page
500   
[cc31608]501    def set_data(self, data_list):
[f32d144]502        """
[5062bbf]503        Add a fitting page on the notebook contained by fitpanel
504       
505        :param data: data to fit
506       
[f32d144]507        :return panel : page just added for further used.
[3f36675]508        is used by fitting module
[5062bbf]509       
[2f189dc]510        """
[cc31608]511        if not data_list:
[2f189dc]512            return None
[cc31608]513        if self.batch_on:
[f32d144]514            return self.set_data_on_batch_mode(data_list)
[cc31608]515        else:
516            data = None
[7f76f89]517            try:
518                data = data_list[0]
519            except:
520                # for 'fitv' files
521                data_list = [data]
522                data = data_list[0]
523               
[cc31608]524            if data is None:
525                return None
[6bbeacd4]526        for page in self.opened_pages.values():
527            #check if the selected data existing in the fitpanel
528            pos = self.GetPageIndex(page)
[dafc36f]529            if not check_data_validity(page.get_data()) and not page.batch_on:
[cc31608]530                #make sure data get placed in 1D empty tab if data is 1D
531                #else data get place on 2D tab empty tab
[a5701e6]532                enable2D = page.get_view_mode()
533                if (data.__class__.__name__ == "Data2D" and enable2D)\
534                or (data.__class__.__name__ == "Data1D" and not enable2D):
[05efe88]535                    page.batch_on = self.batch_on
[61523e2]536                    page._set_save_flag(not page.batch_on)
[cc31608]537                    page.fill_data_combobox(data_list)
[dafc36f]538                    #caption = "FitPage" + str(self.fit_page_index)
539                    self.SetPageText(pos, page.window_caption)
[cc31608]540                    self.SetSelection(pos)
541                    return page
[aefc09f]542        #create new page and add data
[6bbeacd4]543        page = self.add_empty_page()
[9f391af]544        pos = self.GetPageIndex(page)
[cc31608]545        page.fill_data_combobox(data_list)
[66ff250]546        self.opened_pages[page.uid] = page
[09ef5a60]547        self.SetSelection(pos)
[6bbeacd4]548        return page
549       
550    def _onGetstate(self, event):
[cfc0913]551        """
[5062bbf]552        copy the state of a page
[cfc0913]553        """
[6bbeacd4]554        page = event.page
[66ff250]555        if page.uid in self.fit_page_name:
[f32d144]556            self.fit_page_name[page.uid].appendItem(page.createMemento())
[cfc0913]557           
[4e78f56]558    def _onUndo(self, event):
[330573d]559        """
[5062bbf]560        return the previous state of a given page is available
[330573d]561        """
[f32d144]562        page = event.page
[66ff250]563        if page.uid in self.fit_page_name:
[f32d144]564            if self.fit_page_name[page.uid].getCurrentPosition() == 0:
[330573d]565                state = None
566            else:
[66ff250]567                state = self.fit_page_name[page.uid].getPreviousItem()
[fe496eeb]568                page._redo.Enable(True)
[330573d]569            page.reset_page(state)
[fe496eeb]570       
[f32d144]571    def _onRedo(self, event):
[fe496eeb]572        """
[5062bbf]573        return the next state available
[f32d144]574        """
575        page = event.page
[66ff250]576        if page.uid in self.fit_page_name:
[f32d144]577            length = len(self.fit_page_name[page.uid])
578            if self.fit_page_name[page.uid].getCurrentPosition() == length - 1:
[fe496eeb]579                state = None
580                page._redo.Enable(False)
[3b9e023]581                page._redo.Enable(True)
[fe496eeb]582            else:
[f32d144]583                state = self.fit_page_name[page.uid].getNextItem()
584            page.reset_page(state)
[2f189dc]585                 
586    def _close_helper(self, selected_page):
[3f1af74]587        """
[5062bbf]588        Delete the given page from the notebook
[3f1af74]589        """
[2f189dc]590        #remove hint page
[1b1bbf9]591        #if selected_page == self.hint_page:
592        #    return
[2f189dc]593        ## removing sim_page
[f32d144]594        if selected_page == self.sim_page:
595            self._manager.sim_page = None
[2f189dc]596            return
[f32d144]597        if selected_page == self.batch_page:
598            self._manager.batch_page = None
[fa02d95]599            return
[5e48acb]600        """
601        # The below is not working when delete #5 and still have #6.
[cc31608]602        if selected_page.__class__.__name__ == "FitPage":
603            self.fit_page_index -= 1
604        else:
605            self.batch_page_index -= 1
[5e48acb]606        """
[2f189dc]607        ## closing other pages
608        state = selected_page.createMemento()
[f32d144]609        page_finder = self._manager.get_page_finder()
[2f189dc]610        ## removing fit page
[c6036f5]611        data = selected_page.get_data()
612        #Don' t remove plot for 2D
613        flag = True
614        if data.__class__.__name__ == 'Data2D':
615            flag = False
[2f189dc]616        if selected_page in page_finder:
617            #Delete the name of the page into the list of open page
[66ff250]618            for uid, list in self.opened_pages.iteritems():
[2f189dc]619                #Don't return any panel is the exact same page is created
[6bbeacd4]620               
[66ff250]621                if flag and selected_page.uid == uid:
622                    self._manager.remove_plot(uid, theory=False)
[f32d144]623                    break
[2f189dc]624            del page_finder[selected_page]
[f32d144]625 
[2f189dc]626        #Delete the name of the page into the list of open page
[66ff250]627        for uid, list in self.opened_pages.iteritems():
[2f189dc]628            #Don't return any panel is the exact same page is created
[66ff250]629            if selected_page.uid == uid:
630                del self.opened_pages[selected_page.uid]
[f32d144]631                break
[81a7b6c]632        ##remove the check box link to the model name of this page (selected_page)
633        try:
634            self.sim_page.draw_page()
635        except:
636            ## that page is already deleted no need to remove check box on
637            ##non existing page
[f32d144]638            pass
[fa02d95]639        try:
640            self.batch_page.draw_page()
641        except:
642            ## that page is already deleted no need to remove check box on
643            ##non existing page
[f32d144]644            pass
Note: See TracBrowser for help on using the repository browser.