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

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

draw panel according to the fitting type
closing and reopen page i am still working on

  • Property mode set to 100644
File size: 8.6 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       
[dcf29d7]141    def add_fit_page( self,data, page_info=None ):
[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'
[dcf29d7]151        if page_info==None:
152            from pageInfo import  PageInfo
153            myinfo = PageInfo( self, data=data )
154            myinfo.model_list_box = self.model_list_box.get_list()
155            myinfo.event_owner = self.event_owner
156            myinfo.manager = self.manager
157        else:
158            myinfo = page_info
[6e659ae8]159       
160        if not name in self.fit_page_name :
[c77d859]161            from fitpage import FitPage
162            panel = FitPage(parent= self, page_info=myinfo, name=name )
[c9a4377]163            panel.name = name
[6f023e8]164            panel.window_name= "fitpage"
[26bf293]165            self.AddPage(page=panel,caption=name,select=True)
[1fc7411]166            self.fit_page_name.append(name)
[6f023e8]167           
[925a30e]168            return panel
[fee6059]169        else:
[925a30e]170            return None 
[1c66bc5]171       
[9853ad0]172   
[dcf29d7]173    def add_model_page(self,model,page_title, qmin=0, qmax=0.1,
174                        npts=50, topmenu=False,page_info=None):
[9853ad0]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
[dcf29d7]181            @param page_info: contains info about the state of the page
[9853ad0]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:
[dcf29d7]188                self._help_add_model_page(model,page_title, 
189                                qmin=qmin, qmax=qmax, npts=npts, page_info=page_info)
[9853ad0]190            else:
191                self.model_page.select_model(model, page_title)
192        else:
[dcf29d7]193            if  self.draw_model_name ==None:
194                self._create_model_page(model,page_title, qmin=qmin, qmax=qmax,
195                                         npts=npts, page_info=page_info)
196           
197               
198    def _help_add_model_page(self,model,page_title, qmin=0, 
199                             qmax=0.1, npts=50,page_info=None):
[3f1af74]200        """
201            #TODO: fill in description
202           
203            @param qmin: mimimum Q
204            @param qmax: maximum Q
205            @param npts: number of Q points
206        """
[dcf29d7]207        self._create_model_page(model,page_title,qmin=qmin, qmax=qmax,
208                                 npts=npts,page_info= page_info)
[9853ad0]209        # We just created a model page, we are ready to plot the model
210        #self.manager.draw_model(model, model.name)
211        #FOR PLUGIN  for some reason model.name is = BASEcomponent
212        self.manager.draw_model(model)
213   
[dcf29d7]214    def _create_model_page(self,model,page_title, qmin, qmax, npts,page_info=None):
[9853ad0]215        """
216        adding model page occurs here
217        """
[dcf29d7]218        ## creating object that contaning info about model
219        if page_info==None:
220            from pageInfo import  PageInfo
221            myinfo = PageInfo( self, model=model)
222            myinfo.model_list_box = self.model_list_box.get_list()
223            myinfo.event_owner = self.event_owner
224            myinfo.manager = self.manager
225        else:
226            myinfo = page_info
227   
[c77d859]228        from modelpage import ModelPage
[bb18ef1]229        panel = ModelPage(self,myinfo,page_title)
[77e23a2]230       
[bb18ef1]231        self.AddPage(page=panel,caption="Model",select=True)
[77e23a2]232
[bb18ef1]233        panel.name = page_title
234        self.draw_model_name=page_title
235        self.model_page_number=self.GetSelection()
236        self.model_page=self.GetPage(self.GetSelection())
237       
238       
239        # Set the range used to plot models
240        self.model_page.set_range(qmin, qmax, npts)
241       
[3dc83be]242       
[26bf293]243 
[c77d859]244   
245 
Note: See TracBrowser for help on using the repository browser.