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

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 c9636f7 was 0b99881, checked in by Gervaise Alina <gervyh@…>, 16 years ago

working opn refactoring files

  • Property mode set to 100644
File size: 7.2 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
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        wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_DEFAULT_STYLE  )
25       
26       
27        self.manager=None
28        self.parent=parent
29        self.event_owner=None
30       
31        pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE
32        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)
33        #Creating the default page --welcomed page
34        self.about_page=None
35        from sans.guiframe.welcome_panel import PanelAbout
36        self.about_page = PanelAbout(self, -1)
37        self.AddPage(self.about_page,"welcome!")
38     
39       
40        #dictionary of miodel {model class name, model class}
41        self.model_list_box={}
42        # save the title of the last page tab added
43        self.fit_page_name=[]
44        self.draw_model_name=None
45        #model page info
46        self.model_page_number=None
47       
48        self.model_page=None
49        self.sim_page=None
50        # increment number for model name
51        self.count=0
52        #updating the panel
53        self.Update()
54        self.Center()
55       
56       
57    def onClosePage(self, event):
58        """
59             close page and remove all references to the closed page
60        """
61        selected_page = self.GetPage(self.GetSelection())
62        page_number = self.GetSelection()
63        if self.sim_page != selected_page and selected_page!=self.about_page:
64            # remove the check box link to the model name of this page (selected_page)
65            if self.sim_page !=None :
66                self.sim_page.remove_model(selected_page)
67            #remove that page from page_finder of fitting module
68            page_finder=self.manager.get_page_finder() 
69            for page, value in page_finder.iteritems():
70                if page==selected_page:
71                    del page_finder[page]
72                    break
73            #Delete the page from notebook
74            if selected_page.name in self.fit_page_name:
75                self.fit_page_name.remove(selected_page.name)
76               
77            if selected_page.name== self.draw_model_name:
78                self.draw_model_name=None
79                self.model_page=None
80            if  page_number == 1:
81                self.model_page=None
82                self.draw_model_name=None
83           
84        elif selected_page==self.about_page:
85            self.about_page=None
86        else:
87            self.manager.sim_page=None 
88       
89       
90    def set_manager(self, manager):
91        """
92             set panel manager
93             @param manager: instance of plugin fitting
94        """
95        self.manager = manager
96
97       
98    def set_owner(self,owner):
99        """
100            set and owner for fitpanel
101            @param owner: the class responsible of plotting
102        """
103        self.event_owner = owner
104       
105    def add_sim_page(self):
106        """
107            Add the simultaneous fit page
108        """
109        from simfitpage import SimultaneousFitPage
110        self.sim_page = SimultaneousFitPage(self, id=-1)
111        self.AddPage(self.sim_page,caption="Simultaneous Fit",select=True)
112        self.sim_page.set_manager(self.manager)
113        return self.sim_page
114       
115    def add_fit_page( self,data ):
116        """
117            Add a fitting page on the notebook contained by fitpanel
118            @param data: data to fit
119            @return panel : page just added for futher used. is used by fitting module
120        """     
121        try:
122            name = data.name
123        except:
124            name = 'Fit'
125       
126        if not name in self.fit_page_name :
127            from fitpage1D import FitPage1D
128            panel = FitPage1D(parent=self,data=data, id=-1)
129            panel.name=name
130           
131            panel.set_manager(self.manager)
132            panel.set_owner(self.event_owner)
133           
134            self.AddPage(page=panel,caption=name,select=True)
135            panel.populate_box( self.model_list_box)
136            self.fit_page_name.append(name)
137   
138            return panel
139        else:
140            return None 
141       
142    def _help_add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50):
143        """
144            #TODO: fill in description
145           
146            @param qmin: mimimum Q
147            @param qmax: maximum Q
148            @param npts: number of Q points
149        """
150        from modelpage import ModelPage
151       
152        panel = ModelPage(self,model,page_title, -1)
153        panel.set_manager(self.manager)
154        panel.set_owner(self.event_owner)
155        self.AddPage(page=panel,caption="Model",select=True)
156        panel.populate_box( self.model_list_box)
157        panel.name = page_title
158        self.draw_model_name=page_title
159        self.model_page_number=self.GetSelection()
160        self.model_page=self.GetPage(self.GetSelection())
161       
162       
163        # Set the range used to plot models
164        self.model_page.set_range(qmin, qmax, npts)
165       
166        # We just created a model page, we are ready to plot the model
167        #self.manager.draw_model(model, model.name)
168        #FOR PLUGIN  for somereason model.name is = BASEcomponent
169        self.manager.draw_model(model, page_title)
170       
171       
172    def add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50, topmenu=False):
173        """
174            Add a model page only one  to display any model selected from the menu or the page combo box.
175            when this page is closed than the user will be able to open a new one
176           
177            @param model: the model for which paramters will be changed
178            @param page_title: the name of the page
179            @param description: [Coder: fill your description!]
180            @param page_title: [Coder: fill your description!]
181            @param qmin: mimimum Q
182            @param qmax: maximum Q
183            @param npts: number of Q points
184        """
185        if topmenu==True:
186            if  self.draw_model_name ==None:
187                self._help_add_model_page(model,description,page_title, qmin=qmin, qmax=qmax, npts=npts)
188            else:
189                self.model_page.select_model(model, page_title)
190         
191    def get_current_page(self):
192        """
193            @return the current page selected
194        """
195        return self.GetPage(self.GetSelection() )
196 
197   
198    def set_model_list(self,dict):
199         """
200             copy a dictionary of model into its own dictionary
201             @param dict: dictionnary made of model name as key and model class
202             as value
203         """
204         self.model_list_box = dict
205 
Note: See TracBrowser for help on using the repository browser.