source: sasview/sansview/perspectives/fitting/fitpanel.py @ 7292e8a

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 7292e8a was 3199b59, checked in by Gervaise Alina <gervyh@…>, 16 years ago

small bug fixed

  • Property mode set to 100644
File size: 11.2 KB
RevLine 
[d89f09b]1import wx
[26bf293]2import wx.aui
[d89f09b]3import wx.lib
4import numpy
5import string ,re
6#import models
7_BOX_WIDTH = 80
8
[0b92f4f4]9(FitPageEvent, EVT_FIT_PAGE)   = wx.lib.newevent.NewEvent()
[26bf293]10class FitPanel(wx.aui.AuiNotebook):   
11#class FitPanel(wx.aui.AuiNotebook,wx.panel):
[d89f09b]12    """
13        FitPanel class contains fields allowing to fit  models and  data
14        @note: For Fit to be performed the user should check at least one parameter
15        on fit Panel window.
16       
17    """
18    ## Internal name for the AUI manager
19    window_name = "Fit panel"
20    ## Title to appear on top of the window
21    window_caption = "Fit Panel "
[2139c3f]22    CENTER_PANE = True
[d89f09b]23    def __init__(self, parent, *args, **kwargs):
[26bf293]24       
[51d47b5]25        #wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_SCROLL_BUTTONS )
26        wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_DEFAULT_STYLE  )
[94999eb]27       
[26bf293]28       
[d89f09b]29        self.manager=None
30        self.parent=parent
31        self.event_owner=None
[26bf293]32       
33        pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE
34        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)
[94999eb]35        #Creating the default page --welcomed page
[51d47b5]36        self.about_page=None
[94999eb]37        from sans.guiframe.welcome_panel import PanelAbout
38        self.about_page = PanelAbout(self, -1)
39        self.AddPage(self.about_page,"welcome!")
40        #self.about_page.Disable()
41        #Creating a page for simultaneous fitting
[51d47b5]42       
[d89f09b]43       
[2a8fac1]44        self._mgr = self.GetAuiManager()
[26bf293]45
[d89f09b]46       
47        #dictionary of miodel {model class name, model class}
48        self.model_list_box={}
49        # save the title of the last page tab added
[1fc7411]50        self.fit_page_name=[]
[060b857]51        self.draw_model_name=None
[f39511b]52        #model page info
53        self.model_page_number=None
[10c43a5]54       
[f39511b]55        self.model_page=None
[51d47b5]56        self.sim_page=None
[6bcdad1]57        # increment number for model name
58        self.count=0
[f39511b]59        #updating the panel
[26bf293]60        self.Update()
[d89f09b]61        self.Center()
[2a8fac1]62       
63       
[26bf293]64    def onClosePage(self, event):
[51d47b5]65        """
[26bf293]66        self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
[888e62c]67        #print "went here",self.get_current_page(), self.GetPage(0)
[26bf293]68        #event.Skip()
69        if self.GetPageCount() <= 2:
[888e62c]70            #print "wente here"
[26bf293]71           
72            # Prevent last tab from being closed
73            self.ToggleWindowStyle(~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
[51d47b5]74        """
75        selected_page = self.GetPage(self.GetSelection())
76        page_number = self.GetSelection()
77        if self.sim_page != selected_page and selected_page!=self.about_page:
78            # remove the check box link to the model name of this page (selected_page)
[3199b59]79            if self.sim_page !=None :
80                self.sim_page.remove_model(selected_page)
[51d47b5]81            #remove that page from page_finder of fitting module
82            page_finder=self.manager.get_page_finder() 
83            for page, value in page_finder.iteritems():
84                if page==selected_page:
85                    del page_finder[page]
86                    break
87            #Delete the page from notebook
88           
89            #print "on close",selected_page.name,self.GetPageText(page_number),self.draw_model_name
[26bf293]90           
[51d47b5]91            if selected_page.name in self.fit_page_name:
92                self.fit_page_name.remove(selected_page.name)
93               
94            if selected_page.name== self.draw_model_name:
95                print "went here"
96                self.draw_model_name=None
97                self.model_page=None
98            if  page_number == 1:
99                self.model_page=None
100                self.draw_model_name=None
101            #selected_page.Destroy()
102            #self.RemovePage(page_number)
103            #i=self.DeletePage(page_number)
104        elif selected_page==self.about_page:
105            #selected_page.Destroy()
106            #self.DeletePage(page_number)
107            self.about_page=None
108        else:
109           
110            self.manager.sim_page=None 
111            #self.DeletePage(page_number)
[26bf293]112   
113
[7691125]114
[d89f09b]115       
116    def set_manager(self, manager):
117        """
118             set panel manager
119             @param manager: instance of plugin fitting
120        """
121        self.manager = manager
[51d47b5]122        #self.sim_page.set_manager(manager)
[d89f09b]123       
124    def set_owner(self,owner):
125        """
126            set and owner for fitpanel
127            @param owner: the class responsible of plotting
128        """
129        self.event_owner=owner
[51d47b5]130       
131    def add_sim_page(self):
132        from simfitpage import SimultaneousFitPage
133        self.sim_page = SimultaneousFitPage(self, id=-1)
134        self.AddPage(self.sim_page,caption="Simultaneous Fit",select=True)
135        self.sim_page.set_manager(self.manager)
136        return self.sim_page
[d89f09b]137       
[bcd6d51]138    def add_fit_page( self,data ):
[d89f09b]139        """
140            Add a fitting page on the notebook contained by fitpanel
141            @param panel: contains in the page to add
142            @param name: title of the page tab
143            @return panel : page just added for futher used. is used by fitting module
144        """     
[bcd6d51]145        try:
[55e13ab]146            name = data.name # item in Data1D
[bcd6d51]147        except:
148            name = 'Fit'
[6e659ae8]149       
[3e1a859]150        #if self.fit_page_name != name and self.draw_model_name !=name:
[6e659ae8]151        if not name in self.fit_page_name :
[94999eb]152            #self.about_page.Disable()
[6b44403]153            from fitpage1D import FitPage1D
154            panel = FitPage1D(self,data, -1)
[10c43a5]155            panel.name=name
[ef8b580]156            #m_name= "M"+str(self.count) 
[d89f09b]157            panel.set_manager(self.manager)
158            panel.set_owner(self.event_owner)
[9d31a8b]159           
[26bf293]160            self.AddPage(page=panel,caption=name,select=True)
[d89f09b]161            panel.populate_box( self.model_list_box)
[1fc7411]162            self.fit_page_name.append(name)
163   
[ef8b580]164            return panel #,m_name
[fee6059]165        else:
[ef8b580]166            return None #, None
[1c66bc5]167       
[3f1af74]168    def _help_add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50):
169        """
170            #TODO: fill in description
171           
172            @param qmin: mimimum Q
173            @param qmax: maximum Q
174            @param npts: number of Q points
175        """
[f39511b]176        from modelpage import ModelPage
[888e62c]177        #print "fitpanel model", model
[26bf293]178        panel = ModelPage(self,model,page_title, -1)
[f39511b]179        panel.set_manager(self.manager)
180        panel.set_owner(self.event_owner)
[26bf293]181        self.AddPage(page=panel,caption="Model",select=True)
[f39511b]182        panel.populate_box( self.model_list_box)
[ef8b580]183        panel.name = page_title
[f39511b]184        self.draw_model_name=page_title
[26bf293]185        self.model_page_number=self.GetSelection()
186        self.model_page=self.GetPage(self.GetSelection())
[f39511b]187       
[1c66bc5]188       
[3f1af74]189        # Set the range used to plot models
190        self.model_page.set_range(qmin, qmax, npts)
191       
[3dc83be]192        # We just created a model page, we are ready to plot the model
[32d802f]193        #self.manager.draw_model(model, model.name)
194        #FOR PLUGIN  for somereason model.name is = BASEcomponent
195        self.manager.draw_model(model, page_title)
[3f1af74]196       
[3dc83be]197       
198    def add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50, topmenu=False):
[1c66bc5]199        """
200            Add a model page only one  to display any model selected from the menu or the page combo box.
201            when this page is closed than the user will be able to open a new one
[3f1af74]202           
[1c66bc5]203            @param model: the model for which paramters will be changed
204            @param page_title: the name of the page
[3f1af74]205            @param description: [Coder: fill your description!]
206            @param page_title: [Coder: fill your description!]
207            @param qmin: mimimum Q
208            @param qmax: maximum Q
209            @param npts: number of Q points
[1c66bc5]210        """
[10c43a5]211        print "self.draw_model_name none",self.draw_model_name
[ef8b580]212        if topmenu==True:
213            if  self.draw_model_name ==None:
214                print "self.draw_model_name none"
215                self._help_add_model_page(model,description,page_title, qmin=qmin, qmax=qmax, npts=npts)
216            else:
217                #self.model_page.name=page_title
218                #self.draw_model_name=page_title
219                #print "wnent here self.draw_model_name ",self.draw_model_name,self.model_page.name,self.model_page
220               
221                self.model_page.select_model(model, page_title)
[10c43a5]222         
[d89f09b]223    def get_current_page(self):
224        """
225            @return the current page selected
226        """
[26bf293]227        #return self.nb.GetCurrentPage()
228        return self.GetPage(self.GetSelection() )
229 
[6bcdad1]230   
[10c43a5]231    def onClose(self, page=None,page_number=None):
[d89f09b]232        """
233             close the current page except the simpage. remove each check box link to the model
234             selected on that page. remove its reference into page_finder (fitting module)
235        """
[10c43a5]236        print "model page", page_number, page, self.draw_model_name
[f39511b]237        if page!=None and page_number!=None:
[10c43a5]238            i=self.DeletePage(page_number)
239            #self.nb.RemovePage(page_number)
240            #page.Destroy()
[f39511b]241            self.model_page_number=None
242            self.model_page=None
[47d10a2]243            self.draw_model_name=None
[10c43a5]244            print"self.draw_model_name",self.draw_model_name
[f39511b]245            return 
[2dbb681]246        try:
[10c43a5]247            sim_page = self.GetPage(1)
248            selected_page = self.GetPage(self.GetSelection())
[1fc7411]249            #print "sim_page ",sim_page ,selected_page
[2dbb681]250            if sim_page != selected_page:
[1fc7411]251                #print "sim_page ",sim_page ,selected_page
[2dbb681]252                # remove the check box link to the model name of this page (selected_page)
253                sim_page.remove_model(selected_page)
254                #remove that page from page_finder of fitting module
255                page_finder=self.manager.get_page_finder() 
256                for page, value in page_finder.iteritems():
257                    if page==selected_page:
258                        del page_finder[page]
259                        break
260                #Delete the page from notebook
[10c43a5]261                page_number = self.GetSelection()
[1fc7411]262                #print "on close",selected_page.name,self.GetPageText(page_number),self.draw_model_name
263               
264                if selected_page.name in self.fit_page_name:
265                    self.fit_page_name.remove(selected_page.name)
266                   
[10c43a5]267                if selected_page.name== self.draw_model_name:
[1fc7411]268                    #print "went here"
[2dbb681]269                    self.draw_model_name=None
[10c43a5]270                    self.model_page=None
[47d10a2]271                if  page_number == 1:
272                    self.model_page=None
273                    self.draw_model_name=None
[10c43a5]274                #selected_page.Destroy()
275                #self.RemovePage(page_number)
276                i=self.DeletePage(page_number)
[6bcdad1]277                #self.count =self.count -1
[1fc7411]278               
[2dbb681]279        except:
280            raise
[f39511b]281        #print "fitpanel", self.draw_model_name
[55e13ab]282       
[d89f09b]283    def set_model_list(self,dict):
284         """
285             copy a dictionary of model into its own dictionary
286             @param dict: dictionnary made of model name as key and model class
287             as value
288         """
289         self.model_list_box = dict
290 
Note: See TracBrowser for help on using the repository browser.