Changeset c8e1996 in sasview for src/sas/sasgui/perspectives/fitting/basepage.py
- Timestamp:
- Oct 20, 2016 3:54:06 PM (8 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, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 880e845, cf1910f
- Parents:
- 8b645cc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
r313c5c9 rc8e1996 19 19 20 20 from sas.sasgui.guiframe.panel_base import PanelBase 21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList, check_int 21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList, \ 22 check_int 22 23 from sas.sasgui.guiframe.events import PanelOnFocusEvent 23 24 from sas.sasgui.guiframe.events import StatusEvent … … 42 43 _QMAX_DEFAULT = 0.5 43 44 _NPTS_DEFAULT = 50 44 # Control panel width45 # Control panel width 45 46 if sys.platform.count("win32") > 0: 46 47 PANEL_WIDTH = 450 … … 57 58 This class provide general structure of fitpanel page 58 59 """ 59 # #Internal name for the AUI manager60 # Internal name for the AUI manager 60 61 window_name = "Fit Page" 61 # #Title to appear on top of the window62 # Title to appear on top of the window 62 63 window_caption = "Fit Page " 63 64 … … 75 76 PanelBase.__init__(self, parent) 76 77 self.SetupScrolling() 77 # Set window's font size78 # Set window's font size 78 79 self.SetWindowVariant(variant=FONT_VARIANT) 79 80 self.SetBackgroundColour(color) 80 81 81 82 self._ids = iter(self._id_pool) 82 # #parent of the page83 # parent of the page 83 84 self.parent = parent 84 # #manager is the fitting plugin85 # #owner of the page (fitting plugin)85 # manager is the fitting plugin 86 # owner of the page (fitting plugin) 86 87 self.event_owner = None 87 # #current model88 # current model 88 89 self.model = None 89 90 self.m_name = None 90 91 self.index_model = None 91 92 self.panel = None 92 # #data93 # data 93 94 self.data = None 94 # list of available data95 # list of available data 95 96 self.data_list = [] 96 97 self.mask = None 97 98 self.uid = wx.NewId() 98 99 self.graph_id = None 99 # Q range for data set100 # Q range for data set 100 101 self.qmin_data_set = numpy.inf 101 102 self.qmax_data_set = None 102 103 self.npts_data_set = 0 103 # #Q range104 # Q range 104 105 self.qmin = None 105 106 self.qmax = None … … 107 108 self.qmin_x = _QMIN_DEFAULT 108 109 self.npts_x = _NPTS_DEFAULT 109 # #total number of point: float110 # total number of point: float 110 111 self.npts = None 111 112 self.num_points = None 112 # #smear default113 # smear default 113 114 self.current_smearer = None 114 # #2D smear accuracy default115 # 2D smear accuracy default 115 116 self.smear2d_accuracy = 'Low' 116 # #slit smear:117 # slit smear: 117 118 self.dxl = None 118 119 self.dxw = None 119 # #pinhole smear120 # pinhole smear 120 121 self.dx_min = None 121 122 self.dx_max = None 122 # #semar attrbs123 # smear attrbs 123 124 self.enable_smearer = None 124 125 self.disable_smearer = None 125 126 self.pinhole_smearer = None 126 127 self.slit_smearer = None 127 # #weigthattrbs128 # weight attrbs 128 129 self.dI_noweight = None 129 130 self.dI_didata = None 130 131 self.dI_sqrdata = None 131 132 self.dI_idata = None 132 # #other attrbs133 # other attrbs 133 134 self.dq_l = None 134 135 self.dq_r = None … … 149 150 self.disp_cb_dict = {} 150 151 151 # self.state = PageState(parent=parent)152 # #dictionary containing list of models152 # self.state = PageState(parent=parent) 153 # dictionary containing list of models 153 154 self.model_list_box = {} 154 155 155 # #Data member to store the dispersion object created156 # Data member to store the dispersion object created 156 157 self._disp_obj_dict = {} 157 # #selected parameters to apply dispersion158 # selected parameters to apply dispersion 158 159 self.disp_cb_dict = {} 159 # #smearer object160 # smearer object 160 161 self.enable2D = False 161 162 self._has_magnetic = False … … 165 166 self.structurebox = None 166 167 self.categorybox = None 167 # #list of model parameters. each item must have same length168 # #each item related to a given parameters169 # #[cb state, name, value, "+/-", error of fit, min, max , units]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] 170 171 self.parameters = [] 171 172 # non-fittable parameter whose value is astring 172 173 self.str_parameters = [] 173 # #list of parameters to fit , must be like self.parameters174 # list of parameters to fit , must be like self.parameters 174 175 self.param_toFit = [] 175 # #list of looking like parameters but with non fittable parameters info176 # list of looking like parameters but with non fittable parameters info 176 177 self.fixed_param = [] 177 # #list of looking like parameters but with fittable parameters info178 # list of looking like parameters but with fittable parameters info 178 179 self.fittable_param = [] 179 # #list of dispersion parameters180 # list of dispersion parameters 180 181 self.disp_list = [] 181 182 self.disp_name = "" 182 183 183 # #list of orientation parameters184 # list of orientation parameters 184 185 self.orientation_params = [] 185 186 self.orientation_params_disp = [] … … 188 189 # and this - commenting out on 4/8/2014 by PDB. Remove once clear 189 190 # it is pointless. 190 # if self.model !=None:191 # if self.model is not None: 191 192 # self.disp_list = self.model.getDispParamList() 192 193 self.temp_multi_functional = False 193 # #enable model 2D draw194 # enable model 2D draw 194 195 self.enable2D = False 195 # #check that the fit range is correct to plot the model again196 # check that the fit range is correct to plot the model again 196 197 self.fitrange = True 197 # #Create memento to save the current state198 # Create memento to save the current state 198 199 self.state = PageState(parent=self.parent, 199 200 model=self.model, data=self.data) 200 # #flag to determine if state has change201 # flag to determine if state has change 201 202 self.state_change = False 202 # #save customized array203 # save customized array 203 204 self.values = {} # type: Dict[str, List[float, ...]] 204 205 self.weights = {} # type: Dict[str, List[float, ...]] 205 # #retrieve saved state206 # retrieve saved state 206 207 self.number_saved_state = 0 207 # #dictionary of saved state208 # dictionary of saved state 208 209 self.saved_states = {} 209 # #Create context menu for page210 # Create context menu for page 210 211 self.popUpMenu = wx.Menu() 211 212 … … 220 221 self.popUpMenu.AppendSeparator() 221 222 222 # #Default locations223 # Default locations 223 224 self._default_save_location = os.getcwd() 224 # #save initial state on context menu225 # self.onSave(event=None)225 # save initial state on context menu 226 # self.onSave(event=None) 226 227 self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 227 228 … … 229 230 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) 230 231 231 # #create the basic structure of the panel with empty sizer232 # create the basic structure of the panel with empty sizer 232 233 self.define_page_structure() 233 # #drawing Initial dispersion parameters sizer234 # drawing Initial dispersion parameters sizer 234 235 self.set_dispers_sizer() 235 236 236 # #layout237 # layout 237 238 self.set_layout() 238 239 … … 260 261 self._create_default_1d_data() 261 262 262 if self.model !=None:263 if self.model is not None: 263 264 if not self.data.is_data: 264 self._manager.page_finder[self.uid].set_fit_data( data=\265 265 self._manager.page_finder[self.uid].set_fit_data( 266 data=[self.data]) 266 267 self.on_smear_helper(update=True) 267 268 self.state.enable_smearer = self.enable_smearer.GetValue() … … 325 326 self.data.id = str(self.uid) + " data" 326 327 self.data.group_id = str(self.uid) + " Model2D" 327 # #Default values328 # Default values 328 329 self.data.detector.append(Detector()) 329 330 index = len(self.data.detector) - 1 … … 342 343 x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 343 344 y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 344 # #use data info instead345 # use data info instead 345 346 new_x = numpy.tile(x, (len(y), 1)) 346 347 new_y = numpy.tile(y, (len(x), 1)) … … 383 384 Update menu1 on cliking the page tap 384 385 """ 385 if self._manager.menu1 !=None:386 chain_menu = self._manager.menu1.FindItemById( \386 if self._manager.menu1 is not None: 387 chain_menu = self._manager.menu1.FindItemById( 387 388 self._manager.id_reset_flag) 388 389 chain_menu.Enable(self.batch_on) 389 390 sim_menu = self._manager.menu1.FindItemById(self._manager.id_simfit) 390 391 flag = self.data.is_data\ 391 and (self.model !=None)392 and (self.model is not None) 392 393 sim_menu.Enable(not self.batch_on and flag) 393 394 batch_menu = \ … … 530 531 fill sizer containing dispersity info 531 532 """ 532 # print "==== entering set_dispers_sizer ==="533 # print "==== entering set_dispers_sizer ===" 533 534 self.sizer4.Clear(True) 534 535 name = "Polydispersity and Orientational Distribution" … … 536 537 box_description.SetForegroundColour(wx.BLUE) 537 538 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 538 # ----------------------------------------------------539 # ---------------------------------------------------- 539 540 self.disable_disp = wx.RadioButton(self, wx.ID_ANY, 'Off', (10, 10), 540 541 style=wx.RB_GROUP) … … 556 557 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 557 558 id=self.enable_disp.GetId()) 558 # MAC needs SetValue559 # MAC needs SetValue 559 560 self.disable_disp.SetValue(True) 560 561 sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) … … 568 569 sizer_dispersion.Add(self.disp_help_bt) 569 570 570 # #fill a sizer for dispersion571 # fill a sizer for dispersion 571 572 boxsizer1.Add(sizer_dispersion, 0, 572 573 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, … … 575 576 576 577 boxsizer1.Add(self.sizer4_4) 577 # -----------------------------------------------------578 # ----------------------------------------------------- 578 579 self.sizer4.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 579 580 self.sizer4_4.Layout() … … 582 583 583 584 self.Refresh() 584 # #saving the state of enable dispersity button585 # saving the state of enable dispersity button 585 586 self.state.enable_disp = self.enable_disp.GetValue() 586 587 self.state.disable_disp = self.disable_disp.GetValue() … … 592 593 """ 593 594 menu = event.GetEventObject() 594 # #post help message for the selected model595 # post help message for the selected model 595 596 msg = menu.GetHelpString(event.GetId()) 596 597 msg += " reloaded" … … 599 600 name = menu.GetLabel(event.GetId()) 600 601 self._on_select_model_helper() 601 if self.model !=None:602 if self.model is not None: 602 603 self.m_name = self.model.name 603 604 if name in self.saved_states.keys(): 604 605 previous_state = self.saved_states[name] 605 # #reset state of checkbox,textcrtl and regular parameters value606 # reset state of checkbox,textcrtl and regular parameters value 606 607 607 608 self.reset_page(previous_state) … … 626 627 # Ask the user the location of the file to write to. 627 628 path = None 628 if self.parent !=None:629 if self.parent is not None: 629 630 self._default_save_location = \ 630 631 self._manager.parent._default_save_location … … 636 637 self._default_save_location = os.path.dirname(path) 637 638 self._manager.parent._default_save_location = \ 638 639 self._default_save_location 639 640 else: 640 641 return None … … 643 644 # Make sure the ext included in the file name 644 645 fName = os.path.splitext(path)[0] + extens 645 # the manager write the state into file646 # the manager write the state into file 646 647 self._manager.save_fit_state(filepath=fName, fitstate=new_state) 647 648 return new_state … … 651 652 Copy Parameter values to the clipboad 652 653 """ 653 if event !=None:654 if event is not None: 654 655 event.Skip() 655 656 # It seems MAC needs wxCallAfter … … 667 668 Paste Parameter values to the panel if possible 668 669 """ 669 # if event !=None:670 # if event is not None: 670 671 # event.Skip() 671 672 # It seems MAC needs wxCallAfter for the setvalues … … 673 674 wx.CallAfter(self.get_paste) 674 675 # messages depending on the flag 675 # self._copy_info(True)676 # self._copy_info(True) 676 677 677 678 def _copy_info(self, flag): … … 682 683 """ 683 684 # messages depending on the flag 684 if flag ==None:685 if flag is None: 685 686 msg = " Parameter values are copied to the clipboard..." 686 687 infor = 'warning' … … 710 711 save history of the data and model 711 712 """ 712 if self.model ==None:713 if self.model is None: 713 714 msg = "Can not bookmark; Please select Data and Model first..." 714 715 wx.MessageBox(msg, 'Info') … … 716 717 self.save_current_state() 717 718 new_state = self.state.clone() 718 # #Add model state on context menu719 # Add model state on context menu 719 720 self.number_saved_state += 1 720 721 current_time, current_date = self._get_time_stamp() 721 # name= self.model.name+"[%g]"%self.number_saved_state722 # name= self.model.name+"[%g]"%self.number_saved_state 722 723 name = "Fitting: %g]" % self.number_saved_state 723 724 name += self.model.__class__.__name__ … … 725 726 self.saved_states[name] = new_state 726 727 727 # #Add item in the context menu728 # Add item in the context menu 728 729 msg = "Model saved at %s on %s" % (current_time, current_date) 729 # #post help message for the selected model730 # post help message for the selected model 730 731 msg += " Saved! right click on this page to retrieve this model" 731 732 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 761 762 """ 762 763 try: 763 if path ==None:764 if path is None: 764 765 status = " Selected Distribution was not loaded: %s" % path 765 766 wx.PostEvent(self._manager.parent, … … 796 797 Store current state 797 798 """ 798 # #save model option799 if self.model !=None:799 # save model option 800 if self.model is not None: 800 801 self.disp_list = self.model.getDispParamList() 801 802 self.state.disp_list = copy.deepcopy(self.disp_list) 802 803 self.state.model = self.model.clone() 803 804 804 # model combobox: complex code because of mac's silent error805 if self.structurebox !=None:805 # model combobox: complex code because of mac's silent error 806 if self.structurebox is not None: 806 807 if self.structurebox.IsShown(): 807 808 self.state.structurecombobox = 'None' 808 809 s_select = self.structurebox.GetSelection() 809 810 if s_select > 0: 810 self.state.structurecombobox = self.structurebox.\811 GetString(s_select)812 if self.formfactorbox !=None:811 self.state.structurecombobox = \ 812 self.structurebox.GetString(s_select) 813 if self.formfactorbox is not None: 813 814 f_select = self.formfactorbox.GetSelection() 814 815 if f_select > 0: 815 self.state.formfactorcombobox = self.formfactorbox.\816 GetString(f_select)817 if self.categorybox !=None:816 self.state.formfactorcombobox = \ 817 self.formfactorbox.GetString(f_select) 818 if self.categorybox is not None: 818 819 cb_select = self.categorybox.GetSelection() 819 820 if cb_select > 0: 820 self.state.categorycombobox = self.categorybox.\821 GetString(cb_select)821 self.state.categorycombobox = \ 822 self.categorybox.GetString(cb_select) 822 823 823 824 self.state.enable2D = copy.deepcopy(self.enable2D) 824 825 self.state.values = copy.deepcopy(self.values) 825 826 self.state.weights = copy.deepcopy(self.weights) 826 # #save data827 # save data 827 828 self.state.data = copy.deepcopy(self.data) 828 829 self.state.qmax_x = self.qmax_x … … 859 860 self.state.values = copy.deepcopy(self.values) 860 861 self.state.weights = copy.deepcopy(self.weights) 861 # #save plotting range862 # save plotting range 862 863 self._save_plotting_range() 863 864 … … 869 870 self.state.str_parameters = [] 870 871 871 # #save checkbutton state and txtcrtl values872 # save checkbutton state and txtcrtl values 872 873 self._copy_parameters_state(self.str_parameters, 873 874 self.state.str_parameters) … … 881 882 self.state.fittable_param) 882 883 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 883 # save chisqr884 # save chisqr 884 885 self.state.tcChi = self.tcChi.GetValue() 885 886 … … 888 889 Store current state for fit_page 889 890 """ 890 # #save model option891 if self.model !=None:891 # save model option 892 if self.model is not None: 892 893 self.disp_list = self.model.getDispParamList() 893 894 self.state.disp_list = copy.deepcopy(self.disp_list) … … 897 898 self.state.values = copy.deepcopy(self.values) 898 899 self.state.weights = copy.deepcopy(self.weights) 899 # #save data900 # save data 900 901 self.state.data = copy.deepcopy(self.data) 901 902 … … 918 919 self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) 919 920 self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) 920 if hasattr(self, "disp_box") and self.disp_box !=None:921 if hasattr(self, "disp_box") and self.disp_box is not None: 921 922 self.state.disp_box = self.disp_box.GetCurrentSelection() 922 923 923 924 if len(self.disp_cb_dict) > 0: 924 925 for k, v in self.disp_cb_dict.iteritems(): 925 if v ==None:926 if v is None: 926 927 self.state.disp_cb_dict[k] = v 927 928 else: … … 937 938 self.state.weights = copy.deepcopy(self.weights) 938 939 939 # #save plotting range940 # save plotting range 940 941 self._save_plotting_range() 941 942 942 # #save checkbutton state and txtcrtl values943 # save checkbutton state and txtcrtl values 943 944 self._copy_parameters_state(self.orientation_params, 944 945 self.state.orientation_params) … … 959 960 msg = "Please load Data and select Model to start..." 960 961 wx.MessageBox(msg, 'Info') 961 return 962 return True 962 963 963 964 def set_model_state(self, state): … … 968 969 self.disp_list = state.disp_list 969 970 970 # #fill model combobox971 # fill model combobox 971 972 self._show_combox_helper() 972 # select the current model973 # select the current model 973 974 try: 974 975 # to support older version … … 1009 1010 self.structurebox.SetSelection(structfactor_pos) 1010 1011 1011 if state.multi_factor !=None:1012 if state.multi_factor is not None: 1012 1013 self.multifactorbox.SetSelection(state.multi_factor) 1013 1014 1014 # #reset state of checkbox,textcrtl and regular parameters value1015 # reset state of checkbox,textcrtl and regular parameters value 1015 1016 self._reset_parameters_state(self.orientation_params_disp, 1016 1017 state.orientation_params_disp) … … 1020 1021 state.str_parameters) 1021 1022 self._reset_parameters_state(self.parameters, state.parameters) 1022 # #display dispersion info layer1023 # display dispersion info layer 1023 1024 self.enable_disp.SetValue(state.enable_disp) 1024 1025 self.disable_disp.SetValue(state.disable_disp) 1025 1026 1026 if hasattr(self, "disp_box") and self.disp_box !=None:1027 if hasattr(self, "disp_box") and self.disp_box is not None: 1027 1028 self.disp_box.SetSelection(state.disp_box) 1028 1029 n = self.disp_box.GetCurrentSelection() … … 1036 1037 1037 1038 if hasattr(self.disp_cb_dict[item], "SetValue"): 1038 self.disp_cb_dict[item].SetValue( \1039 self.disp_cb_dict[item].SetValue( 1039 1040 state.disp_cb_dict[item]) 1040 1041 # Create the dispersion objects 1041 1042 disp_model = POLYDISPERSITY_MODELS['array']() 1042 1043 if hasattr(state, "values") and \ 1043 self.disp_cb_dict[item].GetValue() ==True:1044 self.disp_cb_dict[item].GetValue() is True: 1044 1045 if len(state.values) > 0: 1045 1046 self.values = state.values … … 1052 1053 self._disp_obj_dict[item] = disp_model 1053 1054 # Set the new model as the dispersion object 1054 # for the selected parameter1055 # for the selected parameter 1055 1056 self.model.set_dispersion(item, disp_model) 1056 1057 … … 1062 1063 for item in keys: 1063 1064 if item in self.disp_list and \ 1064 not itemin self.model.details:1065 item not in self.model.details: 1065 1066 self.model.details[item] = ["", None, None] 1066 1067 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1067 1068 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1068 # #smearing info restore1069 # smearing info restore 1069 1070 if hasattr(self, "enable_smearer"): 1070 # #set smearing value whether or not the data1071 # contain the smearing info1071 # set smearing value whether or not the data 1072 # contain the smearing info 1072 1073 self.enable_smearer.SetValue(state.enable_smearer) 1073 1074 self.disable_smearer.SetValue(state.disable_smearer) … … 1081 1082 self.dI_idata.SetValue(state.dI_idata) 1082 1083 1083 # #we have two more options for smearing1084 # we have two more options for smearing 1084 1085 if self.pinhole_smearer.GetValue(): 1085 1086 self.onPinholeSmear(event=None) … … 1087 1088 self.onSlitSmear(event=None) 1088 1089 1089 # #reset state of checkbox,textcrtl and dispersity parameters value1090 # reset state of checkbox,textcrtl and dispersity parameters value 1090 1091 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1091 1092 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1092 1093 1093 # #draw the model with previous parameters value1094 # draw the model with previous parameters value 1094 1095 self._onparamEnter_helper() 1095 1096 self.select_param(event=None) 1096 # Save state_fit1097 # Save state_fit 1097 1098 self.save_current_state_fit() 1098 1099 self._lay_out() … … 1108 1109 if state.formfactorcombobox in list_item: 1109 1110 return self.categorybox.Items.index(key) 1111 return 0 1110 1112 1111 1113 def reset_page_helper(self, state): … … 1118 1120 state of the graphic interface 1119 1121 """ 1120 if state ==None:1122 if state is None: 1121 1123 return 1122 1124 # set data, etc. from the state … … 1124 1126 data = state.data 1125 1127 1126 if data ==None:1128 if data is None: 1127 1129 data_min = state.qmin 1128 1130 data_max = state.qmax … … 1148 1150 self.disp_list = state.disp_list 1149 1151 1150 # #fill model combobox1152 # fill model combobox 1151 1153 self._show_combox_helper() 1152 # select the current model1154 # select the current model 1153 1155 try: 1154 1156 # to support older version 1155 1157 category_pos = int(state.categorycombobox) 1156 1158 except: 1157 state.formfactorcombobox = unicode(state.formfactorcombobox.lower()) 1159 state.formfactorcombobox = state.formfactorcombobox.lower() 1160 state.formfactorcombobox = \ 1161 state.formfactorcombobox.replace('model', '') 1162 state.formfactorcombobox = unicode(state.formfactorcombobox) 1158 1163 state.categorycombobox = unicode(state.categorycombobox) 1159 category_pos = 01160 1164 if state.categorycombobox in self.categorybox.Items: 1161 1165 category_pos = self.categorybox.Items.index( … … 1180 1184 self.formfactorbox.Select(formfactor_pos) 1181 1185 1186 structfactor_pos = 0 1182 1187 try: 1183 1188 # to support older version … … 1185 1190 except: 1186 1191 if state.structurecombobox is not None: 1187 structfactor_pos = 01188 1192 state.structurecombobox = unicode(state.structurecombobox) 1189 1193 for ind_struct in range(self.structurebox.GetCount()): 1190 1194 if self.structurebox.GetString(ind_struct) == \ 1191 1195 (state.structurecombobox): 1192 1196 structfactor_pos = int(ind_struct) 1193 1197 break … … 1195 1199 self.structurebox.SetSelection(structfactor_pos) 1196 1200 1197 if state.multi_factor !=None:1201 if state.multi_factor is not None: 1198 1202 self.multifactorbox.SetSelection(state.multi_factor) 1199 1203 1200 # draw the panel according to the new model parameter1204 # draw the panel according to the new model parameter 1201 1205 self._on_select_model(event=None) 1202 1206 1203 1207 # take care of 2D button 1204 if data ==None and self.model_view.IsEnabled():1208 if data is None and self.model_view.IsEnabled(): 1205 1209 if self.enable2D: 1206 1210 self.model_view.SetLabel("2D Mode") … … 1208 1212 self.model_view.SetLabel("1D Mode") 1209 1213 1210 # #reset state of checkbox,textcrtl and regular parameters value1214 # reset state of checkbox,textcrtl and regular parameters value 1211 1215 self._reset_parameters_state(self.orientation_params_disp, 1212 1216 state.orientation_params_disp) … … 1216 1220 state.str_parameters) 1217 1221 self._reset_parameters_state(self.parameters, state.parameters) 1218 # #display dispersion info layer1222 # display dispersion info layer 1219 1223 self.enable_disp.SetValue(state.enable_disp) 1220 1224 self.disable_disp.SetValue(state.disable_disp) … … 1224 1228 self._set_dipers_Param(event=None) 1225 1229 self._reset_page_disp_helper(state) 1226 # #plotting range restore1230 # plotting range restore 1227 1231 self._reset_plotting_range(state) 1228 # #smearing info restore1232 # smearing info restore 1229 1233 if hasattr(self, "enable_smearer"): 1230 # #set smearing value whether or not the data1231 # contain the smearing info1234 # set smearing value whether or not the data 1235 # contain the smearing info 1232 1236 self.enable_smearer.SetValue(state.enable_smearer) 1233 1237 self.disable_smearer.SetValue(state.disable_smearer) … … 1247 1251 self.dI_idata.SetValue(False) 1248 1252 1249 # #we have two more options for smearing1253 # we have two more options for smearing 1250 1254 if self.pinhole_smearer.GetValue(): 1251 1255 self.dx_min = state.dx_min 1252 1256 self.dx_max = state.dx_max 1253 if self.dx_min !=None:1257 if self.dx_min is not None: 1254 1258 self.smear_pinhole_min.SetValue(str(self.dx_min)) 1255 if self.dx_max !=None:1259 if self.dx_max is not None: 1256 1260 self.smear_pinhole_max.SetValue(str(self.dx_max)) 1257 1261 self.onPinholeSmear(event=None) … … 1259 1263 self.dxl = state.dxl 1260 1264 self.dxw = state.dxw 1261 if self.dxl !=None:1265 if self.dxl is not None: 1262 1266 self.smear_slit_height.SetValue(str(self.dxl)) 1263 if self.dxw !=None:1267 if self.dxw is not None: 1264 1268 self.smear_slit_width.SetValue(str(self.dxw)) 1265 1269 else: … … 1267 1271 self.onSlitSmear(event=None) 1268 1272 1269 # #reset state of checkbox,textcrtl and dispersity parameters value1273 # reset state of checkbox,textcrtl and dispersity parameters value 1270 1274 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1271 1275 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1272 1276 1273 # #draw the model with previous parameters value1277 # draw the model with previous parameters value 1274 1278 self._onparamEnter_helper() 1275 # reset the value of chisqr when not consistent with the value computed1279 # reset the value of chisqr when not consistent with the value computed 1276 1280 self.tcChi.SetValue(str(self.state.tcChi)) 1277 # #reset context menu items1281 # reset context menu items 1278 1282 self._reset_context_menu() 1279 1283 1280 # #set the value of the current state to the state given as parameter1284 # set the value of the current state to the state given as parameter 1281 1285 self.state = state.clone() 1282 1286 self.state.m_name = self.m_name … … 1289 1293 for item in keys: 1290 1294 if item in self.disp_list and \ 1291 not itemin self.model.details:1295 item not in self.model.details: 1292 1296 self.model.details[item] = ["", None, None] 1293 # for k,v in self.state.disp_cb_dict.iteritems():1297 # for k,v in self.state.disp_cb_dict.iteritems(): 1294 1298 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1295 1299 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) … … 1298 1302 1299 1303 for key, disp_type in state._disp_obj_dict.iteritems(): 1300 # disp_model = disp1304 # disp_model = disp 1301 1305 disp_model = POLYDISPERSITY_MODELS[disp_type]() 1302 1306 self._disp_obj_dict[key] = disp_model … … 1307 1311 self.model.set_dispersion(param_name, disp_model) 1308 1312 self.model._persistency_dict[key] = \ 1309 1313 [state.values, state.weights] 1310 1314 except Exception: 1311 1315 logging.error(traceback.format_exc()) 1312 1316 selection = self._find_polyfunc_selection(disp_model) 1313 1317 for list in self.fittable_param: 1314 if list[1] == key and list[7] !=None:1318 if list[1] == key and list[7] is not None: 1315 1319 list[7].SetSelection(selection) 1316 1320 # For the array disp_model, set the values and weights … … 1341 1345 open a dialog file to selected the customized dispersity 1342 1346 """ 1343 if self.parent !=None:1347 if self.parent is not None: 1344 1348 self._default_save_location = \ 1345 1349 self._manager.parent.get_save_location() … … 1360 1364 for name, _ in self.state.saved_states.iteritems(): 1361 1365 self.number_saved_state += 1 1362 # #Add item in the context menu1366 # Add item in the context menu 1363 1367 wx_id = ids.next() 1364 1368 msg = 'Save model and state %g' % self.number_saved_state … … 1377 1381 save radiobutton containing the type model that can be selected 1378 1382 """ 1379 # self.state.shape_rbutton = self.shape_rbutton.GetValue()1380 # self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue()1381 # self.state.struct_rbutton = self.struct_rbutton.GetValue()1382 # self.state.plugin_rbutton = self.plugin_rbutton.GetValue()1383 # self.state.shape_rbutton = self.shape_rbutton.GetValue() 1384 # self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() 1385 # self.state.struct_rbutton = self.struct_rbutton.GetValue() 1386 # self.state.plugin_rbutton = self.plugin_rbutton.GetValue() 1383 1387 self.state.structurecombobox = self.structurebox.GetLabel() 1384 1388 self.state.formfactorcombobox = self.formfactorbox.GetLabel() 1385 1389 self.state.categorycombobox = self.categorybox.GetLabel() 1386 1390 1387 # #post state to fit panel1391 # post state to fit panel 1388 1392 event = PageInfoEvent(page=self) 1389 1393 wx.PostEvent(self.parent, event) … … 1397 1401 self.state.npts = self.npts_x 1398 1402 1399 def _onparamEnter_helper(self, is_modified =False):1403 def _onparamEnter_helper(self, is_modified=False): 1400 1404 """ 1401 1405 check if values entered by the user are changed and valid to replot … … 1403 1407 """ 1404 1408 # Flag to register when a parameter has changed. 1405 # is_modified = False1409 # is_modified = False 1406 1410 self.fitrange = True 1407 1411 is_2Ddata = False 1408 # self._undo.Enable(True)1412 # self._undo.Enable(True) 1409 1413 # check if 2d data 1410 1414 if self.data.__class__.__name__ == "Data2D": 1411 1415 is_2Ddata = True 1412 if self.model !=None:1413 # Either we get a is_modified = True passed in because1414 # _update_paramv_on_fit() has been called already or1416 if self.model is not None: 1417 # Either we get a is_modified = True passed in because 1418 # _update_paramv_on_fit() has been called already or 1415 1419 # we need to check here ourselves. 1416 1420 if not is_modified: … … 1439 1443 self.fitrange = False 1440 1444 1441 # #if any value is modify draw model with new value1445 # if any value is modify draw model with new value 1442 1446 if not self.fitrange: 1443 # self.btFit.Disable()1447 # self.btFit.Disable() 1444 1448 if is_2Ddata: 1445 1449 self.btEditMask.Disable() … … 1455 1459 self.Refresh() 1456 1460 1457 # logging.info("is_modified flag set to %g",is_modified)1461 # logging.info("is_modified flag set to %g",is_modified) 1458 1462 return is_modified 1459 1463 … … 1462 1466 make sure that update param values just before the fitting 1463 1467 """ 1464 # flag for qmin qmax check values1468 # flag for qmin qmax check values 1465 1469 flag = True 1466 1470 self.fitrange = True 1467 1471 is_modified = False 1468 1472 1469 # wx.PostEvent(self._manager.parent, StatusEvent(status=" \1470 # updating ... ",type="update"))1471 1472 # #So make sure that update param values on_Fit.1473 # self._undo.Enable(True)1474 if self.model !=None:1473 # wx.PostEvent(self._manager.parent, StatusEvent(status=" \ 1474 # updating ... ",type="update")) 1475 1476 # So make sure that update param values on_Fit. 1477 # self._undo.Enable(True) 1478 if self.model is not None: 1475 1479 if self.Npts_total.GetValue() != self.Npts_fit.GetValue(): 1476 1480 if not self.data.is_data: 1477 self._manager.page_finder[self.uid].set_fit_data( data=\1478 1479 # #Check the values1481 self._manager.page_finder[self.uid].set_fit_data( 1482 data=[self.data]) 1483 # Check the values 1480 1484 is_modified = (self._check_value_enter(self.fittable_param) 1481 1482 1485 or self._check_value_enter(self.fixed_param) 1486 or self._check_value_enter(self.parameters)) 1483 1487 1484 1488 # If qmin and qmax have been modified, update qmin and qmax and … … 1521 1525 enable_smearer=enable_smearer, 1522 1526 draw=False) 1523 if self.data !=None:1524 index_data = ((self.qmin_x <= self.data.x) & \1527 if self.data is not None: 1528 index_data = ((self.qmin_x <= self.data.x) & 1525 1529 (self.data.x <= self.qmax_x)) 1526 val = str(len(self.data.x[index_data ==True]))1530 val = str(len(self.data.x[index_data is True])) 1527 1531 self.Npts_fit.SetValue(val) 1528 1532 else: … … 1544 1548 flag = False 1545 1549 1546 # For invalid q range, disable the mask editor and fit button, vs.1550 # For invalid q range, disable the mask editor and fit button, vs. 1547 1551 if not self.fitrange: 1548 1552 if self._is_2D(): 1549 1553 self.btEditMask.Disable() 1550 1554 else: 1551 if self._is_2D() and 1555 if self._is_2D() and self.data.is_data and not self.batch_on: 1552 1556 self.btEditMask.Enable(True) 1553 1557 … … 1562 1566 logging.error(traceback.format_exc()) 1563 1567 1564 return flag, is_modified1568 return flag, is_modified 1565 1569 1566 1570 def _reset_parameters_state(self, listtorestore, statelist): … … 1576 1580 item_page = listtorestore[j] 1577 1581 item_page_info = statelist[j] 1578 # #change the state of the check box for simple parameters1579 if item_page[0] !=None:1582 # change the state of the check box for simple parameters 1583 if item_page[0] is not None: 1580 1584 item_page[0].SetValue(item_page_info[0]) 1581 if item_page[2] !=None:1585 if item_page[2] is not None: 1582 1586 item_page[2].SetValue(item_page_info[2]) 1583 1587 if item_page[2].__class__.__name__ == "ComboBox": … … 1585 1589 fun_val = self.model.fun_list[item_page_info[2]] 1586 1590 self.model.setParam(item_page_info[1], fun_val) 1587 if item_page[3] !=None:1588 # #show or hide text +/-1591 if item_page[3] is not None: 1592 # show or hide text +/- 1589 1593 if item_page_info[2]: 1590 1594 item_page[3].Show(True) 1591 1595 else: 1592 1596 item_page[3].Hide() 1593 if item_page[4] !=None:1594 # #show of hide the text crtl for fitting error1597 if item_page[4] is not None: 1598 # show of hide the text crtl for fitting error 1595 1599 if item_page_info[4][0]: 1596 1600 item_page[4].Show(True) … … 1598 1602 else: 1599 1603 item_page[3].Hide() 1600 if item_page[5] !=None:1601 # #show of hide the text crtl for fitting error1604 if item_page[5] is not None: 1605 # show of hide the text crtl for fitting error 1602 1606 item_page[5].Show(item_page_info[5][0]) 1603 1607 item_page[5].SetValue(item_page_info[5][1]) 1604 1608 1605 if item_page[6] !=None:1606 # #show of hide the text crtl for fitting error1609 if item_page[6] is not None: 1610 # show of hide the text crtl for fitting error 1607 1611 item_page[6].Show(item_page_info[6][0]) 1608 1612 item_page[6].SetValue(item_page_info[6][1]) … … 1620 1624 item_page = listtorestore[j] 1621 1625 item_page_info = statelist[j] 1622 # #change the state of the check box for simple parameters1623 1624 if item_page[0] !=None:1626 # change the state of the check box for simple parameters 1627 1628 if item_page[0] is not None: 1625 1629 item_page[0].SetValue(format_number(item_page_info[0], True)) 1626 1630 1627 if item_page[2] !=None:1631 if item_page[2] is not None: 1628 1632 param_name = item_page_info[1] 1629 1633 value = item_page_info[2] … … 1648 1652 1649 1653 checkbox_state = None 1650 if item[0] !=None:1654 if item[0] is not None: 1651 1655 checkbox_state = item[0].GetValue() 1652 1656 parameter_name = item[1] 1653 1657 parameter_value = None 1654 if item[2] !=None:1658 if item[2] is not None: 1655 1659 parameter_value = item[2].GetValue() 1656 1660 static_text = None 1657 if item[3] !=None:1661 if item[3] is not None: 1658 1662 static_text = item[3].IsShown() 1659 1663 error_value = None 1660 1664 error_state = None 1661 if item[4] !=None:1665 if item[4] is not None: 1662 1666 error_value = item[4].GetValue() 1663 1667 error_state = item[4].IsShown() … … 1665 1669 min_value = None 1666 1670 min_state = None 1667 if item[5] !=None:1671 if item[5] is not None: 1668 1672 min_value = item[5].GetValue() 1669 1673 min_state = item[5].IsShown() … … 1671 1675 max_value = None 1672 1676 max_state = None 1673 if item[6] !=None:1677 if item[6] is not None: 1674 1678 max_value = item[6].GetValue() 1675 1679 max_state = item[6].IsShown() 1676 1680 unit = None 1677 if item[7] !=None:1681 if item[7] is not None: 1678 1682 unit = item[7].GetLabel() 1679 1683 … … 1683 1687 [max_state, max_value], unit]) 1684 1688 1685 1686 1689 def _draw_model(self, update_chisqr=True, source='model'): 1687 1690 """ … … 1702 1705 :param chisqr: update chisqr value [bool] 1703 1706 """ 1704 # if self.check_invalid_panel():1707 # if self.check_invalid_panel(): 1705 1708 # return 1706 if self.model !=None:1709 if self.model is not None: 1707 1710 temp_smear = None 1708 1711 if hasattr(self, "enable_smearer"): … … 1716 1719 is_2d = self._is_2D() 1717 1720 self._manager.draw_model(self.model, 1718 data=self.data,1719 smearer=temp_smear,1720 qmin=float(self.qmin_x),1721 qmax=float(self.qmax_x),1722 page_id=self.uid,1723 toggle_mode_on=toggle_mode_on,1724 state=self.state,1725 enable2D=is_2d,1726 update_chisqr=update_chisqr,1727 source='model',1728 weight=weight)1721 data=self.data, 1722 smearer=temp_smear, 1723 qmin=float(self.qmin_x), 1724 qmax=float(self.qmax_x), 1725 page_id=self.uid, 1726 toggle_mode_on=toggle_mode_on, 1727 state=self.state, 1728 enable2D=is_2d, 1729 update_chisqr=update_chisqr, 1730 source='model', 1731 weight=weight) 1729 1732 1730 1733 def _on_show_sld(self, event=None): … … 1736 1739 1737 1740 from sas.sasgui.plottools import Data1D as pf_data1d 1738 # from sas.sasgui.perspectives.theory.profile_dialog import SLDPanel1741 # from sas.sasgui.perspectives.theory.profile_dialog import SLDPanel 1739 1742 from sas.sasgui.guiframe.local_perspectives.plotting.profile_dialog \ 1740 import SLDPanel1743 import SLDPanel 1741 1744 sld_data = pf_data1d(x, y) 1742 1745 sld_data.name = 'SLD' … … 1791 1794 self.structurebox.Disable() 1792 1795 self.formfactorbox.Clear() 1793 if mod_cat ==None:1796 if mod_cat is None: 1794 1797 return 1795 1798 m_list = [] … … 1853 1856 """ 1854 1857 tcrtl = event.GetEventObject() 1855 # Clear msg if previously shown.1858 # Clear msg if previously shown. 1856 1859 msg = "" 1857 1860 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1872 1875 tcrtl.SetBackgroundColour("pink") 1873 1876 msg = "Model Error: wrong value entered: %s" % \ 1874 1877 sys.exc_info()[1] 1875 1878 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1876 1879 return … … 1880 1883 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1881 1884 return 1882 # Check if # of points for theory model are valid(>0).1883 if self.npts !=None:1885 # Check if # of points for theory model are valid(>0). 1886 if self.npts is not None: 1884 1887 if check_float(self.npts): 1885 1888 temp_npts = float(self.npts.GetValue()) … … 1897 1900 wx.PostEvent(self.parent, event) 1898 1901 self.state_change = False 1899 # Draw the model for a different range1902 # Draw the model for a different range 1900 1903 if not self.data.is_data: 1901 1904 self.create_default_data() … … 1908 1911 1909 1912 tcrtl = event.GetEventObject() 1910 # Clear msg if previously shown.1913 # Clear msg if previously shown. 1911 1914 msg = "" 1912 1915 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1929 1932 tcrtl.SetBackgroundColour("pink") 1930 1933 msg = "Model Error: wrong value entered: %s" % \ 1931 1934 sys.exc_info()[1] 1932 1935 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1933 1936 return … … 1937 1940 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1938 1941 return 1939 # Check if # of points for theory model are valid(>0).1942 # Check if # of points for theory model are valid(>0). 1940 1943 if self.Npts_total.IsEditable(): 1941 1944 if check_float(self.Npts_total): … … 1955 1958 wx.PostEvent(self.parent, event) 1956 1959 self.state_change = False 1957 # Draw the model for a different range1960 # Draw the model for a different range 1958 1961 self.create_default_data() 1959 1962 self._draw_model() … … 1963 1966 call back for model selection 1964 1967 """ 1965 # #reset dictionary containing reference to dispersion1968 # reset dictionary containing reference to dispersion 1966 1969 self._disp_obj_dict = {} 1967 1970 self.disp_cb_dict = {} 1968 1971 self.temp_multi_functional = False 1969 1972 f_id = self.formfactorbox.GetCurrentSelection() 1970 # For MAC1973 # For MAC 1971 1974 form_factor = None 1972 1975 if f_id >= 0: … … 1975 1978 if form_factor is None or \ 1976 1979 not hasattr(form_factor, 'is_form_factor') or \ 1977 not form_factor.is_form_factor:1980 not form_factor.is_form_factor: 1978 1981 self.structurebox.Hide() 1979 1982 self.text2.Hide() … … 1987 1990 self.text2.Enable() 1988 1991 1989 if form_factor !=None:1992 if form_factor is not None: 1990 1993 # set multifactor for Mutifunctional models 1991 1994 if form_factor.is_multiplicity_model: … … 1995 1998 self._set_multfactor_combobox(multiplicity) 1996 1999 self._show_multfactor_combobox() 1997 # ToDo:this info should be called directly from the model2000 # ToDo: this info should be called directly from the model 1998 2001 text = form_factor.multiplicity_info[1] # 'No. of Shells: ' 1999 2002 … … 2004 2007 2005 2008 self.multi_factor = self.multifactorbox.GetClientData(m_id) 2006 if self.multi_factor ==None:2009 if self.multi_factor is None: 2007 2010 self.multi_factor = 0 2008 2011 self.multifactorbox.SetSelection(m_id) … … 2010 2013 text = '' 2011 2014 if form_factor.multiplicity_info[0] == \ 2012 2015 len(form_factor.multiplicity_info[2]): 2013 2016 text = form_factor.multiplicity_info[2][self.multi_factor] 2014 2017 self.mutifactor_text1.SetLabel(text) … … 2031 2034 struct_factor = self.structurebox.GetClientData(s_id) 2032 2035 2033 if struct_factor !=None:2036 if struct_factor is not None: 2034 2037 from sasmodels.sasview_model import MultiplicationModel 2035 2038 self.model = MultiplicationModel(form_factor(self.multi_factor), … … 2038 2041 if len(form_factor.non_fittable) > 0: 2039 2042 self.temp_multi_functional = True 2040 elif form_factor !=None:2043 elif form_factor is not None: 2041 2044 if self.multi_factor is not None: 2042 2045 self.model = form_factor(self.multi_factor) … … 2053 2056 else: 2054 2057 self._has_magnetic = False 2055 # #post state to fit panel2058 # post state to fit panel 2056 2059 self.state.parameters = [] 2057 2060 self.state.model = self.model … … 2063 2066 self.Layout() 2064 2067 2065 2066 2068 def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 2067 2069 """ … … 2083 2085 qmax = float(qmax_ctrl.GetValue()) 2084 2086 if qmin < qmax: 2085 # Make sure to set both colours white.2087 # Make sure to set both colours white. 2086 2088 qmin_ctrl.SetBackgroundColour(wx.WHITE) 2087 2089 qmin_ctrl.Refresh() … … 2103 2105 If valid, setvalues Npts_fit otherwise post msg. 2104 2106 """ 2105 # default flag2107 # default flag 2106 2108 flag = True 2107 2109 # Theory 2108 if self.data ==None and self.enable2D:2110 if self.data is None and self.enable2D: 2109 2111 return flag 2110 2112 for data in self.data_list: … … 2112 2114 radius = numpy.sqrt(data.qx_data * data.qx_data + 2113 2115 data.qy_data * data.qy_data) 2114 # get unmasked index2116 # get unmasked index 2115 2117 index_data = (float(self.qmin.GetValue()) <= radius) & \ 2116 2118 (radius <= float(self.qmax.GetValue())) 2117 2119 index_data = (index_data) & (data.mask) 2118 2120 index_data = (index_data) & (numpy.isfinite(data.data)) … … 2130 2132 flag = False 2131 2133 else: 2132 self.Npts_fit.SetValue(str(len(index_data[index_data ==True])))2134 self.Npts_fit.SetValue(str(len(index_data[index_data is True]))) 2133 2135 self.fitrange = True 2134 2136 … … 2140 2142 If valid, setvalues Npts_fit otherwise post msg. 2141 2143 """ 2142 # default flag2144 # default flag 2143 2145 flag = True 2144 2146 # Theory 2145 if self.data ==None:2147 if self.data is None: 2146 2148 return flag 2147 2149 for data in self.data_list: 2148 2150 # q value from qx and qy 2149 2151 radius = data.x 2150 # get unmasked index2152 # get unmasked index 2151 2153 index_data = (float(self.qmin.GetValue()) <= radius) & \ 2152 2154 (radius <= float(self.qmax.GetValue())) 2153 2155 index_data = (index_data) & (numpy.isfinite(data.y)) 2154 2156 … … 2165 2167 flag = False 2166 2168 else: 2167 self.Npts_fit.SetValue(str(len(index_data[index_data ==True])))2169 self.Npts_fit.SetValue(str(len(index_data[index_data is True]))) 2168 2170 self.fitrange = True 2169 2171 … … 2185 2187 is_modified = False 2186 2188 for item in list: 2187 # skip angle parameters for 1D2189 # skip angle parameters for 1D 2188 2190 if not self.enable2D and item in self.orientation_params: 2189 2191 continue … … 2230 2232 max_ctrl.SetBackgroundColour("pink") 2231 2233 max_ctrl.Refresh() 2232 #msg = "Invalid fit range for %s: min must be smaller than max"%name 2233 #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 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)) 2234 2238 continue 2235 2239 … … 2249 2253 # The configuration has changed but it won't change the 2250 2254 # computed curve so no need to set is_modified to True 2251 # is_modified = True2255 # is_modified = True 2252 2256 self.model.details[name][1:3] = low, high 2253 2257 … … 2267 2271 Redraw the model with the default dispersity (Gaussian) 2268 2272 """ 2269 # #On selction if no model exists.2270 if self.model ==None:2273 # On selction if no model exists. 2274 if self.model is None: 2271 2275 self.disable_disp.SetValue(True) 2272 2276 msg = "Please select a Model first..." … … 2278 2282 self._reset_dispersity() 2279 2283 2280 if self.model ==None:2284 if self.model is None: 2281 2285 self.model_disp.Hide() 2282 2286 self.sizer4_4.Clear(True) … … 2284 2288 2285 2289 if self.enable_disp.GetValue(): 2286 # #layout for model containing no dispersity parameters2290 # layout for model containing no dispersity parameters 2287 2291 2288 2292 self.disp_list = self.model.getDispParamList() … … 2291 2295 self._layout_sizer_noDipers() 2292 2296 else: 2293 # #set gaussian sizer2297 # set gaussian sizer 2294 2298 self._on_select_Disp(event=None) 2295 2299 else: 2296 2300 self.sizer4_4.Clear(True) 2297 2301 2298 # #post state to fit panel2302 # post state to fit panel 2299 2303 self.save_current_state() 2300 if event !=None:2304 if event is not None: 2301 2305 event = PageInfoEvent(page=self) 2302 2306 wx.PostEvent(self.parent, event) 2303 # draw the model with the current dispersity2304 2305 # Wojtek P, Oct 8, 2016: Calling draw_model seems to be unessecary.2306 # By comenting it we save an extra Iq calculation2307 # self._draw_model()2308 2309 # #Need to use FitInside again here to replace the next four lines.2310 # #Otherwised polydispersity off does not resize the scrollwindow.2311 # #PDB Nov 28, 20152307 # draw the model with the current dispersity 2308 2309 # Wojtek P, Oct 8, 2016: Calling draw_model seems to be unessecary. 2310 # By comenting it we save an extra Iq calculation 2311 # self._draw_model() 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, 2015 2312 2316 self.FitInside() 2313 2317 # self.sizer4_4.Layout() … … 2353 2357 self.weights = {} 2354 2358 2355 # from sas.models.dispersion_models import GaussianDispersion2359 # from sas.models.dispersion_models import GaussianDispersion 2356 2360 from sasmodels.weights import GaussianDispersion 2357 2361 if len(self.disp_cb_dict) == 0: … … 2374 2378 logging.error(traceback.format_exc()) 2375 2379 2376 # #save state into2380 # save state into 2377 2381 self.save_current_state() 2378 2382 self.Layout() … … 2386 2390 self._set_sizer_dispersion() 2387 2391 2388 # #Redraw the model2392 # Redraw the model 2389 2393 self._draw_model() 2390 # self._undo.Enable(True)2394 # self._undo.Enable(True) 2391 2395 event = PageInfoEvent(page=self) 2392 2396 wx.PostEvent(self.parent, event) … … 2403 2407 """ 2404 2408 # get ready for new event 2405 if event !=None:2409 if event is not None: 2406 2410 event.Skip() 2407 2411 # Get event object … … 2416 2420 dispersity = disp_box.GetClientData(selection) 2417 2421 2418 # disp_model = GaussianDispersion()2422 # disp_model = GaussianDispersion() 2419 2423 disp_model = dispersity() 2420 2424 # Get param names to reset the values of the param … … 2429 2433 else: 2430 2434 self._del_array_values(name1) 2431 # self._reset_array_disp(param_name)2435 # self._reset_array_disp(param_name) 2432 2436 self._disp_obj_dict[name1] = disp_model 2433 2437 self.model.set_dispersion(param_name, disp_model) … … 2513 2517 if path is None: 2514 2518 self.disp_cb_dict[name].SetValue(False) 2515 # self.noDisper_rbox.SetValue(True)2519 # self.noDisper_rbox.SetValue(True) 2516 2520 return 2517 2521 self._default_save_location = os.path.dirname(path) 2518 if self._manager !=None:2522 if self._manager is not None: 2519 2523 self._manager.parent._default_save_location = \ 2520 2524 self._default_save_location … … 2533 2537 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2534 2538 self._set_array_disp_model(name=name, disp=disp, 2535 2539 values=values, weights=weights) 2536 2540 return basename 2537 2541 … … 2552 2556 # Store the object to make it persist outside the 2553 2557 # scope of this method 2554 # TODO: refactor model to clean this up?2558 # TODO: refactor model to clean this up? 2555 2559 self.state.values = {} 2556 2560 self.state.weights = {} … … 2559 2563 2560 2564 # Set the new model as the dispersion object for the 2561 # selected parameter2562 # self.model.set_dispersion(p, disp_model)2565 # selected parameter 2566 # self.model.set_dispersion(p, disp_model) 2563 2567 # Store a reference to the weights in the model object 2564 # so that2568 # so that 2565 2569 # it's not lost when we use the model within another thread. 2566 2570 self.state.model = self.model.clone() 2567 2571 self.model._persistency_dict[name.split('.')[0]] = \ 2568 2572 [values, weights] 2569 2573 self.state.model._persistency_dict[name.split('.')[0]] = \ 2570 2574 [values, weights] 2571 2575 2572 2576 def _del_array_values(self, name=None): … … 2606 2610 Layout after self._draw_model 2607 2611 """ 2608 if ON_MAC ==True:2612 if ON_MAC is True: 2609 2613 time.sleep(1) 2610 2614 … … 2628 2632 """ 2629 2633 flag = True 2630 # #For 3 different cases: Data2D, Data1D, and theory2631 if self.model ==None:2634 # For 3 different cases: Data2D, Data1D, and theory 2635 if self.model is None: 2632 2636 msg = "Please select a model first..." 2633 2637 wx.MessageBox(msg, 'Info') … … 2641 2645 self.qmin_x = data_min 2642 2646 self.qmax_x = math.sqrt(x * x + y * y) 2643 # self.data.mask = numpy.ones(len(self.data.data),dtype=bool)2647 # self.data.mask = numpy.ones(len(self.data.data),dtype=bool) 2644 2648 # check smearing 2645 2649 if not self.disable_smearer.GetValue(): 2646 # #set smearing value whether or2650 # set smearing value whether or 2647 2651 # not the data contain the smearing info 2648 2652 if self.pinhole_smearer.GetValue(): … … 2651 2655 flag = True 2652 2656 2653 elif self.data ==None:2657 elif self.data is None: 2654 2658 self.qmin_x = _QMIN_DEFAULT 2655 2659 self.qmax_x = _QMAX_DEFAULT … … 2662 2666 # check smearing 2663 2667 if not self.disable_smearer.GetValue(): 2664 # #set smearing value whether or2668 # set smearing value whether or 2665 2669 # not the data contain the smearing info 2666 2670 if self.slit_smearer.GetValue(): … … 2673 2677 flag = False 2674 2678 2675 if flag ==False:2679 if flag is False: 2676 2680 msg = "Cannot Plot :Must enter a number!!! " 2677 2681 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 2690 2694 self.state.qmax = self.qmax_x 2691 2695 2692 # reset the q range values2696 # reset the q range values 2693 2697 self._reset_plotting_range(self.state) 2694 2698 self._draw_model() … … 2731 2735 logging.error(traceback.format_exc()) 2732 2736 # Make sure the resduals plot goes to the last 2733 if res_item !=None:2737 if res_item is not None: 2734 2738 graphs.append(res_item[0]) 2735 2739 canvases.append(res_item[1]) … … 2750 2754 the # to the browser. 2751 2755 2752 :param ev t: on Help Button pressed event2753 """ 2754 2755 if self.model !=None:2756 :param event: on Help Button pressed event 2757 """ 2758 2759 if self.model is not None: 2756 2760 name = self.formfactorbox.GetValue() 2757 _TreeLocation = 'user/models/' + name.lower()+'.html'2761 _TreeLocation = 'user/models/' + name.lower()+'.html' 2758 2762 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 2759 2763 "", name + " Help") … … 2762 2766 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 2763 2767 "", "General Model Help") 2764 2765 2768 2766 2769 def on_model_help_clicked(self, event): … … 2774 2777 give the message that none is available. 2775 2778 2776 :param ev t: on Description Button pressed event2777 """ 2778 2779 if self.model ==None:2779 :param event: on Description Button pressed event 2780 """ 2781 2782 if self.model is None: 2780 2783 name = 'index.html' 2781 2784 else: … … 2784 2787 msg = 'Model description:\n' 2785 2788 info = "Info" 2786 if self.model !=None:2787 #frame.Destroy()2789 if self.model is not None: 2790 # frame.Destroy() 2788 2791 if str(self.model.description).rstrip().lstrip() == '': 2789 2792 msg += "Sorry, no information is available for this model." … … 2854 2857 for key in self.model.magnetic_params: 2855 2858 if key.count('M0') > 0: 2856 # reset mag value to zero fo safety2859 # reset mag value to zero fo safety 2857 2860 self.model.setParam(key, 0.0) 2858 2861 2859 2862 self.Show(False) 2860 2863 self.set_model_param_sizer(self.model) 2861 # self._set_sizer_dispersion()2864 # self._set_sizer_dispersion() 2862 2865 self.state.magnetic_on = self.magnetic_on 2863 2866 self.SetupScrolling() … … 2874 2877 running "file:///...." 2875 2878 2876 :param ev t: Triggers on clicking ? in polydispersity box2879 :param event: Triggers on clicking ? in polydispersity box 2877 2880 """ 2878 2881 … … 2912 2915 content = 'sasview_parameter_values:' 2913 2916 # Do it if params exist 2914 if self.parameters != []:2917 if self.parameters: 2915 2918 2916 2919 # go through the parameters … … 2956 2959 2957 2960 # Do it if params exist 2958 if self.parameters != []:2961 if self.parameters: 2959 2962 2960 2963 for param in self.parameters: 2961 content += param[1] #parameter name2964 content += param[1] # parameter name 2962 2965 content += tab 2963 2966 content += param[1] + "_err" … … 2966 2969 content += crlf 2967 2970 2968 # row of values and errors...2971 # row of values and errors... 2969 2972 for param in self.parameters: 2970 content += param[2].GetValue() #value2973 content += param[2].GetValue() # value 2971 2974 content += tab 2972 content += param[4].GetValue() #error2975 content += param[4].GetValue() # error 2973 2976 content += tab 2974 2977 … … 2976 2979 else: 2977 2980 return False 2978 2979 2981 2980 2982 def get_copy_latex(self): … … 2998 3000 2999 3001 # Do it if params exist 3000 if self.parameters != []:3002 if self.parameters: 3001 3003 3002 3004 content += '{|' … … 3007 3009 3008 3010 for index, param in enumerate(self.parameters): 3009 content += param[1].replace('_', '\_') #parameter name3011 content += param[1].replace('_', '\_') # parameter name 3010 3012 content += ' & ' 3011 3013 content += param[1].replace('_', '\_') + "\_err" … … 3015 3017 content += crlf 3016 3018 3017 # row of values and errors...3019 # row of values and errors... 3018 3020 for index, param in enumerate(self.parameters): 3019 content += param[2].GetValue() #parameter value3021 content += param[2].GetValue() # parameter value 3020 3022 content += ' & ' 3021 content += param[4].GetValue() #parameter error3023 content += param[4].GetValue() # parameter error 3022 3024 if index < len(self.parameters) - 1: 3023 3025 content += ' & ' … … 3030 3032 else: 3031 3033 return False 3032 3033 3034 3034 3035 def set_clipboard(self, content=None): … … 3077 3078 # 1D 3078 3079 else: 3079 # #for 1D all parameters except orientation3080 # for 1D all parameters except orientation 3080 3081 if not item[1] in orient_param: 3081 3082 try: … … 3109 3110 except Exception: 3110 3111 logging.error(traceback.format_exc()) 3111 content += name + ',' + str(check) + ',' +\ 3112 value + disfunc + ',' + bound_lo + ',' +\ 3113 bound_hi + ':' 3112 content += name + ',' + str(check) + ',' + value + disfunc + ',' + \ 3113 bound_lo + ',' + bound_hi + ':' 3114 3114 3115 3115 return content … … 3189 3189 3190 3190 # Do it if params exist 3191 if self.parameters != []:3191 if self.parameters: 3192 3192 # go through the parameters 3193 3193 self._get_paste_helper(self.parameters, … … 3237 3237 pd = int(pd) 3238 3238 except Exception: 3239 # continue3239 # continue 3240 3240 if not pd and pd != '': 3241 3241 continue … … 3265 3265 else: 3266 3266 is_true = None 3267 if is_true !=None:3267 if is_true is not None: 3268 3268 item[0].SetValue(is_true) 3269 3269 # 1D 3270 3270 else: 3271 # #for 1D all parameters except orientation3271 # for 1D all parameters except orientation 3272 3272 if not item[1] in orient_param: 3273 3273 name = item[1] … … 3278 3278 pd = value[0] 3279 3279 if name.count('.') > 0: 3280 # If this is parameter.width, then pd may be a floating 3281 # point value or it may be an array distribution. 3282 # Nothing to do for parameter.npts or parameter.nsigmas. 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. 3283 3284 try: 3284 3285 pd = float(pd) … … 3286 3287 pd = int(pd) 3287 3288 except: 3288 # continue3289 # continue 3289 3290 if not pd and pd != '': 3290 3291 continue … … 3314 3315 else: 3315 3316 is_true = None 3316 if is_true !=None:3317 if is_true is not None: 3317 3318 item[0].SetValue(is_true) 3318 3319 … … 3381 3382 logging.error(traceback.format_exc()) 3382 3383 print "Error in BasePage._paste_poly_help: %s" % \ 3383 3384 sys.exc_info()[1] 3384 3385 3385 3386 def _set_disp_cb(self, isarray, item): … … 3447 3448 self.categorybox.Clear() 3448 3449 cat_list = sorted(self.master_category_dict.keys()) 3449 if not uncat_strin cat_list:3450 if uncat_str not in cat_list: 3450 3451 cat_list.append(uncat_str) 3451 3452 … … 3457 3458 self.categorybox.SetSelection(0) 3458 3459 else: 3459 self.categorybox.SetSelection( \3460 self.categorybox.SetSelection( 3460 3461 self.categorybox.GetSelection()) 3461 # self._on_change_cat(None)3462 # self._on_change_cat(None) 3462 3463 3463 3464 def _on_change_cat(self, event): … … 3467 3468 self.model_name = None 3468 3469 category = self.categorybox.GetStringSelection() 3469 if category ==None:3470 if category is None: 3470 3471 return 3471 3472 self.model_box.Clear() … … 3478 3479 else: 3479 3480 for (model, enabled) in sorted(self.master_category_dict[category], 3480 key=lambda name: name[0]):3481 key=lambda name: name[0]): 3481 3482 if(enabled): 3482 3483 self.model_box.Append(model) … … 3487 3488 """ 3488 3489 # This should only be called once per fit tab 3489 # print "==== Entering _fill_model_sizer"3490 # #Add model function Details button in fitpanel.3491 # #The following 3 lines are for Mac. Let JHC know before modifying...3490 # print "==== Entering _fill_model_sizer" 3491 # Add model function Details button in fitpanel. 3492 # The following 3 lines are for Mac. Let JHC know before modifying... 3492 3493 title = "Model" 3493 3494 self.formfactorbox = None … … 3521 3522 self._populate_listbox() 3522 3523 wx.EVT_COMBOBOX(self.categorybox, wx.ID_ANY, self._show_combox) 3523 # self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes',3524 # self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes', 3524 3525 # style=wx.RB_GROUP) 3525 # self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY,3526 # self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY, 3526 3527 # "Shape-Independent") 3527 # self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY,3528 # self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY, 3528 3529 # "Structure Factor ") 3529 # self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY,3530 # self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY, 3530 3531 # "Uncategorized") 3531 3532 3532 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3533 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3533 3534 # id=self.shape_rbutton.GetId()) 3534 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3535 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3535 3536 # id=self.shape_indep_rbutton.GetId()) 3536 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3537 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3537 3538 # id=self.struct_rbutton.GetId()) 3538 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3539 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3539 3540 # id=self.plugin_rbutton.GetId()) 3540 # MAC needs SetValue3541 # MAC needs SetValue 3541 3542 3542 3543 show_cat_button = wx.Button(self, wx.ID_ANY, "Modify") 3543 3544 cat_tip = "Modify model categories \n" 3544 3545 cat_tip += "(also accessible from the menu bar)." 3545 show_cat_button.SetToolTip( wx.ToolTip(cat_tip))3546 show_cat_button.SetToolTip(wx.ToolTip(cat_tip)) 3546 3547 show_cat_button.Bind(wx.EVT_BUTTON, self._on_modify_cat) 3547 3548 sizer_cat_box.Add(self.categorybox, 1, wx.RIGHT, 3) 3548 sizer_cat_box.Add((10, 10))3549 sizer_cat_box.Add((10, 10)) 3549 3550 sizer_cat_box.Add(show_cat_button) 3550 # self.shape_rbutton.SetValue(True)3551 # self.shape_rbutton.SetValue(True) 3551 3552 3552 3553 sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) 3553 # sizer_radiobutton.Add(self.shape_rbutton)3554 # sizer_radiobutton.Add(self.shape_indep_rbutton)3555 sizer_radiobutton.Add((5, 5))3554 # sizer_radiobutton.Add(self.shape_rbutton) 3555 # sizer_radiobutton.Add(self.shape_indep_rbutton) 3556 sizer_radiobutton.Add((5, 5)) 3556 3557 sizer_radiobutton.Add(self.model_view, 1, wx.RIGHT, 5) 3557 # sizer_radiobutton.Add(self.plugin_rbutton)3558 # sizer_radiobutton.Add(self.struct_rbutton)3559 #sizer_radiobutton.Add((5,5))3558 # sizer_radiobutton.Add(self.plugin_rbutton) 3559 # sizer_radiobutton.Add(self.struct_rbutton) 3560 # sizer_radiobutton.Add((5,5)) 3560 3561 sizer_radiobutton.Add(self.model_help, 1, wx.RIGHT | wx.LEFT, 5) 3561 #sizer_radiobutton.Add((5,5))3562 # sizer_radiobutton.Add((5,5)) 3562 3563 sizer_radiobutton.Add(self.model_func, 1, wx.RIGHT, 5) 3563 3564 sizer_cat.Add(sizer_cat_box, 1, wx.LEFT, 2.5) … … 3575 3576 self.formfactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 3576 3577 self.formfactorbox.SetToolTip(wx.ToolTip("Select a Model")) 3577 if self.model !=None:3578 if self.model is not None: 3578 3579 self.formfactorbox.SetValue(self.model.name) 3579 3580 self.structurebox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) … … 3584 3585 wx.EVT_COMBOBOX(self.structurebox, wx.ID_ANY, self._on_select_model) 3585 3586 wx.EVT_COMBOBOX(self.multifactorbox, wx.ID_ANY, self._on_select_model) 3586 # #check model type to show sizer3587 if self.model !=None:3587 # check model type to show sizer 3588 if self.model is not None: 3588 3589 print "_set_model_sizer_selection: disabled." 3589 # self._set_model_sizer_selection(self.model)3590 # self._set_model_sizer_selection(self.model) 3590 3591 3591 3592 sizer_selection.Add(self.text1) … … 3682 3683 """ 3683 3684 3685 3684 3686 class ModelTextCtrl(wx.TextCtrl): 3685 3687 """ … … 3694 3696 3695 3697 """ 3696 # #Set to True when the mouse is clicked while whole string is selected3698 # Set to True when the mouse is clicked while whole string is selected 3697 3699 full_selection = False 3698 # #Call back for EVT_SET_FOCUS events3700 # Call back for EVT_SET_FOCUS events 3699 3701 _on_set_focus_callback = None 3700 3702 … … 3718 3720 if set_focus_callback is None else set_focus_callback 3719 3721 self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) 3720 self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus \3721 3722 self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \3723 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) 3724 3726 if not ON_MAC: 3725 self.Bind(wx.EVT_LEFT_UP, self._highlight_text \3726 3727 self.Bind(wx.EVT_LEFT_UP, self._highlight_text 3728 if mouse_up_callback is None else mouse_up_callback) 3727 3729 3728 3730 def _on_set_focus(self, event): … … 3764 3766 3765 3767 event.Skip() 3766 # pass3768 # pass
Note: See TracChangeset
for help on using the changeset viewer.