source: sasview/sansview/perspectives/fitting/fitpanel.py @ 96d7959

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 96d7959 was fee6059, checked in by Jae Cho <jhjcho@…>, 16 years ago

Fixed generating an error when calling 'select data for fitting' twice.

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