Changes in src/sas/sasgui/perspectives/fitting/basepage.py [c8e1996:55db501] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
rc8e1996 r55db501 19 19 20 20 from sas.sasgui.guiframe.panel_base import PanelBase 21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList, \ 22 check_int 21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList, check_int 23 22 from sas.sasgui.guiframe.events import PanelOnFocusEvent 24 23 from sas.sasgui.guiframe.events import StatusEvent … … 43 42 _QMAX_DEFAULT = 0.5 44 43 _NPTS_DEFAULT = 50 45 # 44 #Control panel width 46 45 if sys.platform.count("win32") > 0: 47 46 PANEL_WIDTH = 450 … … 58 57 This class provide general structure of fitpanel page 59 58 """ 60 # Internal name for the AUI manager59 ## Internal name for the AUI manager 61 60 window_name = "Fit Page" 62 # Title to appear on top of the window61 ## Title to appear on top of the window 63 62 window_caption = "Fit Page " 64 63 … … 76 75 PanelBase.__init__(self, parent) 77 76 self.SetupScrolling() 78 # 77 #Set window's font size 79 78 self.SetWindowVariant(variant=FONT_VARIANT) 80 79 self.SetBackgroundColour(color) 81 80 82 81 self._ids = iter(self._id_pool) 83 # parent of the page82 ## parent of the page 84 83 self.parent = parent 85 # manager is the fitting plugin86 # owner of the page (fitting plugin)84 ## manager is the fitting plugin 85 ## owner of the page (fitting plugin) 87 86 self.event_owner = None 88 # current model87 ## current model 89 88 self.model = None 90 89 self.m_name = None 91 90 self.index_model = None 92 91 self.panel = None 93 # data92 ## data 94 93 self.data = None 95 # 94 #list of available data 96 95 self.data_list = [] 97 96 self.mask = None 98 97 self.uid = wx.NewId() 99 98 self.graph_id = None 100 # 99 #Q range for data set 101 100 self.qmin_data_set = numpy.inf 102 101 self.qmax_data_set = None 103 102 self.npts_data_set = 0 104 # Q range103 ## Q range 105 104 self.qmin = None 106 105 self.qmax = None … … 108 107 self.qmin_x = _QMIN_DEFAULT 109 108 self.npts_x = _NPTS_DEFAULT 110 # total number of point: float109 ## total number of point: float 111 110 self.npts = None 112 111 self.num_points = None 113 # smear default112 ## smear default 114 113 self.current_smearer = None 115 # 2D smear accuracy default114 ## 2D smear accuracy default 116 115 self.smear2d_accuracy = 'Low' 117 # slit smear:116 ## slit smear: 118 117 self.dxl = None 119 118 self.dxw = None 120 # pinhole smear119 ## pinhole smear 121 120 self.dx_min = None 122 121 self.dx_max = None 123 # smear attrbs122 ##semar attrbs 124 123 self.enable_smearer = None 125 124 self.disable_smearer = None 126 125 self.pinhole_smearer = None 127 126 self.slit_smearer = None 128 # weightattrbs127 ##weigth attrbs 129 128 self.dI_noweight = None 130 129 self.dI_didata = None 131 130 self.dI_sqrdata = None 132 131 self.dI_idata = None 133 # 132 ##other attrbs 134 133 self.dq_l = None 135 134 self.dq_r = None … … 143 142 self.theory_qmin_x = None 144 143 self.theory_qmax_x = None 144 self.cb1 = None 145 145 self.btEditMask = None 146 146 self.btFit = None … … 150 150 self.disp_cb_dict = {} 151 151 152 # 153 # dictionary containing list of models152 #self.state = PageState(parent=parent) 153 ## dictionary containing list of models 154 154 self.model_list_box = {} 155 155 156 # Data member to store the dispersion object created156 ## Data member to store the dispersion object created 157 157 self._disp_obj_dict = {} 158 # selected parameters to apply dispersion158 ## selected parameters to apply dispersion 159 159 self.disp_cb_dict = {} 160 # smearer object160 ## smearer object 161 161 self.enable2D = False 162 162 self._has_magnetic = False … … 166 166 self.structurebox = None 167 167 self.categorybox = None 168 # 169 # each item related to a given parameters170 # 168 ##list of model parameters. each item must have same length 169 ## each item related to a given parameters 170 ##[cb state, name, value, "+/-", error of fit, min, max , units] 171 171 self.parameters = [] 172 172 # non-fittable parameter whose value is astring 173 173 self.str_parameters = [] 174 # list of parameters to fit , must be like self.parameters174 ## list of parameters to fit , must be like self.parameters 175 175 self.param_toFit = [] 176 # list of looking like parameters but with non fittable parameters info176 ## list of looking like parameters but with non fittable parameters info 177 177 self.fixed_param = [] 178 # list of looking like parameters but with fittable parameters info178 ## list of looking like parameters but with fittable parameters info 179 179 self.fittable_param = [] 180 # 180 ##list of dispersion parameters 181 181 self.disp_list = [] 182 182 self.disp_name = "" 183 183 184 # list of orientation parameters184 ## list of orientation parameters 185 185 self.orientation_params = [] 186 186 self.orientation_params_disp = [] … … 189 189 # and this - commenting out on 4/8/2014 by PDB. Remove once clear 190 190 # it is pointless. 191 # if self.model is notNone:191 # if self.model != None: 192 192 # self.disp_list = self.model.getDispParamList() 193 193 self.temp_multi_functional = False 194 # 194 ##enable model 2D draw 195 195 self.enable2D = False 196 # check that the fit range is correct to plot the model again196 ## check that the fit range is correct to plot the model again 197 197 self.fitrange = True 198 # Create memento to save the current state198 ## Create memento to save the current state 199 199 self.state = PageState(parent=self.parent, 200 200 model=self.model, data=self.data) 201 # flag to determine if state has change201 ## flag to determine if state has change 202 202 self.state_change = False 203 # save customized array203 ## save customized array 204 204 self.values = {} # type: Dict[str, List[float, ...]] 205 205 self.weights = {} # type: Dict[str, List[float, ...]] 206 # retrieve saved state206 ## retrieve saved state 207 207 self.number_saved_state = 0 208 # dictionary of saved state208 ## dictionary of saved state 209 209 self.saved_states = {} 210 # Create context menu for page210 ## Create context menu for page 211 211 self.popUpMenu = wx.Menu() 212 212 … … 221 221 self.popUpMenu.AppendSeparator() 222 222 223 # Default locations223 ## Default locations 224 224 self._default_save_location = os.getcwd() 225 # save initial state on context menu226 # 225 ## save initial state on context menu 226 #self.onSave(event=None) 227 227 self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 228 228 … … 230 230 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) 231 231 232 # create the basic structure of the panel with empty sizer232 ## create the basic structure of the panel with empty sizer 233 233 self.define_page_structure() 234 # drawing Initial dispersion parameters sizer234 ## drawing Initial dispersion parameters sizer 235 235 self.set_dispers_sizer() 236 236 237 # layout237 ## layout 238 238 self.set_layout() 239 239 … … 261 261 self._create_default_1d_data() 262 262 263 if self.model is notNone:263 if self.model != None: 264 264 if not self.data.is_data: 265 self._manager.page_finder[self.uid].set_fit_data( 266 data=[self.data])265 self._manager.page_finder[self.uid].set_fit_data(data=\ 266 [self.data]) 267 267 self.on_smear_helper(update=True) 268 268 self.state.enable_smearer = self.enable_smearer.GetValue() … … 281 281 num=self.npts_x, endpoint=True) 282 282 self.data = Data1D(x=x) 283 self.data.xaxis('\\rm{Q}', "A^{-1}") 284 self.data.yaxis('\\rm{Intensity}', "cm^{-1}") 283 #self.data.xaxis('\\rm{Q}', "A^{-1}") 284 self.data.xaxis('\\rm{X}', "") 285 #self.data.yaxis('\\rm{Intensity}', "cm^{-1}") 286 self.data.yaxis('\\rm{Y}', "") 285 287 self.data.is_data = False 286 288 self.data.id = str(self.uid) + " data" … … 307 309 num=self.npts_x, endpoint=True, base=10.0) 308 310 self.data = Data1D(x=x) 309 self.data.xaxis('\\rm{Q}', "A^{-1}") 310 self.data.yaxis('\\rm{Intensity}', "cm^{-1}") 311 #self.data.xaxis('\\rm{Q}', "A^{-1}") 312 #self.data.yaxis('\\rm{Intensity}', "cm^{-1}") 313 self.data.xaxis('\\rm{X}', "") 314 self.data.yaxis('\\rm{Y}', "") 311 315 self.data.is_data = False 312 316 self.data.id = str(self.uid) + " data" … … 326 330 self.data.id = str(self.uid) + " data" 327 331 self.data.group_id = str(self.uid) + " Model2D" 328 # Default values332 ## Default values 329 333 self.data.detector.append(Detector()) 330 334 index = len(self.data.detector) - 1 … … 343 347 x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 344 348 y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 345 # use data info instead349 ## use data info instead 346 350 new_x = numpy.tile(x, (len(y), 1)) 347 351 new_y = numpy.tile(y, (len(x), 1)) … … 384 388 Update menu1 on cliking the page tap 385 389 """ 386 if self._manager.menu1 is notNone:387 chain_menu = self._manager.menu1.FindItemById( 390 if self._manager.menu1 != None: 391 chain_menu = self._manager.menu1.FindItemById(\ 388 392 self._manager.id_reset_flag) 389 393 chain_menu.Enable(self.batch_on) 390 394 sim_menu = self._manager.menu1.FindItemById(self._manager.id_simfit) 391 395 flag = self.data.is_data\ 392 and (self.model is notNone)396 and (self.model != None) 393 397 sim_menu.Enable(not self.batch_on and flag) 394 398 batch_menu = \ … … 531 535 fill sizer containing dispersity info 532 536 """ 533 # 537 #print "==== entering set_dispers_sizer ===" 534 538 self.sizer4.Clear(True) 535 539 name = "Polydispersity and Orientational Distribution" … … 537 541 box_description.SetForegroundColour(wx.BLUE) 538 542 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 539 # 543 #---------------------------------------------------- 540 544 self.disable_disp = wx.RadioButton(self, wx.ID_ANY, 'Off', (10, 10), 541 545 style=wx.RB_GROUP) … … 557 561 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 558 562 id=self.enable_disp.GetId()) 559 # 563 #MAC needs SetValue 560 564 self.disable_disp.SetValue(True) 561 565 sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) … … 569 573 sizer_dispersion.Add(self.disp_help_bt) 570 574 571 # fill a sizer for dispersion575 ## fill a sizer for dispersion 572 576 boxsizer1.Add(sizer_dispersion, 0, 573 577 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, … … 576 580 577 581 boxsizer1.Add(self.sizer4_4) 578 # 582 #----------------------------------------------------- 579 583 self.sizer4.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 580 584 self.sizer4_4.Layout() … … 583 587 584 588 self.Refresh() 585 # saving the state of enable dispersity button589 ## saving the state of enable dispersity button 586 590 self.state.enable_disp = self.enable_disp.GetValue() 587 591 self.state.disable_disp = self.disable_disp.GetValue() … … 593 597 """ 594 598 menu = event.GetEventObject() 595 # post help message for the selected model599 ## post help message for the selected model 596 600 msg = menu.GetHelpString(event.GetId()) 597 601 msg += " reloaded" … … 600 604 name = menu.GetLabel(event.GetId()) 601 605 self._on_select_model_helper() 602 if self.model is notNone:606 if self.model != None: 603 607 self.m_name = self.model.name 604 608 if name in self.saved_states.keys(): 605 609 previous_state = self.saved_states[name] 606 # reset state of checkbox,textcrtl and regular parameters value610 ## reset state of checkbox,textcrtl and regular parameters value 607 611 608 612 self.reset_page(previous_state) … … 627 631 # Ask the user the location of the file to write to. 628 632 path = None 629 if self.parent is notNone:633 if self.parent != None: 630 634 self._default_save_location = \ 631 635 self._manager.parent._default_save_location … … 637 641 self._default_save_location = os.path.dirname(path) 638 642 self._manager.parent._default_save_location = \ 639 self._default_save_location643 self._default_save_location 640 644 else: 641 645 return None … … 644 648 # Make sure the ext included in the file name 645 649 fName = os.path.splitext(path)[0] + extens 646 # 650 #the manager write the state into file 647 651 self._manager.save_fit_state(filepath=fName, fitstate=new_state) 648 652 return new_state … … 652 656 Copy Parameter values to the clipboad 653 657 """ 654 if event is notNone:658 if event != None: 655 659 event.Skip() 656 660 # It seems MAC needs wxCallAfter … … 668 672 Paste Parameter values to the panel if possible 669 673 """ 670 # if event is notNone:674 #if event != None: 671 675 # event.Skip() 672 676 # It seems MAC needs wxCallAfter for the setvalues … … 674 678 wx.CallAfter(self.get_paste) 675 679 # messages depending on the flag 676 # 680 #self._copy_info(True) 677 681 678 682 def _copy_info(self, flag): … … 683 687 """ 684 688 # messages depending on the flag 685 if flag isNone:689 if flag == None: 686 690 msg = " Parameter values are copied to the clipboard..." 687 691 infor = 'warning' … … 711 715 save history of the data and model 712 716 """ 713 if self.model isNone:717 if self.model == None: 714 718 msg = "Can not bookmark; Please select Data and Model first..." 715 719 wx.MessageBox(msg, 'Info') … … 717 721 self.save_current_state() 718 722 new_state = self.state.clone() 719 # 723 ##Add model state on context menu 720 724 self.number_saved_state += 1 721 725 current_time, current_date = self._get_time_stamp() 722 # 726 #name= self.model.name+"[%g]"%self.number_saved_state 723 727 name = "Fitting: %g]" % self.number_saved_state 724 728 name += self.model.__class__.__name__ … … 726 730 self.saved_states[name] = new_state 727 731 728 # Add item in the context menu732 ## Add item in the context menu 729 733 msg = "Model saved at %s on %s" % (current_time, current_date) 730 # post help message for the selected model734 ## post help message for the selected model 731 735 msg += " Saved! right click on this page to retrieve this model" 732 736 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 762 766 """ 763 767 try: 764 if path isNone:768 if path == None: 765 769 status = " Selected Distribution was not loaded: %s" % path 766 770 wx.PostEvent(self._manager.parent, … … 797 801 Store current state 798 802 """ 799 # save model option800 if self.model is notNone:803 ## save model option 804 if self.model != None: 801 805 self.disp_list = self.model.getDispParamList() 802 806 self.state.disp_list = copy.deepcopy(self.disp_list) 803 807 self.state.model = self.model.clone() 804 808 805 # 806 if self.structurebox is notNone:809 #model combobox: complex code because of mac's silent error 810 if self.structurebox != None: 807 811 if self.structurebox.IsShown(): 808 812 self.state.structurecombobox = 'None' 809 813 s_select = self.structurebox.GetSelection() 810 814 if s_select > 0: 811 self.state.structurecombobox = \812 self.structurebox.GetString(s_select)813 if self.formfactorbox is notNone:815 self.state.structurecombobox = self.structurebox.\ 816 GetString(s_select) 817 if self.formfactorbox != None: 814 818 f_select = self.formfactorbox.GetSelection() 815 819 if f_select > 0: 816 self.state.formfactorcombobox = \817 self.formfactorbox.GetString(f_select)818 if self.categorybox is notNone:820 self.state.formfactorcombobox = self.formfactorbox.\ 821 GetString(f_select) 822 if self.categorybox != None: 819 823 cb_select = self.categorybox.GetSelection() 820 824 if cb_select > 0: 821 self.state.categorycombobox = \822 self.categorybox.GetString(cb_select)825 self.state.categorycombobox = self.categorybox.\ 826 GetString(cb_select) 823 827 824 828 self.state.enable2D = copy.deepcopy(self.enable2D) 825 829 self.state.values = copy.deepcopy(self.values) 826 830 self.state.weights = copy.deepcopy(self.weights) 827 # save data831 ## save data 828 832 self.state.data = copy.deepcopy(self.data) 829 833 self.state.qmax_x = self.qmax_x … … 860 864 self.state.values = copy.deepcopy(self.values) 861 865 self.state.weights = copy.deepcopy(self.weights) 862 # save plotting range866 ## save plotting range 863 867 self._save_plotting_range() 864 868 … … 870 874 self.state.str_parameters = [] 871 875 872 # save checkbutton state and txtcrtl values876 ## save checkbutton state and txtcrtl values 873 877 self._copy_parameters_state(self.str_parameters, 874 878 self.state.str_parameters) … … 882 886 self.state.fittable_param) 883 887 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 884 # 888 #save chisqr 885 889 self.state.tcChi = self.tcChi.GetValue() 886 890 … … 889 893 Store current state for fit_page 890 894 """ 891 # save model option892 if self.model is notNone:895 ## save model option 896 if self.model != None: 893 897 self.disp_list = self.model.getDispParamList() 894 898 self.state.disp_list = copy.deepcopy(self.disp_list) … … 898 902 self.state.values = copy.deepcopy(self.values) 899 903 self.state.weights = copy.deepcopy(self.weights) 900 # save data904 ## save data 901 905 self.state.data = copy.deepcopy(self.data) 902 906 … … 919 923 self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) 920 924 self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) 921 if hasattr(self, "disp_box") and self.disp_box is notNone:925 if hasattr(self, "disp_box") and self.disp_box != None: 922 926 self.state.disp_box = self.disp_box.GetCurrentSelection() 923 927 924 928 if len(self.disp_cb_dict) > 0: 925 929 for k, v in self.disp_cb_dict.iteritems(): 926 if v isNone:930 if v == None: 927 931 self.state.disp_cb_dict[k] = v 928 932 else: … … 938 942 self.state.weights = copy.deepcopy(self.weights) 939 943 940 # save plotting range944 ## save plotting range 941 945 self._save_plotting_range() 942 946 943 # save checkbutton state and txtcrtl values947 ## save checkbutton state and txtcrtl values 944 948 self._copy_parameters_state(self.orientation_params, 945 949 self.state.orientation_params) … … 960 964 msg = "Please load Data and select Model to start..." 961 965 wx.MessageBox(msg, 'Info') 962 return True966 return True 963 967 964 968 def set_model_state(self, state): … … 969 973 self.disp_list = state.disp_list 970 974 971 # fill model combobox975 ## fill model combobox 972 976 self._show_combox_helper() 973 # 977 #select the current model 974 978 try: 975 979 # to support older version … … 1010 1014 self.structurebox.SetSelection(structfactor_pos) 1011 1015 1012 if state.multi_factor is notNone:1016 if state.multi_factor != None: 1013 1017 self.multifactorbox.SetSelection(state.multi_factor) 1014 1018 1015 # reset state of checkbox,textcrtl and regular parameters value1019 ## reset state of checkbox,textcrtl and regular parameters value 1016 1020 self._reset_parameters_state(self.orientation_params_disp, 1017 1021 state.orientation_params_disp) … … 1021 1025 state.str_parameters) 1022 1026 self._reset_parameters_state(self.parameters, state.parameters) 1023 # display dispersion info layer1027 ## display dispersion info layer 1024 1028 self.enable_disp.SetValue(state.enable_disp) 1025 1029 self.disable_disp.SetValue(state.disable_disp) 1026 1030 1027 if hasattr(self, "disp_box") and self.disp_box is notNone:1031 if hasattr(self, "disp_box") and self.disp_box != None: 1028 1032 self.disp_box.SetSelection(state.disp_box) 1029 1033 n = self.disp_box.GetCurrentSelection() … … 1037 1041 1038 1042 if hasattr(self.disp_cb_dict[item], "SetValue"): 1039 self.disp_cb_dict[item].SetValue( 1043 self.disp_cb_dict[item].SetValue(\ 1040 1044 state.disp_cb_dict[item]) 1041 1045 # Create the dispersion objects 1042 1046 disp_model = POLYDISPERSITY_MODELS['array']() 1043 1047 if hasattr(state, "values") and \ 1044 self.disp_cb_dict[item].GetValue() isTrue:1048 self.disp_cb_dict[item].GetValue() == True: 1045 1049 if len(state.values) > 0: 1046 1050 self.values = state.values … … 1053 1057 self._disp_obj_dict[item] = disp_model 1054 1058 # Set the new model as the dispersion object 1055 # 1059 #for the selected parameter 1056 1060 self.model.set_dispersion(item, disp_model) 1057 1061 … … 1063 1067 for item in keys: 1064 1068 if item in self.disp_list and \ 1065 item notin self.model.details:1069 not item in self.model.details: 1066 1070 self.model.details[item] = ["", None, None] 1067 1071 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1068 1072 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1069 # smearing info restore1073 ## smearing info restore 1070 1074 if hasattr(self, "enable_smearer"): 1071 # set smearing value whether or not the data1072 # 1075 ## set smearing value whether or not the data 1076 #contain the smearing info 1073 1077 self.enable_smearer.SetValue(state.enable_smearer) 1074 1078 self.disable_smearer.SetValue(state.disable_smearer) … … 1082 1086 self.dI_idata.SetValue(state.dI_idata) 1083 1087 1084 # we have two more options for smearing1088 ## we have two more options for smearing 1085 1089 if self.pinhole_smearer.GetValue(): 1086 1090 self.onPinholeSmear(event=None) … … 1088 1092 self.onSlitSmear(event=None) 1089 1093 1090 # reset state of checkbox,textcrtl and dispersity parameters value1094 ## reset state of checkbox,textcrtl and dispersity parameters value 1091 1095 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1092 1096 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1093 1097 1094 # draw the model with previous parameters value1098 ## draw the model with previous parameters value 1095 1099 self._onparamEnter_helper() 1096 1100 self.select_param(event=None) 1097 # 1101 #Save state_fit 1098 1102 self.save_current_state_fit() 1099 1103 self._lay_out() … … 1109 1113 if state.formfactorcombobox in list_item: 1110 1114 return self.categorybox.Items.index(key) 1111 return 01112 1115 1113 1116 def reset_page_helper(self, state): … … 1120 1123 state of the graphic interface 1121 1124 """ 1122 if state isNone:1125 if state == None: 1123 1126 return 1124 1127 # set data, etc. from the state 1125 1128 # reset page between theory and fitting from bookmarking 1129 #if state.data == None: 1130 # data = None 1131 #else: 1126 1132 data = state.data 1127 1133 1128 if data isNone:1134 if data == None: 1129 1135 data_min = state.qmin 1130 1136 data_max = state.qmax … … 1150 1156 self.disp_list = state.disp_list 1151 1157 1152 # fill model combobox 1158 ## set the state of the radio box 1159 #self.shape_rbutton.SetValue(state.shape_rbutton) 1160 #self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) 1161 #self.struct_rbutton.SetValue(state.struct_rbutton) 1162 #self.plugin_rbutton.SetValue(state.plugin_rbutton) 1163 1164 ## fill model combobox 1153 1165 self._show_combox_helper() 1154 # 1166 #select the current model 1155 1167 try: 1156 1168 # to support older version 1157 1169 category_pos = int(state.categorycombobox) 1158 1170 except: 1159 state.formfactorcombobox = state.formfactorcombobox.lower() 1160 state.formfactorcombobox = \ 1161 state.formfactorcombobox.replace('model', '') 1162 state.formfactorcombobox = unicode(state.formfactorcombobox) 1171 state.formfactorcombobox = unicode(state.formfactorcombobox.lower()) 1163 1172 state.categorycombobox = unicode(state.categorycombobox) 1173 category_pos = 0 1164 1174 if state.categorycombobox in self.categorybox.Items: 1165 1175 category_pos = self.categorybox.Items.index( … … 1184 1194 self.formfactorbox.Select(formfactor_pos) 1185 1195 1186 structfactor_pos = 01187 1196 try: 1188 1197 # to support older version … … 1190 1199 except: 1191 1200 if state.structurecombobox is not None: 1201 structfactor_pos = 0 1192 1202 state.structurecombobox = unicode(state.structurecombobox) 1193 1203 for ind_struct in range(self.structurebox.GetCount()): 1194 1204 if self.structurebox.GetString(ind_struct) == \ 1195 (state.structurecombobox):1205 (state.structurecombobox): 1196 1206 structfactor_pos = int(ind_struct) 1197 1207 break … … 1199 1209 self.structurebox.SetSelection(structfactor_pos) 1200 1210 1201 if state.multi_factor is notNone:1211 if state.multi_factor != None: 1202 1212 self.multifactorbox.SetSelection(state.multi_factor) 1203 1213 1204 # 1214 #draw the panel according to the new model parameter 1205 1215 self._on_select_model(event=None) 1206 1216 1207 1217 # take care of 2D button 1208 if data isNone and self.model_view.IsEnabled():1218 if data == None and self.model_view.IsEnabled(): 1209 1219 if self.enable2D: 1210 1220 self.model_view.SetLabel("2D Mode") … … 1212 1222 self.model_view.SetLabel("1D Mode") 1213 1223 1214 # reset state of checkbox,textcrtl and regular parameters value 1224 ## set the select all check box to the a given state 1225 self.cb1.SetValue(state.cb1) 1226 1227 ## reset state of checkbox,textcrtl and regular parameters value 1215 1228 self._reset_parameters_state(self.orientation_params_disp, 1216 1229 state.orientation_params_disp) … … 1220 1233 state.str_parameters) 1221 1234 self._reset_parameters_state(self.parameters, state.parameters) 1222 # display dispersion info layer1235 ## display dispersion info layer 1223 1236 self.enable_disp.SetValue(state.enable_disp) 1224 1237 self.disable_disp.SetValue(state.disable_disp) … … 1228 1241 self._set_dipers_Param(event=None) 1229 1242 self._reset_page_disp_helper(state) 1230 # 1243 ##plotting range restore 1231 1244 self._reset_plotting_range(state) 1232 # smearing info restore1245 ## smearing info restore 1233 1246 if hasattr(self, "enable_smearer"): 1234 # set smearing value whether or not the data1235 # 1247 ## set smearing value whether or not the data 1248 #contain the smearing info 1236 1249 self.enable_smearer.SetValue(state.enable_smearer) 1237 1250 self.disable_smearer.SetValue(state.disable_smearer) … … 1251 1264 self.dI_idata.SetValue(False) 1252 1265 1253 # we have two more options for smearing1266 ## we have two more options for smearing 1254 1267 if self.pinhole_smearer.GetValue(): 1255 1268 self.dx_min = state.dx_min 1256 1269 self.dx_max = state.dx_max 1257 if self.dx_min is notNone:1270 if self.dx_min != None: 1258 1271 self.smear_pinhole_min.SetValue(str(self.dx_min)) 1259 if self.dx_max is notNone:1272 if self.dx_max != None: 1260 1273 self.smear_pinhole_max.SetValue(str(self.dx_max)) 1261 1274 self.onPinholeSmear(event=None) … … 1263 1276 self.dxl = state.dxl 1264 1277 self.dxw = state.dxw 1265 if self.dxl is notNone:1278 if self.dxl != None: 1266 1279 self.smear_slit_height.SetValue(str(self.dxl)) 1267 if self.dxw is notNone:1280 if self.dxw != None: 1268 1281 self.smear_slit_width.SetValue(str(self.dxw)) 1269 1282 else: … … 1271 1284 self.onSlitSmear(event=None) 1272 1285 1273 # reset state of checkbox,textcrtl and dispersity parameters value1286 ## reset state of checkbox,textcrtl and dispersity parameters value 1274 1287 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1275 1288 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1276 1289 1277 # draw the model with previous parameters value1290 ## draw the model with previous parameters value 1278 1291 self._onparamEnter_helper() 1279 # 1292 #reset the value of chisqr when not consistent with the value computed 1280 1293 self.tcChi.SetValue(str(self.state.tcChi)) 1281 # reset context menu items1294 ## reset context menu items 1282 1295 self._reset_context_menu() 1283 1296 1284 # set the value of the current state to the state given as parameter1297 ## set the value of the current state to the state given as parameter 1285 1298 self.state = state.clone() 1286 1299 self.state.m_name = self.m_name … … 1293 1306 for item in keys: 1294 1307 if item in self.disp_list and \ 1295 item notin self.model.details:1308 not item in self.model.details: 1296 1309 self.model.details[item] = ["", None, None] 1297 # 1310 #for k,v in self.state.disp_cb_dict.iteritems(): 1298 1311 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1299 1312 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) … … 1302 1315 1303 1316 for key, disp_type in state._disp_obj_dict.iteritems(): 1304 # 1317 #disp_model = disp 1305 1318 disp_model = POLYDISPERSITY_MODELS[disp_type]() 1306 1319 self._disp_obj_dict[key] = disp_model … … 1311 1324 self.model.set_dispersion(param_name, disp_model) 1312 1325 self.model._persistency_dict[key] = \ 1313 [state.values, state.weights]1326 [state.values, state.weights] 1314 1327 except Exception: 1315 1328 logging.error(traceback.format_exc()) 1316 1329 selection = self._find_polyfunc_selection(disp_model) 1317 1330 for list in self.fittable_param: 1318 if list[1] == key and list[7] is notNone:1331 if list[1] == key and list[7] != None: 1319 1332 list[7].SetSelection(selection) 1320 1333 # For the array disp_model, set the values and weights … … 1341 1354 logging.error(traceback.format_exc()) 1342 1355 1356 # Make sure the check box updated when all checked 1357 if self.cb1.GetValue(): 1358 self.select_all_param(None) 1359 1343 1360 def _selectDlg(self): 1344 1361 """ 1345 1362 open a dialog file to selected the customized dispersity 1346 1363 """ 1347 if self.parent is notNone:1364 if self.parent != None: 1348 1365 self._default_save_location = \ 1349 1366 self._manager.parent.get_save_location() … … 1364 1381 for name, _ in self.state.saved_states.iteritems(): 1365 1382 self.number_saved_state += 1 1366 # Add item in the context menu1383 ## Add item in the context menu 1367 1384 wx_id = ids.next() 1368 1385 msg = 'Save model and state %g' % self.number_saved_state … … 1381 1398 save radiobutton containing the type model that can be selected 1382 1399 """ 1383 # 1384 # 1385 # 1386 # 1400 #self.state.shape_rbutton = self.shape_rbutton.GetValue() 1401 #self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() 1402 #self.state.struct_rbutton = self.struct_rbutton.GetValue() 1403 #self.state.plugin_rbutton = self.plugin_rbutton.GetValue() 1387 1404 self.state.structurecombobox = self.structurebox.GetLabel() 1388 1405 self.state.formfactorcombobox = self.formfactorbox.GetLabel() 1389 1406 self.state.categorycombobox = self.categorybox.GetLabel() 1390 1407 1391 # post state to fit panel1408 ## post state to fit panel 1392 1409 event = PageInfoEvent(page=self) 1393 1410 wx.PostEvent(self.parent, event) … … 1401 1418 self.state.npts = self.npts_x 1402 1419 1403 def _onparamEnter_helper(self, is_modified=False):1420 def _onparamEnter_helper(self,is_modified = False): 1404 1421 """ 1405 1422 check if values entered by the user are changed and valid to replot … … 1407 1424 """ 1408 1425 # Flag to register when a parameter has changed. 1409 # 1426 #is_modified = False 1410 1427 self.fitrange = True 1411 1428 is_2Ddata = False 1412 # 1429 #self._undo.Enable(True) 1413 1430 # check if 2d data 1414 1431 if self.data.__class__.__name__ == "Data2D": 1415 1432 is_2Ddata = True 1416 if self.model is notNone:1417 # 1418 # 1433 if self.model != None: 1434 #Either we get a is_modified = True passed in because 1435 #_update_paramv_on_fit() has been called already or 1419 1436 # we need to check here ourselves. 1420 1437 if not is_modified: … … 1443 1460 self.fitrange = False 1444 1461 1445 # if any value is modify draw model with new value 1462 if not self.data.is_data: 1463 is_modified = True 1464 1465 ## if any value is modify draw model with new value 1446 1466 if not self.fitrange: 1447 # 1467 #self.btFit.Disable() 1448 1468 if is_2Ddata: 1449 1469 self.btEditMask.Disable() … … 1458 1478 self._draw_model() 1459 1479 self.Refresh() 1460 1461 # logging.info("is_modified flag set to %g",is_modified)1462 1480 return is_modified 1463 1481 … … 1466 1484 make sure that update param values just before the fitting 1467 1485 """ 1468 # 1486 #flag for qmin qmax check values 1469 1487 flag = True 1470 1488 self.fitrange = True 1471 1489 is_modified = False 1472 1490 1473 # 1474 # 1475 1476 # 1477 # 1478 if self.model is notNone:1491 #wx.PostEvent(self._manager.parent, StatusEvent(status=" \ 1492 #updating ... ",type="update")) 1493 1494 ##So make sure that update param values on_Fit. 1495 #self._undo.Enable(True) 1496 if self.model != None: 1479 1497 if self.Npts_total.GetValue() != self.Npts_fit.GetValue(): 1480 1498 if not self.data.is_data: 1481 self._manager.page_finder[self.uid].set_fit_data( 1482 data=[self.data])1483 # 1499 self._manager.page_finder[self.uid].set_fit_data(data=\ 1500 [self.data]) 1501 ##Check the values 1484 1502 is_modified = (self._check_value_enter(self.fittable_param) 1485 or self._check_value_enter(self.fixed_param)1486 or self._check_value_enter(self.parameters))1503 or self._check_value_enter(self.fixed_param) 1504 or self._check_value_enter(self.parameters)) 1487 1505 1488 1506 # If qmin and qmax have been modified, update qmin and qmax and … … 1525 1543 enable_smearer=enable_smearer, 1526 1544 draw=False) 1527 if self.data is notNone:1528 index_data = ((self.qmin_x <= self.data.x) & 1545 if self.data != None: 1546 index_data = ((self.qmin_x <= self.data.x) & \ 1529 1547 (self.data.x <= self.qmax_x)) 1530 val = str(len(self.data.x[index_data isTrue]))1548 val = str(len(self.data.x[index_data == True])) 1531 1549 self.Npts_fit.SetValue(val) 1532 1550 else: … … 1548 1566 flag = False 1549 1567 1550 # 1568 #For invalid q range, disable the mask editor and fit button, vs. 1551 1569 if not self.fitrange: 1552 1570 if self._is_2D(): 1553 1571 self.btEditMask.Disable() 1554 1572 else: 1555 if self._is_2D() and self.data.is_data and not self.batch_on:1573 if self._is_2D() and self.data.is_data and not self.batch_on: 1556 1574 self.btEditMask.Enable(True) 1557 1575 … … 1566 1584 logging.error(traceback.format_exc()) 1567 1585 1568 return flag, 1586 return flag,is_modified 1569 1587 1570 1588 def _reset_parameters_state(self, listtorestore, statelist): … … 1580 1598 item_page = listtorestore[j] 1581 1599 item_page_info = statelist[j] 1582 # 1583 if item_page[0] is notNone:1600 ##change the state of the check box for simple parameters 1601 if item_page[0] != None: 1584 1602 item_page[0].SetValue(item_page_info[0]) 1585 if item_page[2] is notNone:1603 if item_page[2] != None: 1586 1604 item_page[2].SetValue(item_page_info[2]) 1587 1605 if item_page[2].__class__.__name__ == "ComboBox": … … 1589 1607 fun_val = self.model.fun_list[item_page_info[2]] 1590 1608 self.model.setParam(item_page_info[1], fun_val) 1591 if item_page[3] is notNone:1592 # show or hide text +/-1609 if item_page[3] != None: 1610 ## show or hide text +/- 1593 1611 if item_page_info[2]: 1594 1612 item_page[3].Show(True) 1595 1613 else: 1596 1614 item_page[3].Hide() 1597 if item_page[4] is notNone:1598 # show of hide the text crtl for fitting error1615 if item_page[4] != None: 1616 ## show of hide the text crtl for fitting error 1599 1617 if item_page_info[4][0]: 1600 1618 item_page[4].Show(True) … … 1602 1620 else: 1603 1621 item_page[3].Hide() 1604 if item_page[5] is notNone:1605 # show of hide the text crtl for fitting error1622 if item_page[5] != None: 1623 ## show of hide the text crtl for fitting error 1606 1624 item_page[5].Show(item_page_info[5][0]) 1607 1625 item_page[5].SetValue(item_page_info[5][1]) 1608 1626 1609 if item_page[6] is notNone:1610 # show of hide the text crtl for fitting error1627 if item_page[6] != None: 1628 ## show of hide the text crtl for fitting error 1611 1629 item_page[6].Show(item_page_info[6][0]) 1612 1630 item_page[6].SetValue(item_page_info[6][1]) … … 1624 1642 item_page = listtorestore[j] 1625 1643 item_page_info = statelist[j] 1626 # 1627 1628 if item_page[0] is notNone:1644 ##change the state of the check box for simple parameters 1645 1646 if item_page[0] != None: 1629 1647 item_page[0].SetValue(format_number(item_page_info[0], True)) 1630 1648 1631 if item_page[2] is notNone:1649 if item_page[2] != None: 1632 1650 param_name = item_page_info[1] 1633 1651 value = item_page_info[2] … … 1652 1670 1653 1671 checkbox_state = None 1654 if item[0] is notNone:1672 if item[0] != None: 1655 1673 checkbox_state = item[0].GetValue() 1656 1674 parameter_name = item[1] 1657 1675 parameter_value = None 1658 if item[2] is notNone:1676 if item[2] != None: 1659 1677 parameter_value = item[2].GetValue() 1660 1678 static_text = None 1661 if item[3] is notNone:1679 if item[3] != None: 1662 1680 static_text = item[3].IsShown() 1663 1681 error_value = None 1664 1682 error_state = None 1665 if item[4] is notNone:1683 if item[4] != None: 1666 1684 error_value = item[4].GetValue() 1667 1685 error_state = item[4].IsShown() … … 1669 1687 min_value = None 1670 1688 min_state = None 1671 if item[5] is notNone:1689 if item[5] != None: 1672 1690 min_value = item[5].GetValue() 1673 1691 min_state = item[5].IsShown() … … 1675 1693 max_value = None 1676 1694 max_state = None 1677 if item[6] is notNone:1695 if item[6] != None: 1678 1696 max_value = item[6].GetValue() 1679 1697 max_state = item[6].IsShown() 1680 1698 unit = None 1681 if item[7] is notNone:1699 if item[7] != None: 1682 1700 unit = item[7].GetLabel() 1683 1701 … … 1687 1705 [max_state, max_value], unit]) 1688 1706 1707 1689 1708 def _draw_model(self, update_chisqr=True, source='model'): 1690 1709 """ … … 1705 1724 :param chisqr: update chisqr value [bool] 1706 1725 """ 1707 # 1726 #if self.check_invalid_panel(): 1708 1727 # return 1709 if self.model is notNone:1728 if self.model != None: 1710 1729 temp_smear = None 1711 1730 if hasattr(self, "enable_smearer"): … … 1719 1738 is_2d = self._is_2D() 1720 1739 self._manager.draw_model(self.model, 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1740 data=self.data, 1741 smearer=temp_smear, 1742 qmin=float(self.qmin_x), 1743 qmax=float(self.qmax_x), 1744 page_id=self.uid, 1745 toggle_mode_on=toggle_mode_on, 1746 state=self.state, 1747 enable2D=is_2d, 1748 update_chisqr=update_chisqr, 1749 source='model', 1750 weight=weight) 1732 1751 1733 1752 def _on_show_sld(self, event=None): … … 1739 1758 1740 1759 from sas.sasgui.plottools import Data1D as pf_data1d 1741 # 1760 #from sas.sasgui.perspectives.theory.profile_dialog import SLDPanel 1742 1761 from sas.sasgui.guiframe.local_perspectives.plotting.profile_dialog \ 1743 1762 import SLDPanel 1744 1763 sld_data = pf_data1d(x, y) 1745 1764 sld_data.name = 'SLD' … … 1794 1813 self.structurebox.Disable() 1795 1814 self.formfactorbox.Clear() 1796 if mod_cat isNone:1815 if mod_cat == None: 1797 1816 return 1798 1817 m_list = [] … … 1856 1875 """ 1857 1876 tcrtl = event.GetEventObject() 1858 # 1877 #Clear msg if previously shown. 1859 1878 msg = "" 1860 1879 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1875 1894 tcrtl.SetBackgroundColour("pink") 1876 1895 msg = "Model Error: wrong value entered: %s" % \ 1877 sys.exc_info()[1]1896 sys.exc_info()[1] 1878 1897 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1879 1898 return … … 1883 1902 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1884 1903 return 1885 # 1886 if self.npts is notNone:1904 #Check if # of points for theory model are valid(>0). 1905 if self.npts != None: 1887 1906 if check_float(self.npts): 1888 1907 temp_npts = float(self.npts.GetValue()) … … 1900 1919 wx.PostEvent(self.parent, event) 1901 1920 self.state_change = False 1902 # 1921 #Draw the model for a different range 1903 1922 if not self.data.is_data: 1904 1923 self.create_default_data() … … 1911 1930 1912 1931 tcrtl = event.GetEventObject() 1913 # 1932 #Clear msg if previously shown. 1914 1933 msg = "" 1915 1934 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1932 1951 tcrtl.SetBackgroundColour("pink") 1933 1952 msg = "Model Error: wrong value entered: %s" % \ 1934 sys.exc_info()[1]1953 sys.exc_info()[1] 1935 1954 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1936 1955 return … … 1940 1959 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1941 1960 return 1942 # 1961 #Check if # of points for theory model are valid(>0). 1943 1962 if self.Npts_total.IsEditable(): 1944 1963 if check_float(self.Npts_total): … … 1958 1977 wx.PostEvent(self.parent, event) 1959 1978 self.state_change = False 1960 # 1979 #Draw the model for a different range 1961 1980 self.create_default_data() 1962 1981 self._draw_model() … … 1966 1985 call back for model selection 1967 1986 """ 1968 # reset dictionary containing reference to dispersion1987 ## reset dictionary containing reference to dispersion 1969 1988 self._disp_obj_dict = {} 1970 1989 self.disp_cb_dict = {} 1971 1990 self.temp_multi_functional = False 1972 1991 f_id = self.formfactorbox.GetCurrentSelection() 1973 # 1992 #For MAC 1974 1993 form_factor = None 1975 1994 if f_id >= 0: … … 1978 1997 if form_factor is None or \ 1979 1998 not hasattr(form_factor, 'is_form_factor') or \ 1980 1999 not form_factor.is_form_factor: 1981 2000 self.structurebox.Hide() 1982 2001 self.text2.Hide() … … 1990 2009 self.text2.Enable() 1991 2010 1992 if form_factor is notNone:2011 if form_factor != None: 1993 2012 # set multifactor for Mutifunctional models 1994 2013 if form_factor.is_multiplicity_model: … … 1998 2017 self._set_multfactor_combobox(multiplicity) 1999 2018 self._show_multfactor_combobox() 2000 # ToDo:this info should be called directly from the model2019 #ToDo: this info should be called directly from the model 2001 2020 text = form_factor.multiplicity_info[1] # 'No. of Shells: ' 2002 2021 … … 2007 2026 2008 2027 self.multi_factor = self.multifactorbox.GetClientData(m_id) 2009 if self.multi_factor isNone:2028 if self.multi_factor == None: 2010 2029 self.multi_factor = 0 2011 2030 self.multifactorbox.SetSelection(m_id) … … 2013 2032 text = '' 2014 2033 if form_factor.multiplicity_info[0] == \ 2015 len(form_factor.multiplicity_info[2]):2034 len(form_factor.multiplicity_info[2]): 2016 2035 text = form_factor.multiplicity_info[2][self.multi_factor] 2017 2036 self.mutifactor_text1.SetLabel(text) … … 2034 2053 struct_factor = self.structurebox.GetClientData(s_id) 2035 2054 2036 if struct_factor is notNone:2037 from sas models.sasview_model import MultiplicationModel2055 if struct_factor != None: 2056 from sas.sascalc.fit.MultiplicationModel import MultiplicationModel 2038 2057 self.model = MultiplicationModel(form_factor(self.multi_factor), 2039 2058 struct_factor()) … … 2041 2060 if len(form_factor.non_fittable) > 0: 2042 2061 self.temp_multi_functional = True 2043 elif form_factor is notNone:2062 elif form_factor != None: 2044 2063 if self.multi_factor is not None: 2045 2064 self.model = form_factor(self.multi_factor) … … 2056 2075 else: 2057 2076 self._has_magnetic = False 2058 # post state to fit panel2077 ## post state to fit panel 2059 2078 self.state.parameters = [] 2060 2079 self.state.model = self.model … … 2066 2085 self.Layout() 2067 2086 2087 2068 2088 def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 2069 2089 """ … … 2085 2105 qmax = float(qmax_ctrl.GetValue()) 2086 2106 if qmin < qmax: 2087 # 2107 #Make sure to set both colours white. 2088 2108 qmin_ctrl.SetBackgroundColour(wx.WHITE) 2089 2109 qmin_ctrl.Refresh() … … 2105 2125 If valid, setvalues Npts_fit otherwise post msg. 2106 2126 """ 2107 # 2127 #default flag 2108 2128 flag = True 2109 2129 # Theory 2110 if self.data isNone and self.enable2D:2130 if self.data == None and self.enable2D: 2111 2131 return flag 2112 2132 for data in self.data_list: … … 2114 2134 radius = numpy.sqrt(data.qx_data * data.qx_data + 2115 2135 data.qy_data * data.qy_data) 2116 # 2136 #get unmasked index 2117 2137 index_data = (float(self.qmin.GetValue()) <= radius) & \ 2118 (radius <= float(self.qmax.GetValue()))2138 (radius <= float(self.qmax.GetValue())) 2119 2139 index_data = (index_data) & (data.mask) 2120 2140 index_data = (index_data) & (numpy.isfinite(data.data)) … … 2132 2152 flag = False 2133 2153 else: 2134 self.Npts_fit.SetValue(str(len(index_data[index_data isTrue])))2154 self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 2135 2155 self.fitrange = True 2136 2156 … … 2142 2162 If valid, setvalues Npts_fit otherwise post msg. 2143 2163 """ 2144 # 2164 #default flag 2145 2165 flag = True 2146 2166 # Theory 2147 if self.data isNone:2167 if self.data == None: 2148 2168 return flag 2149 2169 for data in self.data_list: 2150 2170 # q value from qx and qy 2151 2171 radius = data.x 2152 # 2172 #get unmasked index 2153 2173 index_data = (float(self.qmin.GetValue()) <= radius) & \ 2154 (radius <= float(self.qmax.GetValue()))2174 (radius <= float(self.qmax.GetValue())) 2155 2175 index_data = (index_data) & (numpy.isfinite(data.y)) 2156 2176 … … 2167 2187 flag = False 2168 2188 else: 2169 self.Npts_fit.SetValue(str(len(index_data[index_data isTrue])))2189 self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 2170 2190 self.fitrange = True 2171 2191 … … 2187 2207 is_modified = False 2188 2208 for item in list: 2189 # 2209 #skip angle parameters for 1D 2190 2210 if not self.enable2D and item in self.orientation_params: 2191 2211 continue … … 2232 2252 max_ctrl.SetBackgroundColour("pink") 2233 2253 max_ctrl.Refresh() 2234 # msg = "Invalid fit range for %s: min must be smaller 2235 # than max"%name 2236 # wx.PostEvent(self._manager.parent, 2237 # StatusEvent(status=msg)) 2254 #msg = "Invalid fit range for %s: min must be smaller than max"%name 2255 #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2238 2256 continue 2239 2257 … … 2253 2271 # The configuration has changed but it won't change the 2254 2272 # computed curve so no need to set is_modified to True 2255 # 2273 #is_modified = True 2256 2274 self.model.details[name][1:3] = low, high 2257 2275 … … 2271 2289 Redraw the model with the default dispersity (Gaussian) 2272 2290 """ 2273 # On selction if no model exists.2274 if self.model isNone:2291 ## On selction if no model exists. 2292 if self.model == None: 2275 2293 self.disable_disp.SetValue(True) 2276 2294 msg = "Please select a Model first..." … … 2282 2300 self._reset_dispersity() 2283 2301 2284 if self.model isNone:2302 if self.model == None: 2285 2303 self.model_disp.Hide() 2286 2304 self.sizer4_4.Clear(True) … … 2288 2306 2289 2307 if self.enable_disp.GetValue(): 2290 # layout for model containing no dispersity parameters2308 ## layout for model containing no dispersity parameters 2291 2309 2292 2310 self.disp_list = self.model.getDispParamList() … … 2295 2313 self._layout_sizer_noDipers() 2296 2314 else: 2297 # set gaussian sizer2315 ## set gaussian sizer 2298 2316 self._on_select_Disp(event=None) 2299 2317 else: 2300 2318 self.sizer4_4.Clear(True) 2301 2319 2302 # post state to fit panel2320 ## post state to fit panel 2303 2321 self.save_current_state() 2304 if event is notNone:2322 if event != None: 2305 2323 event = PageInfoEvent(page=self) 2306 2324 wx.PostEvent(self.parent, event) 2307 # 2308 2309 # 2310 # 2311 # 2312 2313 # Need to use FitInside again here to replace the next four lines.2314 # Otherwised polydispersity off does not resize the scrollwindow.2315 # PDB Nov 28, 20152325 #draw the model with the current dispersity 2326 2327 #Wojtek P, Oct 8, 2016: Calling draw_model seems to be unessecary. 2328 #By comenting it we save an extra Iq calculation 2329 #self._draw_model() 2330 2331 ## Need to use FitInside again here to replace the next four lines. 2332 ## Otherwised polydispersity off does not resize the scrollwindow. 2333 ## PDB Nov 28, 2015 2316 2334 self.FitInside() 2317 2335 # self.sizer4_4.Layout() … … 2357 2375 self.weights = {} 2358 2376 2359 # 2377 #from sas.models.dispersion_models import GaussianDispersion 2360 2378 from sasmodels.weights import GaussianDispersion 2361 2379 if len(self.disp_cb_dict) == 0: … … 2378 2396 logging.error(traceback.format_exc()) 2379 2397 2380 # save state into2398 ## save state into 2381 2399 self.save_current_state() 2382 2400 self.Layout() … … 2390 2408 self._set_sizer_dispersion() 2391 2409 2392 # Redraw the model2410 ## Redraw the model 2393 2411 self._draw_model() 2394 # 2412 #self._undo.Enable(True) 2395 2413 event = PageInfoEvent(page=self) 2396 2414 wx.PostEvent(self.parent, event) … … 2407 2425 """ 2408 2426 # get ready for new event 2409 if event is notNone:2427 if event != None: 2410 2428 event.Skip() 2411 2429 # Get event object … … 2420 2438 dispersity = disp_box.GetClientData(selection) 2421 2439 2422 # 2440 #disp_model = GaussianDispersion() 2423 2441 disp_model = dispersity() 2424 2442 # Get param names to reset the values of the param … … 2433 2451 else: 2434 2452 self._del_array_values(name1) 2435 # 2453 #self._reset_array_disp(param_name) 2436 2454 self._disp_obj_dict[name1] = disp_model 2437 2455 self.model.set_dispersion(param_name, disp_model) … … 2481 2499 item[2].Enable() 2482 2500 2483 # Make sure the check box updated 2484 self.get_all_checked_params() 2501 # Make sure the check box updated when all checked 2502 if self.cb1.GetValue(): 2503 #self.select_all_param(None) 2504 self.get_all_checked_params() 2485 2505 2486 2506 # update params … … 2517 2537 if path is None: 2518 2538 self.disp_cb_dict[name].SetValue(False) 2519 # 2539 #self.noDisper_rbox.SetValue(True) 2520 2540 return 2521 2541 self._default_save_location = os.path.dirname(path) 2522 if self._manager is notNone:2542 if self._manager != None: 2523 2543 self._manager.parent._default_save_location = \ 2524 2544 self._default_save_location … … 2537 2557 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2538 2558 self._set_array_disp_model(name=name, disp=disp, 2539 values=values, weights=weights)2559 values=values, weights=weights) 2540 2560 return basename 2541 2561 … … 2556 2576 # Store the object to make it persist outside the 2557 2577 # scope of this method 2558 # 2578 #TODO: refactor model to clean this up? 2559 2579 self.state.values = {} 2560 2580 self.state.weights = {} … … 2563 2583 2564 2584 # Set the new model as the dispersion object for the 2565 # 2566 # 2585 #selected parameter 2586 #self.model.set_dispersion(p, disp_model) 2567 2587 # Store a reference to the weights in the model object 2568 # 2588 #so that 2569 2589 # it's not lost when we use the model within another thread. 2570 2590 self.state.model = self.model.clone() 2571 2591 self.model._persistency_dict[name.split('.')[0]] = \ 2572 [values, weights]2592 [values, weights] 2573 2593 self.state.model._persistency_dict[name.split('.')[0]] = \ 2574 [values, weights]2594 [values, weights] 2575 2595 2576 2596 def _del_array_values(self, name=None): … … 2610 2630 Layout after self._draw_model 2611 2631 """ 2612 if ON_MAC isTrue:2632 if ON_MAC == True: 2613 2633 time.sleep(1) 2614 2634 … … 2632 2652 """ 2633 2653 flag = True 2634 # 2635 if self.model isNone:2654 ##For 3 different cases: Data2D, Data1D, and theory 2655 if self.model == None: 2636 2656 msg = "Please select a model first..." 2637 2657 wx.MessageBox(msg, 'Info') … … 2645 2665 self.qmin_x = data_min 2646 2666 self.qmax_x = math.sqrt(x * x + y * y) 2647 # 2667 #self.data.mask = numpy.ones(len(self.data.data),dtype=bool) 2648 2668 # check smearing 2649 2669 if not self.disable_smearer.GetValue(): 2650 # set smearing value whether or2670 ## set smearing value whether or 2651 2671 # not the data contain the smearing info 2652 2672 if self.pinhole_smearer.GetValue(): … … 2655 2675 flag = True 2656 2676 2657 elif self.data isNone:2677 elif self.data == None: 2658 2678 self.qmin_x = _QMIN_DEFAULT 2659 2679 self.qmax_x = _QMAX_DEFAULT … … 2666 2686 # check smearing 2667 2687 if not self.disable_smearer.GetValue(): 2668 # set smearing value whether or2688 ## set smearing value whether or 2669 2689 # not the data contain the smearing info 2670 2690 if self.slit_smearer.GetValue(): … … 2677 2697 flag = False 2678 2698 2679 if flag isFalse:2699 if flag == False: 2680 2700 msg = "Cannot Plot :Must enter a number!!! " 2681 2701 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 2694 2714 self.state.qmax = self.qmax_x 2695 2715 2696 # 2716 #reset the q range values 2697 2717 self._reset_plotting_range(self.state) 2698 2718 self._draw_model() … … 2735 2755 logging.error(traceback.format_exc()) 2736 2756 # Make sure the resduals plot goes to the last 2737 if res_item is notNone:2757 if res_item != None: 2738 2758 graphs.append(res_item[0]) 2739 2759 canvases.append(res_item[1]) … … 2754 2774 the # to the browser. 2755 2775 2756 :param ev ent: on Help Button pressed event2757 """ 2758 2759 if self.model is notNone:2776 :param evt: on Help Button pressed event 2777 """ 2778 2779 if self.model != None: 2760 2780 name = self.formfactorbox.GetValue() 2761 _TreeLocation = 'user/models/' 2781 _TreeLocation = 'user/models/'+ name.lower()+'.html' 2762 2782 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 2763 2783 "", name + " Help") … … 2766 2786 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 2767 2787 "", "General Model Help") 2788 2768 2789 2769 2790 def on_model_help_clicked(self, event): … … 2777 2798 give the message that none is available. 2778 2799 2779 :param ev ent: on Description Button pressed event2780 """ 2781 2782 if self.model isNone:2800 :param evt: on Description Button pressed event 2801 """ 2802 2803 if self.model == None: 2783 2804 name = 'index.html' 2784 2805 else: … … 2787 2808 msg = 'Model description:\n' 2788 2809 info = "Info" 2789 if self.model is notNone:2790 #frame.Destroy()2810 if self.model != None: 2811 # frame.Destroy() 2791 2812 if str(self.model.description).rstrip().lstrip() == '': 2792 2813 msg += "Sorry, no information is available for this model." … … 2857 2878 for key in self.model.magnetic_params: 2858 2879 if key.count('M0') > 0: 2859 # 2880 #reset mag value to zero fo safety 2860 2881 self.model.setParam(key, 0.0) 2861 2882 2862 2883 self.Show(False) 2863 2884 self.set_model_param_sizer(self.model) 2864 # 2885 #self._set_sizer_dispersion() 2865 2886 self.state.magnetic_on = self.magnetic_on 2866 2887 self.SetupScrolling() … … 2877 2898 running "file:///...." 2878 2899 2879 :param ev ent: Triggers on clicking ? in polydispersity box2900 :param evt: Triggers on clicking ? in polydispersity box 2880 2901 """ 2881 2902 … … 2915 2936 content = 'sasview_parameter_values:' 2916 2937 # Do it if params exist 2917 if self.parameters:2938 if self.parameters != []: 2918 2939 2919 2940 # go through the parameters … … 2959 2980 2960 2981 # Do it if params exist 2961 if self.parameters:2982 if self.parameters != []: 2962 2983 2963 2984 for param in self.parameters: 2964 content += param[1] #parameter name2985 content += param[1] #parameter name 2965 2986 content += tab 2966 2987 content += param[1] + "_err" … … 2969 2990 content += crlf 2970 2991 2971 # 2992 #row of values and errors... 2972 2993 for param in self.parameters: 2973 content += param[2].GetValue() #value2994 content += param[2].GetValue() #value 2974 2995 content += tab 2975 content += param[4].GetValue() #error2996 content += param[4].GetValue() #error 2976 2997 content += tab 2977 2998 … … 2979 3000 else: 2980 3001 return False 3002 2981 3003 2982 3004 def get_copy_latex(self): … … 3000 3022 3001 3023 # Do it if params exist 3002 if self.parameters:3024 if self.parameters != []: 3003 3025 3004 3026 content += '{|' … … 3009 3031 3010 3032 for index, param in enumerate(self.parameters): 3011 content += param[1].replace('_', '\_') #parameter name3033 content += param[1].replace('_', '\_') #parameter name 3012 3034 content += ' & ' 3013 3035 content += param[1].replace('_', '\_') + "\_err" … … 3017 3039 content += crlf 3018 3040 3019 # 3041 #row of values and errors... 3020 3042 for index, param in enumerate(self.parameters): 3021 content += param[2].GetValue() #parameter value3043 content += param[2].GetValue() #parameter value 3022 3044 content += ' & ' 3023 content += param[4].GetValue() #parameter error3045 content += param[4].GetValue() #parameter error 3024 3046 if index < len(self.parameters) - 1: 3025 3047 content += ' & ' … … 3032 3054 else: 3033 3055 return False 3056 3034 3057 3035 3058 def set_clipboard(self, content=None): … … 3078 3101 # 1D 3079 3102 else: 3080 # for 1D all parameters except orientation3103 ## for 1D all parameters except orientation 3081 3104 if not item[1] in orient_param: 3082 3105 try: … … 3110 3133 except Exception: 3111 3134 logging.error(traceback.format_exc()) 3112 content += name + ',' + str(check) + ',' + value + disfunc + ',' + \ 3113 bound_lo + ',' + bound_hi + ':' 3135 content += name + ',' + str(check) + ',' +\ 3136 value + disfunc + ',' + bound_lo + ',' +\ 3137 bound_hi + ':' 3114 3138 3115 3139 return content … … 3189 3213 3190 3214 # Do it if params exist 3191 if self.parameters:3215 if self.parameters != []: 3192 3216 # go through the parameters 3193 3217 self._get_paste_helper(self.parameters, … … 3237 3261 pd = int(pd) 3238 3262 except Exception: 3239 # 3263 #continue 3240 3264 if not pd and pd != '': 3241 3265 continue … … 3265 3289 else: 3266 3290 is_true = None 3267 if is_true is notNone:3291 if is_true != None: 3268 3292 item[0].SetValue(is_true) 3269 3293 # 1D 3270 3294 else: 3271 # for 1D all parameters except orientation3295 ## for 1D all parameters except orientation 3272 3296 if not item[1] in orient_param: 3273 3297 name = item[1] … … 3278 3302 pd = value[0] 3279 3303 if name.count('.') > 0: 3280 # If this is parameter.width, then pd may be a 3281 # floating point value or it may be an array 3282 # distribution. Nothing to do for parameter.npts or 3283 # parameter.nsigmas. 3304 # If this is parameter.width, then pd may be a floating 3305 # point value or it may be an array distribution. 3306 # Nothing to do for parameter.npts or parameter.nsigmas. 3284 3307 try: 3285 3308 pd = float(pd) … … 3287 3310 pd = int(pd) 3288 3311 except: 3289 # 3312 #continue 3290 3313 if not pd and pd != '': 3291 3314 continue … … 3315 3338 else: 3316 3339 is_true = None 3317 if is_true is notNone:3340 if is_true != None: 3318 3341 item[0].SetValue(is_true) 3319 3320 self.select_param(event=None)3321 self.Refresh()3322 3342 3323 3343 def _paste_poly_help(self, item, value): … … 3382 3402 logging.error(traceback.format_exc()) 3383 3403 print "Error in BasePage._paste_poly_help: %s" % \ 3384 sys.exc_info()[1]3404 sys.exc_info()[1] 3385 3405 3386 3406 def _set_disp_cb(self, isarray, item): … … 3448 3468 self.categorybox.Clear() 3449 3469 cat_list = sorted(self.master_category_dict.keys()) 3450 if uncat_str notin cat_list:3470 if not uncat_str in cat_list: 3451 3471 cat_list.append(uncat_str) 3452 3472 … … 3458 3478 self.categorybox.SetSelection(0) 3459 3479 else: 3460 self.categorybox.SetSelection( 3480 self.categorybox.SetSelection(\ 3461 3481 self.categorybox.GetSelection()) 3462 # 3482 #self._on_change_cat(None) 3463 3483 3464 3484 def _on_change_cat(self, event): … … 3468 3488 self.model_name = None 3469 3489 category = self.categorybox.GetStringSelection() 3470 if category isNone:3490 if category == None: 3471 3491 return 3472 3492 self.model_box.Clear() … … 3479 3499 else: 3480 3500 for (model, enabled) in sorted(self.master_category_dict[category], 3481 3501 key=lambda name: name[0]): 3482 3502 if(enabled): 3483 3503 self.model_box.Append(model) … … 3488 3508 """ 3489 3509 # This should only be called once per fit tab 3490 # 3491 # 3492 # 3510 #print "==== Entering _fill_model_sizer" 3511 ##Add model function Details button in fitpanel. 3512 ##The following 3 lines are for Mac. Let JHC know before modifying... 3493 3513 title = "Model" 3494 3514 self.formfactorbox = None … … 3522 3542 self._populate_listbox() 3523 3543 wx.EVT_COMBOBOX(self.categorybox, wx.ID_ANY, self._show_combox) 3524 # 3544 #self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes', 3525 3545 # style=wx.RB_GROUP) 3526 # 3546 #self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY, 3527 3547 # "Shape-Independent") 3528 # 3548 #self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY, 3529 3549 # "Structure Factor ") 3530 # 3550 #self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY, 3531 3551 # "Uncategorized") 3532 3552 3533 # 3553 #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3534 3554 # id=self.shape_rbutton.GetId()) 3535 # 3555 #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3536 3556 # id=self.shape_indep_rbutton.GetId()) 3537 # 3557 #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3538 3558 # id=self.struct_rbutton.GetId()) 3539 # 3559 #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3540 3560 # id=self.plugin_rbutton.GetId()) 3541 # 3561 #MAC needs SetValue 3542 3562 3543 3563 show_cat_button = wx.Button(self, wx.ID_ANY, "Modify") 3544 3564 cat_tip = "Modify model categories \n" 3545 3565 cat_tip += "(also accessible from the menu bar)." 3546 show_cat_button.SetToolTip( wx.ToolTip(cat_tip))3566 show_cat_button.SetToolTip( wx.ToolTip(cat_tip) ) 3547 3567 show_cat_button.Bind(wx.EVT_BUTTON, self._on_modify_cat) 3548 3568 sizer_cat_box.Add(self.categorybox, 1, wx.RIGHT, 3) 3549 sizer_cat_box.Add((10, 3569 sizer_cat_box.Add((10,10)) 3550 3570 sizer_cat_box.Add(show_cat_button) 3551 # 3571 #self.shape_rbutton.SetValue(True) 3552 3572 3553 3573 sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) 3554 # 3555 # 3556 sizer_radiobutton.Add((5, 3574 #sizer_radiobutton.Add(self.shape_rbutton) 3575 #sizer_radiobutton.Add(self.shape_indep_rbutton) 3576 sizer_radiobutton.Add((5,5)) 3557 3577 sizer_radiobutton.Add(self.model_view, 1, wx.RIGHT, 5) 3558 # 3559 # 3560 #sizer_radiobutton.Add((5,5))3578 #sizer_radiobutton.Add(self.plugin_rbutton) 3579 #sizer_radiobutton.Add(self.struct_rbutton) 3580 # sizer_radiobutton.Add((5,5)) 3561 3581 sizer_radiobutton.Add(self.model_help, 1, wx.RIGHT | wx.LEFT, 5) 3562 #sizer_radiobutton.Add((5,5))3582 # sizer_radiobutton.Add((5,5)) 3563 3583 sizer_radiobutton.Add(self.model_func, 1, wx.RIGHT, 5) 3564 3584 sizer_cat.Add(sizer_cat_box, 1, wx.LEFT, 2.5) … … 3576 3596 self.formfactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 3577 3597 self.formfactorbox.SetToolTip(wx.ToolTip("Select a Model")) 3578 if self.model is notNone:3598 if self.model != None: 3579 3599 self.formfactorbox.SetValue(self.model.name) 3580 3600 self.structurebox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) … … 3585 3605 wx.EVT_COMBOBOX(self.structurebox, wx.ID_ANY, self._on_select_model) 3586 3606 wx.EVT_COMBOBOX(self.multifactorbox, wx.ID_ANY, self._on_select_model) 3587 # check model type to show sizer3588 if self.model is notNone:3607 ## check model type to show sizer 3608 if self.model != None: 3589 3609 print "_set_model_sizer_selection: disabled." 3590 # 3610 #self._set_model_sizer_selection(self.model) 3591 3611 3592 3612 sizer_selection.Add(self.text1) … … 3661 3681 call back for model selection if implemented 3662 3682 """ 3683 def select_all_param(self, event): 3684 """ 3685 set to true or false all checkBox if implemented 3686 """ 3663 3687 def get_weight_flag(self): 3664 3688 """ … … 3682 3706 toggle view of model from 1D to 2D or 2D from 1D if implemented 3683 3707 """ 3684 3685 3708 3686 3709 class ModelTextCtrl(wx.TextCtrl): … … 3696 3719 3697 3720 """ 3698 # Set to True when the mouse is clicked while whole string is selected3721 ## Set to True when the mouse is clicked while whole string is selected 3699 3722 full_selection = False 3700 # Call back for EVT_SET_FOCUS events3723 ## Call back for EVT_SET_FOCUS events 3701 3724 _on_set_focus_callback = None 3702 3725 … … 3720 3743 if set_focus_callback is None else set_focus_callback 3721 3744 self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) 3722 self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus 3723 if kill_focus_callback is None else kill_focus_callback)3724 self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter 3725 if text_enter_callback is None else text_enter_callback)3745 self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus \ 3746 if kill_focus_callback is None else kill_focus_callback) 3747 self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \ 3748 if text_enter_callback is None else text_enter_callback) 3726 3749 if not ON_MAC: 3727 self.Bind(wx.EVT_LEFT_UP, self._highlight_text 3728 if mouse_up_callback is None else mouse_up_callback)3750 self.Bind(wx.EVT_LEFT_UP, self._highlight_text \ 3751 if mouse_up_callback is None else mouse_up_callback) 3729 3752 3730 3753 def _on_set_focus(self, event): … … 3766 3789 3767 3790 event.Skip() 3768 # 3791 #pass
Note: See TracChangeset
for help on using the changeset viewer.