1 | import wx |
---|
2 | import wx.aui |
---|
3 | import wx.lib |
---|
4 | import numpy |
---|
5 | import string ,re |
---|
6 | #import models |
---|
7 | _BOX_WIDTH = 80 |
---|
8 | (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() |
---|
9 | |
---|
10 | class FitPanel(wx.aui.AuiNotebook): |
---|
11 | |
---|
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): |
---|
24 | wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_DEFAULT_STYLE ) |
---|
25 | |
---|
26 | |
---|
27 | self.manager=None |
---|
28 | self.parent=parent |
---|
29 | self.event_owner=None |
---|
30 | |
---|
31 | pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE |
---|
32 | self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage) |
---|
33 | #Creating the default page --welcomed page |
---|
34 | self.about_page=None |
---|
35 | from welcome_panel import PanelAbout |
---|
36 | self.about_page = PanelAbout(self, -1) |
---|
37 | self.AddPage(self.about_page,"welcome!") |
---|
38 | |
---|
39 | |
---|
40 | #dictionary of miodel {model class name, model class} |
---|
41 | self.model_list_box={} |
---|
42 | ##dictionary of page info |
---|
43 | self.page_info_dict={} |
---|
44 | # save the title of the last page tab added |
---|
45 | self.fit_page_name=[] |
---|
46 | self.draw_model_name=None |
---|
47 | #model page info |
---|
48 | self.model_page_number=None |
---|
49 | |
---|
50 | self.model_page=None |
---|
51 | self.sim_page=None |
---|
52 | # increment number for model name |
---|
53 | self.count=0 |
---|
54 | #updating the panel |
---|
55 | self.Update() |
---|
56 | self.Center() |
---|
57 | |
---|
58 | |
---|
59 | def onClosePage(self, event): |
---|
60 | """ |
---|
61 | close page and remove all references to the closed page |
---|
62 | """ |
---|
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) |
---|
72 | |
---|
73 | selected_page = self.GetPage(self.GetSelection()) |
---|
74 | page_number = self.GetSelection() |
---|
75 | |
---|
76 | if self.sim_page != selected_page and selected_page!=self.about_page: |
---|
77 | # remove the check box link to the model name of this page (selected_page) |
---|
78 | if self.sim_page !=None : |
---|
79 | self.sim_page.draw_page() |
---|
80 | |
---|
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 |
---|
88 | |
---|
89 | if page_number == 1: |
---|
90 | self.model_page=None |
---|
91 | self.draw_model_name=None |
---|
92 | |
---|
93 | elif selected_page==self.about_page: |
---|
94 | self.about_page=None |
---|
95 | else: |
---|
96 | self.manager.sim_page=None |
---|
97 | |
---|
98 | |
---|
99 | def set_manager(self, manager): |
---|
100 | """ |
---|
101 | set panel manager |
---|
102 | @param manager: instance of plugin fitting |
---|
103 | """ |
---|
104 | self.manager = manager |
---|
105 | |
---|
106 | |
---|
107 | def set_owner(self,owner): |
---|
108 | """ |
---|
109 | set and owner for fitpanel |
---|
110 | @param owner: the class responsible of plotting |
---|
111 | """ |
---|
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 |
---|
121 | |
---|
122 | |
---|
123 | def get_current_page(self): |
---|
124 | """ |
---|
125 | @return the current page selected |
---|
126 | """ |
---|
127 | return self.GetPage(self.GetSelection() ) |
---|
128 | |
---|
129 | def add_sim_page(self): |
---|
130 | """ |
---|
131 | Add the simultaneous fit page |
---|
132 | """ |
---|
133 | from simfitpage import SimultaneousFitPage |
---|
134 | page_finder= self.manager.get_page_finder() |
---|
135 | self.sim_page = SimultaneousFitPage(self,page_finder=page_finder, id=-1) |
---|
136 | |
---|
137 | self.AddPage(self.sim_page,caption="Simultaneous Fit",select=True) |
---|
138 | self.sim_page.set_manager(self.manager) |
---|
139 | return self.sim_page |
---|
140 | |
---|
141 | def add_fit_page( self,data, page_info=None ): |
---|
142 | """ |
---|
143 | Add a fitting page on the notebook contained by fitpanel |
---|
144 | @param data: data to fit |
---|
145 | @return panel : page just added for futher used. is used by fitting module |
---|
146 | """ |
---|
147 | try: |
---|
148 | name = data.name |
---|
149 | except: |
---|
150 | name = 'Fit' |
---|
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 |
---|
159 | |
---|
160 | if not name in self.fit_page_name : |
---|
161 | from fitpage import FitPage |
---|
162 | panel = FitPage(parent= self, page_info=myinfo, name=name ) |
---|
163 | panel.name = name |
---|
164 | panel.window_name= "fitpage" |
---|
165 | self.AddPage(page=panel,caption=name,select=True) |
---|
166 | self.fit_page_name.append(name) |
---|
167 | |
---|
168 | return panel |
---|
169 | else: |
---|
170 | return None |
---|
171 | |
---|
172 | |
---|
173 | def add_model_page(self,model,page_title, qmin=0, qmax=0.1, |
---|
174 | npts=50, topmenu=False,page_info=None): |
---|
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 |
---|
181 | @param page_info: contains info about the state of the page |
---|
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: |
---|
188 | self._help_add_model_page(model,page_title, |
---|
189 | qmin=qmin, qmax=qmax, npts=npts, page_info=page_info) |
---|
190 | else: |
---|
191 | self.model_page.select_model(model, page_title) |
---|
192 | else: |
---|
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): |
---|
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 | """ |
---|
207 | self._create_model_page(model,page_title,qmin=qmin, qmax=qmax, |
---|
208 | npts=npts,page_info= page_info) |
---|
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 | |
---|
214 | def _create_model_page(self,model,page_title, qmin, qmax, npts,page_info=None): |
---|
215 | """ |
---|
216 | adding model page occurs here |
---|
217 | """ |
---|
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 | |
---|
228 | from modelpage import ModelPage |
---|
229 | panel = ModelPage(self,myinfo,page_title) |
---|
230 | |
---|
231 | self.AddPage(page=panel,caption="Model",select=True) |
---|
232 | |
---|
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 | |
---|
242 | |
---|
243 | |
---|
244 | |
---|
245 | |
---|