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 | |
---|
1232 | self.manager.draw_model(self.model, data=self.data, |
---|
1233 | smearer= temp_smear, |
---|
1234 | qmin=float(self.qmin_x), |
---|
1235 | qmax=float(self.qmax_x), |
---|
1236 | qstep= float(self.num_points), |
---|
1237 | enable2D=self.enable2D) |
---|
1238 | |
---|
1239 | |
---|
1240 | def _set_model_sizer(self,sizer, box_sizer, title="", object=None): |
---|
1241 | """ |
---|
1242 | Use lists to fill a sizer for model info |
---|
1243 | """ |
---|
1244 | |
---|
1245 | sizer.Clear(True) |
---|
1246 | ##For MAC, this should defined here. |
---|
1247 | if box_sizer == None: |
---|
1248 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
1249 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1250 | else: |
---|
1251 | boxsizer1 = box_sizer |
---|
1252 | |
---|
1253 | #-------------------------------------------------------- |
---|
1254 | self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', style=wx.RB_GROUP) |
---|
1255 | self.shape_indep_rbutton = wx.RadioButton(self, -1, "Shape-Independent") |
---|
1256 | self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") |
---|
1257 | self.plugin_rbutton = wx.RadioButton(self, -1, "Customized Models") |
---|
1258 | |
---|
1259 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1260 | id= self.shape_rbutton.GetId() ) |
---|
1261 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1262 | id= self.shape_indep_rbutton.GetId() ) |
---|
1263 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1264 | id= self.struct_rbutton.GetId() ) |
---|
1265 | self.Bind( wx.EVT_RADIOBUTTON, self._show_combox, |
---|
1266 | id= self.plugin_rbutton.GetId() ) |
---|
1267 | #MAC needs SetValue |
---|
1268 | self.shape_rbutton.SetValue(True) |
---|
1269 | |
---|
1270 | sizer_radiobutton = wx.GridSizer(2, 2,5, 5) |
---|
1271 | sizer_radiobutton.Add(self.shape_rbutton) |
---|
1272 | sizer_radiobutton.Add(self.shape_indep_rbutton) |
---|
1273 | sizer_radiobutton.Add(self.plugin_rbutton) |
---|
1274 | sizer_radiobutton.Add(self.struct_rbutton) |
---|
1275 | |
---|
1276 | sizer_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
1277 | |
---|
1278 | self.text1 = wx.StaticText( self,-1,"" ) |
---|
1279 | self.text2 = wx.StaticText( self,-1,"P(Q)*S(Q)" ) |
---|
1280 | |
---|
1281 | |
---|
1282 | self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
1283 | if self.model!=None: |
---|
1284 | self.formfactorbox.SetValue(self.model.name) |
---|
1285 | |
---|
1286 | |
---|
1287 | self.structurebox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
1288 | wx.EVT_COMBOBOX(self.formfactorbox,-1, self._on_select_model) |
---|
1289 | wx.EVT_COMBOBOX(self.structurebox,-1, self._on_select_model) |
---|
1290 | |
---|
1291 | |
---|
1292 | ## fill combox box |
---|
1293 | if len(self.model_list_box)>0: |
---|
1294 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1295 | |
---|
1296 | if len(self.model_list_box)>0: |
---|
1297 | self._populate_box( self.structurebox, |
---|
1298 | self.model_list_box["Structure Factors"]) |
---|
1299 | self.structurebox.Insert("None", 0,None) |
---|
1300 | self.structurebox.SetSelection(0) |
---|
1301 | self.structurebox.Hide() |
---|
1302 | self.text2.Hide() |
---|
1303 | self.structurebox.Disable() |
---|
1304 | self.text2.Disable() |
---|
1305 | |
---|
1306 | if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: |
---|
1307 | self.structurebox.Show() |
---|
1308 | self.text2.Show() |
---|
1309 | self.structurebox.Enable() |
---|
1310 | self.text2.Enable() |
---|
1311 | |
---|
1312 | ## check model type to show sizer |
---|
1313 | if self.model !=None: |
---|
1314 | self._set_model_sizer_selection( self.model ) |
---|
1315 | |
---|
1316 | sizer_selection.Add(self.text1) |
---|
1317 | sizer_selection.Add((5,5)) |
---|
1318 | sizer_selection.Add(self.formfactorbox) |
---|
1319 | sizer_selection.Add((5,5)) |
---|
1320 | sizer_selection.Add(self.text2) |
---|
1321 | sizer_selection.Add((5,5)) |
---|
1322 | sizer_selection.Add(self.structurebox) |
---|
1323 | sizer_selection.Add((5,5)) |
---|
1324 | |
---|
1325 | boxsizer1.Add( sizer_radiobutton ) |
---|
1326 | boxsizer1.Add( (20,20)) |
---|
1327 | boxsizer1.Add( sizer_selection ) |
---|
1328 | if object !=None: |
---|
1329 | boxsizer1.Add( (-72,-72)) |
---|
1330 | boxsizer1.Add( object, 0, wx.ALIGN_RIGHT| wx.RIGHT, 35) |
---|
1331 | boxsizer1.Add( (60,60)) |
---|
1332 | #-------------------------------------------------------- |
---|
1333 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1334 | sizer.Layout() |
---|
1335 | self.SetScrollbars(20,20,25,65) |
---|
1336 | |
---|
1337 | |
---|
1338 | def _show_combox(self, event): |
---|
1339 | """ |
---|
1340 | Show combox box associate with type of model selected |
---|
1341 | """ |
---|
1342 | ## Don't want to populate combo box again if the event comes from check box |
---|
1343 | if self.shape_rbutton.GetValue()and\ |
---|
1344 | event.GetEventObject()==self.shape_rbutton: |
---|
1345 | ##fill the combobox with form factor list |
---|
1346 | self.structurebox.SetSelection(0) |
---|
1347 | self.structurebox.Disable() |
---|
1348 | self.formfactorbox.Clear() |
---|
1349 | self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) |
---|
1350 | |
---|
1351 | if self.shape_indep_rbutton.GetValue()and\ |
---|
1352 | event.GetEventObject()==self.shape_indep_rbutton: |
---|
1353 | ##fill the combobox with shape independent factor list |
---|
1354 | self.structurebox.SetSelection(0) |
---|
1355 | self.structurebox.Disable() |
---|
1356 | self.formfactorbox.Clear() |
---|
1357 | self._populate_box( self.formfactorbox, |
---|
1358 | self.model_list_box["Shape-Independent"]) |
---|
1359 | |
---|
1360 | if self.struct_rbutton.GetValue() and\ |
---|
1361 | event.GetEventObject()==self.struct_rbutton: |
---|
1362 | ##fill the combobox with structure factor list |
---|
1363 | self.structurebox.SetSelection(0) |
---|
1364 | self.structurebox.Disable() |
---|
1365 | self.formfactorbox.Clear() |
---|
1366 | self._populate_box( self.formfactorbox, |
---|
1367 | self.model_list_box["Structure Factors"]) |
---|
1368 | |
---|
1369 | if self.plugin_rbutton.GetValue()and\ |
---|
1370 | event.GetEventObject()==self.plugin_rbutton: |
---|
1371 | |
---|
1372 | ##fill the combobox with form factor list |
---|
1373 | self.structurebox.Disable() |
---|
1374 | self.formfactorbox.Clear() |
---|
1375 | self._populate_box( self.formfactorbox, |
---|
1376 | self.model_list_box["Customized Models"]) |
---|
1377 | |
---|
1378 | self._on_select_model(event=None) |
---|
1379 | self._save_typeOfmodel() |
---|
1380 | self.sizer4_4.Layout() |
---|
1381 | self.sizer4.Layout() |
---|
1382 | self.Layout() |
---|
1383 | self.Refresh() |
---|
1384 | self.SetScrollbars(20,20,25,65) |
---|
1385 | |
---|
1386 | def _populate_box(self, combobox, list): |
---|
1387 | """ |
---|
1388 | fill combox box with dict item |
---|
1389 | @param list: contains item to fill the combox |
---|
1390 | item must model class |
---|
1391 | """ |
---|
1392 | for models in list: |
---|
1393 | model= models() |
---|
1394 | name = model.__class__.__name__ |
---|
1395 | if models.__name__!="NoStructure": |
---|
1396 | if hasattr(model, "name"): |
---|
1397 | name = model.name |
---|
1398 | combobox.Append(name,models) |
---|
1399 | |
---|
1400 | return 0 |
---|
1401 | |
---|
1402 | def _onparamEnter(self,event): |
---|
1403 | """ |
---|
1404 | when enter value on panel redraw model according to changed |
---|
1405 | """ |
---|
1406 | tcrtl= event.GetEventObject() |
---|
1407 | |
---|
1408 | #Clear msg if previously shown. |
---|
1409 | msg= "" |
---|
1410 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1411 | |
---|
1412 | ## save current state |
---|
1413 | self.save_current_state() |
---|
1414 | if event !=None: |
---|
1415 | #self._undo.Enable(True) |
---|
1416 | event = PageInfoEvent(page = self) |
---|
1417 | wx.PostEvent(self.parent, event) |
---|
1418 | |
---|
1419 | if check_float(tcrtl): |
---|
1420 | |
---|
1421 | self._onparamEnter_helper() |
---|
1422 | #event.Skip() |
---|
1423 | else: |
---|
1424 | msg= "Cannot Plot :Must enter a number!!! " |
---|
1425 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1426 | #event.Skip() |
---|
1427 | return |
---|
1428 | |
---|
1429 | def _onQrangeEnter(self, event): |
---|
1430 | """ |
---|
1431 | Check validity of value enter in the Q range field |
---|
1432 | """ |
---|
1433 | |
---|
1434 | tcrtl= event.GetEventObject() |
---|
1435 | #Clear msg if previously shown. |
---|
1436 | msg= "" |
---|
1437 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1438 | # Flag to register when a parameter has changed. |
---|
1439 | is_modified = False |
---|
1440 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
1441 | try: |
---|
1442 | value = float(tcrtl.GetValue()) |
---|
1443 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
1444 | |
---|
1445 | # If qmin and qmax have been modified, update qmin and qmax |
---|
1446 | if self._validate_qrange( self.qmin, self.qmax): |
---|
1447 | tempmin = float(self.qmin.GetValue()) |
---|
1448 | if tempmin != self.qmin_x: |
---|
1449 | self.qmin_x = tempmin |
---|
1450 | tempmax = float(self.qmax.GetValue()) |
---|
1451 | if tempmax != self.qmax_x: |
---|
1452 | self.qmax_x = tempmax |
---|
1453 | else: |
---|
1454 | tcrtl.SetBackgroundColour("pink") |
---|
1455 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
1456 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1457 | return |
---|
1458 | |
---|
1459 | except: |
---|
1460 | tcrtl.SetBackgroundColour("pink") |
---|
1461 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
1462 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1463 | return |
---|
1464 | #Check if # of points for theory model are valid(>0). |
---|
1465 | if self.npts != None: |
---|
1466 | if check_float(self.npts): |
---|
1467 | temp_npts = float(self.npts.GetValue()) |
---|
1468 | if temp_npts != self.num_points: |
---|
1469 | self.num_points = temp_npts |
---|
1470 | is_modified = True |
---|
1471 | else: |
---|
1472 | msg= "Cannot Plot :No npts in that Qrange!!! " |
---|
1473 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1474 | |
---|
1475 | else: |
---|
1476 | tcrtl.SetBackgroundColour("pink") |
---|
1477 | msg= "Model Error:wrong value entered!!!" |
---|
1478 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1479 | |
---|
1480 | #self._undo.Enable(True) |
---|
1481 | self.save_current_state() |
---|
1482 | event = PageInfoEvent(page = self) |
---|
1483 | wx.PostEvent(self.parent, event) |
---|
1484 | self.state_change= False |
---|
1485 | #Draw the model for a different range |
---|
1486 | self._draw_model() |
---|
1487 | |
---|
1488 | def _on_select_model_helper(self): |
---|
1489 | """ |
---|
1490 | call back for model selection |
---|
1491 | """ |
---|
1492 | ## reset dictionary containing reference to dispersion |
---|
1493 | self._disp_obj_dict = {} |
---|
1494 | self.disp_cb_dict ={} |
---|
1495 | |
---|
1496 | f_id = self.formfactorbox.GetCurrentSelection() |
---|
1497 | #For MAC |
---|
1498 | form_factor = None |
---|
1499 | if f_id >= 0: |
---|
1500 | form_factor = self.formfactorbox.GetClientData( f_id ) |
---|
1501 | |
---|
1502 | if not form_factor in self.model_list_box["multiplication"]: |
---|
1503 | self.structurebox.Hide() |
---|
1504 | self.text2.Hide() |
---|
1505 | self.structurebox.Disable() |
---|
1506 | self.structurebox.SetSelection(0) |
---|
1507 | self.text2.Disable() |
---|
1508 | else: |
---|
1509 | self.structurebox.Show() |
---|
1510 | self.text2.Show() |
---|
1511 | self.structurebox.Enable() |
---|
1512 | self.text2.Enable() |
---|
1513 | |
---|
1514 | s_id = self.structurebox.GetCurrentSelection() |
---|
1515 | struct_factor = self.structurebox.GetClientData( s_id ) |
---|
1516 | |
---|
1517 | if struct_factor !=None: |
---|
1518 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
1519 | self.model= MultiplicationModel(form_factor(),struct_factor()) |
---|
1520 | |
---|
1521 | else: |
---|
1522 | if form_factor != None: |
---|
1523 | self.model= form_factor() |
---|
1524 | else: |
---|
1525 | self.model = None |
---|
1526 | return self.model |
---|
1527 | |
---|
1528 | ## post state to fit panel |
---|
1529 | self.state.parameters =[] |
---|
1530 | self.state.model =self.model |
---|
1531 | self.disp_list =self.model.getDispParamList() |
---|
1532 | self.state.disp_list = self.disp_list |
---|
1533 | self.Layout() |
---|
1534 | |
---|
1535 | def _validate_qrange(self, qmin_ctrl, qmax_ctrl): |
---|
1536 | """ |
---|
1537 | Verify that the Q range controls have valid values |
---|
1538 | and that Qmin < Qmax. |
---|
1539 | |
---|
1540 | @param qmin_ctrl: text control for Qmin |
---|
1541 | @param qmax_ctrl: text control for Qmax |
---|
1542 | @return: True is the Q range is value, False otherwise |
---|
1543 | """ |
---|
1544 | qmin_validity = check_float(qmin_ctrl) |
---|
1545 | qmax_validity = check_float(qmax_ctrl) |
---|
1546 | if not (qmin_validity and qmax_validity): |
---|
1547 | return False |
---|
1548 | else: |
---|
1549 | qmin = float(qmin_ctrl.GetValue()) |
---|
1550 | qmax = float(qmax_ctrl.GetValue()) |
---|
1551 | if qmin < qmax: |
---|
1552 | #Make sure to set both colours white. |
---|
1553 | qmin_ctrl.SetBackgroundColour(wx.WHITE) |
---|
1554 | qmin_ctrl.Refresh() |
---|
1555 | qmax_ctrl.SetBackgroundColour(wx.WHITE) |
---|
1556 | qmax_ctrl.Refresh() |
---|
1557 | else: |
---|
1558 | qmin_ctrl.SetBackgroundColour("pink") |
---|
1559 | qmin_ctrl.Refresh() |
---|
1560 | qmax_ctrl.SetBackgroundColour("pink") |
---|
1561 | qmax_ctrl.Refresh() |
---|
1562 | msg= "Invalid Q range: Q min must be smaller than Q max" |
---|
1563 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg)) |
---|
1564 | return False |
---|
1565 | return True |
---|
1566 | |
---|
1567 | def _check_value_enter(self, list, modified): |
---|
1568 | """ |
---|
1569 | @param list: model parameter and panel info |
---|
1570 | each item of the list should be as follow: |
---|
1571 | item=[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
1572 | """ |
---|
1573 | is_modified = modified |
---|
1574 | if len(list)==0: |
---|
1575 | return is_modified |
---|
1576 | for item in list: |
---|
1577 | #skip angle parameters for 1D |
---|
1578 | if self.data.__class__.__name__ !="Data2D": |
---|
1579 | if item in self.orientation_params: |
---|
1580 | continue |
---|
1581 | #try: |
---|
1582 | name = str(item[1]) |
---|
1583 | |
---|
1584 | if string.find(name,".npts") ==-1 and string.find(name,".nsigmas")==-1: |
---|
1585 | ## check model parameters range |
---|
1586 | param_min= None |
---|
1587 | param_max= None |
---|
1588 | |
---|
1589 | ## check minimun value |
---|
1590 | if item[5]!= None and item[5]!= "": |
---|
1591 | if item[5].GetValue().lstrip().rstrip()!="": |
---|
1592 | try: |
---|
1593 | |
---|
1594 | param_min = float(item[5].GetValue()) |
---|
1595 | if not self._validate_qrange(item[5],item[2]): |
---|
1596 | if numpy.isfinite(param_min): |
---|
1597 | item[2].SetValue(format_number(param_min)) |
---|
1598 | |
---|
1599 | item[5].SetBackgroundColour(wx.WHITE) |
---|
1600 | item[2].SetBackgroundColour(wx.WHITE) |
---|
1601 | |
---|
1602 | except: |
---|
1603 | msg = "Wrong Fit parameter range entered " |
---|
1604 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg)) |
---|
1605 | raise ValueError, msg |
---|
1606 | is_modified = True |
---|
1607 | ## check maximum value |
---|
1608 | if item[6]!= None and item[6]!= "": |
---|
1609 | if item[6].GetValue().lstrip().rstrip()!="": |
---|
1610 | try: |
---|
1611 | param_max = float(item[6].GetValue()) |
---|
1612 | if not self._validate_qrange(item[2],item[6]): |
---|
1613 | if numpy.isfinite(param_max): |
---|
1614 | item[2].SetValue(format_number(param_max)) |
---|
1615 | |
---|
1616 | item[6].SetBackgroundColour(wx.WHITE) |
---|
1617 | item[2].SetBackgroundColour(wx.WHITE) |
---|
1618 | except: |
---|
1619 | msg = "Wrong Fit parameter range entered " |
---|
1620 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg)) |
---|
1621 | raise ValueError, msg |
---|
1622 | is_modified = True |
---|
1623 | |
---|
1624 | |
---|
1625 | if param_min != None and param_max !=None: |
---|
1626 | if not self._validate_qrange(item[5], item[6]): |
---|
1627 | msg= "Wrong Fit range entered for parameter " |
---|
1628 | msg+= "name %s of model %s "%(name, self.model.name) |
---|
1629 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg)) |
---|
1630 | |
---|
1631 | if name in self.model.details.keys(): |
---|
1632 | self.model.details[name][1:3]= param_min,param_max |
---|
1633 | is_modified = True |
---|
1634 | |
---|
1635 | else: |
---|
1636 | self.model.details [name] = ["",param_min,param_max] |
---|
1637 | is_modified = True |
---|
1638 | try: |
---|
1639 | value= float(item[2].GetValue()) |
---|
1640 | |
---|
1641 | # If the value of the parameter has changed, |
---|
1642 | # +update the model and set the is_modified flag |
---|
1643 | if value != self.model.getParam(name) and numpy.isfinite(value): |
---|
1644 | self.model.setParam(name,value) |
---|
1645 | is_modified = True |
---|
1646 | except: |
---|
1647 | msg = "Wrong Fit parameter value entered " |
---|
1648 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg)) |
---|
1649 | |
---|
1650 | return is_modified |
---|
1651 | |
---|
1652 | |
---|
1653 | def _set_dipers_Param(self, event): |
---|
1654 | """ |
---|
1655 | respond to self.enable_disp and self.disable_disp radio box. |
---|
1656 | The dispersity object is reset inside the model into Gaussian. |
---|
1657 | When the user select yes , this method display a combo box for more selection |
---|
1658 | when the user selects No,the combo box disappears. |
---|
1659 | Redraw the model with the default dispersity (Gaussian) |
---|
1660 | """ |
---|
1661 | |
---|
1662 | self._reset_dispersity() |
---|
1663 | |
---|
1664 | if self.model ==None: |
---|
1665 | self.model_disp.Hide() |
---|
1666 | self.disp_box.Hide() |
---|
1667 | self.sizer4_4.Clear(True) |
---|
1668 | return |
---|
1669 | |
---|
1670 | if self.enable_disp.GetValue(): |
---|
1671 | self.model_disp.Show(True) |
---|
1672 | self.disp_box.Show(True) |
---|
1673 | ## layout for model containing no dispersity parameters |
---|
1674 | |
---|
1675 | self.disp_list= self.model.getDispParamList() |
---|
1676 | |
---|
1677 | if len(self.disp_list)==0 and len(self.disp_cb_dict)==0: |
---|
1678 | self._layout_sizer_noDipers() |
---|
1679 | else: |
---|
1680 | ## set gaussian sizer |
---|
1681 | self._on_select_Disp(event=None) |
---|
1682 | else: |
---|
1683 | self.model_disp.Hide() |
---|
1684 | self.disp_box.Hide() |
---|
1685 | self.disp_box.SetSelection(0) |
---|
1686 | self.sizer4_4.Clear(True) |
---|
1687 | |
---|
1688 | ## post state to fit panel |
---|
1689 | self.save_current_state() |
---|
1690 | if event !=None: |
---|
1691 | #self._undo.Enable(True) |
---|
1692 | event = PageInfoEvent(page = self) |
---|
1693 | wx.PostEvent(self.parent, event) |
---|
1694 | #draw the model with the current dispersity |
---|
1695 | self._draw_model() |
---|
1696 | self.sizer4_4.Layout() |
---|
1697 | self.sizer5.Layout() |
---|
1698 | self.Layout() |
---|
1699 | self.Refresh() |
---|
1700 | |
---|
1701 | |
---|
1702 | def _layout_sizer_noDipers(self): |
---|
1703 | """ |
---|
1704 | Draw a sizer with no dispersity info |
---|
1705 | """ |
---|
1706 | ix=0 |
---|
1707 | iy=1 |
---|
1708 | self.fittable_param=[] |
---|
1709 | self.fixed_param=[] |
---|
1710 | self.orientation_params_disp=[] |
---|
1711 | |
---|
1712 | self.model_disp.Hide() |
---|
1713 | self.disp_box.Hide() |
---|
1714 | self.sizer4_4.Clear(True) |
---|
1715 | model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') |
---|
1716 | self.sizer4_4.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1717 | self.sizer4_4.Layout() |
---|
1718 | self.sizer4.Layout() |
---|
1719 | self.SetScrollbars(20,20,25,65) |
---|
1720 | |
---|
1721 | |
---|
1722 | def _reset_dispersity(self): |
---|
1723 | """ |
---|
1724 | put gaussian dispersity into current model |
---|
1725 | """ |
---|
1726 | if len(self.param_toFit)>0: |
---|
1727 | for item in self.fittable_param: |
---|
1728 | if item in self.param_toFit: |
---|
1729 | self.param_toFit.remove(item) |
---|
1730 | |
---|
1731 | for item in self.orientation_params_disp: |
---|
1732 | if item in self.param_toFit: |
---|
1733 | self.param_toFit.remove(item) |
---|
1734 | |
---|
1735 | self.fittable_param=[] |
---|
1736 | self.fixed_param=[] |
---|
1737 | self.orientation_params_disp=[] |
---|
1738 | self.values=[] |
---|
1739 | self.weights=[] |
---|
1740 | |
---|
1741 | from sans.models.dispersion_models import GaussianDispersion, ArrayDispersion |
---|
1742 | if len(self.disp_cb_dict)==0: |
---|
1743 | self.save_current_state() |
---|
1744 | self.sizer4_4.Clear(True) |
---|
1745 | self.Layout() |
---|
1746 | |
---|
1747 | return |
---|
1748 | if (len(self.disp_cb_dict)>0) : |
---|
1749 | for p in self.disp_cb_dict: |
---|
1750 | # The parameter was un-selected. Go back to Gaussian model (with 0 pts) |
---|
1751 | disp_model = GaussianDispersion() |
---|
1752 | |
---|
1753 | self._disp_obj_dict[p] = disp_model |
---|
1754 | # Set the new model as the dispersion object for the selected parameter |
---|
1755 | try: |
---|
1756 | self.model.set_dispersion(p, disp_model) |
---|
1757 | except: |
---|
1758 | |
---|
1759 | pass |
---|
1760 | |
---|
1761 | ## save state into |
---|
1762 | self.save_current_state() |
---|
1763 | self.Layout() |
---|
1764 | self.Refresh() |
---|
1765 | |
---|
1766 | |
---|
1767 | def _on_select_Disp(self,event): |
---|
1768 | """ |
---|
1769 | allow selecting different dispersion |
---|
1770 | self.disp_list should change type later .now only gaussian |
---|
1771 | """ |
---|
1772 | n = self.disp_box.GetCurrentSelection() |
---|
1773 | name = self.disp_box.GetValue() |
---|
1774 | dispersity= self.disp_box.GetClientData(n) |
---|
1775 | self.disp_name = name |
---|
1776 | |
---|
1777 | if name.lower() == "array": |
---|
1778 | self._set_sizer_arraydispersion() |
---|
1779 | else: |
---|
1780 | self._set_sizer_dispersion(dispersity= dispersity) |
---|
1781 | |
---|
1782 | self.state.disp_box= n |
---|
1783 | ## Redraw the model |
---|
1784 | self._draw_model() |
---|
1785 | #self._undo.Enable(True) |
---|
1786 | event = PageInfoEvent(page = self) |
---|
1787 | wx.PostEvent(self.parent, event) |
---|
1788 | |
---|
1789 | self.sizer4_4.Layout() |
---|
1790 | self.sizer4.Layout() |
---|
1791 | self.SetScrollbars(20,20,25,65) |
---|
1792 | |
---|
1793 | def _set_sizer_arraydispersion(self): |
---|
1794 | """ |
---|
1795 | draw sizer with array dispersity parameters |
---|
1796 | """ |
---|
1797 | |
---|
1798 | if len(self.param_toFit)>0: |
---|
1799 | for item in self.fittable_param: |
---|
1800 | if item in self.param_toFit: |
---|
1801 | self.param_toFit.remove(item) |
---|
1802 | for item in self.orientation_params_disp: |
---|
1803 | if item in self.param_toFit: |
---|
1804 | self.param_toFit.remove(item) |
---|
1805 | for item in self.model.details.keys(): |
---|
1806 | if item in self.model.fixed: |
---|
1807 | del self.model.details [item] |
---|
1808 | |
---|
1809 | self.fittable_param=[] |
---|
1810 | self.fixed_param=[] |
---|
1811 | self.orientation_params_disp=[] |
---|
1812 | self.sizer4_4.Clear(True) |
---|
1813 | self._reset_dispersity() |
---|
1814 | ix=0 |
---|
1815 | iy=1 |
---|
1816 | disp1 = wx.StaticText(self, -1, 'Array Dispersion') |
---|
1817 | self.sizer4_4.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1818 | |
---|
1819 | # Look for model parameters to which we can apply an ArrayDispersion model |
---|
1820 | # Add a check box for each parameter. |
---|
1821 | self.disp_cb_dict = {} |
---|
1822 | ix+=1 |
---|
1823 | self.noDisper_rbox = wx.RadioButton(self, -1,"None", (10, 10),style= wx.RB_GROUP) |
---|
1824 | self.Bind(wx.EVT_RADIOBUTTON,self.select_disp_angle , id=self.noDisper_rbox.GetId()) |
---|
1825 | #MAC needs SetValue |
---|
1826 | self.noDisper_rbox.SetValue(True) |
---|
1827 | self.sizer4_4.Add(self.noDisper_rbox, (iy, ix), |
---|
1828 | (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1829 | |
---|
1830 | for p in self.model.dispersion.keys(): |
---|
1831 | if not p in self.model.orientation_params: |
---|
1832 | ix+=1 |
---|
1833 | self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) |
---|
1834 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
1835 | self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) |
---|
1836 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1837 | |
---|
1838 | for p in self.model.dispersion.keys(): |
---|
1839 | if p in self.model.orientation_params: |
---|
1840 | ix+=1 |
---|
1841 | self.disp_cb_dict[p] = wx.RadioButton(self, -1, p, (10, 10)) |
---|
1842 | self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() |
---|
1843 | if not (self.enable2D or self.data.__class__.__name__ =="Data2D"): |
---|
1844 | self.disp_cb_dict[p].Hide() |
---|
1845 | else: |
---|
1846 | self.disp_cb_dict[p].Show(True) |
---|
1847 | self.Bind(wx.EVT_RADIOBUTTON, self.select_disp_angle, id=self.disp_cb_dict[p].GetId()) |
---|
1848 | self.sizer4_4.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1849 | |
---|
1850 | |
---|
1851 | ix =0 |
---|
1852 | iy +=1 |
---|
1853 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1854 | self.Layout() |
---|
1855 | |
---|
1856 | self.state.orientation_params =[] |
---|
1857 | self.state.orientation_params_disp =[] |
---|
1858 | self.state.parameters =[] |
---|
1859 | self.state.fittable_param =[] |
---|
1860 | self.state.fixed_param =[] |
---|
1861 | |
---|
1862 | ## save checkbutton state and txtcrtl values |
---|
1863 | |
---|
1864 | self._copy_parameters_state(self.orientation_params, |
---|
1865 | self.state.orientation_params) |
---|
1866 | |
---|
1867 | self._copy_parameters_state(self.orientation_params_disp, |
---|
1868 | self.state.orientation_params_disp) |
---|
1869 | |
---|
1870 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
1871 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
1872 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
1873 | |
---|
1874 | |
---|
1875 | ## post state to fit panel |
---|
1876 | event = PageInfoEvent(page = self) |
---|
1877 | wx.PostEvent(self.parent, event) |
---|
1878 | |
---|
1879 | |
---|
1880 | |
---|
1881 | |
---|
1882 | |
---|
1883 | def _set_range_sizer(self, title, box_sizer=None, object1=None,object=None): |
---|
1884 | """ |
---|
1885 | Fill the Q range sizer |
---|
1886 | """ |
---|
1887 | self.sizer5.Clear(True) |
---|
1888 | #-------------------------------------------------------------- |
---|
1889 | if box_sizer == None: |
---|
1890 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
1891 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1892 | else: |
---|
1893 | #for MAC |
---|
1894 | boxsizer1 = box_sizer |
---|
1895 | |
---|
1896 | self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, |
---|
1897 | kill_focus_callback = self._onQrangeEnter, |
---|
1898 | text_enter_callback = self._onQrangeEnter) |
---|
1899 | self.qmin.SetValue(str(self.qmin_x)) |
---|
1900 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
1901 | |
---|
1902 | self.qmax = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, |
---|
1903 | kill_focus_callback = self._onQrangeEnter, |
---|
1904 | text_enter_callback = self._onQrangeEnter) |
---|
1905 | self.qmax.SetValue(str(self.qmax_x)) |
---|
1906 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
1907 | |
---|
1908 | id = wx.NewId() |
---|
1909 | self.reset_qrange =wx.Button(self,id,'Reset',size=(70,23)) |
---|
1910 | |
---|
1911 | self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked,id=id) |
---|
1912 | self.reset_qrange.SetToolTipString("Reset Q range to the default values") |
---|
1913 | |
---|
1914 | sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) |
---|
1915 | sizer= wx.GridSizer(3, 3,2, 5) |
---|
1916 | |
---|
1917 | sizer.Add(wx.StaticText(self, -1, ' Q range')) |
---|
1918 | sizer.Add(wx.StaticText(self, -1, ' Min')) |
---|
1919 | sizer.Add(wx.StaticText(self, -1, ' Max')) |
---|
1920 | sizer.Add(self.reset_qrange) |
---|
1921 | |
---|
1922 | sizer.Add(self.qmin) |
---|
1923 | sizer.Add(self.qmax) |
---|
1924 | sizer_horizontal.Add(sizer) |
---|
1925 | if object!=None: |
---|
1926 | sizer_horizontal.Add(object) |
---|
1927 | |
---|
1928 | if object1!=None: |
---|
1929 | boxsizer1.Add(object1) |
---|
1930 | boxsizer1.Add((10,10)) |
---|
1931 | boxsizer1.Add(sizer_horizontal) |
---|
1932 | ## save state |
---|
1933 | self.save_current_state() |
---|
1934 | #---------------------------------------------------------------- |
---|
1935 | self.sizer5.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1936 | self.sizer5.Layout() |
---|
1937 | |
---|
1938 | |
---|
1939 | def _fill_save_sizer(self): |
---|
1940 | """ |
---|
1941 | Draw the layout for saving option |
---|
1942 | """ |
---|
1943 | # Skipping save state functionality for release 0.9.0 |
---|
1944 | return |
---|
1945 | |
---|
1946 | self.sizer6.Clear(True) |
---|
1947 | box_description= wx.StaticBox(self, -1,"Save Model") |
---|
1948 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1949 | sizer_save = wx.BoxSizer(wx.HORIZONTAL) |
---|
1950 | |
---|
1951 | self.btSave_title = wx.StaticText(self, -1, 'Save the current Model') |
---|
1952 | self.btSave = wx.Button(self,wx.NewId(),'Save') |
---|
1953 | self.btSave.Bind(wx.EVT_BUTTON, self.onSave,id= self.btSave.GetId()) |
---|
1954 | self.btSave.SetToolTipString("Save the current Model") |
---|
1955 | |
---|
1956 | sizer_save.Add(self.btSave_title) |
---|
1957 | sizer_save.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,45) |
---|
1958 | |
---|
1959 | sizer_save.Add(self.btSave) |
---|
1960 | |
---|
1961 | boxsizer1.Add(sizer_save) |
---|
1962 | self.sizer6.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1963 | self.sizer6.Layout() |
---|
1964 | self.SetScrollbars(20,20,25,65) |
---|
1965 | |
---|
1966 | def _lay_out(self): |
---|
1967 | """ |
---|
1968 | returns self.Layout |
---|
1969 | Note: Mac seems to like this better when self.Layout is called after fitting. |
---|
1970 | """ |
---|
1971 | self._sleep4sec() |
---|
1972 | self.Layout() |
---|
1973 | #self._sleep4sec() |
---|
1974 | return |
---|
1975 | |
---|
1976 | def _sleep4sec(self): |
---|
1977 | """ |
---|
1978 | sleep for 1 sec only applied on Mac |
---|
1979 | Note: This 1sec helps for Mac not to crash on self.:ayout after self._draw_model |
---|
1980 | """ |
---|
1981 | if ON_MAC == True: |
---|
1982 | time.sleep(1) |
---|
1983 | |
---|
1984 | def on_reset_clicked(self,event): |
---|
1985 | """ |
---|
1986 | #On 'Reset' button for Q range clicked |
---|
1987 | """ |
---|
1988 | ##For 3 different cases: Data2D, Data1D, and theory |
---|
1989 | if self.data.__class__.__name__ == "Data2D": |
---|
1990 | data_min= 0 |
---|
1991 | x= max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
1992 | y= max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
1993 | self.qmin_x = data_min |
---|
1994 | self.qmax_x = math.sqrt(x*x + y*y) |
---|
1995 | elif self.data.__class__.__name__ == "Data1D": |
---|
1996 | self.qmin_x = min(self.data.x) |
---|
1997 | self.qmax_x = max(self.data.x) |
---|
1998 | else: |
---|
1999 | self.qmin_x = _QMIN_DEFAULT |
---|
2000 | self.qmax_x = _QMAX_DEFAULT |
---|
2001 | self.num_points = _NPTS_DEFAULT |
---|
2002 | self.state.npts = self.num_points |
---|
2003 | |
---|
2004 | |
---|
2005 | self.state.qmin = self.qmin_x |
---|
2006 | self.state.qmax = self.qmax_x |
---|
2007 | |
---|
2008 | #reset the q range values |
---|
2009 | self._reset_plotting_range(self.state) |
---|
2010 | #Re draw plot |
---|
2011 | self._draw_model() |
---|
2012 | |
---|
2013 | def on_model_help_clicked(self,event): |
---|
2014 | """ |
---|
2015 | #On 'More details' button |
---|
2016 | """ |
---|
2017 | from help_panel import HelpWindow |
---|
2018 | |
---|
2019 | if self.model == None: |
---|
2020 | name = 'FuncHelp' |
---|
2021 | else: |
---|
2022 | name = self.model.origin_name |
---|
2023 | |
---|
2024 | frame = HelpWindow(None, -1, pageToOpen="doc/model_functions.html") |
---|
2025 | frame.Show(True) |
---|
2026 | if frame.rhelp.HasAnchor(name): |
---|
2027 | frame.rhelp.ScrollToAnchor(name) |
---|
2028 | else: |
---|
2029 | msg= "Model does not contains an available description " |
---|
2030 | msg +="Please try searching in the Help window" |
---|
2031 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
2032 | |
---|