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