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