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