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