Changeset 4a7ad5f in sasview
- Timestamp:
- Nov 23, 2010 4:12:46 PM (14 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:
- 07c4599
- Parents:
- a54e4be
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
rda9ac4e6 r4a7ad5f 38 38 window_caption = "Basic page " 39 39 40 def __init__(self,parent, page_info): 41 """ 42 """ 43 wx.ScrolledWindow.__init__(self, parent,style=wx.FULL_REPAINT_ON_RESIZE) 40 def __init__(self, parent, page_info): 41 """ 42 """ 43 wx.ScrolledWindow.__init__(self, parent, 44 style=wx.FULL_REPAINT_ON_RESIZE) 44 45 #Set window's font size 45 46 self.SetWindowVariant(variant=FONT_VARIANT) … … 48 49 self.parent = parent 49 50 ## manager is the fitting plugin 50 self.manager = None51 self.manager = None 51 52 ## owner of the page (fitting plugin) 52 self.event_owner = None53 self.event_owner = None 53 54 ## current model 54 55 self.model = None … … 93 94 ## each item related to a given parameters 94 95 ##[cb state, name, value, "+/-", error of fit, min, max , units] 95 self.parameters =[]96 self.parameters = [] 96 97 # non-fittable parameter whose value is astring 97 98 self.str_parameters = [] 98 99 ## list of parameters to fit , must be like self.parameters 99 self.param_toFit =[]100 self.param_toFit = [] 100 101 ## list of looking like parameters but with non fittable parameters info 101 self.fixed_param =[]102 self.fixed_param = [] 102 103 ## list of looking like parameters but with fittable parameters info 103 self.fittable_param =[]104 self.fittable_param = [] 104 105 ##list of dispersion parameters 105 self.disp_list =[]106 self.disp_name =""106 self.disp_list = [] 107 self.disp_name = "" 107 108 108 109 ## list of orientation parameters 109 self.orientation_params =[]110 self.orientation_params_disp =[]111 if self.model != None:112 self.disp_list = self.model.getDispParamList()110 self.orientation_params = [] 111 self.orientation_params_disp = [] 112 if self.model != None: 113 self.disp_list = self.model.getDispParamList() 113 114 114 115 ##enable model 2D draw 115 self.enable2D = False116 self.enable2D = False 116 117 ## check that the fit range is correct to plot the model again 117 self.fitrange = True118 self.fitrange = True 118 119 ## Create memento to save the current state 119 self.state= PageState(parent= self.parent,model=self.model, data=self.data) 120 self.state = PageState(parent=self.parent, 121 model=self.model, data=self.data) 120 122 ## flag to determine if state has change 121 self.state_change = False123 self.state_change = False 122 124 ## save customized array 123 self.values =[]124 self.weights =[]125 self.values = [] 126 self.weights = [] 125 127 ## retrieve saved state 126 self.number_saved_state = 0128 self.number_saved_state = 0 127 129 ## dictionary of saved state 128 self.saved_states={} 129 130 self.saved_states = {} 130 131 ## Create context menu for page 131 132 self.popUpMenu = wx.Menu() 132 133 #id = wx.NewId() 133 #self._undo = wx.MenuItem(self.popUpMenu,id, "Undo","cancel the previous action") 134 #self._undo = wx.MenuItem(self.popUpMenu,id, "Undo", 135 #"cancel the previous action") 134 136 #self.popUpMenu.AppendItem(self._undo) 135 137 #self._undo.Enable(False) … … 137 139 138 140 #id = wx.NewId() 139 #self._redo = wx.MenuItem(self.popUpMenu,id,"Redo"," Restore the previous action") 141 #self._redo = wx.MenuItem(self.popUpMenu,id,"Redo", 142 #" Restore the previous action") 140 143 #self.popUpMenu.AppendItem(self._redo) 141 144 #self._redo.Enable(False) … … 144 147 #if sys.platform.count("win32")>0: 145 148 id = wx.NewId() 146 self._keep = wx.MenuItem(self.popUpMenu,id,"BookMark"," Keep the panel status to recall it later") 149 self._keep = wx.MenuItem(self.popUpMenu,id,"BookMark", 150 " Keep the panel status to recall it later") 147 151 self.popUpMenu.AppendItem(self._keep) 148 152 self._keep.Enable(True) … … 181 185 _on_set_focus_callback = None 182 186 183 def __init__(self, parent, id=-1, value=wx.EmptyString, pos=wx.DefaultPosition, 184 size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.TextCtrlNameStr, 185 kill_focus_callback = None, set_focus_callback = None, 186 mouse_up_callback = None, text_enter_callback = None): 187 def __init__(self, parent, id=-1, 188 value=wx.EmptyString, 189 pos=wx.DefaultPosition, 190 size=wx.DefaultSize, 191 style=0, 192 validator=wx.DefaultValidator, 193 name=wx.TextCtrlNameStr, 194 kill_focus_callback=None, 195 set_focus_callback=None, 196 mouse_up_callback=None, 197 text_enter_callback = None): 187 198 188 wx.TextCtrl.__init__(self, parent, id, value, pos, size, style, validator, name) 199 wx.TextCtrl.__init__(self, parent, id, value, pos, 200 size, style, validator, name) 189 201 190 202 # Bind appropriate events … … 382 394 if self.model_list_box is None: 383 395 return 384 if len(self.model_list_box)>0: 385 self._populate_box( self.formfactorbox,self.model_list_box["Shapes"]) 396 if len(self.model_list_box) > 0: 397 self._populate_box(self.formfactorbox, 398 self.model_list_box["Shapes"]) 386 399 387 if len(self.model_list_box) >0:388 self._populate_box( 400 if len(self.model_list_box) > 0: 401 self._populate_box(self.structurebox, 389 402 self.model_list_box["Structure Factors"]) 390 self.structurebox.Insert("None", 0, None)403 self.structurebox.Insert("None", 0, None) 391 404 self.structurebox.SetSelection(0) 392 405 self.structurebox.Hide() … … 410 423 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 411 424 #---------------------------------------------------- 412 self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), style=wx.RB_GROUP) 425 self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), 426 style=wx.RB_GROUP) 413 427 self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 414 428 415 429 416 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.disable_disp.GetId()) 417 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.enable_disp.GetId()) 430 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 431 id=self.disable_disp.GetId()) 432 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 433 id=self.enable_disp.GetId()) 418 434 #MAC needs SetValue 419 435 self.disable_disp.SetValue(True) … … 481 497 ## Redraw the model ??? 482 498 self._draw_model() 483 # Go through the list of dispersion check boxes to identify which one has changed 499 # Go through the list of dispersion check boxes to identify 500 # which one has changed 484 501 for p in self.disp_cb_dict: 485 502 self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() … … 488 505 if self.disp_cb_dict[p].GetValue() == True: 489 506 490 ##Temp. FIX for V1.0 regarding changing checkbox to radiobutton. 491 ##This (self._reset_dispersity) should be removed when the array dispersion is fixed. 507 ##Temp. FIX for V1.0 regarding changing checkbox 508 #to radiobutton. 509 ##This (self._reset_dispersity) should be removed 510 #when the array dispersion is fixed. 492 511 self._reset_dispersity() 493 512 … … 509 528 except: 510 529 msg="Could not read input file" 511 wx.PostEvent(self.parent.parent, StatusEvent(status= msg)) 530 wx.PostEvent(self.parent.parent, 531 StatusEvent(status=msg)) 512 532 return 513 533 … … 516 536 if self.values is None or self.weights is None or \ 517 537 self.values ==[] or self.weights ==[]: 518 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 519 "The loaded %s distrubtion is corrupted or empty" % p)) 538 msg = "The loaded %s distrubtion is" 539 msg + " corrupted or empty" % p 540 wx.PostEvent(self.parent.parent, 541 StatusEvent(status=msg)) 520 542 return 521 543 522 544 # Tell the user that we are about to apply the distribution 523 wx.PostEvent(self.parent.parent, StatusEvent(status=\524 "Applying loaded %s distribution: %s" % (p, path)))545 msg = "Applying loaded %s distribution: %s" % (p, path) 546 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 525 547 526 548 # Create the dispersion objects … … 529 551 disp_model.set_weights(self.values, self.weights) 530 552 531 # Store the object to make it persist outside the scope of this method 553 # Store the object to make it persist outside the 554 # scope of this method 532 555 #TODO: refactor model to clean this up? 533 556 self._disp_obj_dict[p] = disp_model 534 557 self.state._disp_obj_dict [p]= disp_model 535 self.state.values =[]536 self.state.weights =[]558 self.state.values = [] 559 self.state.weights = [] 537 560 self.state.values = copy.deepcopy(self.values) 538 561 self.state.weights = copy.deepcopy(self.weights) 539 # Set the new model as the dispersion object for the selected parameter 562 # Set the new model as the dispersion object for the 563 #selected parameter 540 564 self.model.set_dispersion(p, disp_model) 541 # Store a reference to the weights in the model object so that 565 # Store a reference to the weights in the model object 566 #so that 542 567 # it's not lost when we use the model within another thread. 543 568 #TODO: total hack - fix this … … 545 570 546 571 self.model._persistency_dict = {} 547 self.model._persistency_dict[p] = [self.values, self.weights] 548 self.state.model._persistency_dict[p] = [self.values, self.weights] 572 self.model._persistency_dict[p] = \ 573 [self.values, self.weights] 574 self.state.model._persistency_dict[p] = \ 575 [self.values,self.weights] 549 576 else: 550 577 self._reset_dispersity() … … 760 787 self.state.smearer = copy.deepcopy(self.smearer) 761 788 if hasattr(self,"enable_smearer"): 762 self.state.enable_smearer = copy.deepcopy(self.enable_smearer.GetValue()) 763 self.state.disable_smearer = copy.deepcopy(self.disable_smearer.GetValue()) 764 765 self.state.pinhole_smearer = copy.deepcopy(self.pinhole_smearer.GetValue()) 789 self.state.enable_smearer = \ 790 copy.deepcopy(self.enable_smearer.GetValue()) 791 self.state.disable_smearer = \ 792 copy.deepcopy(self.disable_smearer.GetValue()) 793 794 self.state.pinhole_smearer = \ 795 copy.deepcopy(self.pinhole_smearer.GetValue()) 766 796 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 767 797 … … 805 835 806 836 self._copy_parameters_state(self.parameters, self.state.parameters) 807 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 837 self._copy_parameters_state(self.fittable_param, 838 self.state.fittable_param) 808 839 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 809 840 #save chisqr … … 845 876 self.state.smearer = copy.deepcopy(self.smearer) 846 877 if hasattr(self,"enable_smearer"): 847 self.state.enable_smearer = copy.deepcopy(self.enable_smearer.GetValue()) 848 self.state.disable_smearer = copy.deepcopy(self.disable_smearer.GetValue()) 849 850 self.state.pinhole_smearer = copy.deepcopy(self.pinhole_smearer.GetValue()) 878 self.state.enable_smearer = \ 879 copy.deepcopy(self.enable_smearer.GetValue()) 880 self.state.disable_smearer = \ 881 copy.deepcopy(self.disable_smearer.GetValue()) 882 883 self.state.pinhole_smearer = \ 884 copy.deepcopy(self.pinhole_smearer.GetValue()) 851 885 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 852 886 … … 854 888 self.state.disp_box = self.disp_box.GetCurrentSelection() 855 889 856 if len(self.disp_cb_dict) >0:857 for k 890 if len(self.disp_cb_dict) > 0: 891 for k, v in self.disp_cb_dict.iteritems(): 858 892 859 if v == None :860 self.state.disp_cb_dict[k] = v893 if v == None : 894 self.state.disp_cb_dict[k] = v 861 895 else: 862 896 try: 863 self.state.disp_cb_dict[k] =v.GetValue()897 self.state.disp_cb_dict[k] = v.GetValue() 864 898 except: 865 self.state.disp_cb_dict[k] = None899 self.state.disp_cb_dict[k] = None 866 900 867 if len(self._disp_obj_dict) >0:901 if len(self._disp_obj_dict) > 0: 868 902 for k , v in self._disp_obj_dict.iteritems(): 869 903 870 self.state._disp_obj_dict[k] = v904 self.state._disp_obj_dict[k] = v 871 905 872 906 … … 883 917 self.state.orientation_params_disp) 884 918 self._copy_parameters_state(self.parameters, self.state.parameters) 885 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 919 self._copy_parameters_state(self.fittable_param, 920 self.state.fittable_param) 886 921 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 887 922 … … 909 944 state of the graphic interface 910 945 """ 911 if state == None:946 if state == None: 912 947 #self._undo.Enable(False) 913 948 return … … 961 996 n= self.disp_box.GetCurrentSelection() 962 997 dispersity= self.disp_box.GetClientData(n) 963 name = dispersity.__name__998 name = dispersity.__name__ 964 999 965 1000 self._set_dipers_Param(event=None) 966 1001 967 if name =="ArrayDispersion":1002 if name == "ArrayDispersion": 968 1003 969 1004 for item in self.disp_cb_dict.keys(): 970 1005 971 if hasattr(self.disp_cb_dict[item],"SetValue") : 972 self.disp_cb_dict[item].SetValue(state.disp_cb_dict[item]) 1006 if hasattr(self.disp_cb_dict[item], "SetValue") : 1007 self.disp_cb_dict[item].SetValue(\ 1008 state.disp_cb_dict[item]) 973 1009 # Create the dispersion objects 974 1010 from sans.models.dispersion_models import ArrayDispersion 975 1011 disp_model = ArrayDispersion() 976 if hasattr(state,"values")and self.disp_cb_dict[item].GetValue()==True: 1012 if hasattr(state,"values")and\ 1013 self.disp_cb_dict[item].GetValue() == True: 977 1014 if len(state.values)>0: 978 1015 self.values=state.values 979 1016 self.weights=state.weights 980 disp_model.set_weights(self.values, state.weights) 1017 disp_model.set_weights(self.values, 1018 state.weights) 981 1019 else: 982 1020 self._reset_dispersity() 983 1021 984 1022 self._disp_obj_dict[item] = disp_model 985 # Set the new model as the dispersion object for the selected parameter 1023 # Set the new model as the dispersion object 1024 #for the selected parameter 986 1025 self.model.set_dispersion(item, disp_model) 987 1026 988 self.model._persistency_dict[item] = [state.values, state.weights] 1027 self.model._persistency_dict[item] = \ 1028 [state.values, state.weights] 989 1029 990 1030 else: 991 1031 keys = self.model.getParamList() 992 1032 for item in keys: 993 if item in self.disp_list and not self.model.details.has_key(item): 994 self.model.details[item]=["",None,None] 1033 if item in self.disp_list and \ 1034 not self.model.details.has_key(item): 1035 self.model.details[item] = ["", None, None] 995 1036 for k,v in self.state.disp_cb_dict.iteritems(): 996 1037 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) … … 1001 1042 ## smearing info restore 1002 1043 if hasattr(self, "enable_smearer"): 1003 ## set smearing value whether or not the data contain the smearing info 1044 ## set smearing value whether or not the data 1045 #contain the smearing info 1004 1046 self.enable_smearer.SetValue(state.enable_smearer) 1005 1047 self.disable_smearer.SetValue(state.disable_smearer) … … 1103 1145 from sans.models.dispersion_models import ArrayDispersion 1104 1146 disp_model = ArrayDispersion() 1105 if hasattr(state,"values")and self.disp_cb_dict[item].GetValue()==True: 1106 if len(state.values)>0: 1107 self.values=state.values 1108 self.weights=state.weights 1109 disp_model.set_weights(self.values, state.weights) 1147 if hasattr(state,"values") and\ 1148 self.disp_cb_dict[item].GetValue()==True: 1149 if len(state.values) > 0: 1150 self.values = state.values 1151 self.weights = state.weights 1152 disp_model.set_weights(self.values, 1153 state.weights) 1110 1154 else: 1111 1155 self._reset_dispersity() 1112 1156 1113 1157 self._disp_obj_dict[item] = disp_model 1114 # Set the new model as the dispersion object for the selected parameter 1158 # Set the new model as the dispersion 1159 #object for the selected parameter 1115 1160 self.model.set_dispersion(item, disp_model) 1116 1161 1117 self.model._persistency_dict[item] = [state.values, state.weights] 1162 self.model._persistency_dict[item] = [state.values, 1163 state.weights] 1118 1164 1119 1165 else: 1120 1166 keys = self.model.getParamList() 1121 1167 for item in keys: 1122 if item in self.disp_list and not self.model.details.has_key(item): 1168 if item in self.disp_list and \ 1169 not self.model.details.has_key(item): 1123 1170 self.model.details[item]=["",None,None] 1124 1171 for k,v in self.state.disp_cb_dict.iteritems(): … … 1131 1178 ## smearing info restore 1132 1179 if hasattr(self,"enable_smearer"): 1133 ## set smearing value whether or not the data contain the smearing info 1180 ## set smearing value whether or not the data 1181 #contain the smearing info 1134 1182 self.enable_smearer.SetValue(state.enable_smearer) 1135 1183 self.disable_smearer.SetValue(state.disable_smearer) … … 1161 1209 import os 1162 1210 dlg = wx.FileDialog(self, "Choose a weight file", 1163 self._default_save_location , "", "*.*", wx.OPEN) 1211 self._default_save_location , "", 1212 "*.*", wx.OPEN) 1164 1213 path = None 1165 1214 if dlg.ShowModal() == wx.ID_OK: … … 1176 1225 ## Add item in the context menu 1177 1226 id = wx.NewId() 1178 self.popUpMenu.Append(id,name, 'Save model and state %g'%self.number_saved_state) 1227 msg = 'Save model and state %g' % self.number_saved_state 1228 self.popUpMenu.Append(id, name, msg) 1179 1229 wx.EVT_MENU(self, id, self.onResetModel) 1180 1230 … … 1210 1260 self.state.qmin = self.qmin_x 1211 1261 self.state.qmax = self.qmax_x 1212 if self.npts!=None: 1213 self.state.npts= self.num_points 1214 1262 if self.npts != None: 1263 self.state.npts = self.num_points 1215 1264 1216 1265 def _onparamEnter_helper(self): … … 1221 1270 # Flag to register when a parameter has changed. 1222 1271 is_modified = False 1223 self.fitrange = True1272 self.fitrange = True 1224 1273 is_2Ddata = False 1225 1274 #self._undo.Enable(True) 1226 1275 # check if 2d data 1227 if self.data.__class__.__name__ == "Data2D":1276 if self.data.__class__.__name__ == "Data2D": 1228 1277 is_2Ddata = True 1229 1278 if self.model !=None: 1230 1279 try: 1231 is_modified =self._check_value_enter( self.fittable_param ,is_modified) 1232 is_modified =self._check_value_enter( self.fixed_param ,is_modified) 1233 is_modified =self._check_value_enter( self.parameters ,is_modified) 1280 is_modified = self._check_value_enter(self.fittable_param, 1281 is_modified) 1282 is_modified = self._check_value_enter(self.fixed_param, 1283 is_modified) 1284 is_modified = self._check_value_enter(self.parameters, 1285 is_modified) 1234 1286 except: 1235 1287 pass … … 1312 1364 flag = self.update_pinhole_smear() 1313 1365 else: 1314 self.manager.set_smearer_nodraw(smearer=temp_smearer, qmin= float(self.qmin_x), 1366 self.manager.set_smearer_nodraw(smearer=temp_smearer, 1367 qmin=float(self.qmin_x), 1368 qmax=float(self.qmax_x)) 1369 elif not self._is_2D(): 1370 self.manager.set_smearer(smearer=temp_smearer, 1371 qmin=float(self.qmin_x), 1315 1372 qmax= float(self.qmax_x)) 1316 elif not self._is_2D(): 1317 self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x), 1318 qmax= float(self.qmax_x)) 1319 index_data = ((self.qmin_x <= self.data.x)&(self.data.x <= self.qmax_x)) 1320 self.Npts_fit.SetValue(str(len(self.data.x[index_data==True]))) 1373 index_data = ((self.qmin_x <= self.data.x)&\ 1374 (self.data.x <= self.qmax_x)) 1375 val = str(len(self.data.x[index_data==True])) 1376 self.Npts_fit.SetValue(val) 1321 1377 flag = True 1322 1378 if self._is_2D(): … … 1338 1394 1339 1395 if not flag: 1340 msg= "Cannot Plot or Fit :Must select a model or Fitting range is not valid!!! " 1341 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 1396 msg = "Cannot Plot or Fit :Must select a " 1397 msg += " model or Fitting range is not valid!!! " 1398 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1342 1399 1343 1400 self.save_current_state() … … 1351 1408 return is_modified 1352 1409 1353 def _reset_parameters_state(self, listtorestore, statelist):1410 def _reset_parameters_state(self, listtorestore, statelist): 1354 1411 """ 1355 1412 Reset the parameters at the given state 1356 1413 """ 1357 if len(statelist) ==0 or len(listtorestore)==0:1414 if len(statelist) == 0 or len(listtorestore) == 0: 1358 1415 return 1359 if len(statelist) != len(listtorestore):1416 if len(statelist) != len(listtorestore): 1360 1417 return 1361 1418 … … 1442 1499 1443 1500 statelist.append([checkbox_state, parameter_name, parameter_value, 1444 static_text ,[error_state,error_value], 1445 [min_state,min_value],[max_state , max_value],unit]) 1501 static_text ,[error_state, error_value], 1502 [min_state, min_value], 1503 [max_state, max_value], unit]) 1446 1504 1447 1505 def _set_model_sizer_selection(self, model): … … 1453 1511 if hasattr(model ,"s_model"): 1454 1512 1455 class_name= model.s_model.__class__ 1456 name= model.s_model.name 1457 flag= name != "NoStructure" 1458 if flag and (class_name in self.model_list_box["Structure Factors"]): 1513 class_name = model.s_model.__class__ 1514 name = model.s_model.name 1515 flag = (name != "NoStructure") 1516 if flag and \ 1517 (class_name in self.model_list_box["Structure Factors"]): 1459 1518 self.structurebox.Show() 1460 1519 self.text2.Show() … … 1463 1522 items = self.structurebox.GetItems() 1464 1523 self.sizer1.Layout() 1465 self.SetScrollbars(20, 20,25,65)1524 self.SetScrollbars(20, 20, 25 ,65) 1466 1525 for i in range(len(items)): 1467 1526 if items[i]== str(name):
Note: See TracChangeset
for help on using the changeset viewer.