source: sasview/sansview/perspectives/fitting/new_fitpanel.py @ 1374fbe4

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

refactore panels

  • Property mode set to 100644
File size: 8.0 KB
RevLine 
[68dada4]1import wx
2import wx.aui
3import wx.lib
4import numpy
5import string ,re
6#import models
7_BOX_WIDTH = 80
8
9
[c80c06f]10class FitPanel(wx.aui.AuiNotebook):   
11#class FitPanel(wx.aui.AuiNotebook,wx.panel):
[68dada4]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 "
22    CENTER_PANE = True
23    def __init__(self, parent, *args, **kwargs):
[c80c06f]24       
25        wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_SCROLL_BUTTONS )
26       
[68dada4]27        self.manager=None
28        self.parent=parent
29        self.event_owner=None
[c80c06f]30       
31        pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE
32        self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)
33
[68dada4]34        #Creating an initial page for simultaneous fitting
35        from simfitpage import SimultaneousFitPage
[c80c06f]36        self.sim_page = SimultaneousFitPage(self, -1)
37        self.AddPage(self.sim_page,"Simultaneous Fit")
38       
39
[68dada4]40       
41        #dictionary of miodel {model class name, model class}
42        self.model_list_box={}
43        # save the title of the last page tab added
44        self.fit_page_name=None
45        self.draw_model_name=None
46        #model page info
47        self.model_page_number=None
48        self.page_name=None
49        self.model_page=None
50        # increment number for model name
51        self.count=0
52        #updating the panel
[c80c06f]53        self.Update()
[68dada4]54        self.Center()
[c80c06f]55    def onClosePage(self, event):
56        self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
57        print "went here",self.get_current_page(), self.GetPage(0)
58        #event.Skip()
59        if self.GetPageCount() <= 2:
60            print "wente here"
61           
62            # Prevent last tab from being closed
63            self.ToggleWindowStyle(~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
64           
65
66   
67
[68dada4]68
69       
70    def set_manager(self, manager):
71        """
72             set panel manager
73             @param manager: instance of plugin fitting
74        """
75        self.manager = manager
76        self.sim_page.set_manager(manager)
77       
78    def set_owner(self,owner):
79        """
80            set and owner for fitpanel
81            @param owner: the class responsible of plotting
82        """
83        self.event_owner=owner
84     
85       
86    def add_fit_page( self,data ):
87        """
88            Add a fitting page on the notebook contained by fitpanel
89            @param panel: contains in the page to add
90            @param name: title of the page tab
91            @return panel : page just added for futher used. is used by fitting module
92        """     
93        try:
94            name = data.name # item in Data1D
95        except:
96            name = 'Fit'
97        if self.fit_page_name != name:
98            self.count +=1
99            if data.__class__.__name__=='Data2D':
100                 from fitpage2D import FitPage2D
[c80c06f]101                 panel = FitPage2D(self,data, -1)
[68dada4]102                 
103            else:
104               
105                from fitpage1D import FitPage1D
[c80c06f]106                panel = FitPage1D(self,data, -1)
[68dada4]107            m_name= "M"+str(self.count) 
108            panel.set_manager(self.manager)
109            panel.set_owner(self.event_owner)
110           
[c80c06f]111            self.AddPage(page=panel,caption=name,select=True)
[68dada4]112            panel.populate_box( self.model_list_box)
113            self.fit_page_name = name
114            return panel,m_name
115       
116    def _help_add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50):
117        """
118            #TODO: fill in description
119           
120            @param qmin: mimimum Q
121            @param qmax: maximum Q
122            @param npts: number of Q points
123        """
124        from modelpage import ModelPage
[c80c06f]125        panel = ModelPage(self,model,page_title, -1)
[68dada4]126        panel.set_manager(self.manager)
127        panel.set_owner(self.event_owner)
[c80c06f]128        self.AddPage(page=panel,caption="Model",select=True)
[68dada4]129        panel.populate_box( self.model_list_box)
130        self.draw_model_name=page_title
[c80c06f]131        self.model_page_number=self.GetSelection()
132        self.model_page=self.GetPage(self.GetSelection())
[68dada4]133       
134       
135        # Set the range used to plot models
136        self.model_page.set_range(qmin, qmax, npts)
137       
138        # We just created a model page, we are ready to plot the model
139        #self.manager.draw_model(model, model.name)
140        #FOR PLUGIN  for somereason model.name is = BASEcomponent
141        self.manager.draw_model(model, page_title)
142       
143       
144    def add_model_page(self,model,description,page_title, qmin=0, qmax=0.1, npts=50, topmenu=False):
145        """
146            Add a model page only one  to display any model selected from the menu or the page combo box.
147            when this page is closed than the user will be able to open a new one
148           
149            @param model: the model for which paramters will be changed
150            @param page_title: the name of the page
151            @param description: [Coder: fill your description!]
152            @param page_title: [Coder: fill your description!]
153            @param qmin: mimimum Q
154            @param qmax: maximum Q
155            @param npts: number of Q points
156        """
157        if  self.draw_model_name ==None:
158            self._help_add_model_page(model,description,page_title, qmin=qmin, qmax=qmax, npts=npts)
159        elif topmenu==True:
160            self.model_page.select_model(model, page_title)
161           
162    def get_current_page(self):
163        """
164            @return the current page selected
165        """
166        #return self.nb.GetCurrentPage()
[c80c06f]167        return self.GetPage(self.GetSelection() )
168 
[68dada4]169   
[c80c06f]170    def old_onClose(self, page=None,page_number=None):
[68dada4]171        """
172             close the current page except the simpage. remove each check box link to the model
173             selected on that page. remove its reference into page_finder (fitting module)
174        """
175        print "model page", page_number, page
176        if page!=None and page_number!=None:
177           
178            self.nb.RemovePage(page_number)
179            page.Destroy()
180            self.model_page_number=None
181            self.model_page=None
182            self.draw_model_name=None
183            return 
184        try:
185            sim_page = self.nb.GetPage(0)
186            selected_page = self.nb.GetPage(self.nb.GetSelection())
187           
188            if sim_page != selected_page:
189                # remove the check box link to the model name of this page (selected_page)
190                sim_page.remove_model(selected_page)
191                #remove that page from page_finder of fitting module
192                page_finder=self.manager.get_page_finder() 
193                for page, value in page_finder.iteritems():
194                    if page==selected_page:
195                        del page_finder[page]
196                        break
197                #Delete the page from notebook
198                page_number = self.nb.GetSelection()
199                if self.nb.GetPageText(page_number)== self.page_name:
200                    self.draw_model_name=None
201                if  page_number == 1:
202                    self.model_page=None
203                    self.draw_model_name=None
204                selected_page.Destroy()
205                self.nb.RemovePage(page_number)
206                #self.count =self.count -1
207                self.fit_page_name=None
208        except:
209            raise
210        #print "fitpanel", self.draw_model_name
211       
212    def set_model_list(self,dict):
213         """
214             copy a dictionary of model into its own dictionary
215             @param dict: dictionnary made of model name as key and model class
216             as value
217         """
218         self.model_list_box = dict
219 
Note: See TracBrowser for help on using the repository browser.