source: sasview/sansview/perspectives/fitting/fitpanel.py @ 743d75c

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

close bug fixed

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