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