source: sasview/sansview/perspectives/fitting/fitpanel.py @ 76dab10

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 76dab10 was b491d6e, checked in by Gervaise Alina <gervyh@…>, 16 years ago

comments removed

  • Property mode set to 100644
File size: 10.8 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        """
66        """
67        selected_page = self.GetPage(self.GetSelection())
68        page_number = self.GetSelection()
69        if self.sim_page != selected_page and selected_page!=self.about_page:
70            # remove the check box link to the model name of this page (selected_page)
[3199b59]71            if self.sim_page !=None :
72                self.sim_page.remove_model(selected_page)
[51d47b5]73            #remove that page from page_finder of fitting module
74            page_finder=self.manager.get_page_finder() 
75            for page, value in page_finder.iteritems():
76                if page==selected_page:
77                    del page_finder[page]
78                    break
79            #Delete the page from notebook
80           
81            #print "on close",selected_page.name,self.GetPageText(page_number),self.draw_model_name
[26bf293]82           
[51d47b5]83            if selected_page.name in self.fit_page_name:
84                self.fit_page_name.remove(selected_page.name)
85               
86            if selected_page.name== self.draw_model_name:
[ed2ea6a]87                #print "went here"
[51d47b5]88                self.draw_model_name=None
89                self.model_page=None
90            if  page_number == 1:
91                self.model_page=None
92                self.draw_model_name=None
93            #selected_page.Destroy()
94            #self.RemovePage(page_number)
95            #i=self.DeletePage(page_number)
96        elif selected_page==self.about_page:
97            #selected_page.Destroy()
98            #self.DeletePage(page_number)
99            self.about_page=None
100        else:
101           
102            self.manager.sim_page=None 
103            #self.DeletePage(page_number)
[26bf293]104   
105
[7691125]106
[d89f09b]107       
108    def set_manager(self, manager):
109        """
110             set panel manager
111             @param manager: instance of plugin fitting
112        """
113        self.manager = manager
[51d47b5]114        #self.sim_page.set_manager(manager)
[d89f09b]115       
116    def set_owner(self,owner):
117        """
118            set and owner for fitpanel
119            @param owner: the class responsible of plotting
120        """
121        self.event_owner=owner
[51d47b5]122       
123    def add_sim_page(self):
124        from simfitpage import SimultaneousFitPage
125        self.sim_page = SimultaneousFitPage(self, id=-1)
126        self.AddPage(self.sim_page,caption="Simultaneous Fit",select=True)
127        self.sim_page.set_manager(self.manager)
128        return self.sim_page
[d89f09b]129       
[bcd6d51]130    def add_fit_page( self,data ):
[d89f09b]131        """
132            Add a fitting page on the notebook contained by fitpanel
133            @param panel: contains in the page to add
134            @param name: title of the page tab
135            @return panel : page just added for futher used. is used by fitting module
136        """     
[bcd6d51]137        try:
[55e13ab]138            name = data.name # item in Data1D
[bcd6d51]139        except:
140            name = 'Fit'
[6e659ae8]141       
[3e1a859]142        #if self.fit_page_name != name and self.draw_model_name !=name:
[6e659ae8]143        if not name in self.fit_page_name :
[94999eb]144            #self.about_page.Disable()
[6b44403]145            from fitpage1D import FitPage1D
146            panel = FitPage1D(self,data, -1)
[10c43a5]147            panel.name=name
[ef8b580]148            #m_name= "M"+str(self.count) 
[d89f09b]149            panel.set_manager(self.manager)
150            panel.set_owner(self.event_owner)
[9d31a8b]151           
[26bf293]152            self.AddPage(page=panel,caption=name,select=True)
[d89f09b]153            panel.populate_box( self.model_list_box)
[1fc7411]154            self.fit_page_name.append(name)
155   
[ef8b580]156            return panel #,m_name
[fee6059]157        else:
[ef8b580]158            return None #, None
[1c66bc5]159       
[3f1af74]160    def _help_add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50):
161        """
162            #TODO: fill in description
163           
164            @param qmin: mimimum Q
165            @param qmax: maximum Q
166            @param npts: number of Q points
167        """
[f39511b]168        from modelpage import ModelPage
[888e62c]169        #print "fitpanel model", model
[26bf293]170        panel = ModelPage(self,model,page_title, -1)
[f39511b]171        panel.set_manager(self.manager)
172        panel.set_owner(self.event_owner)
[26bf293]173        self.AddPage(page=panel,caption="Model",select=True)
[f39511b]174        panel.populate_box( self.model_list_box)
[ef8b580]175        panel.name = page_title
[f39511b]176        self.draw_model_name=page_title
[26bf293]177        self.model_page_number=self.GetSelection()
178        self.model_page=self.GetPage(self.GetSelection())
[f39511b]179       
[1c66bc5]180       
[3f1af74]181        # Set the range used to plot models
182        self.model_page.set_range(qmin, qmax, npts)
183       
[3dc83be]184        # We just created a model page, we are ready to plot the model
[32d802f]185        #self.manager.draw_model(model, model.name)
186        #FOR PLUGIN  for somereason model.name is = BASEcomponent
187        self.manager.draw_model(model, page_title)
[3f1af74]188       
[3dc83be]189       
190    def add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50, topmenu=False):
[1c66bc5]191        """
192            Add a model page only one  to display any model selected from the menu or the page combo box.
193            when this page is closed than the user will be able to open a new one
[3f1af74]194           
[1c66bc5]195            @param model: the model for which paramters will be changed
196            @param page_title: the name of the page
[3f1af74]197            @param description: [Coder: fill your description!]
198            @param page_title: [Coder: fill your description!]
199            @param qmin: mimimum Q
200            @param qmax: maximum Q
201            @param npts: number of Q points
[1c66bc5]202        """
[b491d6e]203        #print "self.draw_model_name none",self.draw_model_name
[ef8b580]204        if topmenu==True:
205            if  self.draw_model_name ==None:
[b491d6e]206                #print "self.draw_model_name none"
[ef8b580]207                self._help_add_model_page(model,description,page_title, qmin=qmin, qmax=qmax, npts=npts)
208            else:
209                #self.model_page.name=page_title
210                #self.draw_model_name=page_title
211                #print "wnent here self.draw_model_name ",self.draw_model_name,self.model_page.name,self.model_page
212               
213                self.model_page.select_model(model, page_title)
[10c43a5]214         
[d89f09b]215    def get_current_page(self):
216        """
217            @return the current page selected
218        """
[26bf293]219        #return self.nb.GetCurrentPage()
220        return self.GetPage(self.GetSelection() )
221 
[6bcdad1]222   
[10c43a5]223    def onClose(self, page=None,page_number=None):
[d89f09b]224        """
225             close the current page except the simpage. remove each check box link to the model
226             selected on that page. remove its reference into page_finder (fitting module)
227        """
[ed2ea6a]228        #print "model page", page_number, page, self.draw_model_name
[f39511b]229        if page!=None and page_number!=None:
[10c43a5]230            i=self.DeletePage(page_number)
231            #self.nb.RemovePage(page_number)
232            #page.Destroy()
[f39511b]233            self.model_page_number=None
234            self.model_page=None
[47d10a2]235            self.draw_model_name=None
[ed2ea6a]236            #print"self.draw_model_name",self.draw_model_name
[f39511b]237            return 
[2dbb681]238        try:
[10c43a5]239            sim_page = self.GetPage(1)
240            selected_page = self.GetPage(self.GetSelection())
[1fc7411]241            #print "sim_page ",sim_page ,selected_page
[2dbb681]242            if sim_page != selected_page:
[1fc7411]243                #print "sim_page ",sim_page ,selected_page
[2dbb681]244                # remove the check box link to the model name of this page (selected_page)
245                sim_page.remove_model(selected_page)
246                #remove that page from page_finder of fitting module
247                page_finder=self.manager.get_page_finder() 
248                for page, value in page_finder.iteritems():
249                    if page==selected_page:
250                        del page_finder[page]
251                        break
252                #Delete the page from notebook
[10c43a5]253                page_number = self.GetSelection()
[1fc7411]254                #print "on close",selected_page.name,self.GetPageText(page_number),self.draw_model_name
255               
256                if selected_page.name in self.fit_page_name:
257                    self.fit_page_name.remove(selected_page.name)
258                   
[10c43a5]259                if selected_page.name== self.draw_model_name:
[1fc7411]260                    #print "went here"
[2dbb681]261                    self.draw_model_name=None
[10c43a5]262                    self.model_page=None
[47d10a2]263                if  page_number == 1:
264                    self.model_page=None
265                    self.draw_model_name=None
[10c43a5]266                #selected_page.Destroy()
267                #self.RemovePage(page_number)
268                i=self.DeletePage(page_number)
[6bcdad1]269                #self.count =self.count -1
[1fc7411]270               
[2dbb681]271        except:
272            raise
[f39511b]273        #print "fitpanel", self.draw_model_name
[55e13ab]274       
[d89f09b]275    def set_model_list(self,dict):
276         """
277             copy a dictionary of model into its own dictionary
278             @param dict: dictionnary made of model name as key and model class
279             as value
280         """
281         self.model_list_box = dict
282 
Note: See TracBrowser for help on using the repository browser.