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

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

removing all codes.and add highlight for textcrtl

  • Property mode set to 100644
File size: 8.3 KB
RevLine 
[d89f09b]1import wx
[26bf293]2import wx.aui
[d89f09b]3import wx.lib
4import numpy
5import string ,re
6#import models
7_BOX_WIDTH = 80
[6f023e8]8(PageInfoEvent, EVT_PAGE_INFO)   = wx.lib.newevent.NewEvent()
[00c3aac]9
[26bf293]10class FitPanel(wx.aui.AuiNotebook):   
[925a30e]11
[d89f09b]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 "
[2139c3f]22    CENTER_PANE = True
[d89f09b]23    def __init__(self, parent, *args, **kwargs):
[51d47b5]24        wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_DEFAULT_STYLE  )
[94999eb]25       
[26bf293]26       
[d89f09b]27        self.manager=None
28        self.parent=parent
29        self.event_owner=None
[26bf293]30       
31        pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE
32        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)
[94999eb]33        #Creating the default page --welcomed page
[51d47b5]34        self.about_page=None
[1328e03]35        from welcome_panel import PanelAbout
[94999eb]36        self.about_page = PanelAbout(self, -1)
37        self.AddPage(self.about_page,"welcome!")
[925a30e]38     
[51d47b5]39       
[d89f09b]40        #dictionary of miodel {model class name, model class}
41        self.model_list_box={}
[00c3aac]42        ##dictionary of page info
43        self.page_info_dict={}
[d89f09b]44        # save the title of the last page tab added
[1fc7411]45        self.fit_page_name=[]
[060b857]46        self.draw_model_name=None
[f39511b]47        #model page info
48        self.model_page_number=None
[10c43a5]49       
[f39511b]50        self.model_page=None
[51d47b5]51        self.sim_page=None
[6bcdad1]52        # increment number for model name
53        self.count=0
[f39511b]54        #updating the panel
[26bf293]55        self.Update()
[d89f09b]56        self.Center()
[2a8fac1]57       
58       
[26bf293]59    def onClosePage(self, event):
[51d47b5]60        """
[925a30e]61             close page and remove all references to the closed page
[51d47b5]62        """
[9853ad0]63        page_info = self.get_current_page().page_info.clone()
64        page_info.page_name = self.get_current_page().page_info.page_name
65        page_finder = self.manager.get_page_finder() 
66        fitproblem = None
67       
68        if self.get_current_page() in page_finder:
69            fitproblem= page_finder[self.get_current_page()]
70           
71        self.manager._add_page_onmenu(page_info.page_name, page_info, fitproblem)
[6f023e8]72       
[51d47b5]73        selected_page = self.GetPage(self.GetSelection())
74        page_number = self.GetSelection()
[9853ad0]75       
[51d47b5]76        if self.sim_page != selected_page and selected_page!=self.about_page:
[2140e68]77            # remove the check box link to the model name of this page (selected_page)
78            if self.sim_page !=None :
[1d2782d]79                self.sim_page.draw_page()
[2140e68]80           
[51d47b5]81            #Delete the page from notebook
82            if selected_page.name in self.fit_page_name:
83                self.fit_page_name.remove(selected_page.name)
84               
85            if selected_page.name== self.draw_model_name:
86                self.draw_model_name=None
87                self.model_page=None
[9853ad0]88               
[51d47b5]89            if  page_number == 1:
90                self.model_page=None
91                self.draw_model_name=None
[925a30e]92           
[51d47b5]93        elif selected_page==self.about_page:
94            self.about_page=None
95        else:
96            self.manager.sim_page=None 
[925a30e]97       
[d89f09b]98       
99    def set_manager(self, manager):
100        """
101             set panel manager
102             @param manager: instance of plugin fitting
103        """
104        self.manager = manager
[925a30e]105
[d89f09b]106       
107    def set_owner(self,owner):
108        """
109            set and owner for fitpanel
110            @param owner: the class responsible of plotting
111        """
[c77d859]112        self.event_owner = owner
113   
114    def set_model_list(self,dict):
115         """
116             copy a dictionary of model into its own dictionary
117             @param dict: dictionnary made of model name as key and model class
118             as value
119         """
120         self.model_list_box = dict
[51d47b5]121       
[c77d859]122 
123    def get_current_page(self):
124        """
125            @return the current page selected
126        """
127        return self.GetPage(self.GetSelection() )
128   
[51d47b5]129    def add_sim_page(self):
[925a30e]130        """
131            Add the simultaneous fit page
132        """
[51d47b5]133        from simfitpage import SimultaneousFitPage
[b28717b]134        page_finder= self.manager.get_page_finder()
135        self.sim_page = SimultaneousFitPage(self,page_finder=page_finder, id=-1)
136       
[51d47b5]137        self.AddPage(self.sim_page,caption="Simultaneous Fit",select=True)
138        self.sim_page.set_manager(self.manager)
139        return self.sim_page
[d89f09b]140       
[bcd6d51]141    def add_fit_page( self,data ):
[d89f09b]142        """
143            Add a fitting page on the notebook contained by fitpanel
[925a30e]144            @param data: data to fit
[d89f09b]145            @return panel : page just added for futher used. is used by fitting module
146        """     
[bcd6d51]147        try:
[925a30e]148            name = data.name
[bcd6d51]149        except:
150            name = 'Fit'
[c77d859]151        from pageInfo import  PageInfo
152        myinfo = PageInfo( self, data=data )
153        myinfo.model_list_box = self.model_list_box.get_list()
154        myinfo.event_owner =self.event_owner
[6e659ae8]155       
156        if not name in self.fit_page_name :
[c9a4377]157           
[c77d859]158            from fitpage import FitPage
159            panel = FitPage(parent= self, page_info=myinfo, name=name )
[c9a4377]160            panel.name = name
[6f023e8]161            panel.window_name= "fitpage"
[d89f09b]162            panel.set_manager(self.manager)
163            panel.set_owner(self.event_owner)
[9d31a8b]164           
[26bf293]165            self.AddPage(page=panel,caption=name,select=True)
[c77d859]166            #panel.populate_box( self.model_list_box)
[1fc7411]167            self.fit_page_name.append(name)
[6f023e8]168           
[925a30e]169            return panel
[fee6059]170        else:
[925a30e]171            return None 
[1c66bc5]172       
[9853ad0]173   
174    def add_model_page(self,model,page_title, qmin=0, qmax=0.1, npts=50, topmenu=False):
175        """
176            Add a model page only one  to display any model selected from the menu or the page combo box.
177            when this page is closed than the user will be able to open a new one
178           
179            @param model: the model for which paramters will be changed
180            @param page_title: the name of the page
181            @param page_title: [Coder: fill your description!]
182            @param qmin: mimimum Q
183            @param qmax: maximum Q
184            @param npts: number of Q points
185        """
186        if topmenu==True:
187            if  self.draw_model_name ==None:
188                self._help_add_model_page(model,page_title, qmin=qmin, qmax=qmax, npts=npts)
189            else:
190                self.model_page.select_model(model, page_title)
191        else:
192            self._create_model_page(model,page_title, qmin=qmin, qmax=qmax, npts=npts)
193         
[c9a4377]194    def _help_add_model_page(self,model,page_title, qmin=0, qmax=0.1, npts=50):
[3f1af74]195        """
196            #TODO: fill in description
197           
198            @param qmin: mimimum Q
199            @param qmax: maximum Q
200            @param npts: number of Q points
201        """
[9853ad0]202        self._create_model_page(model,page_title,qmin=qmin, qmax=qmax, npts=npts)
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)
207   
208    def _create_model_page(self,model,page_title, qmin, qmax, npts):
209        """
210        adding model page occurs here
211        """
212       
[bb18ef1]213        ## storing page info
214        from pageInfo import  PageInfo
215        myinfo = PageInfo( self, model )
[c77d859]216        myinfo.model_list_box = self.model_list_box.get_list()
217        myinfo.event_owner =self.event_owner
[bb18ef1]218       
[c77d859]219        from modelpage import ModelPage
[bb18ef1]220        panel = ModelPage(self,myinfo,page_title)
221        panel.set_manager(self.manager)
222        panel.set_owner(self.event_owner)
223       
224       
225        self.AddPage(page=panel,caption="Model",select=True)
[c77d859]226        #panel.populate_box( self.model_list_box)
[bb18ef1]227        panel.name = page_title
228        self.draw_model_name=page_title
229        self.model_page_number=self.GetSelection()
230        self.model_page=self.GetPage(self.GetSelection())
231       
232       
233        # Set the range used to plot models
234        self.model_page.set_range(qmin, qmax, npts)
235       
[3dc83be]236       
[26bf293]237 
[c77d859]238   
239 
Note: See TracBrowser for help on using the repository browser.