source: sasview/sansview/perspectives/fitting/fitpanel.py @ 1fc7411

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

error handling for selected data to fit

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