1 | |
---|
2 | import sys,re,string, wx |
---|
3 | import wx.lib.newevent |
---|
4 | from sans.guiframe.events import StatusEvent |
---|
5 | from sans.guiframe.panel_base import PanelBase |
---|
6 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
7 | #Control panel width |
---|
8 | if sys.platform.count("darwin")==0: |
---|
9 | PANEL_WID = 420 |
---|
10 | FONT_VARIANT = 0 |
---|
11 | else: |
---|
12 | PANEL_WID = 490 |
---|
13 | FONT_VARIANT = 1 |
---|
14 | |
---|
15 | def get_fittableParam( model): |
---|
16 | """ |
---|
17 | return list of fittable parameters name of a model |
---|
18 | |
---|
19 | :param model: the model used |
---|
20 | |
---|
21 | """ |
---|
22 | fittable_param=[] |
---|
23 | |
---|
24 | for item in model.getParamList(): |
---|
25 | if not item in model.getDispParamList(): |
---|
26 | if not item in model.non_fittable: |
---|
27 | fittable_param.append(item) |
---|
28 | |
---|
29 | for item in model.fixed: |
---|
30 | fittable_param.append(item) |
---|
31 | |
---|
32 | return fittable_param |
---|
33 | |
---|
34 | class SimultaneousFitPage(ScrolledPanel, PanelBase): |
---|
35 | """ |
---|
36 | Simultaneous fitting panel |
---|
37 | All that needs to be defined are the |
---|
38 | two data members window_name and window_caption |
---|
39 | """ |
---|
40 | ## Internal name for the AUI manager |
---|
41 | window_name = "simultaneous Fit page" |
---|
42 | ## Title to appear on top of the window |
---|
43 | window_caption = "Simultaneous Fit Page" |
---|
44 | |
---|
45 | |
---|
46 | def __init__(self, parent,page_finder ={}, *args, **kwargs): |
---|
47 | ScrolledPanel.__init__(self, parent,style= wx.FULL_REPAINT_ON_RESIZE ) |
---|
48 | PanelBase.__init__(self, parent) |
---|
49 | """ |
---|
50 | Simultaneous page display |
---|
51 | """ |
---|
52 | ##Font size |
---|
53 | self.SetWindowVariant(variant = FONT_VARIANT) |
---|
54 | self.uid = wx.NewId() |
---|
55 | self.parent = parent |
---|
56 | ## store page_finder |
---|
57 | self.page_finder = page_finder |
---|
58 | ## list contaning info to set constraint |
---|
59 | ## look like self.constraint_dict[page_id]= page |
---|
60 | self.constraint_dict={} |
---|
61 | ## item list self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] |
---|
62 | self.constraints_list=[] |
---|
63 | ## list of current model |
---|
64 | self.model_list=[] |
---|
65 | ## selected mdoel to fit |
---|
66 | self.model_toFit=[] |
---|
67 | ## number of constraint |
---|
68 | self.nb_constraint= 0 |
---|
69 | self.uid = wx.NewId() |
---|
70 | ## draw page |
---|
71 | self.define_page_structure() |
---|
72 | self.draw_page() |
---|
73 | self.set_layout() |
---|
74 | |
---|
75 | def define_page_structure(self): |
---|
76 | """ |
---|
77 | Create empty sizer for a panel |
---|
78 | """ |
---|
79 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
80 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
81 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
82 | self.sizer3 = wx.BoxSizer(wx.VERTICAL) |
---|
83 | |
---|
84 | self.sizer1.SetMinSize((PANEL_WID,-1)) |
---|
85 | self.sizer2.SetMinSize((PANEL_WID,-1)) |
---|
86 | self.sizer3.SetMinSize((PANEL_WID,-1)) |
---|
87 | self.vbox.Add(self.sizer1) |
---|
88 | self.vbox.Add(self.sizer2) |
---|
89 | self.vbox.Add(self.sizer3) |
---|
90 | |
---|
91 | def set_scroll(self): |
---|
92 | """ |
---|
93 | """ |
---|
94 | self.SetScrollbars(20,20,25,65) |
---|
95 | self.Layout() |
---|
96 | |
---|
97 | def set_layout(self): |
---|
98 | """ |
---|
99 | layout |
---|
100 | """ |
---|
101 | self.vbox.Layout() |
---|
102 | self.vbox.Fit(self) |
---|
103 | self.SetSizer(self.vbox) |
---|
104 | self.set_scroll() |
---|
105 | self.Centre() |
---|
106 | |
---|
107 | def onRemove(self, event): |
---|
108 | """ |
---|
109 | Remove constraint fields |
---|
110 | """ |
---|
111 | if len(self.constraints_list)==1: |
---|
112 | self.hide_constraint.SetValue(True) |
---|
113 | self._hide_constraint() |
---|
114 | return |
---|
115 | if len(self.constraints_list)==0: |
---|
116 | return |
---|
117 | for item in self.constraints_list: |
---|
118 | length= len(item) |
---|
119 | if event.GetId()==item[length-2].GetId(): |
---|
120 | sizer= item[length-1] |
---|
121 | sizer.Clear(True) |
---|
122 | self.sizer_constraints.Remove(sizer) |
---|
123 | |
---|
124 | self.sizer2.Layout() |
---|
125 | self.SetScrollbars(20,20,25,65) |
---|
126 | self.constraints_list.remove(item) |
---|
127 | self.nb_constraint -= 1 |
---|
128 | break |
---|
129 | |
---|
130 | def onFit(self, event): |
---|
131 | """ |
---|
132 | signal for fitting |
---|
133 | |
---|
134 | """ |
---|
135 | ## making sure all parameters content a constraint |
---|
136 | ## validity of the constraint expression is own by fit engine |
---|
137 | if self.show_constraint.GetValue(): |
---|
138 | self._set_constraint() |
---|
139 | ## model was actually selected from this page to be fit |
---|
140 | if len(self.model_toFit) >= 1 : |
---|
141 | self.manager._reset_schedule_problem(value=0) |
---|
142 | for item in self.model_list: |
---|
143 | if item[0].GetValue(): |
---|
144 | self.manager.schedule_for_fit(value=1, uid=item[2]) |
---|
145 | self.manager.onFit(uid=self.uid) |
---|
146 | else: |
---|
147 | msg= "Select at least one model to fit " |
---|
148 | wx.PostEvent(self.parent.Parent, StatusEvent(status=msg)) |
---|
149 | |
---|
150 | def set_manager(self, manager): |
---|
151 | """ |
---|
152 | set panel manager |
---|
153 | |
---|
154 | :param manager: instance of plugin fitting |
---|
155 | |
---|
156 | """ |
---|
157 | self.manager = manager |
---|
158 | |
---|
159 | def check_all_model_name(self,event): |
---|
160 | """ |
---|
161 | check all models names |
---|
162 | """ |
---|
163 | self.model_toFit = [] |
---|
164 | if self.cb1.GetValue()== True: |
---|
165 | for item in self.model_list: |
---|
166 | if item[0].IsEnabled(): |
---|
167 | item[0].SetValue(True) |
---|
168 | self.model_toFit.append(item) |
---|
169 | |
---|
170 | ## constraint info |
---|
171 | self._store_model() |
---|
172 | ## display constraint fields |
---|
173 | if self.show_constraint.GetValue(): |
---|
174 | self._show_constraint() |
---|
175 | return |
---|
176 | else: |
---|
177 | for item in self.model_list: |
---|
178 | item[0].SetValue(False) |
---|
179 | |
---|
180 | self.model_toFit=[] |
---|
181 | ##constraint info |
---|
182 | self._hide_constraint() |
---|
183 | |
---|
184 | def check_model_name(self,event): |
---|
185 | """ |
---|
186 | Save information related to checkbox and their states |
---|
187 | """ |
---|
188 | self.model_toFit=[] |
---|
189 | for item in self.model_list: |
---|
190 | if item[0].GetValue()==True: |
---|
191 | self.model_toFit.append(item) |
---|
192 | else: |
---|
193 | if item in self.model_toFit: |
---|
194 | self.model_toFit.remove(item) |
---|
195 | self.cb1.SetValue(False) |
---|
196 | |
---|
197 | ## display constraint fields |
---|
198 | if len(self.model_toFit)==2: |
---|
199 | self._store_model() |
---|
200 | if self.show_constraint.GetValue() and len(self.constraints_list)==0: |
---|
201 | self._show_constraint() |
---|
202 | elif len(self.model_toFit)< 2: |
---|
203 | ##constraint info |
---|
204 | self._hide_constraint() |
---|
205 | |
---|
206 | ## set the value of the main check button |
---|
207 | if len(self.model_list)==len(self.model_toFit): |
---|
208 | self.cb1.SetValue(True) |
---|
209 | return |
---|
210 | else: |
---|
211 | self.cb1.SetValue(False) |
---|
212 | |
---|
213 | def draw_page(self): |
---|
214 | """ |
---|
215 | Draw a sizer containing couples of data and model |
---|
216 | """ |
---|
217 | self.model_list=[] |
---|
218 | self.model_toFit=[] |
---|
219 | self.constraints_list=[] |
---|
220 | self.constraint_dict={} |
---|
221 | self.nb_constraint= 0 |
---|
222 | |
---|
223 | if len(self.model_list)>0: |
---|
224 | for item in self.model_list: |
---|
225 | item[0].SetValue(False) |
---|
226 | self.manager.schedule_for_fit(value=0, uid=item[2]) |
---|
227 | |
---|
228 | self.sizer1.Clear(True) |
---|
229 | box_description= wx.StaticBox(self, -1,"Fit Combinations") |
---|
230 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
231 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
232 | sizer_couples = wx.GridBagSizer(5,5) |
---|
233 | #------------------------------------------------------ |
---|
234 | if len(self.page_finder)==0: |
---|
235 | msg = " No fit combinations are found! \n\n" |
---|
236 | msg += " Please load data and set up at least two fit panels first..." |
---|
237 | sizer_title.Add(wx.StaticText(self, -1, msg)) |
---|
238 | else: |
---|
239 | ## store model |
---|
240 | self._store_model() |
---|
241 | |
---|
242 | self.cb1 = wx.CheckBox(self, -1,'Select all') |
---|
243 | self.cb1.SetValue(False) |
---|
244 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name) |
---|
245 | |
---|
246 | sizer_title.Add((10,10),0, |
---|
247 | wx.TOP|wx.BOTTOM|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
248 | sizer_title.Add(self.cb1,0, |
---|
249 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
250 | |
---|
251 | ## draw list of model and data name |
---|
252 | self._fill_sizer_model_list(sizer_couples) |
---|
253 | ## draw the sizer containing constraint info |
---|
254 | self._fill_sizer_constraint() |
---|
255 | ## draw fit button |
---|
256 | self._fill_sizer_fit() |
---|
257 | #-------------------------------------------------------- |
---|
258 | boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=5) |
---|
259 | boxsizer1.Add(sizer_couples, flag= wx.TOP|wx.BOTTOM,border=5) |
---|
260 | |
---|
261 | self.sizer1.Add(boxsizer1,1, wx.EXPAND | wx.ALL, 10) |
---|
262 | self.sizer1.Layout() |
---|
263 | self.SetScrollbars(20,20,25,65) |
---|
264 | self.AdjustScrollbars() |
---|
265 | |
---|
266 | def _store_model(self): |
---|
267 | """ |
---|
268 | Store selected model |
---|
269 | """ |
---|
270 | if len(self.model_toFit) < 2: |
---|
271 | return |
---|
272 | for item in self.model_toFit: |
---|
273 | model = item[3] |
---|
274 | page_id= item[2] |
---|
275 | self.constraint_dict[page_id] = model |
---|
276 | |
---|
277 | def _display_constraint(self, event): |
---|
278 | """ |
---|
279 | Show fields to add constraint |
---|
280 | """ |
---|
281 | if len(self.model_toFit)< 2: |
---|
282 | msg= "Select at least 2 models to add constraint " |
---|
283 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
284 | ## hide button |
---|
285 | self._hide_constraint() |
---|
286 | return |
---|
287 | if self.show_constraint.GetValue(): |
---|
288 | self._show_constraint() |
---|
289 | return |
---|
290 | else: |
---|
291 | self._hide_constraint() |
---|
292 | return |
---|
293 | |
---|
294 | def _show_constraint(self): |
---|
295 | """ |
---|
296 | Show constraint fields |
---|
297 | """ |
---|
298 | self.btAdd.Show(True) |
---|
299 | if len(self.constraints_list)!= 0: |
---|
300 | nb_fit_param = 0 |
---|
301 | for model in self.constraint_dict.values(): |
---|
302 | nb_fit_param += len(get_fittableParam(model)) |
---|
303 | ##Don't add anymore |
---|
304 | if len(self.constraints_list) == nb_fit_param: |
---|
305 | msg= "Cannot add another constraint .Maximum of number " |
---|
306 | msg += "Parameters name reached %s"%str(nb_fit_param) |
---|
307 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
308 | self.sizer_constraints.Layout() |
---|
309 | self.sizer2.Layout() |
---|
310 | self.SetScrollbars(20,20,25,65) |
---|
311 | return |
---|
312 | |
---|
313 | if len(self.model_toFit) < 2 : |
---|
314 | msg= "Select at least 2 model to add constraint " |
---|
315 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
316 | self.sizer_constraints.Layout() |
---|
317 | self.sizer2.Layout() |
---|
318 | self.SetScrollbars(20,20,25,65) |
---|
319 | return |
---|
320 | |
---|
321 | sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) |
---|
322 | model_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
323 | model_cbox.Clear() |
---|
324 | param_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
325 | param_cbox.Hide() |
---|
326 | |
---|
327 | #This is for GetCLientData() _on_select_param: Was None return on MAC. |
---|
328 | self.param_cbox = param_cbox |
---|
329 | |
---|
330 | wx.EVT_COMBOBOX(param_cbox,-1, self._on_select_param) |
---|
331 | ctl2 = wx.TextCtrl(self, -1) |
---|
332 | egal_txt= wx.StaticText(self,-1," = ") |
---|
333 | btRemove = wx.Button(self,wx.NewId(),'Remove') |
---|
334 | btRemove.Bind(wx.EVT_BUTTON, self.onRemove,id= btRemove.GetId()) |
---|
335 | btRemove.SetToolTipString("Remove constraint.") |
---|
336 | |
---|
337 | for id,model in self.constraint_dict.iteritems(): |
---|
338 | ## check if all parameters have been selected for constraint |
---|
339 | ## then do not allow add constraint on parameters |
---|
340 | model_cbox.Append( str(model.name), model) |
---|
341 | |
---|
342 | #This is for GetCLientData() passing to self._on_select_param: Was None return on MAC. |
---|
343 | self.model_cbox = model_cbox |
---|
344 | |
---|
345 | wx.EVT_COMBOBOX(model_cbox,-1, self._on_select_model) |
---|
346 | |
---|
347 | sizer_constraint.Add(model_cbox, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
348 | sizer_constraint.Add(param_cbox, flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
349 | sizer_constraint.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
350 | sizer_constraint.Add(ctl2, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
351 | sizer_constraint.Add(btRemove, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
352 | |
---|
353 | self.sizer_constraints.Insert(before=self.nb_constraint, |
---|
354 | item=sizer_constraint, flag= wx.TOP|wx.BOTTOM|wx.EXPAND, |
---|
355 | border=5) |
---|
356 | ##[combobox1, combobox2,=,textcrtl, remove button ] |
---|
357 | self.constraints_list.append([model_cbox, param_cbox, egal_txt, ctl2,btRemove,sizer_constraint]) |
---|
358 | |
---|
359 | self.nb_constraint += 1 |
---|
360 | self.sizer_constraints.Layout() |
---|
361 | self.sizer2.Layout() |
---|
362 | self.SetScrollbars(20,20,25,65) |
---|
363 | |
---|
364 | def _hide_constraint(self): |
---|
365 | """ |
---|
366 | hide buttons related constraint |
---|
367 | """ |
---|
368 | for id in self.page_finder.iterkeys(): |
---|
369 | self.page_finder[id].clear_model_param() |
---|
370 | |
---|
371 | self.nb_constraint =0 |
---|
372 | self.constraint_dict={} |
---|
373 | if hasattr(self,"btAdd"): |
---|
374 | self.btAdd.Hide() |
---|
375 | self._store_model() |
---|
376 | self.constraints_list=[] |
---|
377 | self.sizer_constraints.Clear(True) |
---|
378 | self.sizer_constraints.Layout() |
---|
379 | self.sizer2.Layout() |
---|
380 | self.SetScrollbars(20,20,25,65) |
---|
381 | self.AdjustScrollbars() |
---|
382 | |
---|
383 | def _on_select_model(self, event): |
---|
384 | """ |
---|
385 | fill combox box with list of parameters |
---|
386 | """ |
---|
387 | ##This way PC/MAC both work, instead of using event.GetClientData(). |
---|
388 | n = self.model_cbox.GetCurrentSelection() |
---|
389 | model = self.model_cbox.GetClientData(n) |
---|
390 | |
---|
391 | param_list= get_fittableParam(model) |
---|
392 | length = len(self.constraints_list) |
---|
393 | if length < 1: |
---|
394 | return |
---|
395 | param_cbox = self.constraints_list[length-1][1] |
---|
396 | param_cbox.Clear() |
---|
397 | ## insert only fittable paramaters |
---|
398 | for param in param_list: |
---|
399 | param_cbox.Append( str(param), model) |
---|
400 | |
---|
401 | param_cbox.Show(True) |
---|
402 | self.sizer2.Layout() |
---|
403 | self.SetScrollbars(20,20,25,65) |
---|
404 | |
---|
405 | def _on_select_param(self, event): |
---|
406 | """ |
---|
407 | Store the appropriate constraint in the page_finder |
---|
408 | """ |
---|
409 | ##This way PC/MAC both work, instead of using event.GetClientData(). |
---|
410 | n = self.param_cbox.GetCurrentSelection() |
---|
411 | model = self.param_cbox.GetClientData(n) |
---|
412 | param = event.GetString() |
---|
413 | |
---|
414 | length = len(self.constraints_list) |
---|
415 | if length < 1: |
---|
416 | return |
---|
417 | egal_txt = self.constraints_list[length-1][2] |
---|
418 | egal_txt.Show(True) |
---|
419 | |
---|
420 | ctl2 = self.constraints_list[length-1][3] |
---|
421 | ctl2.Show(True) |
---|
422 | #self.sizer2.Layout() |
---|
423 | self.SetScrollbars(20,20,25,65) |
---|
424 | |
---|
425 | def _onAdd_constraint(self, event): |
---|
426 | """ |
---|
427 | Add another line for constraint |
---|
428 | """ |
---|
429 | if not self.show_constraint.GetValue(): |
---|
430 | msg= " Select Yes to add Constraint " |
---|
431 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
432 | return |
---|
433 | ## check that a constraint is added before allow to add another cosntraint |
---|
434 | for item in self.constraints_list: |
---|
435 | model_cbox = item[0] |
---|
436 | if model_cbox.GetString(0)=="": |
---|
437 | msg= " Select a model Name! " |
---|
438 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
439 | return |
---|
440 | param_cbox = item[1] |
---|
441 | if param_cbox.GetString(0)=="": |
---|
442 | msg= " Select a parameter Name! " |
---|
443 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
444 | return |
---|
445 | ctl2 = item[3] |
---|
446 | if ctl2.GetValue().lstrip().rstrip()=="": |
---|
447 | model= param_cbox.GetClientData(param_cbox.GetCurrentSelection()) |
---|
448 | msg= " Enter a constraint for %s.%s! "%(model.name,param_cbox.GetString(0)) |
---|
449 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
450 | return |
---|
451 | ## some model or parameters can be constrained |
---|
452 | self._show_constraint() |
---|
453 | |
---|
454 | def _fill_sizer_fit(self): |
---|
455 | """ |
---|
456 | Draw fit button |
---|
457 | """ |
---|
458 | self.sizer3.Clear(True) |
---|
459 | box_description= wx.StaticBox(self, -1,"Fit ") |
---|
460 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
461 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
462 | |
---|
463 | self.btFit = wx.Button(self,wx.NewId(),'Fit') |
---|
464 | self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id= self.btFit.GetId()) |
---|
465 | self.btFit.SetToolTipString("Perform fit.") |
---|
466 | |
---|
467 | text= "Hint: Park fitting engine will be selected \n" |
---|
468 | text+= "automatically for more than 2 combinations checked" |
---|
469 | text_hint = wx.StaticText(self,-1,text) |
---|
470 | |
---|
471 | sizer_button.Add(text_hint, wx.RIGHT|wx.EXPAND, 10) |
---|
472 | sizer_button.Add(self.btFit, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
473 | |
---|
474 | boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
475 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
476 | self.sizer3.Layout() |
---|
477 | self.SetScrollbars(20,20,25,65) |
---|
478 | |
---|
479 | def _fill_sizer_constraint(self): |
---|
480 | """ |
---|
481 | Fill sizer containing constraint info |
---|
482 | """ |
---|
483 | msg = "Select at least 2 model to add constraint " |
---|
484 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
485 | |
---|
486 | self.sizer2.Clear(True) |
---|
487 | box_description= wx.StaticBox(self, -1,"Fit Constraints") |
---|
488 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
489 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
490 | self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) |
---|
491 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
492 | |
---|
493 | self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) |
---|
494 | self.show_constraint = wx.RadioButton(self, -1, 'Yes', (10, 30)) |
---|
495 | self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, |
---|
496 | id= self.hide_constraint.GetId() ) |
---|
497 | self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, |
---|
498 | id= self.show_constraint.GetId() ) |
---|
499 | self.hide_constraint.SetValue(True) |
---|
500 | sizer_title.Add( wx.StaticText(self,-1," Model") ) |
---|
501 | sizer_title.Add(( 10,10) ) |
---|
502 | sizer_title.Add( wx.StaticText(self,-1," Parameter") ) |
---|
503 | sizer_title.Add(( 10,10) ) |
---|
504 | sizer_title.Add( wx.StaticText(self,-1," Add Constraint?") ) |
---|
505 | sizer_title.Add(( 10,10) ) |
---|
506 | sizer_title.Add( self.show_constraint ) |
---|
507 | sizer_title.Add( self.hide_constraint ) |
---|
508 | sizer_title.Add(( 10,10) ) |
---|
509 | |
---|
510 | self.btAdd =wx.Button(self,wx.NewId(),'Add') |
---|
511 | self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint,id= self.btAdd.GetId()) |
---|
512 | self.btAdd.SetToolTipString("Add another constraint?") |
---|
513 | self.btAdd.Hide() |
---|
514 | |
---|
515 | text_hint = wx.StaticText(self,-1,"Example: [M0][paramter] = M1.parameter") |
---|
516 | sizer_button.Add(text_hint, 0 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
517 | sizer_button.Add(self.btAdd, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
518 | |
---|
519 | boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
520 | boxsizer1.Add(self.sizer_constraints, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
521 | boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
522 | |
---|
523 | self.sizer2.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
524 | self.sizer2.Layout() |
---|
525 | self.SetScrollbars(20,20,25,65) |
---|
526 | |
---|
527 | def _set_constraint(self): |
---|
528 | """ |
---|
529 | get values from the constrainst textcrtl ,parses them into model name |
---|
530 | parameter name and parameters values. |
---|
531 | store them in a list self.params .when when params is not empty set_model |
---|
532 | uses it to reset the appropriate model and its appropriates parameters |
---|
533 | """ |
---|
534 | for item in self.constraints_list: |
---|
535 | model = item[0].GetClientData(item[0].GetCurrentSelection()) |
---|
536 | param = item[1].GetString(item[1].GetCurrentSelection()) |
---|
537 | constraint = item[3].GetValue().lstrip().rstrip() |
---|
538 | if param.lstrip().rstrip()=="": |
---|
539 | param= None |
---|
540 | msg= " Constraint will be ignored!. missing parameters in combobox" |
---|
541 | msg+= " to set constraint! " |
---|
542 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
543 | for id, value in self.constraint_dict.iteritems(): |
---|
544 | if model == value: |
---|
545 | if constraint == "": |
---|
546 | msg= " Constraint will be ignored!. missing value in textcrtl" |
---|
547 | msg+= " to set constraint! " |
---|
548 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
549 | constraint = None |
---|
550 | for fid in self.page_finder[id].iterkeys(): |
---|
551 | self.page_finder[id].set_model_param(param, |
---|
552 | constraint, fid=fid) |
---|
553 | break |
---|
554 | |
---|
555 | def _fill_sizer_model_list(self,sizer): |
---|
556 | """ |
---|
557 | Receive a dictionary containing information to display model name |
---|
558 | |
---|
559 | :param page_finder: the dictionary containing models information |
---|
560 | |
---|
561 | """ |
---|
562 | ix = 0 |
---|
563 | iy = 0 |
---|
564 | list=[] |
---|
565 | sizer.Clear(True) |
---|
566 | |
---|
567 | new_name = wx.StaticText(self, -1, 'New Model Name', style=wx.ALIGN_CENTER) |
---|
568 | new_name.SetBackgroundColour('orange') |
---|
569 | sizer.Add(new_name,(iy, ix),(1,1), |
---|
570 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
571 | ix += 2 |
---|
572 | model_type = wx.StaticText(self, -1, ' Model Type') |
---|
573 | model_type.SetBackgroundColour('grey') |
---|
574 | sizer.Add(model_type,(iy, ix),(1,1), |
---|
575 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
576 | ix += 1 |
---|
577 | data_used = wx.StaticText(self, -1, ' Used Data') |
---|
578 | data_used.SetBackgroundColour('grey') |
---|
579 | sizer.Add(data_used,(iy, ix),(1,1), |
---|
580 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
581 | ix += 1 |
---|
582 | tab_used = wx.StaticText(self, -1, ' Fit Tab') |
---|
583 | tab_used.SetBackgroundColour('grey') |
---|
584 | sizer.Add(tab_used,(iy, ix),(1,1), |
---|
585 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
586 | for id, value in self.page_finder.iteritems(): |
---|
587 | try: |
---|
588 | ix = 0 |
---|
589 | iy += 1 |
---|
590 | for fitproblem in value.get_fit_problem(): |
---|
591 | data = fitproblem.get_fit_data() |
---|
592 | model = fitproblem.get_model() |
---|
593 | name = '_' |
---|
594 | if model is not None: |
---|
595 | name = str(model.name) |
---|
596 | cb = wx.CheckBox(self, -1, name) |
---|
597 | cb.SetValue(False) |
---|
598 | cb.Enable(model is not None and data.is_data) |
---|
599 | sizer.Add(cb, (iy, ix), (1, 1), |
---|
600 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
601 | wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) |
---|
602 | ix += 2 |
---|
603 | type = model.__class__.__name__ |
---|
604 | model_type = wx.StaticText(self, -1, str(type)) |
---|
605 | sizer.Add(model_type, (iy, ix), (1, 1), |
---|
606 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
607 | name = '-' |
---|
608 | if data is not None and data.is_data: |
---|
609 | name = str(data.name) |
---|
610 | data_used = wx.StaticText(self, -1, name) |
---|
611 | ix += 1 |
---|
612 | sizer.Add(data_used, (iy, ix), (1, 1), |
---|
613 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
614 | ix += 1 |
---|
615 | caption = value.get_fit_tab_caption() |
---|
616 | tab_caption_used= wx.StaticText(self, -1, str(caption)) |
---|
617 | sizer.Add(tab_caption_used, (iy, ix), (1, 1), |
---|
618 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
619 | |
---|
620 | self.model_list.append([cb,value,id,model]) |
---|
621 | |
---|
622 | except: |
---|
623 | raise |
---|
624 | #pass |
---|
625 | iy += 1 |
---|
626 | sizer.Add((20, 20), (iy, ix), (1, 1), |
---|
627 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
628 | sizer.Layout() |
---|
629 | |
---|
630 | def on_set_focus(self, event=None): |
---|
631 | """ |
---|
632 | The derivative class is on focus if implemented |
---|
633 | """ |
---|
634 | if self.parent is not None: |
---|
635 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) |
---|
636 | self.page_finder = self.parent.get_page_finder() |
---|
637 | |
---|