Changeset a074145 in sasview for sansview/perspectives
- Timestamp:
- Apr 9, 2009 5:06:08 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 2d5f7a1
- Parents:
- 800fc80
- Location:
- sansview/perspectives/fitting
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
r7c845cb ra074145 3 3 import wx 4 4 import numpy 5 import time 5 6 6 7 from sans.guiframe.utils import format_number … … 67 68 68 69 self.state= PageState(parent= self.parent,model=self.model, data=self.data) 70 71 ## retrieve saved state 72 self.number_saved_state= 0 73 ## dictionary of saved state 74 self.saved_states={} 75 self.slicerpop = wx.Menu() 76 self.slicerpop.SetTitle("Model Saved States") 77 ## save initial state on context menu 78 self.onSave(event=None) 79 self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 80 69 81 ## create the basic structure of the panel with empty sizer 70 82 self.define_page_structure() … … 72 84 self.set_dispers_sizer() 73 85 self._fill_save_sizer() 74 75 86 ## layout 76 87 self.set_layout() 77 88 89 90 def onContextMenu(self, event): 91 """ 92 Retrieve the state selected state 93 """ 94 pos = event.GetPosition() 95 pos = self.ScreenToClient(pos) 96 self.PopupMenu(self.slicerpop, pos) 97 98 78 99 79 100 def define_page_structure(self): … … 106 127 self.vbox.Add(self.sizer6) 107 128 129 108 130 def set_layout(self): 109 131 """ … … 117 139 self.Centre() 118 140 141 119 142 def set_scroll(self): 120 143 self.SetScrollbars(20,20,200,100) 121 144 self.Layout() 122 145 self.SetAutoLayout(True) 146 123 147 124 148 def set_owner(self,owner): … … 166 190 sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) 167 191 sizer_dispersion.Add((20,20)) 168 sizer_dispersion.Add(wx.StaticText(self,-1,'Polydispersity: ')) 192 name="Polydispersity and \nOrientation average " 193 sizer_dispersion.Add(wx.StaticText(self,-1,name)) 169 194 sizer_dispersion.Add(self.enable_disp ) 170 195 sizer_dispersion.Add((20,20)) … … 273 298 return 274 299 300 301 def onResetModel(self, event): 302 """ 303 Reset model state 304 """ 305 ## post help message for the selected model 306 msg = self.slicerpop.GetHelpString(event.GetId()) 307 msg +=" reloaded" 308 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 309 310 name= self.slicerpop.GetLabel(event.GetId()) 311 if name in self.saved_states.keys(): 312 previous_state = self.saved_states[name] 313 self.reset_page(previous_state) 314 315 275 316 def onSave(self, event): 276 317 """ 277 318 save history of the data and model 278 319 """ 279 self.state.model= self.model 280 self.state.data = self.data 281 import os 282 283 284 path = None 285 dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.txt", wx.SAVE) 286 if dlg.ShowModal() == wx.ID_OK: 287 path = dlg.GetPath() 288 mypath = os.path.basename(path) 289 290 dlg.Destroy() 291 292 if not path == None: 293 out = open(path, 'w') 294 has_data = self.data !=None 295 has_model = self.model!=None 296 import time 297 year, month, day,hour,minute,second,tda,ty,tm_isdst= time.gmtime() 298 import os.path 299 out.write("Title: State for %s\n"%os.path.basename(path)) 300 out.write("Date: %g\%g\%g \n"%(year, month, day)) 301 out.write("GMT Time: %g:%g:%g \n\n"%(hour,minute, second)) 302 # Sanity check 303 if has_data: 304 out.write("Fit Data name: %s\n\n"%self.data.name) 305 306 if has_model: 307 out.write("Model name: %s\n"%self.model.name) 308 if len(self.parameters)>0: 309 out.write("Parameters Info:\n") 310 msg= "Name\t\tValues\t\t+\-\tErrors\t\tMin\t\tMax\t\tUnits\t\tstate\n" 311 out.write(msg) 312 ##self.parameters= 313 ##[cb state, name, value, "+/-", error of fit, min, max , units] 314 for item in self.parameters: 315 if item[1]!=None: 316 name= item[1] 317 else: 318 name="" 319 if item[2]!=None: 320 value= str(item[2].GetValue().rstrip().lstrip()) 321 else: 322 value="" 323 if item[3]!=None: 324 sign= str(item[3].GetLabelText().rstrip().lstrip()) 325 else: 326 sign="" 327 if item[4]!=None: 328 error= str(item[4].GetValue().rstrip().lstrip()) 329 else: 330 error="" 331 if item[5]!=None: 332 min= str(item[5].GetValue().rstrip().lstrip()) 333 else: 334 min="" 335 if item[6]!=None: 336 max= str(item[6].GetValue().rstrip().lstrip()) 337 else: 338 max="" 339 if item[7]!=None: 340 unit= str(item[7].GetLabelText().rstrip().lstrip()) 341 else: 342 unit="" 343 if item[0]!=None: 344 if item[0].GetValue(): 345 state= "Fitted" 346 else: 347 state= "Not Fitted" 348 else: 349 state="Not Fitted" 350 351 msg= "%s\t\t%s\t\t%s\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n"\ 352 %(name,value,sign,error,min,max,unit,state) 353 out.write(msg) 354 355 356 out.close() 357 358 320 if self.model==None: 321 return 322 if hasattr(self,"enable_disp"): 323 self.state.enable_disp=self.enable_disp.GetValue() 324 if hasattr(self, "disp_box"): 325 self.state.disp_box=SetSelection(self.disp_box.GetSelection()) 326 327 self.state.model = self.model.clone() 328 new_state = self.state.clone() 329 330 ##Add model state on context menu 331 self.number_saved_state += 1 332 name= self.model.name+"[%g]"%self.number_saved_state 333 self.saved_states[name]= new_state 334 335 ## Add item in the context menu 336 year, month, day,hour,minute,second,tda,ty,tm_isdst= time.gmtime() 337 my_time= str(hour)+"hrs "+str(minute)+"min "+str(second)+"s" 338 date= str( month)+"|"+str(day)+"|"+str(year) 339 msg= "Model saved at %s on %s"%(my_time, date) 340 ## post help message for the selected model 341 msg +=" Saved! right click on this page to retrieve this model" 342 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 343 344 id = wx.NewId() 345 self.slicerpop.Append(id,name,str(msg)) 346 wx.EVT_MENU(self, id, self.onResetModel) 347 359 348 def onSetFocus(self, evt): 360 349 """ … … 461 450 wx.PostEvent(self.parent, event) 462 451 452 463 453 def reset_page_helper(self, state): 464 454 """ … … 485 475 ##plotting range restore 486 476 self._reset_plotting_range() 487 477 ## reset context menu items 478 self._reset_context_menu() 488 479 ## reset state of checkbox,textcrtl and parameters value 489 480 if hasattr(self, "cb1"): … … 496 487 self._draw_model() 497 488 489 490 491 498 492 499 493 def _selectDlg(self): … … 510 504 511 505 506 def _reset_context_menu(self): 507 """ 508 reset the context menu 509 """ 510 for name, state in self.state.saved_states.iteritems(): 511 self.number_saved_state += 1 512 ## Add item in the context menu 513 id = wx.NewId() 514 self.slicerpop.Append(id,name, 'Save model and state %g'%self.number_saved_state) 515 wx.EVT_MENU(self, id, self.onResetModel) 516 512 517 def _reset_plotting_range(self): 513 518 """ … … 542 547 """ 543 548 if self.model !=None: 544 549 ## save current state 550 self.save_current_state() 545 551 # Flag to register when a parameter has changed. 546 552 is_modified = False … … 569 575 self.num_points = float(self.npts.GetValue()) 570 576 is_modified = True 571 ## save current state 572 self.save_current_state() 577 573 578 574 579 ## if any value is modify draw model with new value … … 952 957 self.structurebox.SetSelection(0) 953 958 954 959 955 960 s_id = self.structurebox.GetCurrentSelection() 956 961 struct_factor = self.structurebox.GetClientData( s_id ) 957 962 958 963 if struct_factor !=None: 959 964 from sans.models.MultiplicationModel import MultiplicationModel … … 961 966 else: 962 967 self.model= form_factor() 963 968 964 969 ## post state to fit panel 965 970 self.save_current_state() -
sansview/perspectives/fitting/fitpage.py
r7c845cb ra074145 76 76 self.sizer3.Layout() 77 77 self.SetScrollbars(20,20,200,100) 78 79 80 def _on_display_description(self, event): 81 """ 82 Show or Hide description 83 @param event: wx.EVT_RADIOBUTTON 84 """ 85 self._on_display_description_helper() 86 87 88 89 def _on_display_description_helper(self): 90 """ 91 Show or Hide description 92 @param event: wx.EVT_RADIOBUTTON 93 """ 94 ## save state of radiobox 95 #self.page_info. save_radiobox_state( self.description_hide ) 96 #self.page_info. save_radiobox_state( self.description_show ) 97 ## Show description 98 if not self.description_show.GetValue(): 99 self.sizer_description.Clear(True) 100 101 else: 102 #model=self.page_info.model 103 104 description="" 105 if self.model!=None: 106 description = self.model.description 107 #description = self.page_info.model.description 108 self.description = wx.StaticText( self,-1,str(description) ) 109 self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) 110 111 self.Layout() 112 78 113 79 114 80 def _fill_range_sizer(self): … … 406 372 wx.PostEvent(self.event_owner, evt) 407 373 374 375 def _onparamEnter(self,event): 376 """ 377 when enter value on panel redraw model according to changed 378 """ 379 self._onparamEnter_helper() 380 self.compute_chisqr() 381 382 408 383 def reset_page(self, state): 409 384 """ … … 413 388 evt = ModelEventbox(model=self.model) 414 389 wx.PostEvent(self.event_owner, evt) 415 416 417 def _onparamEnter(self,event): 418 """ 419 when enter value on panel redraw model according to changed 420 """ 421 self._onparamEnter_helper() 422 self.compute_chisqr() 423 424 390 391 425 392 def get_range(self): 426 393 """ … … 662 629 663 630 664 def set_model_description(self,description,sizer):665 """666 fill a sizer with description667 @param description: of type string668 @param sizer: wx.BoxSizer()669 """670 671 sizer.Clear(True)672 box_description= wx.StaticBox(self, -1, 'Model Description')673 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)674 675 self.description = wx.StaticText( self,-1,str(description) )676 sizer_selection=wx.BoxSizer(wx.HORIZONTAL)677 678 679 self.description_show = wx.RadioButton(self, -1, 'Show', style=wx.RB_GROUP)680 self.description_hide = wx.RadioButton(self, -1, 'Hide')681 682 self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description,683 id=self.description_hide.GetId() )684 685 self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description,686 id=self.description_show.GetId() )687 688 self.model_description = wx.Button(self, -1, "More Details")689 690 691 #self.page_info.save_radiobox_state( self.description_hide )692 #self.page_info.save_radiobox_state( self.description_show )693 694 sizer_selection.Add( self.description_show )695 sizer_selection.Add( (20,20))696 sizer_selection.Add( self.description_hide )697 sizer_selection.Add( (20,20))698 sizer_selection.Add( self.model_description )699 700 701 self.sizer_description=wx.BoxSizer(wx.HORIZONTAL)702 self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 )703 704 boxsizer1.Add( sizer_selection)705 boxsizer1.Add( (20,20))706 boxsizer1.Add( self.sizer_description)707 708 709 sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)710 sizer.Layout()711 712 713 714 631 715 632 def set_model_param_sizer(self, model): -
sansview/perspectives/fitting/fitpanel.py
r7c845cb ra074145 134 134 if selected_page.window_name in self.list_fitpage_name: 135 135 self.list_fitpage_name.remove(selected_page.window_name) 136 137 138 139 136 140 137 141 138 def set_manager(self, manager): -
sansview/perspectives/fitting/modelpage.py
r7c845cb ra074145 34 34 description="" 35 35 if self.model!=None: 36 #description = self.page_info.model.description37 36 description = self.model.description 38 self.set_model_param_sizer(self.model) 37 38 self.select_model(self.model, self.model.name) 39 39 self.set_model_description(description,self.sizer2) 40 41 42 40 41 42 43 43 44 44 def _on_display_description(self, event): … … 56 56 @param event: wx.EVT_RADIOBUTTON 57 57 """ 58 ## save state of radiobox 59 #self.page_info. save_radiobox_state( self.description_hide ) 60 #self.page_info. save_radiobox_state( self.description_show ) 58 61 59 ## Show description 62 60 if not self.description_show.GetValue(): … … 64 62 65 63 else: 66 #model=self.page_info.model67 64 description="" 68 65 if self.model!=None: 69 #description = self.page_info.model.description70 66 description = self.model.description 67 71 68 self.description = wx.StaticText( self,-1,str(description) ) 72 69 self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) … … 293 290 self.model_description.Bind(wx.EVT_BUTTON,self.on_button_clicked) 294 291 self.model_description.SetToolTipString("Click Model Functions in HelpWindow...") 295 296 #self.page_info.save_radiobox_state( self.description_hide ) 297 #self.page_info.save_radiobox_state( self.description_show ) 298 292 299 293 sizer_selection.Add( self.description_show ) 300 294 sizer_selection.Add( (20,20)) -
sansview/perspectives/fitting/pagestate.py
rb787e68c ra074145 1 1 2 2 3 import wx4 3 import copy 5 4 … … 45 44 #contains link between a model and selected parameters to fit 46 45 self.param_toFit =[] 47 # dictionary of model type and model class46 ##dictionary of model type and model class 48 47 self.model_list_box = None 49 48 ## save the state of the context menu 49 self.saved_states={} 50 50 ## save current value of combobox 51 51 self.formfactorcombobox = "" … … 93 93 obj.npts = copy.deepcopy(self.npts ) 94 94 obj.cb1 = copy.deepcopy(self.cb1) 95 for name, state in self.saved_states.iteritems(): 96 copy_name = copy.deepcopy(name) 97 copy_state = state.clone() 98 obj.saved_states[copy_name]= copy_state 99 100 95 101 96 102 return obj
Note: See TracChangeset
for help on using the changeset viewer.