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

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

models added

  • Property mode set to 100644
File size: 6.1 KB
Line 
1import wx
2import wx.lib
3import numpy
4import string ,re
5#import models
6_BOX_WIDTH = 80
7
8
9   
10class FitPanel(wx.Panel):
11    """
12        FitPanel class contains fields allowing to fit  models and  data
13        @note: For Fit to be performed the user should check at least one parameter
14        on fit Panel window.
15       
16    """
17    ## Internal name for the AUI manager
18    window_name = "Fit panel"
19    ## Title to appear on top of the window
20    window_caption = "Fit Panel "
21   
22   
23    def __init__(self, parent, *args, **kwargs):
24        wx.Panel.__init__(self, parent, *args, **kwargs)
25        self.manager=None
26        self.parent=parent
27        self.event_owner=None
28        #self.menu_mng = models.ModelManager()
29        self.nb = wx.Notebook(self)
30        self.sizer = wx.BoxSizer(wx.VERTICAL)
31        self.sizer.Add(self.nb, 0, wx.EXPAND)
32        #Creating an initial page for simultaneous fitting
33        from simfitpage import SimultaneousFitPage
34        self.sim_page = SimultaneousFitPage(self.nb, -1)
35       
36        #self.fit_panel.add_page(self.sim_page,"Simultaneous Fit")
37        self.nb.AddPage(self.sim_page,"Simultaneous Fit")
38       
39        #dictionary of miodel {model class name, model class}
40        self.model_list_box={}
41        # save the title of the last page tab added
42        self.fit_page_name=None
43        self.draw_model_name=None
44        self.page_name="Model View"
45        self.nb.Update()
46        self.SetSizer(self.sizer)
47        self.sizer.Fit(self)
48        self.Center()
49       
50       
51    def set_manager(self, manager):
52        """
53             set panel manager
54             @param manager: instance of plugin fitting
55        """
56        self.manager = manager
57        self.sim_page.set_manager(manager)
58       
59    def set_owner(self,owner):
60        """
61            set and owner for fitpanel
62            @param owner: the class responsible of plotting
63        """
64        self.event_owner=owner
65     
66       
67    def add_fit_page( self,page_title ):
68        """
69            Add a fitting page on the notebook contained by fitpanel
70            @param panel: contains in the page to add
71            @param name: title of the page tab
72            @return panel : page just added for futher used. is used by fitting module
73        """     
74        if self.fit_page_name != page_title:
75            from fitpage import FitPage
76            panel = FitPage(self.nb, -1)
77            panel.set_manager(self.manager)
78            panel.set_owner(self.event_owner)
79            self.nb.AddPage(page=panel,text=page_title,select=True)
80            panel.populate_box( self.model_list_box)
81            self.fit_page_name = page_title
82            return panel
83       
84       
85    def add_model_page(self,model,description,page_title):
86        """
87            Add a model page only one  to display any model selected from the menu or the page combo box.
88            when this page is closed than the user will be able to open a new one
89            @param model: the model for which paramters will be changed
90            @param page_title: the name of the page
91        """
92        if  page_title !=self.draw_model_name or self.draw_model_name ==None: 
93            from modelpage import ModelPage
94            panel = ModelPage(self.nb,model,description, -1)
95            panel.set_manager(self.manager)
96            panel.set_owner(self.event_owner)
97            self.nb.AddPage(page=panel,text=page_title,select=True)
98            panel.populate_box( self.model_list_box)
99            self.draw_model_name=page_title
100        else:
101            for i in range(self.nb.GetPageCount()):
102                if self.nb.GetPageText(i)==self.page_name:
103                    page=self.nb.GetPage(i)
104                    page.set_page(model,description)
105                    break
106               
107           
108    def get_notebook(self):
109        """
110            @return self.nb: return its own notebook mostly used by fitting module
111        """
112        return self.nb
113   
114    def get_page(self, n):
115        """
116            @return page at position n
117            @param n: page number
118        """
119        return self.nb.GetPage(n)
120   
121   
122    def get_page_count(self):
123        """ @return  number total of pages contained in notebook"""
124        return self.nb.GetPageCount()
125       
126       
127    def get_current_page(self):
128        """
129            @return the current page selected
130        """
131        return self.nb.GetCurrentPage()
132   
133   
134    def get_selected_page(self):
135        """ @return the page just selected by the user """
136        return self.nb.GetPage(self.nb.GetSelection())
137   
138    def onClose(self):
139        """
140             close the current page except the simpage. remove each check box link to the model
141             selected on that page. remove its reference into page_finder (fitting module)
142        """
143       
144        sim_page = self.nb.GetPage(0)
145        selected_page = self.nb.GetPage(self.nb.GetSelection())
146       
147        if sim_page != selected_page:
148            # remove the check box link to the model name of this page (selected_page)
149            sim_page.remove_model(selected_page)
150            #remove that page from page_finder of fitting module
151            page_finder=self.manager.get_page_finder() 
152            for page, value in page_finder.iteritems():
153                if page==selected_page:
154                    del page_finder[page]
155                    break
156            #Delete the page from notebook
157            page_number = self.nb.GetSelection()
158            if self.nb.GetPageText(page_number)== self.page_name:
159                self.draw_model_name=None
160               
161            selected_page.Destroy()
162            self.nb.RemovePage(page_number)
163            #self.name=None
164            self.fit_page_name=None
165           
166    def set_model_list(self,dict):
167         """
168             copy a dictionary of model into its own dictionary
169             @param dict: dictionnary made of model name as key and model class
170             as value
171         """
172         self.model_list_box = dict
173 
Note: See TracBrowser for help on using the repository browser.