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