1 | |
---|
2 | import sys, os |
---|
3 | import wx |
---|
4 | import numpy |
---|
5 | import time |
---|
6 | import copy |
---|
7 | from sans.guiframe.utils import format_number,check_float |
---|
8 | from sans.guicomm.events import StatusEvent |
---|
9 | import pagestate |
---|
10 | from pagestate import PageState |
---|
11 | (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() |
---|
12 | (PreviousStateEvent, EVT_PREVIOUS_STATE) = wx.lib.newevent.NewEvent() |
---|
13 | (NextStateEvent, EVT_NEXT_STATE) = wx.lib.newevent.NewEvent() |
---|
14 | _BOX_WIDTH = 76 |
---|
15 | |
---|
16 | class BasicPage(wx.ScrolledWindow): |
---|
17 | """ |
---|
18 | This class provide general structure of fitpanel page |
---|
19 | """ |
---|
20 | ## Internal name for the AUI manager |
---|
21 | window_name = "Basic Page" |
---|
22 | ## Title to appear on top of the window |
---|
23 | window_caption = "Basic page " |
---|
24 | |
---|
25 | def __init__(self,parent, page_info): |
---|
26 | wx.ScrolledWindow.__init__(self, parent, |
---|
27 | style= wx.FULL_REPAINT_ON_RESIZE ) |
---|
28 | ##window_name |
---|
29 | self.window_name = page_info.window_name |
---|
30 | ##window_caption |
---|
31 | self.window_caption = page_info.window_caption |
---|
32 | ## parent of the page |
---|
33 | self.parent = parent |
---|
34 | ## manager is the fitting plugin |
---|
35 | self.manager= page_info.manager |
---|
36 | ## owner of the page (fitting plugin) |
---|
37 | self.event_owner= page_info.event_owner |
---|
38 | ## current model |
---|
39 | self.model = page_info.model |
---|
40 | ## data |
---|
41 | self.data = page_info.data |
---|
42 | ## dictionary containing list of models |
---|
43 | self.model_list_box = page_info.model_list_box |
---|
44 | ## Data member to store the dispersion object created |
---|
45 | self._disp_obj_dict = {} |
---|
46 | ## selected parameters to apply dispersion |
---|
47 | self.disp_cb_dict ={} |
---|
48 | ## smearer object |
---|
49 | self.smearer = None |
---|
50 | |
---|
51 | ##list of model parameters. each item must have same length |
---|
52 | ## each item related to a given parameters |
---|
53 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
54 | self.parameters=[] |
---|
55 | ## list of parameters to fit , must be like self.parameters |
---|
56 | self.param_toFit=[] |
---|
57 | ## list of looking like parameters but with non fittable parameters info |
---|
58 | self.fixed_param=[] |
---|
59 | ## list of looking like parameters but with fittable parameters info |
---|
60 | self.fittable_param=[] |
---|
61 | ##list of dispersion parameters |
---|
62 | self.disp_list=[] |
---|
63 | self.disp_name="" |
---|
64 | ## list of orientation parameters |
---|
65 | self.orientation_params=[] |
---|
66 | self.orientation_params_disp=[] |
---|
67 | if self.model !=None: |
---|
68 | self.disp_list= self.model.getDispParamList() |
---|
69 | |
---|
70 | ##enable model 2D draw |
---|
71 | self.enable2D= False |
---|
72 | ## check that the fit range is correct to plot the model again |
---|
73 | self.fitrange= True |
---|
74 | ## Q range |
---|
75 | self.qmin_x= 0.0001 |
---|
76 | self.qmax_x= 0.13 |
---|
77 | self.num_points= 50 |
---|
78 | |
---|
79 | ## Create memento to save the current state |
---|
80 | self.state= PageState(parent= self.parent,model=self.model, data=self.data) |
---|
81 | ## flag to determine if state has change |
---|
82 | self.state_change= False |
---|
83 | ## save customized array |
---|
84 | self.values=[] |
---|
85 | self.weights=[] |
---|
86 | ## retrieve saved state |
---|
87 | self.number_saved_state= 0 |
---|
88 | ## dictionary of saved state |
---|
89 | self.saved_states={} |
---|
90 | |
---|
91 | ## Create context menu for page |
---|
92 | self.popUpMenu = wx.Menu() |
---|
93 | id = wx.NewId() |
---|
94 | self._undo = wx.MenuItem(self.popUpMenu,id, "Undo","cancel the previous action") |
---|
95 | self.popUpMenu.AppendItem(self._undo) |
---|
96 | self._undo.Enable(False) |
---|
97 | wx.EVT_MENU(self, id, self.onUndo) |
---|
98 | |
---|
99 | id = wx.NewId() |
---|
100 | self._redo = wx.MenuItem(self.popUpMenu,id,"Redo"," Restore the previous action") |
---|
101 | self.popUpMenu.AppendItem(self._redo) |
---|
102 | self._redo.Enable(False) |
---|
103 | wx.EVT_MENU(self, id, self.onRedo) |
---|
104 | self.popUpMenu.AppendSeparator() |
---|
105 | |
---|
106 | id = wx.NewId() |
---|
107 | self._keep = wx.MenuItem(self.popUpMenu,id,"Keep"," Keep the panel status to recall it later") |
---|
108 | self.popUpMenu.AppendItem(self._keep) |
---|
109 | self._keep.Enable(True) |
---|
110 | wx.EVT_MENU(self, id, self.onSave) |
---|
111 | self.popUpMenu.AppendSeparator() |
---|
112 | |
---|
113 | ## Default locations |
---|
114 | self._default_save_location = os.getcwd() |
---|
115 | ## save initial state on context menu |
---|
116 | #self.onSave(event=None) |
---|
117 | self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) |
---|
118 | |
---|
119 | ## create the basic structure of the panel with empty sizer |
---|
120 | self.define_page_structure() |
---|
121 | ## drawing Initial dispersion parameters sizer |
---|
122 | self.set_dispers_sizer() |
---|
123 | self._fill_save_sizer() |
---|
124 | ## layout |
---|
125 | self.set_layout() |
---|
126 | |
---|
127 | class ModelTextCtrl(wx.TextCtrl): |
---|
128 | """ |
---|
129 | Text control for model and fit parameters. |
---|
130 | Binds the appropriate events for user interactions. |
---|
131 | Default callback methods can be overwritten on initialization |
---|
132 | |
---|
133 | @param kill_focus_callback: callback method for EVT_KILL_FOCUS event |
---|
134 | @param set_focus_callback: callback method for EVT_SET_FOCUS event |
---|
135 | @param mouse_up_callback: callback method for EVT_LEFT_UP event |
---|
136 | @param text_enter_callback: callback method for EVT_TEXT_ENTER event |
---|
137 | """ |
---|
138 | def __init__(self, parent, id=-1, value=wx.EmptyString, pos=wx.DefaultPosition, |
---|
139 | size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.TextCtrlNameStr, |
---|
140 | kill_focus_callback = None, set_focus_callback = None, |
---|
141 | mouse_up_callback = None, text_enter_callback = None): |
---|
142 | |
---|
143 | wx.TextCtrl.__init__(self, parent, id, value, pos, size, style, validator, name) |
---|
144 | |
---|
145 | # Bind appropriate events |
---|
146 | self.Bind(wx.EVT_SET_FOCUS, parent.onSetFocus \ |
---|
147 | if set_focus_callback is None else set_focus_callback) |
---|
148 | self.Bind(wx.EVT_KILL_FOCUS, parent._onparamEnter \ |
---|
149 | if kill_focus_callback is None else kill_focus_callback) |
---|
150 | self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \ |
---|
151 | if text_enter_callback is None else text_enter_callback) |
---|
152 | self.Bind(wx.EVT_LEFT_UP, parent._highlight_text \ |
---|
153 | if mouse_up_callback is None else mouse_up_callback) |
---|
154 | |
---|
155 | def onContextMenu(self, event): |
---|
156 | """ |
---|
157 | Retrieve the state selected state |
---|
158 | """ |
---|
159 | # Skipping the save state functionality for release 0.9.0 |
---|
160 | #return |
---|
161 | |
---|
162 | pos = event.GetPosition() |
---|
163 | pos = self.ScreenToClient(pos) |
---|
164 | |
---|
165 | self.PopupMenu(self.popUpMenu, pos) |
---|
166 | |
---|
167 | |
---|
168 | def onUndo(self, event): |
---|
169 | """ |
---|
170 | Cancel the previous action |
---|
171 | """ |
---|
172 | #print "enable undo" |
---|
173 | event = PreviousStateEvent(page = self) |
---|
174 | wx.PostEvent(self.parent, event) |
---|
175 | |
---|
176 | |
---|
177 | def onRedo(self, event): |
---|
178 | """ |
---|
179 | Restore the previous action cancelled |
---|
180 | """ |
---|
181 | print "enable redo" |
---|
182 | event = NextStateEvent(page= self) |
---|
183 | wx.PostEvent(self.parent, event) |
---|
184 | |
---|
185 | |
---|
186 | def define_page_structure(self): |
---|
187 | """ |
---|
188 | Create empty sizer for a panel |
---|
189 | """ |
---|
190 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
191 | self.sizer0 = wx.BoxSizer(wx.VERTICAL) |
---|
192 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
193 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
194 | self.sizer3 = wx.BoxSizer(wx.VERTICAL) |
---|
195 | self.sizer4 = wx.BoxSizer(wx.VERTICAL) |
---|
196 | self.sizer5 = wx.BoxSizer(wx.VERTICAL) |
---|
197 | self.sizer6 = wx.BoxSizer(wx.VERTICAL) |
---|
198 | |
---|
199 | self.sizer0.SetMinSize((375,-1)) |
---|
200 | self.sizer1.SetMinSize((375,-1)) |
---|
201 | self.sizer2.SetMinSize((375,-1)) |
---|
202 | self.sizer3.SetMinSize((375,-1)) |
---|
203 | self.sizer4.SetMinSize((375,-1)) |
---|
204 | self.sizer5.SetMinSize((375,-1)) |
---|
205 | self.sizer6.SetMinSize((375,-1)) |
---|
206 | |
---|
207 | self.vbox.Add(self.sizer0) |
---|
208 | self.vbox.Add(self.sizer1) |
---|
209 | self.vbox.Add(self.sizer2) |
---|
210 | self.vbox.Add(self.sizer3) |
---|
211 | self.vbox.Add(self.sizer4) |
---|
212 | self.vbox.Add(self.sizer5) |
---|
213 | self.vbox.Add(self.sizer6) |
---|
214 | |
---|
215 | |
---|
216 | def set_layout(self): |
---|
217 | """ |
---|
218 | layout |
---|
219 | """ |
---|
220 | self.vbox.Layout() |
---|
221 | self.vbox.Fit(self) |
---|
222 | self.SetSizer(self.vbox) |
---|
223 | |
---|
224 | self.set_scroll() |
---|
225 | self.Centre() |
---|
226 | |
---|
227 | |
---|
228 | def set_scroll(self): |
---|
229 | self.SetScrollbars(20,20,25,65) |
---|
230 | self.Layout() |
---|
231 | self.SetAutoLayout(True) |
---|
232 | |
---|
233 | |
---|
234 | def set_owner(self,owner): |
---|
235 | """ |
---|
236 | set owner of fitpage |
---|
237 | @param owner: the class responsible of plotting |
---|
238 | """ |
---|
239 | self.event_owner = owner |
---|
240 | self.state.event_owner = owner |
---|
241 | |
---|
242 | def set_manager(self, manager): |
---|
243 | """ |
---|
244 | set panel manager |
---|
245 | @param manager: instance of plugin fitting |
---|
246 | """ |
---|
247 | self.manager = manager |
---|
248 | self.state.manager = manager |
---|
249 | |
---|
250 | def populate_box(self, dict): |
---|
251 | """ |
---|
252 | Store list of model |
---|
253 | @param dict: dictionary containing list of models |
---|
254 | """ |
---|
255 | self.model_list_box = dict |
---|
256 | self.state.model_list_box = self.model_list_box |
---|
257 | |
---|
258 | |
---|
259 | |
---|
260 | def set_dispers_sizer(self): |
---|
261 | """ |
---|
262 | fill sizer containing dispersity info |
---|
263 | """ |
---|
264 | self.sizer4.Clear(True) |
---|
265 | name="Polydispersity and Orientational Distribution" |
---|
266 | box_description= wx.StaticBox(self, -1,name) |
---|
267 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
268 | #---------------------------------------------------- |
---|
269 | self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), style=wx.RB_GROUP) |
---|
270 | self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) |
---|
271 | |
---|
272 | |
---|
273 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.disable_disp.GetId()) |
---|
274 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.enable_disp.GetId()) |
---|
275 | |
---|
276 | sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) |
---|
277 | sizer_dispersion.Add((20,20)) |
---|
278 | name=""#Polydispersity and \nOrientational Distribution " |
---|
279 | sizer_dispersion.Add(wx.StaticText(self,-1,name)) |
---|
280 | sizer_dispersion.Add(self.enable_disp ) |
---|
281 | sizer_dispersion.Add((20,20)) |
---|
282 | sizer_dispersion.Add(self.disable_disp ) |
---|
283 | sizer_dispersion.Add((10,10)) |
---|
284 | |
---|
285 | ## fill a sizer with the combobox to select dispersion type |
---|
286 | sizer_select_dispers = wx.BoxSizer(wx.HORIZONTAL) |
---|
287 | self.model_disp = wx.StaticText(self, -1, 'Distribution Function ') |
---|
288 | |
---|
289 | import sans.models.dispersion_models |
---|
290 | self.polydisp= sans.models.dispersion_models.models |
---|
291 | self.disp_box = wx.ComboBox(self, -1) |
---|
292 | |
---|
293 | for key, value in self.polydisp.iteritems(): |
---|
294 | name = str(key) |
---|
295 | self.disp_box.Append(name,value) |
---|
296 | |
---|
297 | self.disp_box.SetStringSelection("gaussian") |
---|
298 | wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) |
---|
299 | |
---|
300 | sizer_select_dispers.Add((10,10)) |
---|
301 | sizer_select_dispers.Add(self.model_disp) |
---|
302 | sizer_select_dispers.Add(self.disp_box,0, |
---|
303 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
304 | |
---|
305 | self.model_disp.Hide() |
---|
306 | self.disp_box.Hide() |
---|
307 | |
---|
308 | boxsizer1.Add( sizer_dispersion,0, |
---|
309 | wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5) |
---|
310 | #boxsizer1.Add( (10,10) ) |
---|
311 | boxsizer1.Add( sizer_select_dispers ) |
---|
312 | self.sizer4_4 = wx.GridBagSizer(5,5) |
---|
313 | boxsizer1.Add( self.sizer4_4 ) |
---|
314 | #----------------------------------------------------- |
---|
315 | self.sizer4.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
316 | self.sizer4_4.Layout() |
---|
317 | self.sizer4.Layout() |
---|
318 | self.Layout() |
---|
319 | self.SetScrollbars(20,20,25,65) |
---|
320 | self.Refresh() |
---|
321 | ## saving the state of enable dispersity button |
---|
322 | self.state.enable_disp= self.enable_disp.GetValue() |
---|
323 | self.state.disable_disp= self.disable_disp.GetValue() |
---|
324 | |
---|
325 | |
---|
326 | def select_disp_angle(self, event): |
---|
327 | """ |
---|
328 | Event for when a user select a parameter to average over. |
---|
329 | @param event: check box event |
---|
330 | """ |
---|
331 | self.values=[] |
---|
332 | self.weights=[] |
---|
333 | # Go through the list of dispersion check boxes to identify which one has changed |
---|
334 | |
---|
335 | for p in self.disp_cb_dict: |
---|
336 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
337 | # Catch which one of the box was just checked or unchecked. |
---|
338 | if event.GetEventObject() == self.disp_cb_dict[p]: |
---|
339 | |
---|
340 | if self.disp_cb_dict[p].GetValue() == True: |
---|
341 | |
---|
342 | ##Temp. FIX for V1.0 regarding changing checkbox to radiobutton. |
---|
343 | ##This (self._reset_dispersity) should be removed when the array dispersion is fixed. |
---|
344 | self._reset_dispersity() |
---|
345 | |
---|
346 | # The user wants this parameter to be averaged. |
---|
347 | # Pop up the file selection dialog. |
---|
348 | path = self._selectDlg() |
---|
349 | |
---|
350 | # If nothing was selected, just return |
---|
351 | if path is None: |
---|
352 | self.disp_cb_dict[p].SetValue(False) |
---|
353 | return |
---|
354 | try: |
---|
355 | self._default_save_location = os.path.dirname(path) |
---|
356 | except: |
---|
357 | pass |
---|
358 | try: |
---|
359 | self.values,self.weights = self.read_file(path) |
---|
360 | except: |
---|
361 | msg="Could not read input file" |
---|
362 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg)) |
---|
363 | return |
---|
364 | |
---|
365 | # If any of the two arrays is empty, notify the user that we won't |
---|
366 | # proceed |
---|
367 | if self.values is None or self.weights is None or \ |
---|
368 | self.values ==[] or self.weights ==[]: |
---|
369 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
370 | "The loaded %s distrubtion is corrupted or empty" % p)) |
---|
371 | return |
---|
372 | |
---|
373 | # Tell the user that we are about to apply the distribution |
---|
374 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
375 | "Applying loaded %s distribution: %s" % (p, path))) |
---|
376 | |
---|
377 | # Create the dispersion objects |
---|
378 | from sans.models.dispersion_models import ArrayDispersion |
---|
379 | disp_model = ArrayDispersion() |
---|
380 | disp_model.set_weights(self.values, self.weights) |
---|
381 | |
---|
382 | # Store the object to make it persist outside the scope of this method |
---|
383 | #TODO: refactor model to clean this up? |
---|
384 | self._disp_obj_dict[p] = disp_model |
---|
385 | self.state._disp_obj_dict [p]= disp_model |
---|
386 | self.state.values=[] |
---|
387 | self.state.weights=[] |
---|
388 | self.state.values = copy.deepcopy(self.values) |
---|
389 | self.state.weights = copy.deepcopy(self.weights) |
---|
390 | # Set the new model as the dispersion object for the selected parameter |
---|
391 | self.model.set_dispersion(p, disp_model) |
---|
392 | # Store a reference to the weights in the model object so that |
---|
393 | # it's not lost when we use the model within another thread. |
---|
394 | #TODO: total hack - fix this |
---|
395 | self.state.model= self.model.clone() |
---|
396 | #if not hasattr(self.model, "_persistency_dict"): |
---|
397 | self.model._persistency_dict = {} |
---|
398 | self.model._persistency_dict[p] = [self.values, self.weights] |
---|
399 | self.state.model._persistency_dict[p] = [self.values, self.weights] |
---|
400 | else: |
---|
401 | self._reset_dispersity() |
---|
402 | |
---|
403 | ## Redraw the model ??? |
---|
404 | self._draw_model() |
---|
405 | |
---|
406 | ## post state to fit panel |
---|
407 | event = PageInfoEvent(page = self) |
---|
408 | wx.PostEvent(self.parent, event) |
---|
409 | |
---|
410 | |
---|
411 | def onResetModel(self, event): |
---|
412 | """ |
---|
413 | Reset model state |
---|
414 | """ |
---|
415 | ## post help message for the selected model |
---|
416 | msg = self.popUpMenu.GetHelpString(event.GetId()) |
---|
417 | msg +=" reloaded" |
---|
418 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
419 | |
---|
420 | name= self.popUpMenu.GetLabel(event.GetId()) |
---|
421 | self._on_select_model_helper() |
---|
422 | |
---|
423 | if name in self.saved_states.keys(): |
---|
424 | previous_state = self.saved_states[name] |
---|
425 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
426 | self.reset_page(previous_state) |
---|
427 | |
---|
428 | def onSave(self, event): |
---|
429 | """ |
---|
430 | save history of the data and model |
---|
431 | """ |
---|
432 | if self.model==None: |
---|
433 | return |
---|
434 | if hasattr(self,"enable_disp"): |
---|
435 | self.state.enable_disp = copy.deepcopy(self.enable_disp.GetValue()) |
---|
436 | if hasattr(self, "disp_box"): |
---|
437 | self.state.disp_box = copy.deepcopy(self.disp_box.GetSelection()) |
---|
438 | |
---|
439 | self.state.model = self.model.clone() |
---|
440 | self.state.model.name= self.model.name |
---|
441 | #if not hasattr(self.model, "_persistency_dict"): |
---|
442 | #self.model._persistency_dict = {} |
---|
443 | #self.state.model._persistency_dict= copy.deepcopy(self.model._persistency_dict) |
---|
444 | |
---|
445 | new_state = self.state.clone() |
---|
446 | new_state.model.name = self.state.model.name |
---|
447 | |
---|
448 | new_state.enable2D = copy.deepcopy(self.enable2D) |
---|
449 | ##Add model state on context menu |
---|
450 | self.number_saved_state += 1 |
---|
451 | name= self.model.name+"[%g]"%self.number_saved_state |
---|
452 | self.saved_states[name]= new_state |
---|
453 | |
---|
454 | ## Add item in the context menu |
---|
455 | |
---|
456 | year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() |
---|
457 | my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" " |
---|
458 | date= str( month)+"|"+str(day)+"|"+str(year) |
---|
459 | msg= "Model saved at %s on %s"%(my_time, date) |
---|
460 | ## post help message for the selected model |
---|
461 | msg +=" Saved! right click on this page to retrieve this model" |
---|
462 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
463 | |
---|
464 | id = wx.NewId() |
---|
465 | self.popUpMenu.Append(id,name,str(msg)) |
---|
466 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
467 | |
---|
468 | |
---|
469 | def onSetFocus(self, evt): |
---|
470 | """ |
---|
471 | highlight the current textcrtl and hide the error text control shown |
---|
472 | after fitting |
---|
473 | """ |
---|
474 | |
---|
475 | if hasattr(self,"text2_3"): |
---|
476 | self.text2_3.Hide() |
---|
477 | if len(self.parameters)>0: |
---|
478 | for item in self.parameters: |
---|
479 | ## hide statictext +/- |
---|
480 | if item[3]!=None: |
---|
481 | item[3].Hide() |
---|
482 | ## hide textcrtl for error after fit |
---|
483 | if item[4]!=None: |
---|
484 | item[4].Clear() |
---|
485 | item[4].Hide() |
---|
486 | if len(self.fittable_param)>0: |
---|
487 | for item in self.fittable_param: |
---|
488 | ## hide statictext +/- |
---|
489 | if item[3]!=None: |
---|
490 | item[3].Hide() |
---|
491 | ## hide textcrtl for error after fit |
---|
492 | if item[4]!=None: |
---|
493 | item[4].Clear() |
---|
494 | item[4].Hide() |
---|
495 | self.Layout() |
---|
496 | return |
---|
497 | |
---|
498 | def _highlight_text(self, event): |
---|
499 | """ |
---|
500 | Highlight text of a TextCtrl only of no text has be selected |
---|
501 | @param event: mouse event |
---|
502 | """ |
---|
503 | control = event.GetEventObject() |
---|
504 | # Check that we have a TextCtrl |
---|
505 | if issubclass(control.__class__, wx.TextCtrl): |
---|
506 | # Check whether text has been selected, |
---|
507 | # if not, select the whole string |
---|
508 | |
---|
509 | (start, end) = control.GetSelection() |
---|
510 | if start==end: |
---|
511 | control.SetSelection(-1,-1) |
---|
512 | |
---|
513 | # Make sure the mouse event is available to other listeners |
---|
514 | event.Skip() |
---|
515 | |
---|
516 | |
---|
517 | def read_file(self, path): |
---|
518 | """ |
---|
519 | Read two columns file |
---|
520 | @param path: the path to the file to read |
---|
521 | """ |
---|
522 | try: |
---|
523 | if path==None: |
---|
524 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
525 | " Selected Distribution was not loaded: %s"%path)) |
---|
526 | return None, None |
---|
527 | input_f = open(path, 'r') |
---|
528 | buff = input_f.read() |
---|
529 | lines = buff.split('\n') |
---|
530 | |
---|
531 | angles = [] |
---|
532 | weights=[] |
---|
533 | for line in lines: |
---|
534 | toks = line.split() |
---|
535 | try: |
---|
536 | angle = float(toks[0]) |
---|
537 | weight = float(toks[1]) |
---|
538 | except: |
---|
539 | # Skip non-data lines |
---|
540 | pass |
---|
541 | angles.append(angle) |
---|
542 | weights.append(weight) |
---|
543 | return numpy.array(angles), numpy.array(weights) |
---|
544 | except: |
---|
545 | raise |
---|
546 | |
---|
547 | |
---|
548 | def createMemento(self): |
---|
549 | """ |
---|
550 | return the current state of the page |
---|
551 | """ |
---|
552 | return self.state.clone() |
---|
553 | |
---|
554 | |
---|
555 | def save_current_state(self): |
---|
556 | """ |
---|
557 | Store current state |
---|
558 | """ |
---|
559 | ## save model option |
---|
560 | if self.model!= None: |
---|
561 | self.disp_list= self.model.getDispParamList() |
---|
562 | self.state.disp_list= copy.deepcopy(self.disp_list) |
---|
563 | self.state.model = self.model.clone() |
---|
564 | |
---|
565 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
566 | self.state.values= copy.deepcopy(self.values) |
---|
567 | self.state.weights = copy.deepcopy( self.weights) |
---|
568 | ## save data |
---|
569 | self.state.data= copy.deepcopy(self.data) |
---|
570 | try: |
---|
571 | n = self.disp_box.GetCurrentSelection() |
---|
572 | dispersity= self.disp_box.GetClientData(n) |
---|
573 | name= dispersity.__name__ |
---|
574 | self.disp_name = name |
---|
575 | if name == "GaussianDispersion" : |
---|
576 | if hasattr(self,"cb1"): |
---|
577 | self.state.cb1= self.cb1.GetValue() |
---|
578 | except: |
---|
579 | pass |
---|
580 | |
---|
581 | if hasattr(self,"enable_disp"): |
---|
582 | self.state.enable_disp= self.enable_disp.GetValue() |
---|
583 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
584 | |
---|
585 | self.state.smearer = copy.deepcopy(self.smearer) |
---|
586 | if hasattr(self,"enable_smearer"): |
---|
587 | self.state.enable_smearer = copy.deepcopy(self.enable_smearer.GetValue()) |
---|
588 | self.state.disable_smearer = copy.deepcopy(self.disable_smearer.GetValue()) |
---|
589 | |
---|
590 | if hasattr(self,"disp_box"): |
---|
591 | self.state.disp_box = self.disp_box.GetCurrentSelection() |
---|
592 | |
---|
593 | if len(self.disp_cb_dict)>0: |
---|
594 | for k , v in self.disp_cb_dict.iteritems(): |
---|
595 | |
---|
596 | if v ==None : |
---|
597 | self.state.disp_cb_dict[k]= v |
---|
598 | else: |
---|
599 | try: |
---|
600 | self.state.disp_cb_dict[k]=v.GetValue() |
---|
601 | except: |
---|
602 | self.state.disp_cb_dict[k]= None |
---|
603 | |
---|
604 | if len(self._disp_obj_dict)>0: |
---|
605 | for k , v in self._disp_obj_dict.iteritems(): |
---|
606 | |
---|
607 | self.state._disp_obj_dict[k]= v |
---|
608 | |
---|
609 | |
---|
610 | self.state.values = copy.deepcopy(self.values) |
---|
611 | self.state.weights = copy.deepcopy(self.weights) |
---|
612 | ## save plotting range |
---|
613 | self._save_plotting_range() |
---|
614 | |
---|
615 | self.state.orientation_params =[] |
---|
616 | self.state.orientation_params_disp =[] |
---|
617 | self.state.parameters =[] |
---|
618 | self.state.fittable_param =[] |
---|
619 | self.state.fixed_param =[] |
---|
620 | |
---|
621 | |
---|
622 | ## save checkbutton state and txtcrtl values |
---|
623 | self._copy_parameters_state(self.orientation_params, |
---|
624 | self.state.orientation_params) |
---|
625 | self._copy_parameters_state(self.orientation_params_disp, |
---|
626 | self.state.orientation_params_disp) |
---|
627 | |
---|
628 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
629 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
630 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
631 | |
---|
632 | |
---|
633 | def reset_page_helper(self, state): |
---|
634 | """ |
---|
635 | Use page_state and change the state of existing page |
---|
636 | @precondition: the page is already drawn or created |
---|
637 | @postcondition: the state of the underlying data change as well as the |
---|
638 | state of the graphic interface |
---|
639 | """ |
---|
640 | if state ==None: |
---|
641 | self._undo.Enable(False) |
---|
642 | return |
---|
643 | |
---|
644 | self.model= state.model |
---|
645 | self.data = state.data |
---|
646 | self.smearer= state.smearer |
---|
647 | self.enable2D= state.enable2D |
---|
648 | |
---|
649 | #??? |
---|
650 | self.disp_cb_dict = state.disp_cb_dict |
---|
651 | self.disp_list =state.disp_list |
---|
652 | |
---|
653 | |
---|
654 | ## set the state of the radio box |
---|
655 | self.shape_rbutton.SetValue(state.shape_rbutton ) |
---|
656 | self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) |
---|
657 | self.struct_rbutton.SetValue(state.struct_rbutton ) |
---|
658 | self.plugin_rbutton.SetValue(state.plugin_rbutton) |
---|
659 | ##draw sizer containing model parameters value for the current model |
---|
660 | self._set_model_sizer_selection( self.model ) |
---|
661 | self.set_model_param_sizer(self.model) |
---|
662 | |
---|
663 | ## reset value of combox box |
---|
664 | self.structurebox.SetSelection(state.structurecombobox ) |
---|
665 | self.formfactorbox.SetSelection(state.formfactorcombobox) |
---|
666 | |
---|
667 | |
---|
668 | ## enable the view 2d button if this is a modelpage type |
---|
669 | if hasattr(self,"model_view"): |
---|
670 | if self.enable2D: |
---|
671 | self.model_view.Disable() |
---|
672 | else: |
---|
673 | self.model_view.Enable() |
---|
674 | ## set the select all check box to the a given state |
---|
675 | if hasattr(self, "cb1"): |
---|
676 | self.cb1.SetValue(state.cb1) |
---|
677 | |
---|
678 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
679 | |
---|
680 | self._reset_parameters_state(self.orientation_params_disp, |
---|
681 | state.orientation_params_disp) |
---|
682 | self._reset_parameters_state(self.orientation_params, |
---|
683 | state.orientation_params) |
---|
684 | self._reset_parameters_state(self.parameters,state.parameters) |
---|
685 | ## display dispersion info layer |
---|
686 | self.enable_disp.SetValue(state.enable_disp) |
---|
687 | self.disable_disp.SetValue(state.disable_disp) |
---|
688 | |
---|
689 | if hasattr(self, "disp_box"): |
---|
690 | |
---|
691 | self.disp_box.SetSelection(state.disp_box) |
---|
692 | n= self.disp_box.GetCurrentSelection() |
---|
693 | dispersity= self.disp_box.GetClientData(n) |
---|
694 | name= dispersity.__name__ |
---|
695 | |
---|
696 | self._set_dipers_Param(event=None) |
---|
697 | |
---|
698 | #self.disp_cb_dict = {} |
---|
699 | #for k,v in self.state.disp_cb_dict.iteritems(): |
---|
700 | # self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
701 | # self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
702 | |
---|
703 | if name=="ArrayDispersion": |
---|
704 | |
---|
705 | for item in self.disp_cb_dict.keys(): |
---|
706 | |
---|
707 | if hasattr(self.disp_cb_dict[item],"SetValue") : |
---|
708 | self.disp_cb_dict[item].SetValue(state.disp_cb_dict[item]) |
---|
709 | # Create the dispersion objects |
---|
710 | from sans.models.dispersion_models import ArrayDispersion |
---|
711 | disp_model = ArrayDispersion() |
---|
712 | if hasattr(state,"values")and self.disp_cb_dict[item].GetValue()==True: |
---|
713 | if len(state.values)>0: |
---|
714 | self.values=state.values |
---|
715 | self.weights=state.weights |
---|
716 | disp_model.set_weights(self.values, state.weights) |
---|
717 | else: |
---|
718 | self._reset_dispersity() |
---|
719 | |
---|
720 | self._disp_obj_dict[item] = disp_model |
---|
721 | # Set the new model as the dispersion object for the selected parameter |
---|
722 | self.model.set_dispersion(item, disp_model) |
---|
723 | |
---|
724 | #self.model._persistency_dict = {} |
---|
725 | self.model._persistency_dict[item] = [state.values, state.weights] |
---|
726 | |
---|
727 | else: |
---|
728 | |
---|
729 | for k,v in self.state.disp_cb_dict.iteritems(): |
---|
730 | self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
731 | self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
732 | |
---|
733 | #self._disp_obj_dict={} |
---|
734 | #for k , v in self.state._disp_obj_dict.iteritems(): |
---|
735 | # self._disp_obj_dict[k]=v |
---|
736 | |
---|
737 | ##plotting range restore |
---|
738 | self._reset_plotting_range(state) |
---|
739 | ## smearing info restore |
---|
740 | if hasattr(self,"enable_smearer"): |
---|
741 | ## set smearing value whether or not the data contain the smearing info |
---|
742 | self.enable_smearer.SetValue(state.enable_smearer) |
---|
743 | self.disable_smearer.SetValue(state.disable_smearer) |
---|
744 | self.tcChi.SetLabel(str( state.tcChi)) |
---|
745 | self.sizer5.Layout() |
---|
746 | self.Layout() |
---|
747 | self.Refresh() |
---|
748 | #self.compute_chisqr(smearer= self.smearer) |
---|
749 | #self._draw_model() |
---|
750 | ## reset state of checkbox,textcrtl and dispersity parameters value |
---|
751 | self._reset_parameters_state(self.fittable_param,state.fittable_param) |
---|
752 | self._reset_parameters_state(self.fixed_param,state.fixed_param) |
---|
753 | |
---|
754 | ## draw the model with previous parameters value |
---|
755 | self._onparamEnter_helper() |
---|
756 | |
---|
757 | ## reset context menu items |
---|
758 | self._reset_context_menu() |
---|
759 | |
---|
760 | #self._reset_dispersity() |
---|
761 | #self._set_dipers_Param(event=None) #to bo removed //resets disper para value |
---|
762 | |
---|
763 | #self.disp_cb_dict = {} |
---|
764 | #for k,v in self.state.disp_cb_dict.iteritems(): |
---|
765 | #self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
766 | #self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
767 | |
---|
768 | |
---|
769 | ## set the value of the current state to the state given as parameter |
---|
770 | self.state = state.clone() |
---|
771 | self._draw_model() |
---|
772 | |
---|
773 | |
---|
774 | def _selectDlg(self): |
---|
775 | """ |
---|
776 | open a dialog file to selected the customized dispersity |
---|
777 | """ |
---|
778 | import os |
---|
779 | dlg = wx.FileDialog(self, "Choose a weight file", |
---|
780 | self._default_save_location , "", "*.*", wx.OPEN) |
---|
781 | path = None |
---|
782 | if dlg.ShowModal() == wx.ID_OK: |
---|
783 | path = dlg.GetPath() |
---|
784 | dlg.Destroy() |
---|
785 | return path |
---|
786 | |
---|
787 | |
---|
788 | def _reset_context_menu(self): |
---|
789 | """ |
---|
790 | reset the context menu |
---|
791 | """ |
---|
792 | for name, state in self.state.saved_states.iteritems(): |
---|
793 | self.number_saved_state += 1 |
---|
794 | ## Add item in the context menu |
---|
795 | id = wx.NewId() |
---|
796 | self.popUpMenu.Append(id,name, 'Save model and state %g'%self.number_saved_state) |
---|
797 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
798 | |
---|
799 | |
---|
800 | def _reset_plotting_range(self, state): |
---|
801 | """ |
---|
802 | Reset the plotting range to a given state |
---|
803 | """ |
---|
804 | self.qmin.SetValue(str(state.qmin)) |
---|
805 | self.qmax.SetValue(str(state.qmax)) |
---|
806 | if self.state.npts!=None: |
---|
807 | self.npts.SetValue(str(state.npts)) |
---|
808 | |
---|
809 | |
---|
810 | def _save_typeOfmodel(self): |
---|
811 | """ |
---|
812 | save radiobutton containing the type model that can be selected |
---|
813 | """ |
---|
814 | self.state.shape_rbutton = self.shape_rbutton.GetValue() |
---|
815 | self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() |
---|
816 | self.state.struct_rbutton = self.struct_rbutton.GetValue() |
---|
817 | self.state.plugin_rbutton = self.plugin_rbutton.GetValue() |
---|
818 | self.state.structurebox= self.structurebox.GetCurrentSelection() |
---|
819 | self.state.formfactorbox = self.formfactorbox.GetCurrentSelection() |
---|
820 | |
---|
821 | self._undo.Enable(True) |
---|
822 | ## post state to fit panel |
---|
823 | event = PageInfoEvent(page = self) |
---|
824 | wx.PostEvent(self.parent, event) |
---|
825 | |
---|
826 | |
---|
827 | def _save_plotting_range(self ): |
---|
828 | """ |
---|
829 | save the state of plotting range |
---|
830 | """ |
---|
831 | self.state.qmin = self.qmin_x |
---|
832 | self.state.qmax = self.qmax_x |
---|
833 | if self.npts!=None: |
---|
834 | self.state.npts= self.num_points |
---|
835 | |
---|
836 | |
---|
837 | def _onparamEnter_helper(self): |
---|
838 | """ |
---|
839 | check if values entered by the user are changed and valid to replot |
---|
840 | model |
---|
841 | use : _check_value_enter |
---|
842 | """ |
---|
843 | self._undo.Enable(True) |
---|
844 | if self.model !=None: |
---|
845 | |
---|
846 | |
---|
847 | # Flag to register when a parameter has changed. |
---|
848 | is_modified = False |
---|
849 | is_modified =self._check_value_enter( self.fittable_param ,is_modified) |
---|
850 | is_modified =self._check_value_enter( self.fixed_param ,is_modified) |
---|
851 | is_modified =self._check_value_enter( self.parameters ,is_modified) |
---|
852 | |
---|
853 | self.sizer3.Layout() |
---|
854 | self.Layout() |
---|
855 | self.Refresh() |
---|
856 | # Here we should check whether the boundaries have been modified. |
---|
857 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
858 | # set the is_modified flag to True |
---|
859 | from sans.guiframe.utils import check_value |
---|
860 | if check_value( self.qmin, self.qmax): |
---|
861 | if float(self.qmin.GetValue()) != self.qmin_x: |
---|
862 | self.qmin_x = float(self.qmin.GetValue()) |
---|
863 | is_modified = True |
---|
864 | if float(self.qmax.GetValue()) != self.qmax_x: |
---|
865 | self.qmax_x = float(self.qmax.GetValue()) |
---|
866 | is_modified = True |
---|
867 | self.fitrange = True |
---|
868 | else: |
---|
869 | self.fitrange = False |
---|
870 | if self.npts != None: |
---|
871 | if check_float(self.npts): |
---|
872 | if float(self.npts.GetValue()) != self.num_points: |
---|
873 | self.num_points = float(self.npts.GetValue()) |
---|
874 | is_modified = True |
---|
875 | else: |
---|
876 | msg= "Cannot Plot :Must enter a number!!! " |
---|
877 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
878 | |
---|
879 | |
---|
880 | ## if any value is modify draw model with new value |
---|
881 | if is_modified: |
---|
882 | self.state_change= True |
---|
883 | self._draw_model() |
---|
884 | self.save_current_state() |
---|
885 | |
---|
886 | |
---|
887 | def _reset_parameters_state(self, listtorestore,statelist): |
---|
888 | """ |
---|
889 | Reset the parameters at the given state |
---|
890 | """ |
---|
891 | if len(statelist)==0 or len(listtorestore)==0 : |
---|
892 | return |
---|
893 | if len(statelist)!= len(listtorestore) : |
---|
894 | return |
---|
895 | for j in range(len(listtorestore)): |
---|
896 | item_page = listtorestore[j] |
---|
897 | item_page_info = statelist[j] |
---|
898 | ##change the state of the check box for simple parameters |
---|
899 | if item_page[0]!=None: |
---|
900 | item_page[0].SetValue(item_page_info[0]) |
---|
901 | |
---|
902 | if item_page[2]!=None: |
---|
903 | item_page[2].SetValue(item_page_info[2]) |
---|
904 | |
---|
905 | if item_page[3]!=None: |
---|
906 | ## show or hide text +/- |
---|
907 | if item_page_info[2]: |
---|
908 | item_page[3].Show(True) |
---|
909 | else: |
---|
910 | item_page[3].Hide() |
---|
911 | if item_page[4]!=None: |
---|
912 | ## show of hide the text crtl for fitting error |
---|
913 | if item_page_info[4][0]: |
---|
914 | item_page[4].Show(True) |
---|
915 | item_page[4].SetValue(item_page_info[4][1]) |
---|
916 | else: |
---|
917 | item_page[3].Hide() |
---|
918 | if item_page[5]!=None: |
---|
919 | ## show of hide the text crtl for fitting error |
---|
920 | if item_page_info[5][0]: |
---|
921 | item_page[5].Show(True) |
---|
922 | item_page[5].SetValue(item_page_info[4][1]) |
---|
923 | else: |
---|
924 | item_page[5].Hide() |
---|
925 | |
---|
926 | if item_page[6]!=None: |
---|
927 | ## show of hide the text crtl for fitting error |
---|
928 | if item_page_info[6][0]: |
---|
929 | item_page[6].Show(True) |
---|
930 | item_page[6].SetValue(item_page_info[6][1]) |
---|
931 | else: |
---|
932 | item_page[6].Hide() |
---|
933 | |
---|
934 | |
---|
935 | def _copy_parameters_state(self, listtocopy, statelist): |
---|
936 | """ |
---|
937 | copy the state of button |
---|
938 | @param listtocopy: the list of check button to copy |
---|
939 | @param statelist: list of state object to store the current state |
---|
940 | """ |
---|
941 | if len(listtocopy)==0: |
---|
942 | return |
---|
943 | |
---|
944 | for item in listtocopy: |
---|
945 | |
---|
946 | checkbox_state = None |
---|
947 | if item[0]!= None: |
---|
948 | checkbox_state= item[0].GetValue() |
---|
949 | parameter_name = item[1] |
---|
950 | parameter_value = None |
---|
951 | if item[2]!=None: |
---|
952 | parameter_value = item[2].GetValue() |
---|
953 | static_text = None |
---|
954 | if item[3]!=None: |
---|
955 | static_text = item[3].IsShown() |
---|
956 | error_value = None |
---|
957 | error_state = None |
---|
958 | if item[4]!= None: |
---|
959 | error_value = item[4].GetValue() |
---|
960 | error_state = item[4].IsShown() |
---|
961 | |
---|
962 | min_value = None |
---|
963 | min_state = None |
---|
964 | if item[5]!= None: |
---|
965 | min_value = item[5].GetValue() |
---|
966 | min_state = item[5].IsShown() |
---|
967 | |
---|
968 | max_value = None |
---|
969 | max_state = None |
---|
970 | if item[6]!= None: |
---|
971 | max_value = item[6].GetValue() |
---|
972 | max_state = item[6].IsShown() |
---|
973 | unit=None |
---|
974 | if item[7]!=None: |
---|
975 | unit = item[7].GetLabel() |
---|
976 | |
---|
977 | statelist.append([checkbox_state, parameter_name, parameter_value, |
---|
978 | static_text ,[error_state,error_value], |
---|
979 | [min_state,min_value],[max_state , max_value],unit]) |
---|
980 | |
---|
981 | |
---|
982 | |
---|
983 | def _set_model_sizer_selection(self, model): |
---|
984 | """ |
---|
985 | Display the sizer according to the type of the current model |
---|
986 | """ |
---|
987 | if model ==None: |
---|
988 | return |
---|
989 | if hasattr(model ,"s_model"): |
---|
990 | |
---|
991 | class_name= model.s_model.__class__ |
---|
992 | name= model.s_model.name |
---|
993 | flag= name != "NoStructure" |
---|
994 | if flag and (class_name in self.model_list_box["Structure Factors"]): |
---|
995 | self.structurebox.Show() |
---|
996 | self.text2.Show() |
---|
997 | self.structurebox.Enable() |
---|
998 | self.text2.Enable() |
---|
999 | items = self.structurebox.GetItems() |
---|
1000 | self.sizer1.Layout() |
---|
1001 | self.SetScrollbars(20,20,25,65) |
---|
1002 | for i in range(len(items)): |
---|
1003 | if items[i]== str(name): |
---|
1004 | self.structurebox.SetSelection(i) |
---|
1005 | break |
---|
1006 | |
---|
1007 | if hasattr(model ,"p_model"): |
---|
1008 | class_name = model.p_model.__class__ |
---|
1009 | name = model.p_model.name |
---|
1010 | self.formfactorbox.Clear() |
---|
1011 | |
---|
1012 | for k, list in self.model_list_box.iteritems(): |
---|
1013 | if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: |
---|
1014 | self.shape_rbutton.SetValue(True) |
---|
1015 | ## fill the form factor list with new model |
---|
1016 | self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1017 | items = self.formfactorbox.GetItems() |
---|
1018 | ## set comboxbox to the selected item |
---|
1019 | for i in range(len(items)): |
---|
1020 | if items[i]== str(name): |
---|
1021 | self.formfactorbox.SetSelection(i) |
---|
1022 | break |
---|
1023 | return |
---|
1024 | elif k == "Shape-Independent": |
---|
1025 | self.shape_indep_rbutton.SetValue(True) |
---|
1026 | elif k == "Structure Factors": |
---|
1027 | self.struct_rbutton.SetValue(True) |
---|
1028 | else: |
---|
1029 | self.plugin_rbutton.SetValue(True) |
---|
1030 | |
---|
1031 | if class_name in list: |
---|
1032 | ## fill the form factor list with new model |
---|
1033 | self._populate_box(self.formfactorbox, list) |
---|
1034 | items = self.formfactorbox.GetItems() |
---|
1035 | ## set comboxbox to the selected item |
---|
1036 | for i in range(len(items)): |
---|
1037 | if items[i]== str(name): |
---|
1038 | self.formfactorbox.SetSelection(i) |
---|
1039 | break |
---|
1040 | break |
---|
1041 | else: |
---|
1042 | |
---|
1043 | ## Select the model from the menu |
---|
1044 | class_name = model.__class__ |
---|
1045 | name = model.name |
---|
1046 | self.formfactorbox.Clear() |
---|
1047 | items = self.formfactorbox.GetItems() |
---|
1048 | |
---|
1049 | for k, list in self.model_list_box.iteritems(): |
---|
1050 | if k in["P(Q)*S(Q)","Shapes" ] and class_name in self.model_list_box["Shapes"]: |
---|
1051 | if class_name in self.model_list_box["P(Q)*S(Q)"]: |
---|
1052 | self.structurebox.Show() |
---|
1053 | self.text2.Show() |
---|
1054 | self.structurebox.Enable() |
---|
1055 | self.structurebox.SetSelection(0) |
---|
1056 | self.text2.Enable() |
---|
1057 | else: |
---|
1058 | self.structurebox.Hide() |
---|
1059 | self.text2.Hide() |
---|
1060 | self.structurebox.Disable() |
---|
1061 | self.structurebox.SetSelection(0) |
---|
1062 | self.text2.Disable() |
---|
1063 | |
---|
1064 | self.shape_rbutton.SetValue(True) |
---|
1065 | ## fill the form factor list with new model |
---|
1066 | self._populate_box(self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1067 | items = self.formfactorbox.GetItems() |
---|
1068 | ## set comboxbox to the selected item |
---|
1069 | for i in range(len(items)): |
---|
1070 | if items[i]== str(name): |
---|
1071 | self.formfactorbox.SetSelection(i) |
---|
1072 | break |
---|
1073 | return |
---|
1074 | elif k == "Shape-Independent": |
---|
1075 | self.shape_indep_rbutton.SetValue(True) |
---|
1076 | elif k == "Structure Factors": |
---|
1077 | self.struct_rbutton.SetValue(True) |
---|
1078 | else: |
---|
1079 | self.plugin_rbutton.SetValue(True) |
---|
1080 | if class_name in list: |
---|
1081 | self.structurebox.SetSelection(0) |
---|
1082 | self.structurebox.Disable() |
---|
1083 | self.text2.Disable() |
---|
1084 | ## fill the form factor list with new model |
---|
1085 | self._populate_box(self.formfactorbox, list) |
---|
1086 | items = self.formfactorbox.GetItems() |
---|
1087 | ## set comboxbox to the selected item |
---|
1088 | for i in range(len(items)): |
---|
1089 | if items[i]== str(name): |
---|
1090 | self.formfactorbox.SetSelection(i) |
---|
1091 | break |
---|
1092 | break |
---|
1093 | |
---|
1094 | |
---|
1095 | def _draw_model(self): |
---|
1096 | """ |
---|
1097 | Method to draw or refresh a plotted model. |
---|
1098 | The method will use the data member from the model page |
---|
1099 | to build a call to the fitting perspective manager. |
---|
1100 | |
---|
1101 | [Note to coder: This way future changes will be done in only one place.] |
---|
1102 | """ |
---|
1103 | if self.model !=None: |
---|
1104 | temp_smear=None |
---|
1105 | if hasattr(self, "enable_smearer"): |
---|
1106 | if self.enable_smearer.GetValue(): |
---|
1107 | temp_smear= self.smearer |
---|
1108 | |
---|
1109 | self.manager.draw_model(self.model, data=self.data, |
---|
1110 | smearer= temp_smear, |
---|
1111 | qmin=float(self.qmin_x), qmax=float(self.qmax_x), |
---|
1112 | qstep= float(self.num_points), |
---|
1113 | enable2D=self.enable2D) |
---|
1114 | |
---|
1115 | |
---|
1116 | def _set_model_sizer(self, sizer, title="", object=None): |
---|
1117 | """ |
---|
1118 | Use lists to fill a sizer for model info |
---|
1119 | """ |
---|
1120 | |
---|
1121 | sizer.Clear(True) |
---|
1122 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
1123 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1124 | #-------------------------------------------------------- |
---|
1125 | self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', style=wx.RB_GROUP) |
---|
1126 | self.shape_indep_rbutton = wx.RadioButton(self, -1, "Shape-Independent") |
---|
1127 | self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") |
---|
1128 | self.plugin_rbutton = wx.RadioButton(self, -1, "Customized Models") |
---|
1129 | |
---|
1130 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1131 | id= self.shape_rbutton.GetId() ) |
---|
1132 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1133 | id= self.shape_indep_rbutton.GetId() ) |
---|
1134 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1135 | id= self.struct_rbutton.GetId() ) |
---|
1136 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1137 | id= self.plugin_rbutton.GetId() ) |
---|
1138 | |
---|
1139 | |
---|
1140 | sizer_radiobutton = wx.GridSizer(2, 2,5, 5) |
---|
1141 | sizer_radiobutton.Add(self.shape_rbutton) |
---|
1142 | sizer_radiobutton.Add(self.shape_indep_rbutton) |
---|
1143 | sizer_radiobutton.Add(self.plugin_rbutton) |
---|
1144 | sizer_radiobutton.Add(self.struct_rbutton) |
---|
1145 | |
---|
1146 | sizer_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
1147 | |
---|
1148 | self.text1 = wx.StaticText( self,-1,"" ) |
---|
1149 | self.text2 = wx.StaticText( self,-1,"P(Q)*S(Q)" ) |
---|
1150 | |
---|
1151 | |
---|
1152 | self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
1153 | if self.model!=None: |
---|
1154 | self.formfactorbox.SetValue(self.model.name) |
---|
1155 | |
---|
1156 | |
---|
1157 | self.structurebox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
1158 | wx.EVT_COMBOBOX(self.formfactorbox,-1, self._on_select_model) |
---|
1159 | wx.EVT_COMBOBOX(self.structurebox,-1, self._on_select_model) |
---|
1160 | |
---|
1161 | |
---|
1162 | ## fill combox box |
---|
1163 | if len(self.model_list_box)>0: |
---|
1164 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1165 | |
---|
1166 | if len(self.model_list_box)>0: |
---|
1167 | self._populate_box( self.structurebox, |
---|
1168 | self.model_list_box["Structure Factors"]) |
---|
1169 | self.structurebox.Insert("None", 0,None) |
---|
1170 | self.structurebox.SetSelection(0) |
---|
1171 | self.structurebox.Hide() |
---|
1172 | self.text2.Hide() |
---|
1173 | self.structurebox.Disable() |
---|
1174 | self.text2.Disable() |
---|
1175 | |
---|
1176 | if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: |
---|
1177 | self.structurebox.Show() |
---|
1178 | self.text2.Show() |
---|
1179 | self.structurebox.Enable() |
---|
1180 | self.text2.Enable() |
---|
1181 | |
---|
1182 | ## check model type to show sizer |
---|
1183 | if self.model !=None: |
---|
1184 | self._set_model_sizer_selection( self.model ) |
---|
1185 | |
---|
1186 | sizer_selection.Add(self.text1) |
---|
1187 | sizer_selection.Add((5,5)) |
---|
1188 | sizer_selection.Add(self.formfactorbox) |
---|
1189 | sizer_selection.Add((5,5)) |
---|
1190 | sizer_selection.Add(self.text2) |
---|
1191 | sizer_selection.Add((5,5)) |
---|
1192 | sizer_selection.Add(self.structurebox) |
---|
1193 | sizer_selection.Add((5,5)) |
---|
1194 | |
---|
1195 | boxsizer1.Add( sizer_radiobutton ) |
---|
1196 | boxsizer1.Add( (20,20)) |
---|
1197 | boxsizer1.Add( sizer_selection ) |
---|
1198 | if object !=None: |
---|
1199 | boxsizer1.Add( (-72,-72)) |
---|
1200 | boxsizer1.Add( object, 0, wx.ALIGN_RIGHT| wx.RIGHT, 10) |
---|
1201 | boxsizer1.Add( (60,60)) |
---|
1202 | #-------------------------------------------------------- |
---|
1203 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1204 | sizer.Layout() |
---|
1205 | self.SetScrollbars(20,20,25,65) |
---|
1206 | |
---|
1207 | |
---|
1208 | def _show_combox(self, event): |
---|
1209 | """ |
---|
1210 | Show combox box associate with type of model selected |
---|
1211 | """ |
---|
1212 | ## Don't want to populate combo box again if the event comes from check box |
---|
1213 | if self.shape_rbutton.GetValue()and\ |
---|
1214 | event.GetEventObject()==self.shape_rbutton: |
---|
1215 | ##fill the combobox with form factor list |
---|
1216 | self.structurebox.SetSelection(0) |
---|
1217 | self.structurebox.Disable() |
---|
1218 | self.formfactorbox.Clear() |
---|
1219 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1220 | |
---|
1221 | if self.shape_indep_rbutton.GetValue()and\ |
---|
1222 | event.GetEventObject()==self.shape_indep_rbutton: |
---|
1223 | ##fill the combobox with shape independent factor list |
---|
1224 | self.structurebox.SetSelection(0) |
---|
1225 | self.structurebox.Disable() |
---|
1226 | self.formfactorbox.Clear() |
---|
1227 | self._populate_box( self.formfactorbox, |
---|
1228 | self.model_list_box["Shape-Independent"]) |
---|
1229 | |
---|
1230 | if self.struct_rbutton.GetValue() and\ |
---|
1231 | event.GetEventObject()==self.struct_rbutton: |
---|
1232 | ##fill the combobox with structure factor list |
---|
1233 | self.structurebox.SetSelection(0) |
---|
1234 | self.structurebox.Disable() |
---|
1235 | self.formfactorbox.Clear() |
---|
1236 | self._populate_box( self.formfactorbox, |
---|
1237 | self.model_list_box["Structure Factors"]) |
---|
1238 | |
---|
1239 | if self.plugin_rbutton.GetValue()and\ |
---|
1240 | event.GetEventObject()==self.plugin_rbutton: |
---|
1241 | |
---|
1242 | ##fill the combobox with form factor list |
---|
1243 | self.structurebox.Disable() |
---|
1244 | self.formfactorbox.Clear() |
---|
1245 | self._populate_box( self.formfactorbox, |
---|
1246 | self.model_list_box["Customized Models"]) |
---|
1247 | |
---|
1248 | self._on_select_model(event=None) |
---|
1249 | self._save_typeOfmodel() |
---|
1250 | self.sizer4_4.Layout() |
---|
1251 | self.sizer4.Layout() |
---|
1252 | self.Layout() |
---|
1253 | self.Refresh() |
---|
1254 | self.SetScrollbars(20,20,25,65) |
---|
1255 | |
---|
1256 | def _populate_box(self, combobox, list): |
---|
1257 | """ |
---|
1258 | fill combox box with dict item |
---|
1259 | @param list: contains item to fill the combox |
---|
1260 | item must model class |
---|
1261 | """ |
---|
1262 | for models in list: |
---|
1263 | model= models() |
---|
1264 | name = model.__class__.__name__ |
---|
1265 | if models.__name__!="NoStructure": |
---|
1266 | if hasattr(model, "name"): |
---|
1267 | name = model.name |
---|
1268 | combobox.Append(name,models) |
---|
1269 | |
---|
1270 | return 0 |
---|
1271 | |
---|
1272 | |
---|
1273 | def _on_select_model_helper(self): |
---|
1274 | """ |
---|
1275 | call back for model selection |
---|
1276 | """ |
---|
1277 | ## reset dictionary containing reference to dispersion |
---|
1278 | self._disp_obj_dict = {} |
---|
1279 | self.disp_cb_dict ={} |
---|
1280 | f_id = self.formfactorbox.GetCurrentSelection() |
---|
1281 | form_factor = self.formfactorbox.GetClientData( f_id ) |
---|
1282 | if not form_factor in self.model_list_box["multiplication"]: |
---|
1283 | self.structurebox.Hide() |
---|
1284 | self.text2.Hide() |
---|
1285 | self.structurebox.Disable() |
---|
1286 | self.structurebox.SetSelection(0) |
---|
1287 | self.text2.Disable() |
---|
1288 | else: |
---|
1289 | self.structurebox.Show() |
---|
1290 | self.text2.Show() |
---|
1291 | self.structurebox.Enable() |
---|
1292 | self.text2.Enable() |
---|
1293 | |
---|
1294 | s_id = self.structurebox.GetCurrentSelection() |
---|
1295 | struct_factor = self.structurebox.GetClientData( s_id ) |
---|
1296 | |
---|
1297 | if struct_factor !=None: |
---|
1298 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
1299 | self.model= MultiplicationModel(form_factor(),struct_factor()) |
---|
1300 | |
---|
1301 | else: |
---|
1302 | if form_factor != None: |
---|
1303 | self.model= form_factor() |
---|
1304 | else: |
---|
1305 | self.model = None |
---|
1306 | return self.model |
---|
1307 | |
---|
1308 | ## post state to fit panel |
---|
1309 | self.state.parameters =[] |
---|
1310 | self.state.model =self.model |
---|
1311 | |
---|
1312 | self.disp_list =self.model.getDispParamList() |
---|
1313 | self.state.disp_list = self.disp_list |
---|
1314 | self.sizer4_4.Layout() |
---|
1315 | self.sizer4.Layout() |
---|
1316 | self.Layout() |
---|
1317 | self.SetScrollbars(20,20,25,65) |
---|
1318 | self.Refresh() |
---|
1319 | |
---|
1320 | |
---|
1321 | |
---|
1322 | def _onparamEnter(self,event): |
---|
1323 | """ |
---|
1324 | when enter value on panel redraw model according to changed |
---|
1325 | """ |
---|
1326 | tcrtl= event.GetEventObject() |
---|
1327 | ## save current state |
---|
1328 | self.save_current_state() |
---|
1329 | if event !=None: |
---|
1330 | self._undo.Enable(True) |
---|
1331 | event = PageInfoEvent(page = self) |
---|
1332 | wx.PostEvent(self.parent, event) |
---|
1333 | |
---|
1334 | if check_float(tcrtl): |
---|
1335 | |
---|
1336 | self._onparamEnter_helper() |
---|
1337 | else: |
---|
1338 | msg= "Cannot Plot :Must enter a number!!! " |
---|
1339 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1340 | return |
---|
1341 | |
---|
1342 | |
---|
1343 | def _check_value_enter(self, list, modified): |
---|
1344 | """ |
---|
1345 | @param list: model parameter and panel info |
---|
1346 | each item of the list should be as follow: |
---|
1347 | item=[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
1348 | """ |
---|
1349 | is_modified = modified |
---|
1350 | if len(list)==0: |
---|
1351 | return is_modified |
---|
1352 | for item in list: |
---|
1353 | try: |
---|
1354 | name = str(item[1]) |
---|
1355 | if hasattr(self,"text2_3"): |
---|
1356 | self.text2_3.Hide() |
---|
1357 | ## check model parameters range |
---|
1358 | ## check minimun value |
---|
1359 | param_min= None |
---|
1360 | param_max= None |
---|
1361 | if item[5]!= None: |
---|
1362 | if item[5].GetValue().lstrip().rstrip()!="": |
---|
1363 | param_min = float(item[5].GetValue()) |
---|
1364 | |
---|
1365 | ## check maximum value |
---|
1366 | if item[6]!= None: |
---|
1367 | if item[6].GetValue().lstrip().rstrip()!="": |
---|
1368 | param_max = float(item[6].GetValue()) |
---|
1369 | |
---|
1370 | from sans.guiframe.utils import check_value |
---|
1371 | if param_min != None and param_max !=None: |
---|
1372 | if not check_value(item[5], item[6]): |
---|
1373 | msg= "Wrong Fit range entered for parameter " |
---|
1374 | msg+= "name %s of model %s "%(name, self.model.name) |
---|
1375 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1376 | if name in self.model.details.keys(): |
---|
1377 | self.model.details[name][1:]= param_min,param_max |
---|
1378 | |
---|
1379 | ## hide statictext +/- |
---|
1380 | if item[3]!=None: |
---|
1381 | item[3].Hide() |
---|
1382 | ## hide textcrtl for error after fit |
---|
1383 | if item[4]!=None: |
---|
1384 | item[4].Clear() |
---|
1385 | item[4].Hide() |
---|
1386 | |
---|
1387 | value= float(item[2].GetValue()) |
---|
1388 | |
---|
1389 | # If the value of the parameter has changed, |
---|
1390 | # +update the model and set the is_modified flag |
---|
1391 | if value != self.model.getParam(name): |
---|
1392 | self.model.setParam(name,value) |
---|
1393 | is_modified = True |
---|
1394 | |
---|
1395 | except: |
---|
1396 | msg= "Model Drawing Error:wrong value entered : %s"% sys.exc_value |
---|
1397 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1398 | return |
---|
1399 | |
---|
1400 | return is_modified |
---|
1401 | |
---|
1402 | |
---|
1403 | def _set_dipers_Param(self, event): |
---|
1404 | """ |
---|
1405 | respond to self.enable_disp and self.disable_disp radio box. |
---|
1406 | The dispersity object is reset inside the model into Gaussian. |
---|
1407 | When the user select yes , this method display a combo box for more selection |
---|
1408 | when the user selects No,the combo box disappears. |
---|
1409 | Redraw the model with the default dispersity (Gaussian) |
---|
1410 | """ |
---|
1411 | |
---|
1412 | self._reset_dispersity() |
---|
1413 | |
---|
1414 | if self.model ==None: |
---|
1415 | self.model_disp.Hide() |
---|
1416 | self.disp_box.Hide() |
---|
1417 | self.sizer4_4.Clear(True) |
---|
1418 | |
---|
1419 | return |
---|
1420 | |
---|
1421 | if self.enable_disp.GetValue(): |
---|
1422 | self.model_disp.Show(True) |
---|
1423 | self.disp_box.Show(True) |
---|
1424 | ## layout for model containing no dispersity parameters |
---|
1425 | |
---|
1426 | self.disp_list= self.model.getDispParamList() |
---|
1427 | |
---|
1428 | if len(self.disp_list)==0 and len(self.disp_cb_dict)==0: |
---|
1429 | self._layout_sizer_noDipers() |
---|
1430 | else: |
---|
1431 | ## set gaussian sizer |
---|
1432 | self._on_select_Disp(event=None) |
---|
1433 | else: |
---|
1434 | self.model_disp.Hide() |
---|
1435 | self.disp_box.Hide() |
---|
1436 | self.disp_box.SetSelection(0) |
---|
1437 | self.sizer4_4.Clear(True) |
---|
1438 | |
---|
1439 | ## post state to fit panel |
---|
1440 | self.save_current_state() |
---|
1441 | if event !=None: |
---|
1442 | self._undo.Enable(True) |
---|
1443 | event = PageInfoEvent(page = self) |
---|
1444 | wx.PostEvent(self.parent, event) |
---|
1445 | #draw the model with the current dispersity |
---|
1446 | self._draw_model() |
---|
1447 | self.sizer4_4.Layout() |
---|
1448 | self.sizer4.Layout() |
---|
1449 | self.Layout() |
---|
1450 | self.Refresh() |
---|
1451 | self.SetScrollbars(20,20,25,65) |
---|
1452 | |
---|
1453 | |
---|
1454 | def _layout_sizer_noDipers(self): |
---|
1455 | """ |
---|
1456 | Draw a sizer with no dispersity info |
---|
1457 | """ |
---|
1458 | ix=0 |
---|
1459 | iy=1 |
---|
1460 | self.fittable_param=[] |
---|
1461 | self.fixed_param=[] |
---|
1462 | self.orientation_params_disp=[] |
---|
1463 | |
---|
1464 | self.model_disp.Hide() |
---|
1465 | self.disp_box.Hide() |
---|
1466 | self.sizer4_4.Clear(True) |
---|
1467 | model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') |
---|
1468 | self.sizer4_4.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1469 | self.sizer4_4.Layout() |
---|
1470 | self.sizer4.Layout() |
---|
1471 | self.SetScrollbars(20,20,25,65) |
---|
1472 | |
---|
1473 | |
---|
1474 | def _reset_dispersity(self): |
---|
1475 | """ |
---|
1476 | put gaussian dispersity into current model |
---|
1477 | """ |
---|
1478 | if len(self.param_toFit)>0: |
---|
1479 | for item in self.fittable_param: |
---|
1480 | if item in self.param_toFit: |
---|
1481 | self.param_toFit.remove(item) |
---|
1482 | for item in self.orientation_params_disp: |
---|
1483 | if item in self.param_toFit: |
---|
1484 | self.param_toFit.remove(item) |
---|
1485 | |
---|
1486 | self.fittable_param=[] |
---|
1487 | self.fixed_param=[] |
---|
1488 | self.orientation_params_disp=[] |
---|
1489 | self.values=[] |
---|
1490 | self.weights=[] |
---|
1491 | |
---|
1492 | |
---|
1493 | from sans.models.dispersion_models import GaussianDispersion, ArrayDispersion |
---|
1494 | if len(self.disp_cb_dict)==0: |
---|
1495 | self.sizer4_4.Clear(True) |
---|
1496 | self.sizer4_4.Layout() |
---|
1497 | self.sizer4.Layout() |
---|
1498 | self.Layout() |
---|
1499 | self.Refresh() |
---|
1500 | self.SetScrollbars(20,20,25,65) |
---|
1501 | return |
---|
1502 | if (len(self.disp_cb_dict)>0) : |
---|
1503 | for p in self.disp_cb_dict: |
---|
1504 | # The parameter was un-selected. Go back to Gaussian model (with 0 pts) |
---|
1505 | disp_model = GaussianDispersion() |
---|
1506 | |
---|
1507 | self._disp_obj_dict[p] = disp_model |
---|
1508 | # Set the new model as the dispersion object for the selected parameter |
---|
1509 | try: |
---|
1510 | self.model.set_dispersion(p, disp_model) |
---|
1511 | except: |
---|
1512 | pass |
---|
1513 | # Redraw the model |
---|
1514 | #self._draw_model() |
---|
1515 | ## save state into |
---|
1516 | self.save_current_state() |
---|
1517 | self.sizer4_4.Layout() |
---|
1518 | self.sizer4.Layout() |
---|
1519 | self.Layout() |
---|
1520 | self.SetScrollbars(20,20,25,65) |
---|
1521 | self.Refresh() |
---|
1522 | |
---|
1523 | |
---|
1524 | |
---|
1525 | def _on_select_Disp(self,event): |
---|
1526 | """ |
---|
1527 | allow selecting different dispersion |
---|
1528 | self.disp_list should change type later .now only gaussian |
---|
1529 | """ |
---|
1530 | |
---|
1531 | n = self.disp_box.GetCurrentSelection() |
---|
1532 | name = self.disp_box.GetValue() |
---|
1533 | dispersity= self.disp_box.GetClientData(n) |
---|
1534 | |
---|
1535 | self.disp_name = name |
---|
1536 | |
---|
1537 | if name.lower() == "array": |
---|
1538 | self._set_sizer_arraydispersion() |
---|
1539 | else: |
---|
1540 | self._set_sizer_dispersion(dispersity= dispersity) |
---|
1541 | |
---|
1542 | |
---|
1543 | self.state.disp_box= n |
---|
1544 | |
---|
1545 | self._undo.Enable(True) |
---|
1546 | event = PageInfoEvent(page = self) |
---|
1547 | wx.PostEvent(self.parent, event) |
---|
1548 | |
---|
1549 | self.sizer4_4.Layout() |
---|
1550 | self.sizer4.Layout() |
---|
1551 | self.Layout() |
---|
1552 | self.SetScrollbars(20,20,25,65) |
---|
1553 | self.Refresh() |
---|
1554 | |
---|
1555 | def _set_sizer_arraydispersion(self): |
---|
1556 | """ |
---|
1557 | draw sizer with array dispersity parameters |
---|
1558 | """ |
---|
1559 | |
---|
1560 | if len(self.param_toFit)>0: |
---|
1561 | for item in self.fittable_param: |
---|
1562 | if item in self.param_toFit: |
---|
1563 | self.param_toFit.remove(item) |
---|
1564 | for item in self.orientation_params_disp: |
---|
1565 | if item in self.param_toFit: |
---|
1566 | self.param_toFit.remove(item) |
---|
1567 | |
---|
1568 | |
---|
1569 | self.fittable_param=[] |
---|
1570 | self.fixed_param=[] |
---|
1571 | self.orientation_params_disp=[] |
---|
1572 | self.sizer4_4.Clear(True) |
---|
1573 | self._reset_dispersity() |
---|
1574 | ix=0 |
---|
1575 | iy=1 |
---|
1576 | disp1 = wx.StaticText(self, -1, 'Array Dispersion') |
---|
1577 | self.sizer4_4.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1578 | |
---|
1579 | # Look for model parameters to which we can apply an ArrayDispersion model |
---|
1580 | # Add a check box for each parameter. |
---|
1581 | self.disp_cb_dict = {} |
---|
1582 | |
---|
1583 | for p in self.model.dispersion.keys(): |
---|
1584 | if not p in self.model.orientation_params: |
---|
1585 | ix+=1 |
---|
1586 | self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) |
---|
1587 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
1588 | |
---|
1589 | wx.EVT_RADIOBUTTON(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle) |
---|
1590 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1591 | for p in self.model.dispersion.keys(): |
---|
1592 | if p in self.model.orientation_params: |
---|
1593 | ix+=1 |
---|
1594 | self.disp_cb_dict[p] = wx.CheckBox(self, -1, p, (10, 10)) |
---|
1595 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
1596 | #print "self.enable2D",self.enable2D |
---|
1597 | if not (self.enable2D or self.data.__class__.__name__ =="Data2D"): |
---|
1598 | self.disp_cb_dict[p].Hide() |
---|
1599 | self.disp_cb_dict[p].Disable() |
---|
1600 | else: |
---|
1601 | self.disp_cb_dict[p].Show(True) |
---|
1602 | self.disp_cb_dict[p].Enable() |
---|
1603 | |
---|
1604 | wx.EVT_CHECKBOX(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle) |
---|
1605 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1606 | |
---|
1607 | |
---|
1608 | ix =0 |
---|
1609 | iy +=1 |
---|
1610 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1611 | self.sizer4_4.Layout() |
---|
1612 | self.sizer4.Layout() |
---|
1613 | self.SetScrollbars(20,20,25,65) |
---|
1614 | ## save state into |
---|
1615 | |
---|
1616 | self.state.orientation_params =[] |
---|
1617 | self.state.orientation_params_disp =[] |
---|
1618 | self.state.parameters =[] |
---|
1619 | self.state.fittable_param =[] |
---|
1620 | self.state.fixed_param =[] |
---|
1621 | |
---|
1622 | ## save checkbutton state and txtcrtl values |
---|
1623 | |
---|
1624 | self._copy_parameters_state(self.orientation_params, |
---|
1625 | self.state.orientation_params) |
---|
1626 | |
---|
1627 | self._copy_parameters_state(self.orientation_params_disp, |
---|
1628 | self.state.orientation_params_disp) |
---|
1629 | |
---|
1630 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
1631 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
1632 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
1633 | |
---|
1634 | |
---|
1635 | ## post state to fit panel |
---|
1636 | event = PageInfoEvent(page = self) |
---|
1637 | wx.PostEvent(self.parent, event) |
---|
1638 | |
---|
1639 | |
---|
1640 | |
---|
1641 | |
---|
1642 | |
---|
1643 | def _set_range_sizer(self, title, object1=None,object=None): |
---|
1644 | """ |
---|
1645 | Fill the |
---|
1646 | """ |
---|
1647 | self.sizer5.Clear(True) |
---|
1648 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
1649 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1650 | #-------------------------------------------------------------- |
---|
1651 | self.qmin = BasicPage.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
1652 | self.qmin.SetValue(str(self.qmin_x)) |
---|
1653 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
1654 | #self.qmin.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
1655 | #self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
1656 | #self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
1657 | |
---|
1658 | self.qmax = BasicPage.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
1659 | self.qmax.SetValue(str(self.qmax_x)) |
---|
1660 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
1661 | #self.qmax.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
1662 | #self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
1663 | #self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
1664 | |
---|
1665 | sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) |
---|
1666 | sizer= wx.GridSizer(3, 3,5, 5) |
---|
1667 | |
---|
1668 | sizer.Add((5,5)) |
---|
1669 | sizer.Add(wx.StaticText(self, -1, 'Min')) |
---|
1670 | sizer.Add(wx.StaticText(self, -1, 'Max')) |
---|
1671 | sizer.Add(wx.StaticText(self, -1, 'Q range')) |
---|
1672 | |
---|
1673 | sizer.Add(self.qmin) |
---|
1674 | sizer.Add(self.qmax) |
---|
1675 | sizer_horizontal.Add(sizer) |
---|
1676 | if object!=None: |
---|
1677 | sizer_horizontal.Add(object) |
---|
1678 | |
---|
1679 | if object1!=None: |
---|
1680 | boxsizer1.Add(object1) |
---|
1681 | boxsizer1.Add((10,10)) |
---|
1682 | boxsizer1.Add(sizer_horizontal) |
---|
1683 | ## save state |
---|
1684 | self.save_current_state() |
---|
1685 | #---------------------------------------------------------------- |
---|
1686 | self.sizer5.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1687 | self.sizer5.Layout() |
---|
1688 | self.Layout() |
---|
1689 | self.SetScrollbars(20,20,25,65) |
---|
1690 | |
---|
1691 | |
---|
1692 | def _fill_save_sizer(self): |
---|
1693 | """ |
---|
1694 | Draw the layout for saving option |
---|
1695 | """ |
---|
1696 | # Skipping save state functionality for release 0.9.0 |
---|
1697 | #return |
---|
1698 | |
---|
1699 | self.sizer6.Clear(True) |
---|
1700 | box_description= wx.StaticBox(self, -1,"Save Status") |
---|
1701 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1702 | sizer_save = wx.BoxSizer(wx.HORIZONTAL) |
---|
1703 | |
---|
1704 | self.btSave_title = wx.StaticText(self, -1, 'Save the current panel status') |
---|
1705 | self.btSave = wx.Button(self,wx.NewId(),'Save') |
---|
1706 | self.btSave.Bind(wx.EVT_BUTTON, self.onSave,id= self.btSave.GetId()) |
---|
1707 | self.btSave.SetToolTipString("Save current panel status") |
---|
1708 | |
---|
1709 | sizer_save.Add(self.btSave_title) |
---|
1710 | sizer_save.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,45) |
---|
1711 | |
---|
1712 | sizer_save.Add(self.btSave) |
---|
1713 | |
---|
1714 | boxsizer1.Add(sizer_save) |
---|
1715 | self.sizer6.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1716 | self.sizer6.Layout() |
---|
1717 | self.SetScrollbars(20,20,25,65) |
---|
1718 | |
---|
1719 | def on_model_help_clicked(self,event): |
---|
1720 | """ |
---|
1721 | #On 'More details' button |
---|
1722 | """ |
---|
1723 | from helpPanel import HelpWindow |
---|
1724 | |
---|
1725 | if self.model == None: |
---|
1726 | name = 'FuncHelp' |
---|
1727 | else: |
---|
1728 | name = self.model.origin_name |
---|
1729 | |
---|
1730 | frame = HelpWindow(None, -1, pageToOpen="doc/model_functions.html") |
---|
1731 | frame.Show(True) |
---|
1732 | if frame.rhelp.HasAnchor(name): |
---|
1733 | frame.rhelp.ScrollToAnchor(name) |
---|
1734 | else: |
---|
1735 | msg= "Model does not contains an available description " |
---|
1736 | msg +="Please try searching in the Help window" |
---|
1737 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1738 | |
---|