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 = None |
---|
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 | ## get the fit range of very fit problem |
---|
140 | for id, value in self.page_finder.iteritems(): |
---|
141 | qmin, qmax= self.page_finder[id].get_range() |
---|
142 | value.set_range(qmin, qmax) |
---|
143 | ## model was actually selected from this page to be fit |
---|
144 | if len(self.model_toFit) >= 1 : |
---|
145 | self.manager._reset_schedule_problem(value=0) |
---|
146 | for item in self.model_list: |
---|
147 | if item[0].GetValue(): |
---|
148 | self.manager.schedule_for_fit( value=1, fitproblem =item[1]) |
---|
149 | self.manager.onFit(None) |
---|
150 | else: |
---|
151 | msg= "Select at least one model to fit " |
---|
152 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
153 | |
---|
154 | def set_manager(self, manager): |
---|
155 | """ |
---|
156 | set panel manager |
---|
157 | |
---|
158 | :param manager: instance of plugin fitting |
---|
159 | |
---|
160 | """ |
---|
161 | self.manager = manager |
---|
162 | |
---|
163 | def check_all_model_name(self,event): |
---|
164 | """ |
---|
165 | check all models names |
---|
166 | """ |
---|
167 | self.model_toFit = [] |
---|
168 | if self.cb1.GetValue()== True: |
---|
169 | for item in self.model_list: |
---|
170 | item[0].SetValue(True) |
---|
171 | self.model_toFit.append(item) |
---|
172 | |
---|
173 | ## constraint info |
---|
174 | self._store_model() |
---|
175 | ## display constraint fields |
---|
176 | if self.show_constraint.GetValue(): |
---|
177 | self._show_constraint() |
---|
178 | return |
---|
179 | else: |
---|
180 | for item in self.model_list: |
---|
181 | item[0].SetValue(False) |
---|
182 | |
---|
183 | self.model_toFit=[] |
---|
184 | ##constraint info |
---|
185 | self._hide_constraint() |
---|
186 | |
---|
187 | def check_model_name(self,event): |
---|
188 | """ |
---|
189 | Save information related to checkbox and their states |
---|
190 | """ |
---|
191 | self.model_toFit=[] |
---|
192 | for item in self.model_list: |
---|
193 | if item[0].GetValue()==True: |
---|
194 | self.model_toFit.append(item) |
---|
195 | else: |
---|
196 | if item in self.model_toFit: |
---|
197 | self.model_toFit.remove(item) |
---|
198 | self.cb1.SetValue(False) |
---|
199 | |
---|
200 | ## display constraint fields |
---|
201 | if len(self.model_toFit)==2: |
---|
202 | self._store_model() |
---|
203 | if self.show_constraint.GetValue() and len(self.constraints_list)==0: |
---|
204 | self._show_constraint() |
---|
205 | elif len(self.model_toFit)< 2: |
---|
206 | ##constraint info |
---|
207 | self._hide_constraint() |
---|
208 | |
---|
209 | ## set the value of the main check button |
---|
210 | if len(self.model_list)==len(self.model_toFit): |
---|
211 | self.cb1.SetValue(True) |
---|
212 | return |
---|
213 | else: |
---|
214 | self.cb1.SetValue(False) |
---|
215 | |
---|
216 | def draw_page(self): |
---|
217 | """ |
---|
218 | Draw a sizer containing couples of data and model |
---|
219 | """ |
---|
220 | self.model_list=[] |
---|
221 | self.model_toFit=[] |
---|
222 | self.constraints_list=[] |
---|
223 | self.constraint_dict={} |
---|
224 | self.nb_constraint= 0 |
---|
225 | |
---|
226 | if len(self.model_list)>0: |
---|
227 | for item in self.model_list: |
---|
228 | item[0].SetValue(False) |
---|
229 | self.manager.schedule_for_fit( value=0,fitproblem =item[1]) |
---|
230 | |
---|
231 | self.sizer1.Clear(True) |
---|
232 | box_description= wx.StaticBox(self, -1,"Fit Combinations") |
---|
233 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
234 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
235 | sizer_couples = wx.GridBagSizer(5,5) |
---|
236 | #------------------------------------------------------ |
---|
237 | if len(self.page_finder)==0: |
---|
238 | msg = " No fit combinations are found! \n\n" |
---|
239 | msg += " Please load data and set up at least two fit panels first..." |
---|
240 | sizer_title.Add(wx.StaticText(self, -1, msg)) |
---|
241 | else: |
---|
242 | ## store model |
---|
243 | self._store_model() |
---|
244 | |
---|
245 | self.cb1 = wx.CheckBox(self, -1,'Select all') |
---|
246 | self.cb1.SetValue(False) |
---|
247 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name) |
---|
248 | |
---|
249 | sizer_title.Add((10,10),0, |
---|
250 | wx.TOP|wx.BOTTOM|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
251 | sizer_title.Add(self.cb1,0, |
---|
252 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
253 | |
---|
254 | ## draw list of model and data name |
---|
255 | self._fill_sizer_model_list(sizer_couples) |
---|
256 | ## draw the sizer containing constraint info |
---|
257 | self._fill_sizer_constraint() |
---|
258 | ## draw fit button |
---|
259 | self._fill_sizer_fit() |
---|
260 | #-------------------------------------------------------- |
---|
261 | boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=5) |
---|
262 | boxsizer1.Add(sizer_couples, flag= wx.TOP|wx.BOTTOM,border=5) |
---|
263 | |
---|
264 | self.sizer1.Add(boxsizer1,1, wx.EXPAND | wx.ALL, 10) |
---|
265 | self.sizer1.Layout() |
---|
266 | self.SetScrollbars(20,20,25,65) |
---|
267 | self.AdjustScrollbars() |
---|
268 | |
---|
269 | def _store_model(self): |
---|
270 | """ |
---|
271 | Store selected model |
---|
272 | """ |
---|
273 | if len(self.model_toFit) < 2: |
---|
274 | return |
---|
275 | for item in self.model_toFit: |
---|
276 | model = item[3] |
---|
277 | page_id= item[2] |
---|
278 | self.constraint_dict[page_id] = model |
---|
279 | |
---|
280 | def _display_constraint(self, event): |
---|
281 | """ |
---|
282 | Show fields to add constraint |
---|
283 | """ |
---|
284 | if len(self.model_toFit)< 2: |
---|
285 | msg= "Select at least 2 models to add constraint " |
---|
286 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
287 | ## hide button |
---|
288 | self._hide_constraint() |
---|
289 | return |
---|
290 | if self.show_constraint.GetValue(): |
---|
291 | self._show_constraint() |
---|
292 | return |
---|
293 | else: |
---|
294 | self._hide_constraint() |
---|
295 | return |
---|
296 | |
---|
297 | def _show_constraint(self): |
---|
298 | """ |
---|
299 | Show constraint fields |
---|
300 | """ |
---|
301 | self.btAdd.Show(True) |
---|
302 | if len(self.constraints_list)!= 0: |
---|
303 | nb_fit_param = 0 |
---|
304 | for model in self.constraint_dict.values(): |
---|
305 | nb_fit_param += len(get_fittableParam(model)) |
---|
306 | ##Don't add anymore |
---|
307 | if len(self.constraints_list) == nb_fit_param: |
---|
308 | msg= "Cannot add another constraint .Maximum of number " |
---|
309 | msg += "Parameters name reached %s"%str(nb_fit_param) |
---|
310 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
311 | self.sizer_constraints.Layout() |
---|
312 | self.sizer2.Layout() |
---|
313 | self.SetScrollbars(20,20,25,65) |
---|
314 | return |
---|
315 | |
---|
316 | if len(self.model_toFit) < 2 : |
---|
317 | msg= "Select at least 2 model to add constraint " |
---|
318 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
319 | self.sizer_constraints.Layout() |
---|
320 | self.sizer2.Layout() |
---|
321 | self.SetScrollbars(20,20,25,65) |
---|
322 | return |
---|
323 | |
---|
324 | sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) |
---|
325 | model_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
326 | model_cbox.Clear() |
---|
327 | param_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
328 | param_cbox.Hide() |
---|
329 | |
---|
330 | #This is for GetCLientData() _on_select_param: Was None return on MAC. |
---|
331 | self.param_cbox = param_cbox |
---|
332 | |
---|
333 | wx.EVT_COMBOBOX(param_cbox,-1, self._on_select_param) |
---|
334 | ctl2 = wx.TextCtrl(self, -1) |
---|
335 | egal_txt= wx.StaticText(self,-1," = ") |
---|
336 | btRemove = wx.Button(self,wx.NewId(),'Remove') |
---|
337 | btRemove.Bind(wx.EVT_BUTTON, self.onRemove,id= btRemove.GetId()) |
---|
338 | btRemove.SetToolTipString("Remove constraint.") |
---|
339 | |
---|
340 | for id,model in self.constraint_dict.iteritems(): |
---|
341 | ## check if all parameters have been selected for constraint |
---|
342 | ## then do not allow add constraint on parameters |
---|
343 | model_cbox.Append( str(model.name), model) |
---|
344 | |
---|
345 | #This is for GetCLientData() passing to self._on_select_param: Was None return on MAC. |
---|
346 | self.model_cbox = model_cbox |
---|
347 | |
---|
348 | wx.EVT_COMBOBOX(model_cbox,-1, self._on_select_model) |
---|
349 | |
---|
350 | sizer_constraint.Add(model_cbox, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
351 | sizer_constraint.Add(param_cbox, flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
352 | sizer_constraint.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
353 | sizer_constraint.Add(ctl2, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
354 | sizer_constraint.Add(btRemove, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
355 | |
---|
356 | self.sizer_constraints.Insert(before=self.nb_constraint, |
---|
357 | item=sizer_constraint, flag= wx.TOP|wx.BOTTOM|wx.EXPAND, |
---|
358 | border=5) |
---|
359 | ##[combobox1, combobox2,=,textcrtl, remove button ] |
---|
360 | self.constraints_list.append([model_cbox, param_cbox, egal_txt, ctl2,btRemove,sizer_constraint]) |
---|
361 | |
---|
362 | self.nb_constraint += 1 |
---|
363 | self.sizer_constraints.Layout() |
---|
364 | self.sizer2.Layout() |
---|
365 | self.SetScrollbars(20,20,25,65) |
---|
366 | |
---|
367 | def _hide_constraint(self): |
---|
368 | """ |
---|
369 | hide buttons related constraint |
---|
370 | """ |
---|
371 | for id in self.page_finder.iterkeys(): |
---|
372 | self.page_finder[id].clear_model_param() |
---|
373 | |
---|
374 | self.nb_constraint =0 |
---|
375 | self.constraint_dict={} |
---|
376 | if hasattr(self,"btAdd"): |
---|
377 | self.btAdd.Hide() |
---|
378 | self._store_model() |
---|
379 | self.constraints_list=[] |
---|
380 | self.sizer_constraints.Clear(True) |
---|
381 | self.sizer_constraints.Layout() |
---|
382 | self.sizer2.Layout() |
---|
383 | self.SetScrollbars(20,20,25,65) |
---|
384 | self.AdjustScrollbars() |
---|
385 | |
---|
386 | def _on_select_model(self, event): |
---|
387 | """ |
---|
388 | fill combox box with list of parameters |
---|
389 | """ |
---|
390 | ##This way PC/MAC both work, instead of using event.GetClientData(). |
---|
391 | n = self.model_cbox.GetCurrentSelection() |
---|
392 | model = self.model_cbox.GetClientData(n) |
---|
393 | |
---|
394 | param_list= get_fittableParam(model) |
---|
395 | length = len(self.constraints_list) |
---|
396 | if length < 1: |
---|
397 | return |
---|
398 | param_cbox = self.constraints_list[length-1][1] |
---|
399 | param_cbox.Clear() |
---|
400 | ## insert only fittable paramaters |
---|
401 | for param in param_list: |
---|
402 | param_cbox.Append( str(param), model) |
---|
403 | |
---|
404 | param_cbox.Show(True) |
---|
405 | self.sizer2.Layout() |
---|
406 | self.SetScrollbars(20,20,25,65) |
---|
407 | |
---|
408 | def _on_select_param(self, event): |
---|
409 | """ |
---|
410 | Store the appropriate constraint in the page_finder |
---|
411 | """ |
---|
412 | ##This way PC/MAC both work, instead of using event.GetClientData(). |
---|
413 | n = self.param_cbox.GetCurrentSelection() |
---|
414 | model = self.param_cbox.GetClientData(n) |
---|
415 | param = event.GetString() |
---|
416 | |
---|
417 | length = len(self.constraints_list) |
---|
418 | if length < 1: |
---|
419 | return |
---|
420 | egal_txt = self.constraints_list[length-1][2] |
---|
421 | egal_txt.Show(True) |
---|
422 | |
---|
423 | ctl2 = self.constraints_list[length-1][3] |
---|
424 | ctl2.Show(True) |
---|
425 | #self.sizer2.Layout() |
---|
426 | self.SetScrollbars(20,20,25,65) |
---|
427 | |
---|
428 | def _onAdd_constraint(self, event): |
---|
429 | """ |
---|
430 | Add another line for constraint |
---|
431 | """ |
---|
432 | if not self.show_constraint.GetValue(): |
---|
433 | msg= " Select Yes to add Constraint " |
---|
434 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
435 | return |
---|
436 | ## check that a constraint is added before allow to add another cosntraint |
---|
437 | for item in self.constraints_list: |
---|
438 | model_cbox = item[0] |
---|
439 | if model_cbox.GetString(0)=="": |
---|
440 | msg= " Select a model Name! " |
---|
441 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
442 | return |
---|
443 | param_cbox = item[1] |
---|
444 | if param_cbox.GetString(0)=="": |
---|
445 | msg= " Select a parameter Name! " |
---|
446 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
447 | return |
---|
448 | ctl2 = item[3] |
---|
449 | if ctl2.GetValue().lstrip().rstrip()=="": |
---|
450 | model= param_cbox.GetClientData(param_cbox.GetCurrentSelection()) |
---|
451 | msg= " Enter a constraint for %s.%s! "%(model.name,param_cbox.GetString(0)) |
---|
452 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
453 | return |
---|
454 | ## some model or parameters can be constrained |
---|
455 | self._show_constraint() |
---|
456 | |
---|
457 | def _fill_sizer_fit(self): |
---|
458 | """ |
---|
459 | Draw fit button |
---|
460 | """ |
---|
461 | self.sizer3.Clear(True) |
---|
462 | box_description= wx.StaticBox(self, -1,"Fit ") |
---|
463 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
464 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
465 | |
---|
466 | self.btFit = wx.Button(self,wx.NewId(),'Fit') |
---|
467 | self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id= self.btFit.GetId()) |
---|
468 | self.btFit.SetToolTipString("Perform fit.") |
---|
469 | |
---|
470 | text= "Hint: Park fitting engine will be selected \n" |
---|
471 | text+= "automatically for more than 2 combinations checked" |
---|
472 | text_hint = wx.StaticText(self,-1,text) |
---|
473 | |
---|
474 | sizer_button.Add(text_hint, wx.RIGHT|wx.EXPAND, 10) |
---|
475 | sizer_button.Add(self.btFit, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
476 | |
---|
477 | boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
478 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
479 | self.sizer3.Layout() |
---|
480 | self.SetScrollbars(20,20,25,65) |
---|
481 | |
---|
482 | def _fill_sizer_constraint(self): |
---|
483 | """ |
---|
484 | Fill sizer containing constraint info |
---|
485 | """ |
---|
486 | msg = "Select at least 2 model to add constraint " |
---|
487 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
488 | |
---|
489 | self.sizer2.Clear(True) |
---|
490 | box_description= wx.StaticBox(self, -1,"Fit Constraints") |
---|
491 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
492 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
493 | self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) |
---|
494 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
495 | |
---|
496 | self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) |
---|
497 | self.show_constraint = wx.RadioButton(self, -1, 'Yes', (10, 30)) |
---|
498 | self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, |
---|
499 | id= self.hide_constraint.GetId() ) |
---|
500 | self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, |
---|
501 | id= self.show_constraint.GetId() ) |
---|
502 | self.hide_constraint.SetValue(True) |
---|
503 | sizer_title.Add( wx.StaticText(self,-1," Model") ) |
---|
504 | sizer_title.Add(( 10,10) ) |
---|
505 | sizer_title.Add( wx.StaticText(self,-1," Parameter") ) |
---|
506 | sizer_title.Add(( 10,10) ) |
---|
507 | sizer_title.Add( wx.StaticText(self,-1," Add Constraint?") ) |
---|
508 | sizer_title.Add(( 10,10) ) |
---|
509 | sizer_title.Add( self.show_constraint ) |
---|
510 | sizer_title.Add( self.hide_constraint ) |
---|
511 | sizer_title.Add(( 10,10) ) |
---|
512 | |
---|
513 | self.btAdd =wx.Button(self,wx.NewId(),'Add') |
---|
514 | self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint,id= self.btAdd.GetId()) |
---|
515 | self.btAdd.SetToolTipString("Add another constraint?") |
---|
516 | self.btAdd.Hide() |
---|
517 | |
---|
518 | text_hint = wx.StaticText(self,-1,"Example: [M0][paramter] = M1.parameter") |
---|
519 | sizer_button.Add(text_hint, 0 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
520 | sizer_button.Add(self.btAdd, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
521 | |
---|
522 | boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
523 | boxsizer1.Add(self.sizer_constraints, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
524 | boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
525 | |
---|
526 | self.sizer2.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
527 | self.sizer2.Layout() |
---|
528 | self.SetScrollbars(20,20,25,65) |
---|
529 | |
---|
530 | def _set_constraint(self): |
---|
531 | """ |
---|
532 | get values from the constrainst textcrtl ,parses them into model name |
---|
533 | parameter name and parameters values. |
---|
534 | store them in a list self.params .when when params is not empty set_model |
---|
535 | uses it to reset the appropriate model and its appropriates parameters |
---|
536 | """ |
---|
537 | for item in self.constraints_list: |
---|
538 | model = item[0].GetClientData(item[0].GetCurrentSelection()) |
---|
539 | param = item[1].GetString(item[1].GetCurrentSelection()) |
---|
540 | constraint = item[3].GetValue().lstrip().rstrip() |
---|
541 | if param.lstrip().rstrip()=="": |
---|
542 | param= None |
---|
543 | msg= " Constraint will be ignored!. missing parameters in combobox" |
---|
544 | msg+= " to set constraint! " |
---|
545 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
546 | for id, value in self.constraint_dict.iteritems(): |
---|
547 | if model == value: |
---|
548 | if constraint == "": |
---|
549 | msg= " Constraint will be ignored!. missing value in textcrtl" |
---|
550 | msg+= " to set constraint! " |
---|
551 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
552 | constraint = None |
---|
553 | self.page_finder[id].set_model_param(param,constraint) |
---|
554 | break |
---|
555 | |
---|
556 | def _fill_sizer_model_list(self,sizer): |
---|
557 | """ |
---|
558 | Receive a dictionary containing information to display model name |
---|
559 | |
---|
560 | :param page_finder: the dictionary containing models information |
---|
561 | |
---|
562 | """ |
---|
563 | ix = 0 |
---|
564 | iy = 0 |
---|
565 | list=[] |
---|
566 | sizer.Clear(True) |
---|
567 | |
---|
568 | new_name = wx.StaticText(self, -1, 'New Model Name', style=wx.ALIGN_CENTER) |
---|
569 | new_name.SetBackgroundColour('orange') |
---|
570 | sizer.Add(new_name,(iy, ix),(1,1), |
---|
571 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
572 | ix += 2 |
---|
573 | model_type = wx.StaticText(self, -1, ' Model Type') |
---|
574 | model_type.SetBackgroundColour('grey') |
---|
575 | sizer.Add(model_type,(iy, ix),(1,1), |
---|
576 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
577 | ix += 1 |
---|
578 | data_used = wx.StaticText(self, -1, ' Used Data') |
---|
579 | data_used.SetBackgroundColour('grey') |
---|
580 | sizer.Add(data_used,(iy, ix),(1,1), |
---|
581 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
582 | ix += 1 |
---|
583 | tab_used = wx.StaticText(self, -1, ' Fit Tab') |
---|
584 | tab_used.SetBackgroundColour('grey') |
---|
585 | sizer.Add(tab_used,(iy, ix),(1,1), |
---|
586 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
587 | for id, value in self.page_finder.iteritems(): |
---|
588 | try: |
---|
589 | ix = 0 |
---|
590 | iy += 1 |
---|
591 | model = value.get_model() |
---|
592 | name = '_' |
---|
593 | if model is not None: |
---|
594 | name = str(model.name) |
---|
595 | cb = wx.CheckBox(self, -1, name) |
---|
596 | cb.SetValue(False) |
---|
597 | cb.Enable(model is not None) |
---|
598 | sizer.Add( cb,( iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
599 | wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) |
---|
600 | ix += 2 |
---|
601 | type = model.__class__.__name__ |
---|
602 | model_type = wx.StaticText(self, -1, str(type)) |
---|
603 | sizer.Add(model_type,( iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
604 | data = value.get_fit_data() |
---|
605 | name = '-' |
---|
606 | if data is not None: |
---|
607 | name = str(data.name) |
---|
608 | data_used = wx.StaticText(self, -1, name) |
---|
609 | ix += 1 |
---|
610 | sizer.Add(data_used,( iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
611 | |
---|
612 | ix += 1 |
---|
613 | caption = value.get_fit_tab_caption() |
---|
614 | tab_caption_used= wx.StaticText(self, -1, str(caption)) |
---|
615 | sizer.Add(tab_caption_used,( iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
616 | |
---|
617 | self.model_list.append([cb,value,id,model]) |
---|
618 | |
---|
619 | except: |
---|
620 | raise |
---|
621 | #pass |
---|
622 | iy += 1 |
---|
623 | sizer.Add((20,20),( iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
624 | sizer.Layout() |
---|