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,style= wx.FULL_REPAINT_ON_RESIZE ) |
---|
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 | |
---|
321 | #This is for GetCLientData() _on_select_param: Was None return on MAC. |
---|
322 | self.param_cbox = param_cbox |
---|
323 | |
---|
324 | wx.EVT_COMBOBOX(param_cbox,-1, self._on_select_param) |
---|
325 | ctl2 = wx.TextCtrl(self, -1) |
---|
326 | egal_txt= wx.StaticText(self,-1," = ") |
---|
327 | btRemove = wx.Button(self,wx.NewId(),'Remove') |
---|
328 | btRemove.Bind(wx.EVT_BUTTON, self.onRemove,id= btRemove.GetId()) |
---|
329 | btRemove.SetToolTipString("Remove constraint.") |
---|
330 | |
---|
331 | |
---|
332 | for page,model in self.constraint_dict.iteritems(): |
---|
333 | ## check if all parameters have been selected for constraint |
---|
334 | ## then do not allow add constraint on parameters |
---|
335 | model_cbox.Append( str(model.name), model) |
---|
336 | |
---|
337 | #This is for GetCLientData() passing to self._on_select_param: Was None return on MAC. |
---|
338 | self.model_cbox = model_cbox |
---|
339 | |
---|
340 | wx.EVT_COMBOBOX(model_cbox,-1, self._on_select_model) |
---|
341 | |
---|
342 | |
---|
343 | sizer_constraint.Add(model_cbox, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
344 | sizer_constraint.Add(param_cbox, flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
345 | sizer_constraint.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND,border=5) |
---|
346 | sizer_constraint.Add(ctl2, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
347 | sizer_constraint.Add(btRemove, flag= wx.RIGHT|wx.EXPAND,border=10) |
---|
348 | |
---|
349 | self.sizer_constraints.Insert(before=self.nb_constraint, |
---|
350 | item=sizer_constraint, flag= wx.TOP|wx.BOTTOM|wx.EXPAND, |
---|
351 | border=5) |
---|
352 | ##[combobox1, combobox2,=,textcrtl, remove button ] |
---|
353 | self.constraints_list.append([model_cbox, param_cbox, egal_txt, ctl2,btRemove,sizer_constraint]) |
---|
354 | |
---|
355 | |
---|
356 | self.nb_constraint += 1 |
---|
357 | self.sizer_constraints.Layout() |
---|
358 | self.sizer2.Layout() |
---|
359 | self.SetScrollbars(20,20,200,100) |
---|
360 | |
---|
361 | def _hide_constraint(self): |
---|
362 | """ |
---|
363 | hide buttons related constraint |
---|
364 | """ |
---|
365 | for page in self.page_finder.iterkeys(): |
---|
366 | self.page_finder[page].clear_model_param() |
---|
367 | |
---|
368 | self.nb_constraint =0 |
---|
369 | self.constraint_dict={} |
---|
370 | if hasattr(self,"btAdd"): |
---|
371 | self.btAdd.Hide() |
---|
372 | self._store_model() |
---|
373 | |
---|
374 | self.constraints_list=[] |
---|
375 | self.sizer_constraints.Clear(True) |
---|
376 | self.sizer_constraints.Layout() |
---|
377 | self.sizer2.Layout() |
---|
378 | self.SetScrollbars(20,20,200,100) |
---|
379 | self.AdjustScrollbars() |
---|
380 | |
---|
381 | |
---|
382 | |
---|
383 | def _on_select_model(self, event): |
---|
384 | """ |
---|
385 | fill combox box with list of parameters |
---|
386 | """ |
---|
387 | ##This way PC/MAC both work, instead of using event.GetClientData(). |
---|
388 | n = self.model_cbox.GetCurrentSelection() |
---|
389 | model = self.model_cbox.GetClientData(n) |
---|
390 | |
---|
391 | param_list= get_fittableParam(model) |
---|
392 | length = len(self.constraints_list) |
---|
393 | if length < 1: |
---|
394 | return |
---|
395 | |
---|
396 | param_cbox = self.constraints_list[length-1][1] |
---|
397 | param_cbox.Clear() |
---|
398 | ## insert only fittable paramaters |
---|
399 | for param in param_list: |
---|
400 | param_cbox.Append( str(param), model) |
---|
401 | |
---|
402 | param_cbox.Show(True) |
---|
403 | |
---|
404 | |
---|
405 | self.sizer2.Layout() |
---|
406 | self.SetScrollbars(20,20,200,100) |
---|
407 | |
---|
408 | |
---|
409 | def _on_select_param(self, event): |
---|
410 | """ |
---|
411 | Store the appropriate constraint in the page_finder |
---|
412 | """ |
---|
413 | ##This way PC/MAC both work, instead of using event.GetClientData(). |
---|
414 | n = self.param_cbox.GetCurrentSelection() |
---|
415 | model = self.param_cbox.GetClientData(n) |
---|
416 | param = event.GetString() |
---|
417 | |
---|
418 | length = len(self.constraints_list) |
---|
419 | if length < 1: |
---|
420 | return |
---|
421 | egal_txt = self.constraints_list[length-1][2] |
---|
422 | egal_txt.Show(True) |
---|
423 | |
---|
424 | ctl2 = self.constraints_list[length-1][3] |
---|
425 | ctl2.Show(True) |
---|
426 | |
---|
427 | |
---|
428 | self.sizer2.Layout() |
---|
429 | self.SetScrollbars(20,20,200,100) |
---|
430 | |
---|
431 | |
---|
432 | def _onAdd_constraint(self, event): |
---|
433 | """ |
---|
434 | Add another line for constraint |
---|
435 | """ |
---|
436 | |
---|
437 | if not self.show_constraint.GetValue(): |
---|
438 | msg= " Select Yes to add Constraint " |
---|
439 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
440 | return |
---|
441 | |
---|
442 | ## check that a constraint is added before allow to add another cosntraint |
---|
443 | |
---|
444 | for item in self.constraints_list: |
---|
445 | model_cbox = item[0] |
---|
446 | if model_cbox.GetString(0)=="": |
---|
447 | msg= " Select a model Name! " |
---|
448 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
449 | return |
---|
450 | param_cbox = item[1] |
---|
451 | if param_cbox.GetString(0)=="": |
---|
452 | msg= " Select a parameter Name! " |
---|
453 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
454 | return |
---|
455 | ctl2 = item[3] |
---|
456 | if ctl2.GetValue().lstrip().rstrip()=="": |
---|
457 | model= param_cbox.GetClientData(param_cbox.GetCurrentSelection()) |
---|
458 | msg= " Enter a constraint for %s.%s! "%(model.name,param_cbox.GetString(0)) |
---|
459 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
460 | return |
---|
461 | |
---|
462 | ## some model or parameters can be constrained |
---|
463 | self._show_constraint() |
---|
464 | |
---|
465 | def _fill_sizer_fit(self): |
---|
466 | """ |
---|
467 | Draw fit fit button |
---|
468 | """ |
---|
469 | self.sizer3.Clear(True) |
---|
470 | box_description= wx.StaticBox(self, -1,"Fit ") |
---|
471 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
472 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
473 | |
---|
474 | self.btFit = wx.Button(self,wx.NewId(),'Fit') |
---|
475 | self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id= self.btFit.GetId()) |
---|
476 | self.btFit.SetToolTipString("Perform fit.") |
---|
477 | |
---|
478 | text= "Hint: Park fitting engine will be selected \n" |
---|
479 | text+= "automatically for more than 2 combinations checked" |
---|
480 | text_hint = wx.StaticText(self,-1,text) |
---|
481 | |
---|
482 | sizer_button.Add(text_hint, wx.RIGHT|wx.EXPAND, 10) |
---|
483 | sizer_button.Add(self.btFit, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
484 | |
---|
485 | boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
486 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
487 | self.sizer3.Layout() |
---|
488 | self.SetScrollbars(20,20,200,100) |
---|
489 | |
---|
490 | def _fill_sizer_constraint(self): |
---|
491 | """ |
---|
492 | Fill sizer containing constraint info |
---|
493 | """ |
---|
494 | msg= "Select at least 2 model to add constraint " |
---|
495 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
496 | |
---|
497 | self.sizer2.Clear(True) |
---|
498 | |
---|
499 | box_description= wx.StaticBox(self, -1,"Fit Constraints") |
---|
500 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
501 | sizer_title = wx.BoxSizer(wx.HORIZONTAL) |
---|
502 | self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) |
---|
503 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
504 | |
---|
505 | self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) |
---|
506 | self.show_constraint = wx.RadioButton(self, -1, 'Yes', (10, 30)) |
---|
507 | |
---|
508 | self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, |
---|
509 | id= self.hide_constraint.GetId() ) |
---|
510 | |
---|
511 | self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, |
---|
512 | id= self.show_constraint.GetId() ) |
---|
513 | self.hide_constraint.SetValue(True) |
---|
514 | sizer_title.Add( wx.StaticText(self,-1," Model") ) |
---|
515 | sizer_title.Add(( 10,10) ) |
---|
516 | sizer_title.Add( wx.StaticText(self,-1," Parameter") ) |
---|
517 | sizer_title.Add(( 10,10) ) |
---|
518 | sizer_title.Add( wx.StaticText(self,-1," Add Constraint?") ) |
---|
519 | sizer_title.Add(( 10,10) ) |
---|
520 | sizer_title.Add( self.show_constraint ) |
---|
521 | sizer_title.Add( self.hide_constraint ) |
---|
522 | sizer_title.Add(( 10,10) ) |
---|
523 | |
---|
524 | self.btAdd =wx.Button(self,wx.NewId(),'Add') |
---|
525 | self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint,id= self.btAdd.GetId()) |
---|
526 | self.btAdd.SetToolTipString("Add another constraint?") |
---|
527 | self.btAdd.Hide() |
---|
528 | |
---|
529 | |
---|
530 | text_hint = wx.StaticText(self,-1,"Example: [M0][paramter] = M1.parameter") |
---|
531 | sizer_button.Add(text_hint, 0 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
532 | sizer_button.Add(self.btAdd, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
533 | |
---|
534 | |
---|
535 | boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
536 | boxsizer1.Add(self.sizer_constraints, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
537 | boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10) |
---|
538 | |
---|
539 | self.sizer2.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
540 | self.sizer2.Layout() |
---|
541 | self.SetScrollbars(20,20,200,100) |
---|
542 | |
---|
543 | |
---|
544 | |
---|
545 | def _set_constraint(self): |
---|
546 | """ |
---|
547 | get values from the constrainst textcrtl ,parses them into model name |
---|
548 | parameter name and parameters values. |
---|
549 | store them in a list self.params .when when params is not empty set_model |
---|
550 | uses it to reset the appropriate model and its appropriates parameters |
---|
551 | """ |
---|
552 | for item in self.constraints_list: |
---|
553 | |
---|
554 | model = item[0].GetClientData(item[0].GetCurrentSelection()) |
---|
555 | param = item[1].GetString(item[1].GetCurrentSelection()) |
---|
556 | constraint = item[3].GetValue().lstrip().rstrip() |
---|
557 | if param.lstrip().rstrip()=="": |
---|
558 | param= None |
---|
559 | msg= " Constraint will be ignored!. missing parameters in combobox" |
---|
560 | msg+= " to set constraint! " |
---|
561 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
562 | for page , value in self.constraint_dict.iteritems(): |
---|
563 | if model == value: |
---|
564 | if constraint == "": |
---|
565 | msg= " Constraint will be ignored!. missing value in textcrtl" |
---|
566 | msg+= " to set constraint! " |
---|
567 | wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) |
---|
568 | constraint = None |
---|
569 | self.page_finder[page].set_model_param(param,constraint) |
---|
570 | break |
---|
571 | |
---|
572 | |
---|
573 | |
---|
574 | def _fill_sizer_model_list(self,sizer): |
---|
575 | """ |
---|
576 | Receive a dictionary containing information to display model name |
---|
577 | @param page_finder: the dictionary containing models information |
---|
578 | """ |
---|
579 | ix = 0 |
---|
580 | iy = 0 |
---|
581 | list=[] |
---|
582 | sizer.Clear(True) |
---|
583 | |
---|
584 | new_name = wx.StaticText(self, -1, 'New Model Name', style=wx.ALIGN_CENTER) |
---|
585 | new_name.SetBackgroundColour('orange') |
---|
586 | sizer.Add(new_name,(iy, ix),(1,1), |
---|
587 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
588 | |
---|
589 | ix +=2 |
---|
590 | model_type = wx.StaticText(self, -1, ' Model Type') |
---|
591 | model_type.SetBackgroundColour('grey') |
---|
592 | sizer.Add(model_type,(iy, ix),(1,1), |
---|
593 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
594 | ix +=1 |
---|
595 | data_used = wx.StaticText(self, -1, ' Used Data') |
---|
596 | data_used.SetBackgroundColour('grey') |
---|
597 | sizer.Add(data_used,(iy, ix),(1,1), |
---|
598 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
599 | |
---|
600 | for page, value in self.page_finder.iteritems(): |
---|
601 | try: |
---|
602 | ix = 0 |
---|
603 | iy += 1 |
---|
604 | model = value.get_model() |
---|
605 | cb = wx.CheckBox(self, -1, str(model.name)) |
---|
606 | cb.SetValue(False) |
---|
607 | sizer.Add( cb,( iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
608 | wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) |
---|
609 | |
---|
610 | ix +=2 |
---|
611 | type = model.__class__.__name__ |
---|
612 | model_type = wx.StaticText(self, -1, str(type)) |
---|
613 | sizer.Add(model_type,( iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
614 | |
---|
615 | ix +=1 |
---|
616 | data = value.get_fit_data() |
---|
617 | data_used= wx.StaticText(self, -1, str(data.name)) |
---|
618 | sizer.Add(data_used,( iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
619 | |
---|
620 | self.model_list.append([cb,value,page,model]) |
---|
621 | |
---|
622 | except: |
---|
623 | pass |
---|
624 | iy +=1 |
---|
625 | sizer.Add((20,20),( iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
626 | sizer.Layout() |
---|
627 | |
---|
628 | |
---|
629 | |
---|
630 | |
---|
631 | class HelpWindow(wx.Frame): |
---|
632 | def __init__(self, parent, id, title): |
---|
633 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
---|
634 | |
---|
635 | page_finder ={} |
---|
636 | ## create random data |
---|
637 | from danse.common.plottools.plottables import Data1D |
---|
638 | data= Data1D(x=[1,2], y=[3,4], dy=[0.1, 0,1]) |
---|
639 | data.name="mydata.txt" |
---|
640 | ## create model |
---|
641 | from sans.models.CylinderModel import CylinderModel |
---|
642 | model = CylinderModel() |
---|
643 | model.name="M0" |
---|
644 | |
---|
645 | |
---|
646 | from fitproblem import FitProblem |
---|
647 | page_finder["page"]= FitProblem() |
---|
648 | ## fill the page_finder |
---|
649 | page_finder["page"].add_fit_data(data) |
---|
650 | page_finder["page"].set_model(model) |
---|
651 | self.page = SimultaneousFitPage(self, page_finder=page_finder) |
---|
652 | |
---|
653 | |
---|
654 | |
---|
655 | self.Centre() |
---|
656 | self.Show(True) |
---|
657 | |
---|
658 | |
---|
659 | |
---|
660 | if __name__=="__main__": |
---|
661 | app = wx.App() |
---|
662 | HelpWindow(None, -1, 'HelpWindow') |
---|
663 | app.MainLoop() |
---|
664 | |
---|