source: sasview/sansview/perspectives/fitting/fitpanel.py @ 2e83ff3

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 2e83ff3 was 4fc6dbf, checked in by Gervaise Alina <gervyh@…>, 16 years ago

some mofif added

  • 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   
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        id = wx.NewId()
40        self.btClose =wx.Button(self,id,'Close')
41        self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id)
42        self.btClose.SetToolTipString("Close page.")
43   
44        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
45        sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
46        sizer_button.Add(self.btClose, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
47        self.sizer.Add(sizer_button,1, wx.EXPAND)
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        self.page_name="Model View"
54        self.nb.Update()
55        self.SetSizer(self.sizer)
56        self.sizer.Fit(self)
57        self.Center()
58       
59       
60    def set_manager(self, manager):
61        """
62             set panel manager
63             @param manager: instance of plugin fitting
64        """
65        self.manager = manager
66        self.sim_page.set_manager(manager)
67       
68    def set_owner(self,owner):
69        """
70            set and owner for fitpanel
71            @param owner: the class responsible of plotting
72        """
73        self.event_owner=owner
74     
75       
76    def add_fit_page( self,page_title ):
77        """
78            Add a fitting page on the notebook contained by fitpanel
79            @param panel: contains in the page to add
80            @param name: title of the page tab
81            @return panel : page just added for futher used. is used by fitting module
82        """     
83        if self.fit_page_name != page_title:
84            from fitpage import FitPage
85            panel = FitPage(self.nb, -1)
86            panel.set_manager(self.manager)
87            panel.set_owner(self.event_owner)
88            self.nb.AddPage(page=panel,text=page_title,select=True)
89            panel.populate_box( self.model_list_box)
90            self.fit_page_name = page_title
91            return panel
92       
93       
94    def add_model_page(self,model,description,page_title):
95        """
96            Add a model page only one  to display any model selected from the menu or the page combo box.
97            when this page is closed than the user will be able to open a new one
98            @param model: the model for which paramters will be changed
99            @param page_title: the name of the page
100        """
101        if  page_title !=self.draw_model_name or self.draw_model_name ==None: 
102            from modelpage import ModelPage
103            panel = ModelPage(self.nb,model,description, -1)
104            panel.set_manager(self.manager)
105            panel.set_owner(self.event_owner)
106            self.nb.AddPage(page=panel,text=page_title,select=True)
107            panel.populate_box( self.model_list_box)
108            self.draw_model_name=page_title
109        else:
110            for i in range(self.nb.GetPageCount()):
111                if self.nb.GetPageText(i)==self.page_name:
112                    page=self.nb.GetPage(i)
113                    page.set_page(model,description)
114                    break
115               
116           
117    def get_notebook(self):
118        """
119            @return self.nb: return its own notebook mostly used by fitting module
120        """
121        return self.nb
122   
123    def get_page(self, n):
124        """
125            @return page at position n
126            @param n: page number
127        """
128        return self.nb.GetPage(n)
129   
130   
131    def get_page_count(self):
132        """ @return  number total of pages contained in notebook"""
133        return self.nb.GetPageCount()
134       
135       
136    def get_current_page(self):
137        """
138            @return the current page selected
139        """
140        return self.nb.GetCurrentPage()
141   
142   
143    def get_selected_page(self):
144        """ @return the page just selected by the user """
145        return self.nb.GetPage(self.nb.GetSelection())
146   
147    def onClose(self,event):
148        """
149             close the current page except the simpage. remove each check box link to the model
150             selected on that page. remove its reference into page_finder (fitting module)
151        """
152        sim_page = self.nb.GetPage(0)
153        selected_page = self.nb.GetPage(self.nb.GetSelection())
154       
155        if sim_page != selected_page:
156            # remove the check box link to the model name of this page (selected_page)
157            sim_page.remove_model(selected_page)
158            #remove that page from page_finder of fitting module
159            page_finder=self.manager.get_page_finder() 
160            for page, value in page_finder.iteritems():
161                if page==selected_page:
162                    del page_finder[page]
163                    break
164            #Delete the page from notebook
165            page_number = self.nb.GetSelection()
166            if self.nb.GetPageText(page_number)== self.page_name:
167                self.draw_model_name=None
168               
169            selected_page.Destroy()
170            self.nb.RemovePage(page_number)
171            #self.name=None
172            self.fit_page_name=None
173           
174    def set_model_list(self,dict):
175         """
176             copy a dictionary of model into its own dictionary
177             @param dict: dictionnary made of model name as key and model class
178             as value
179         """
180         self.model_list_box = dict
181 
Note: See TracBrowser for help on using the repository browser.