source: sasview/sansview/perspectives/fitting/old_fitpanel.py @ 24cab5d

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 24cab5d was c77d859, checked in by Gervaise Alina <gervyh@…>, 16 years ago

new interface design —→ proposition

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