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 | ## 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(None) |
---|
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 | item[0].SetValue(True) |
---|
167 | self.model_toFit.append(item) |
---|
168 | |
---|
169 | ## constraint info |
---|
170 | self._store_model() |
---|
171 | ## display constraint fields |
---|
172 | if self.show_constraint.GetValue(): |
---|
173 | self._show_constraint() |
---|
174 | return |
---|
175 | else: |
---|
176 | for item in self.model_list: |
---|
177 | item[0].SetValue(False) |
---|
178 | |
---|
179 | self.model_toFit=[] |
---|
180 | ##constraint info |
---|
181 | self._hide_constraint() |
---|
182 | |
---|
183 | def check_model_name(self,event): |
---|
184 | """ |
---|
185 | Save information related to checkbox and their states |
---|
186 | """ |
---|
187 | self.model_toFit=[] |
---|
188 | for item in self.model_list: |
---|
189 | if item[0].GetValue()==True: |
---|
190 | self.model_toFit.append(item) |
---|
191 | else: |
---|
192 | if item in self.model_toFit: |
---|
193 | self.model_toFit.remove(item) |
---|
194 | self.cb1.SetValue(False) |
---|
195 | |
---|
196 | ## display constraint fields |
---|
197 | if len(self.model_toFit)==2: |
---|
198 | self._store_model() |
---|
199 | if self.show_constraint.GetValue() and len(self.constraints_list)==0: |
---|
200 | self._show_constraint() |
---|
201 | elif len(self.model_toFit)< 2: |
---|
202 | ##constraint info |
---|
203 | self._hide_constraint() |
---|
204 | |
---|
205 | ## set the value of the main check button |
---|
206 | if len(self.model_list)==len(self.model_toFit): |
---|
207 | self.cb1.SetValue(True) |
---|
208 | return |
---|
209 | else: |
---|
210 | self.cb1.SetValue(False) |
---|
211 | |
---|
212 | def draw_page(self): |
---|
213 | """ |
---|
214 | Draw a sizer containing couples of data and model |
---|
215 | """ |
---|
216 | self.model_list=[] |
---|
217 | self.model_toFit=[] |
---|
218 | self.constraints_list=[] |
---|
219 | self.constraint_dict={} |
---|
220 | self.nb_constraint= 0 |
---|
221 | |
---|
222 | if len(self.model_list)>0: |
---|
223 | for item in self.model_list: |
---|
224 | item[0].SetValue(False) |
---|
225 | self.manager.schedule_for_fit(value=0, uid=item[2]) |
---|
226 | |
---|
227 | self.sizer1.Clear(True) |
---|
228 | box_description= wx.StaticBox(self, -1,"Fit Combinations") |
---|
229 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
230 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
231 | sizer_couples = wx.GridBagSizer(5,5) |
---|
232 | #------------------------------------------------------ |
---|
233 | if len(self.page_finder)==0: |
---|
234 | msg = " No fit combinations are found! \n\n" |
---|
235 | msg += " Please load data and set up at least two fit panels first..." |
---|
236 | sizer_title.Add(wx.StaticText(self, -1, msg)) |
---|
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 | for fid in self.page_finder[id].iterkeys(): |
---|
550 | self.page_finder[id].set_model_param(param, |
---|
551 | constraint, fid=fid) |
---|
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 | for fitproblem in value.get_fit_problem(): |
---|
590 | model = fitproblem.get_model() |
---|
591 | name = '_' |
---|
592 | if model is not None: |
---|
593 | name = str(model.name) |
---|
594 | cb = wx.CheckBox(self, -1, name) |
---|
595 | cb.SetValue(False) |
---|
596 | cb.Enable(model is not None) |
---|
597 | sizer.Add(cb, (iy, ix), (1, 1), |
---|
598 | 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), |
---|
604 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
605 | data = fitproblem.get_fit_data() |
---|
606 | name = '-' |
---|
607 | if data is not None: |
---|
608 | name = str(data.name) |
---|
609 | data_used = wx.StaticText(self, -1, name) |
---|
610 | ix += 1 |
---|
611 | sizer.Add(data_used, (iy, ix), (1, 1), |
---|
612 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
613 | ix += 1 |
---|
614 | caption = value.get_fit_tab_caption() |
---|
615 | tab_caption_used= wx.StaticText(self, -1, str(caption)) |
---|
616 | sizer.Add(tab_caption_used, (iy, ix), (1, 1), |
---|
617 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
618 | |
---|
619 | self.model_list.append([cb,value,id,model]) |
---|
620 | |
---|
621 | except: |
---|
622 | raise |
---|
623 | #pass |
---|
624 | iy += 1 |
---|
625 | sizer.Add((20, 20), (iy, ix), (1, 1), |
---|
626 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
627 | sizer.Layout() |
---|
628 | |
---|