source: sasview/sansview/perspectives/fitting/fitpanel.py @ 25c8653

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

comments removed

  • Property mode set to 100644
File size: 10.8 KB
Line 
1import wx
2import wx.aui
3import wx.lib
4import numpy
5import string ,re
6#import models
7_BOX_WIDTH = 80
8
9(FitPageEvent, EVT_FIT_PAGE)   = wx.lib.newevent.NewEvent()
10class FitPanel(wx.aui.AuiNotebook):   
11#class FitPanel(wx.aui.AuiNotebook,wx.panel):
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 "
22    CENTER_PANE = True
23    def __init__(self, parent, *args, **kwargs):
24       
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  )
27       
28       
29        self.manager=None
30        self.parent=parent
31        self.event_owner=None
32       
33        pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE
34        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)
35        #Creating the default page --welcomed page
36        self.about_page=None
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
42       
43       
44        self._mgr = self.GetAuiManager()
45
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
50        self.fit_page_name=[]
51        self.draw_model_name=None
52        #model page info
53        self.model_page_number=None
54       
55        self.model_page=None
56        self.sim_page=None
57        # increment number for model name
58        self.count=0
59        #updating the panel
60        self.Update()
61        self.Center()
62       
63       
64    def onClosePage(self, event):
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)
71            if self.sim_page !=None :
72                self.sim_page.remove_model(selected_page)
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
82           
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:
87                #print "went here"
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)
104   
105
106
107       
108    def set_manager(self, manager):
109        """
110             set panel manager
111             @param manager: instance of plugin fitting
112        """
113        self.manager = manager
114        #self.sim_page.set_manager(manager)
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
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
129       
130    def add_fit_page( self,data ):
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        """     
137        try:
138            name = data.name # item in Data1D
139        except:
140            name = 'Fit'
141       
142        #if self.fit_page_name != name and self.draw_model_name !=name:
143        if not name in self.fit_page_name :
144            #self.about_page.Disable()
145            from fitpage1D import FitPage1D
146            panel = FitPage1D(self,data, -1)
147            panel.name=name
148            #m_name= "M"+str(self.count) 
149            panel.set_manager(self.manager)
150            panel.set_owner(self.event_owner)
151           
152            self.AddPage(page=panel,caption=name,select=True)
153            panel.populate_box( self.model_list_box)
154            self.fit_page_name.append(name)
155   
156            return panel #,m_name
157        else:
158            return None #, None
159       
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        """
168        from modelpage import ModelPage
169        #print "fitpanel model", model
170        panel = ModelPage(self,model,page_title, -1)
171        panel.set_manager(self.manager)
172        panel.set_owner(self.event_owner)
173        self.AddPage(page=panel,caption="Model",select=True)
174        panel.populate_box( self.model_list_box)
175        panel.name = page_title
176        self.draw_model_name=page_title
177        self.model_page_number=self.GetSelection()
178        self.model_page=self.GetPage(self.GetSelection())
179       
180       
181        # Set the range used to plot models
182        self.model_page.set_range(qmin, qmax, npts)
183       
184        # We just created a model page, we are ready to plot the model
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)
188       
189       
190    def add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50, topmenu=False):
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
194           
195            @param model: the model for which paramters will be changed
196            @param page_title: the name of the page
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
202        """
203        #print "self.draw_model_name none",self.draw_model_name
204        if topmenu==True:
205            if  self.draw_model_name ==None:
206                #print "self.draw_model_name none"
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)
214         
215    def get_current_page(self):
216        """
217            @return the current page selected
218        """
219        #return self.nb.GetCurrentPage()
220        return self.GetPage(self.GetSelection() )
221 
222   
223    def onClose(self, page=None,page_number=None):
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        """
228        #print "model page", page_number, page, self.draw_model_name
229        if page!=None and page_number!=None:
230            i=self.DeletePage(page_number)
231            #self.nb.RemovePage(page_number)
232            #page.Destroy()
233            self.model_page_number=None
234            self.model_page=None
235            self.draw_model_name=None
236            #print"self.draw_model_name",self.draw_model_name
237            return 
238        try:
239            sim_page = self.GetPage(1)
240            selected_page = self.GetPage(self.GetSelection())
241            #print "sim_page ",sim_page ,selected_page
242            if sim_page != selected_page:
243                #print "sim_page ",sim_page ,selected_page
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
253                page_number = self.GetSelection()
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                   
259                if selected_page.name== self.draw_model_name:
260                    #print "went here"
261                    self.draw_model_name=None
262                    self.model_page=None
263                if  page_number == 1:
264                    self.model_page=None
265                    self.draw_model_name=None
266                #selected_page.Destroy()
267                #self.RemovePage(page_number)
268                i=self.DeletePage(page_number)
269                #self.count =self.count -1
270               
271        except:
272            raise
273        #print "fitpanel", self.draw_model_name
274       
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.