source: sasview/sansview/perspectives/fitting/fitpanel.py @ 45ed4dad

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 45ed4dad was a074145, checked in by Gervaise Alina <gervyh@…>, 16 years ago

removing unsused code in fitpage

  • Property mode set to 100644
File size: 10.2 KB
Line 
1import wx
2import wx.aui
3import wx.lib
4import numpy
5import string ,re
6#import models
7_BOX_WIDTH = 80
8import basepage
9
10class PageInfo(object):
11    """
12        this class contains the minimum numbers of data members
13        a fitpage or model page need to be initialized.
14    """
15    data = None
16    model= None
17    manager= None
18    event_owner= None
19    model_list_box = None
20    name=None
21     ## Internal name for the AUI manager
22    window_name = "Page"
23    ## Title to appear on top of the window
24    window_caption = "Page"
25   
26    def __init__(self, model=None,data=None, manager=None,
27                  event_owner=None,model_list_box=None , name=None):
28        """
29            Initialize data members
30        """
31        self.data = data
32        self.model= model
33        self.manager= manager
34        self.event_owner= event_owner
35        self.model_list_box = model_list_box
36        self.name=None
37        self.window_name = "Page"
38        self.window_caption = "Page"
39   
40class FitPanel(wx.aui.AuiNotebook):   
41
42    """
43        FitPanel class contains fields allowing to fit  models and  data
44        @note: For Fit to be performed the user should check at least one parameter
45        on fit Panel window.
46       
47    """
48    ## Internal name for the AUI manager
49    window_name = "Fit panel"
50    ## Title to appear on top of the window
51    window_caption = "Fit Panel "
52    CENTER_PANE = True
53    def __init__(self, parent, *args, **kwargs):
54        wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_DEFAULT_STYLE  )
55       
56       
57        self.manager=None
58        self.parent=parent
59        self.event_owner=None
60       
61        pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE
62        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)
63        #Creating the default page --welcomed page
64        self.about_page=None
65        from welcome_panel import PanelAbout
66        self.about_page = PanelAbout(self, -1)
67        self.AddPage(self.about_page,"welcome!")
68     
69       
70        #dictionary of miodel {model class name, model class}
71        self.model_list_box={}
72        ##dictionary of page info
73        self.page_info_dict={}
74        ## save the title of the last page tab added
75        self.fit_page_name={}
76        ## list of existing fit page
77        self.list_fitpage_name=[]
78   
79        #model page info
80        self.model_page_number=None
81       
82        self.model_page=None
83        self.sim_page=None
84        ## get the state of a page
85        self.Bind(basepage.EVT_PAGE_INFO, self._onGetstate)
86        # increment number for model name
87        self.count=0
88        #updating the panel
89        self.Update()
90        self.Center()
91       
92       
93    def onClosePage(self, event):
94        """
95             close page and remove all references to the closed page
96        """
97        selected_page = self.GetPage(self.GetSelection())
98        ## removing about page
99        if selected_page==self.about_page:
100            self.about_page=None
101            return 
102        ## removing sim_page
103        if selected_page == self.sim_page:
104            self.manager.sim_page=None 
105            return
106       
107        ## closing other pages
108        state = selected_page.createMemento()
109        page_name = selected_page.window_name
110        page_finder = self.manager.get_page_finder() 
111        fitproblem = None
112        ## removing model page
113        if selected_page == self.model_page:
114            fitproblem = selected_page.model.clone()
115            self.model_page = None
116            ## page on menu
117            self.manager._add_page_onmenu(page_name, fitproblem)
118        else:
119            if selected_page in page_finder:
120       
121                fitproblem= page_finder[selected_page].clone()
122                ## page on menu
123                self.manager._add_page_onmenu(page_name, fitproblem)
124                del page_finder[selected_page]
125            ##remove the check box link to the model name of this page (selected_page)
126            try:
127                self.sim_page.draw_page()
128            except:
129                ## that page is already deleted no need to remove check box on
130                ##non existing page
131                pass
132               
133        #Delete the name of the page into the list of open page
134        if selected_page.window_name in self.list_fitpage_name:
135            self.list_fitpage_name.remove(selected_page.window_name)
136           
137       
138    def set_manager(self, manager):
139        """
140             set panel manager
141             @param manager: instance of plugin fitting
142        """
143        self.manager = manager
144
145       
146    def set_owner(self,owner):
147        """
148            set and owner for fitpanel
149            @param owner: the class responsible of plotting
150        """
151        self.event_owner = owner
152   
153    def set_model_list(self,dict):
154         """
155             copy a dictionary of model into its own dictionary
156             @param dict: dictionnary made of model name as key and model class
157             as value
158         """
159         self.model_list_box = dict
160       
161 
162    def get_current_page(self):
163        """
164            @return the current page selected
165        """
166        return self.GetPage(self.GetSelection() )
167   
168    def add_sim_page(self):
169        """
170            Add the simultaneous fit page
171        """
172        from simfitpage import SimultaneousFitPage
173        page_finder= self.manager.get_page_finder()
174        self.sim_page = SimultaneousFitPage(self,page_finder=page_finder, id=-1)
175       
176        self.AddPage(self.sim_page,caption="Simultaneous Fit",select=True)
177        self.sim_page.set_manager(self.manager)
178        return self.sim_page
179       
180    def add_fit_page( self,data, reset=False ):
181        """
182            Add a fitting page on the notebook contained by fitpanel
183            @param data: data to fit
184            @return panel : page just added for further used. is used by fitting module
185        """     
186        try:
187            name = data.name
188        except:
189            name = 'Fit'
190        if not name in self.list_fitpage_name:
191            myinfo = PageInfo( data=data, name=name )
192            myinfo.model_list_box = self.model_list_box.get_list()
193            myinfo.event_owner = self.event_owner
194            myinfo.manager = self.manager
195            myinfo.window_name = name
196            myinfo.window_caption = name
197       
198            #if not name in self.fit_page_name :
199            from fitpage import FitPage
200            panel = FitPage(parent= self, page_info=myinfo)
201           
202            self.AddPage(page=panel, caption=name, select=True)
203            self.list_fitpage_name.append(name)
204            if reset:
205                if name in self.fit_page_name.keys():
206                    memento= self.fit_page_name[name][0]
207                    panel.reset_page(memento)
208            else:
209                self.fit_page_name[name]=[]
210                self.fit_page_name[name].insert(0,panel.createMemento())
211         
212            return panel
213        else:
214            return None 
215       
216   
217    def add_model_page(self,model,page_title="Model", qmin=0, qmax=0.1,
218                        npts=50, topmenu=False, reset=False):
219        """
220            Add a model page only one  to display any model selected from the menu or the page combo box.
221            when this page is closed than the user will be able to open a new one
222           
223            @param model: the model for which paramters will be changed
224            @param page_title: the name of the page
225            @param page_info: contains info about the state of the page
226            @param qmin: mimimum Q
227            @param qmax: maximum Q
228            @param npts: number of Q points
229        """
230        if topmenu==True:
231            if not page_title in self.fit_page_name.keys()or reset==True:
232                self._help_add_model_page(model=model, page_title=page_title,
233                                qmin=qmin, qmax=qmax, npts=npts, reset=reset)
234            else:
235                self.model_page.select_model(model, page_title)
236                self.fit_page_name[page_title].insert(0,self.model_page.createMemento())
237     
238           
239    def  _onGetstate(self, event):
240        """
241            copy the state of a page
242        """
243        page= event.page
244        if page.window_name in self.fit_page_name:
245            self.fit_page_name[page.window_name].insert(0,page.createMemento()) 
246           
247               
248    def _help_add_model_page(self,model,page_title="Model", qmin=0, 
249                             qmax=0.1, npts=50,reset= False):
250        """
251            #TODO: fill in description
252           
253            @param qmin: mimimum Q
254            @param qmax: maximum Q
255            @param npts: number of Q points
256        """
257        ## creating object that contaning info about model
258        myinfo = PageInfo(model= model ,name= page_title)
259        myinfo.model_list_box = self.model_list_box.get_list()
260        myinfo.event_owner = self.event_owner
261        myinfo.manager = self.manager
262        myinfo.window_name = page_title
263        myinfo.window_caption = page_title
264     
265        from modelpage import ModelPage
266        panel = ModelPage(self,myinfo)
267       
268        self.AddPage(page=panel,caption=page_title,select=True)
269
270        self.model_page_number=self.GetSelection()
271        self.model_page=self.GetPage(self.GetSelection())
272        # Set the range used to plot models
273        self.model_page.set_range(qmin, qmax, npts)
274        ##  resetting page
275        if reset:
276            if page_title in self.fit_page_name.keys():
277               
278                memento= self.fit_page_name[page_title][0]
279                panel.reset_page(memento)
280        else:
281            self.fit_page_name[page_title]=[]
282            self.fit_page_name[page_title].insert(0,panel.createMemento())
283         
284        # We just created a model page, we are ready to plot the model
285        #self.manager.draw_model(model, model.name)
286        #FOR PLUGIN  for some reason model.name is = BASEcomponent
287        self.manager.draw_model(model)
288 
289 
Note: See TracBrowser for help on using the repository browser.