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

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

working on simpage

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