source: sasview/sansview/perspectives/fitting/fitpanel.py @ 7437880

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 7437880 was 7437880, checked in by Gervaise Alina <gervyh@…>, 15 years ago

page layout fix

  • Property mode set to 100644
File size: 12.6 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   
54    def __init__(self, parent, *args, **kwargs):
55        wx.aui.AuiNotebook.__init__(self,parent,-1,
56                    style= wx.aui.AUI_NB_WINDOWLIST_BUTTON|wx.aui.AUI_NB_DEFAULT_STYLE|wx.CLIP_CHILDREN  )
57   
58        self.manager=None
59        self.parent=parent
60        self.event_owner=None
61       
62        pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE
63        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)
64        ##Creating the default page --welcomed page
65        self.about_page=None
66        from welcome_panel import PanelAbout
67        self.about_page = PanelAbout(self, -1)
68        self.AddPage(self.about_page,"Welcome!")
69     
70       
71        #dictionary of miodel {model class name, model class}
72        self.model_list_box={}
73        ##dictionary of page info
74        self.page_info_dict={}
75        ## save the title of the last page tab added
76        self.fit_page_name={}
77        ## list of existing fit page
78        self.list_fitpage_name=[]
79   
80        #model page info
81        self.model_page_number=None
82        ## fit page number for model plot
83        self.fit_page1D_number=None
84        self.fit_page2D_number=None
85        self.model_page=None
86        self.sim_page=None
87        ## get the state of a page
88        self.Bind(basepage.EVT_PAGE_INFO, self._onGetstate)
89        # increment number for model name
90        self.count=0
91        #updating the panel
92        self.Update()
93        self.Center()
94       
95       
96    def onClosePage(self, event):
97        """
98             close page and remove all references to the closed page
99        """
100        selected_page = self.GetPage(self.GetSelection())
101        ## removing about page
102        if selected_page==self.about_page:
103            self.about_page=None
104            return 
105        ## removing sim_page
106        if selected_page == self.sim_page:
107            self.manager.sim_page=None 
108            return
109       
110        ## closing other pages
111        state = selected_page.createMemento()
112        page_name = selected_page.window_name
113        page_finder = self.manager.get_page_finder() 
114        fitproblem = None
115        ## removing model page
116        if selected_page == self.model_page:
117            fitproblem = selected_page.model.clone()
118            self.model_page = None
119            self.count =0
120            ## page on menu
121            self.manager._add_page_onmenu(page_name, fitproblem)
122        else:
123            if selected_page in page_finder:
124       
125                fitproblem= page_finder[selected_page].clone()
126                if self.GetPageIndex(selected_page)==self.fit_page1D_number:
127                    self.fit_page1D_number=None
128                if self.GetPageIndex(selected_page)==self.fit_page2D_number:
129                    self.fit_page2D_number=None
130                ## page on menu
131                self.manager._add_page_onmenu(page_name, fitproblem)
132                del page_finder[selected_page]
133            ##remove the check box link to the model name of this page (selected_page)
134            try:
135                self.sim_page.draw_page()
136            except:
137                ## that page is already deleted no need to remove check box on
138                ##non existing page
139                pass
140               
141        #Delete the name of the page into the list of open page
142        if selected_page.window_name in self.list_fitpage_name:
143            self.list_fitpage_name.remove(selected_page.window_name)
144           
145       
146    def set_manager(self, manager):
147        """
148             set panel manager
149             @param manager: instance of plugin fitting
150        """
151        self.manager = manager
152
153       
154    def set_owner(self,owner):
155        """
156            set and owner for fitpanel
157            @param owner: the class responsible of plotting
158        """
159        self.event_owner = owner
160   
161    def set_model_list(self,dict):
162         """
163             copy a dictionary of model into its own dictionary
164             @param dict: dictionnary made of model name as key and model class
165             as value
166         """
167         self.model_list_box = dict
168       
169 
170    def get_current_page(self):
171        """
172            @return the current page selected
173        """
174        return self.GetPage(self.GetSelection() )
175   
176    def add_sim_page(self):
177        """
178            Add the simultaneous fit page
179        """
180        from simfitpage import SimultaneousFitPage
181        page_finder= self.manager.get_page_finder()
182        self.sim_page = SimultaneousFitPage(self,page_finder=page_finder, id=-1)
183       
184        self.AddPage(self.sim_page,caption="Simultaneous Fit",select=True)
185        self.sim_page.set_manager(self.manager)
186        return self.sim_page
187       
188    def add_fit_page( self,data, reset=False ):
189        """
190            Add a fitting page on the notebook contained by fitpanel
191            @param data: data to fit
192            @return panel : page just added for further used. is used by fitting module
193        """     
194        if data.is_data:
195            name = data.name
196        else:
197            if data.__class__.__name__=="Data2D":
198                name = 'Model 2D Fit'
199            else:
200                name = 'Model 1D Fit'
201        if not name in self.list_fitpage_name:
202            myinfo = PageInfo( data=data, name=name )
203            myinfo.model_list_box = self.model_list_box.get_list()
204            myinfo.event_owner = self.event_owner
205            myinfo.manager = self.manager
206            myinfo.window_name = name
207            myinfo.window_caption = name
208       
209            #if not name in self.fit_page_name :
210            from fitpage import FitPage
211            panel = FitPage(parent= self, page_info=myinfo)
212           
213            self.AddPage(page=panel, caption=name, select=True)
214            if name == 'Model 1D Fit':
215                self.fit_page1D_number= self.GetPageIndex(panel)
216            if name =='Model 2D Fit':
217                self.fit_page2D_number= self.GetPageIndex(panel)
218               
219            self.list_fitpage_name.append(name)
220            if reset:
221                if name in self.fit_page_name.keys():
222                    memento= self.fit_page_name[name][0]
223                    panel.reset_page(memento)
224            else:
225                self.fit_page_name[name]=[]
226                self.fit_page_name[name].insert(0,panel.createMemento())
227            #GetPage(self, page_idx)
228            return panel
229        elif name =='Model 1D Fit':
230            if self.fit_page1D_number!=None:
231                panel =self.GetPage(self.fit_page1D_number) 
232                self.fit_page_name[name]=[]
233                self.fit_page_name[name].insert(0,panel.createMemento())
234                return panel
235            return None
236        elif name =='Model 2D Fit':
237            if self.fit_page2D_number!=None:
238                panel =self.GetPage(self.fit_page2D_number) 
239                self.fit_page_name[name]=[]
240                self.fit_page_name[name].insert(0,panel.createMemento())
241                return panel
242            return None
243        return None
244       
245   
246    def add_model_page(self,model,page_title="Model", qmin=0.0001, qmax=0.13,
247                        npts=50, topmenu=False, reset=False):
248        """
249            Add a model page only one  to display any model selected from the menu or the page combo box.
250            when this page is closed than the user will be able to open a new one
251           
252            @param model: the model for which paramters will be changed
253            @param page_title: the name of the page
254            @param page_info: contains info about the state of the page
255            @param qmin: mimimum Q
256            @param qmax: maximum Q
257            @param npts: number of Q points
258        """
259        if topmenu==True:
260            ##first time to open model page
261            if self.count==0 :
262                #if not page_title in self.list_fitpage_name :
263                self._help_add_model_page(model=model, page_title=page_title,
264                                qmin=qmin, qmax=qmax, npts=npts, reset=reset)
265                self.count +=1
266            else:
267                self.model_page.select_model(model)
268                self.fit_page_name[page_title].insert(0,self.model_page.createMemento())
269     
270     
271     
272    def _close_fitpage(self,data):
273        """
274            close a fit page when its data is completely remove from the graph
275        """
276        name = data.name
277        for index in range(self.GetPageCount()):
278            if self.GetPageText(index)== name:
279                selected_page = self.GetPage(index) 
280   
281                if index ==self.fit_page1D_number:
282                    self.fit_page1D_number=None
283                if index ==self.fit_page2D_number:
284                    self.fit_page2D_number=None
285                if selected_page in self.manager.page_finder:
286                    del self.manager.page_finder[selected_page]
287                ##remove the check box link to the model name of this page (selected_page)
288                try:
289                    self.sim_page.draw_page()
290                except:
291                    ## that page is already deleted no need to remove check box on
292                    ##non existing page
293                    pass
294               
295                #Delete the name of the page into the list of open page
296                if selected_page.window_name in self.list_fitpage_name:
297                    self.list_fitpage_name.remove(selected_page.window_name)
298                self.DeletePage(index)
299                break
300       
301       
302    def  _onGetstate(self, event):
303        """
304            copy the state of a page
305        """
306        page= event.page
307        if page.window_name in self.fit_page_name:
308            self.fit_page_name[page.window_name].insert(0,page.createMemento()) 
309           
310               
311    def _help_add_model_page(self,model,page_title="Model", qmin=0.0001, 
312                             qmax=0.13, npts=50,reset= False):
313        """
314            #TODO: fill in description
315           
316            @param qmin: mimimum Q
317            @param qmax: maximum Q
318            @param npts: number of Q points
319        """
320        ## creating object that contaning info about model
321        myinfo = PageInfo(model= model ,name= page_title)
322        myinfo.model_list_box = self.model_list_box.get_list()
323        myinfo.event_owner = self.event_owner
324        myinfo.manager = self.manager
325        myinfo.window_name = page_title
326        myinfo.window_caption = page_title
327     
328        from modelpage import ModelPage
329        panel = ModelPage(self,myinfo)
330       
331        self.AddPage(page=panel, caption=page_title, select=True)
332
333        self.model_page_number=self.GetSelection()
334        self.model_page=self.GetPage(self.GetSelection())
335     
336        ##  resetting page
337        if reset:
338            if page_title in self.fit_page_name.keys():
339
340                memento= self.fit_page_name[page_title][0]
341                panel.reset_page(memento)
342        else:
343            self.fit_page_name[page_title]=[]
344            self.fit_page_name[page_title].insert(0,panel.createMemento())
345       
346 
Note: See TracBrowser for help on using the repository browser.