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