Changeset c8e1996 in sasview for src/sas/sasgui/perspectives
- 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
- Location:
- src/sas/sasgui/perspectives/fitting
- Files:
-
- 4 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 -
src/sas/sasgui/perspectives/fitting/fitpage.py
r3bec50a rc8e1996 14 14 from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS 15 15 16 from sas.sasgui.guiframe.events import StatusEvent 17 from sas.sasgui.guiframe.events import NewPlotEvent 18 from sas.sasgui.guiframe.events import PlotQrangeEvent 16 from sas.sasgui.guiframe.events import StatusEvent, NewPlotEvent, \ 17 PlotQrangeEvent 19 18 from sas.sasgui.guiframe.dataFitting import check_data_validity 20 from sas.sasgui.guiframe.utils import format_number 21 from sas.sasgui.guiframe.utils import check_float 19 from sas.sasgui.guiframe.utils import format_number, check_float 22 20 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 21 22 from sas.sasgui.perspectives.fitting.basepage import BasicPage as BasicPage 23 from sas.sasgui.perspectives.fitting.basepage import PageInfoEvent as \ 24 PageInfoEvent 25 from sas.sascalc.data_util.qsmearing import smear_selection 26 from .basepage import ModelTextCtrl 23 27 24 28 (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() … … 28 32 SMEAR_SIZE_H = 0.00 29 33 30 from sas.sasgui.perspectives.fitting.basepage import BasicPage as BasicPage31 from sas.sasgui.perspectives.fitting.basepage import PageInfoEvent as PageInfoEvent32 from sas.sascalc.data_util.qsmearing import smear_selection33 from .basepage import ModelTextCtrl34 35 34 36 35 class FitPage(BasicPage): … … 49 48 BasicPage.__init__(self, parent, color=color) 50 49 51 # #draw sizer50 # draw sizer 52 51 self._fill_data_sizer() 53 52 self.is_2D = None … … 72 71 self.enable_fit_button() 73 72 self.fill_data_combobox(data_list=self.data_list) 74 # create a default data for an empty panel73 # create a default data for an empty panel 75 74 self.create_default_data() 76 75 self._manager.frame.Bind(wx.EVT_SET_FOCUS, self.on_set_focus) … … 105 104 self.data_box_description.SetForegroundColour(dname_color) 106 105 boxsizer1 = wx.StaticBoxSizer(self.data_box_description, wx.VERTICAL) 107 # ----------------------------------------------------------106 # ---------------------------------------------------------- 108 107 sizer_data = wx.BoxSizer(wx.HORIZONTAL) 109 108 self.dataSource = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) … … 134 133 self.enable_datasource() 135 134 if len(data_list) > 0: 136 # find the maximum range covering all data135 # find the maximum range covering all data 137 136 qmin, qmax, npts = self.compute_data_set_range(data_list) 138 137 self.qmin_data_set = qmin … … 185 184 186 185 :return: True or False 187 188 186 """ 189 187 if self.data.__class__.__name__ == "Data2D" or \ … … 199 197 buttons, xi^2, number of points etc. 200 198 """ 201 is_2 Ddata = False199 is_2d_data = False 202 200 203 201 # Check if data is 2D 204 202 if self.data.__class__.__name__ == "Data2D" or \ 205 203 self.enable2D: 206 is_2 Ddata = True204 is_2d_data = True 207 205 208 206 title = "Fitting" 209 # smear messages & titles207 # smear messages & titles 210 208 smear_message_none = "No smearing is selected..." 211 209 smear_message_dqdata = "The dQ data is being used for smearing..." … … 225 223 self._get_smear_info() 226 224 227 # Sizers225 # Sizers 228 226 box_description_range = wx.StaticBox(self, wx.ID_ANY, str(title)) 229 227 box_description_range.SetForegroundColour(wx.BLUE) … … 244 242 sizer_weighting = wx.BoxSizer(wx.HORIZONTAL) 245 243 weighting_box.SetMinSize((_DATA_BOX_WIDTH, 40)) 246 # Filling the sizer containing weighting info.244 # Filling the sizer containing weighting info. 247 245 self.dI_noweight = wx.RadioButton(self, wx.ID_ANY, 248 246 'No Weighting', style=wx.RB_GROUP) … … 286 284 self._on_select_accuracy) 287 285 288 # Fit button286 # Fit button 289 287 self.btFit = wx.Button(self, self._ids.next(), 'Fit') 290 288 self.default_bt_colour = self.btFit.GetDefaultAttributes() … … 292 290 self.btFit.SetToolTipString("Start fitting.") 293 291 294 # General Help button292 # General Help button 295 293 self.btFitHelp = wx.Button(self, wx.ID_ANY, 'Help') 296 294 self.btFitHelp.SetToolTipString("General fitting help.") 297 295 self.btFitHelp.Bind(wx.EVT_BUTTON, self._onFitHelp) 298 296 299 # Resolution Smearing Help button (for now use same technique as300 # used for dI help to get tiniest possible button that works301 # both on MAC and PC. Should completely rewrite the fitting sizer302 # in future. This is minimum to get out release 3.1297 # Resolution Smearing Help button (for now use same technique as 298 # used for dI help to get tiniest possible button that works 299 # both on MAC and PC. Should completely rewrite the fitting sizer 300 # in future. This is minimum to get out release 3.1 303 301 # comment June 14, 2015 --- PDB 304 302 if sys.platform.count("win32") > 0: 305 size_q = (20, 15) # on PC303 size_q = (20, 15) # on PC 306 304 else: 307 size_q = (30, 20) # on MAC305 size_q = (30, 20) # on MAC 308 306 self.btSmearHelp = wx.Button(self, wx.ID_ANY, '?', 309 307 style=wx.BU_EXACTFIT, size=size_q) … … 311 309 self.btSmearHelp.Bind(wx.EVT_BUTTON, self._onSmearHelp) 312 310 313 # textcntrl for custom resolution311 # textcntrl for custom resolution 314 312 self.smear_pinhole_max = ModelTextCtrl(self, wx.ID_ANY, 315 313 size=(_BOX_WIDTH - 25, 20), … … 329 327 text_enter_callback=self.onSlitSmear) 330 328 331 # #smear329 # smear 332 330 self.smear_data_left = BGTextCtrl(self, wx.ID_ANY, 333 331 size=(_BOX_WIDTH - 25, 20), style=0) … … 337 335 self.smear_data_right.SetValue(str(self.dq_r)) 338 336 339 # set default values for smear337 # set default values for smear 340 338 self.smear_pinhole_max.SetValue(str(self.dx_max)) 341 339 self.smear_pinhole_min.SetValue(str(self.dx_min)) … … 343 341 self.smear_slit_width.SetValue(str(self.dxw)) 344 342 345 # Filling the sizer containing instruments smearing info.343 # Filling the sizer containing instruments smearing info. 346 344 self.disable_smearer = wx.RadioButton(self, wx.ID_ANY, 347 345 'None', style=wx.RB_GROUP) 348 346 self.enable_smearer = wx.RadioButton(self, wx.ID_ANY, 'Use dQ Data') 349 # self.enable_smearer.SetToolTipString(350 # "Click to use the loaded dQ data for smearing.")347 # self.enable_smearer.SetToolTipString( 348 # "Click to use the loaded dQ data for smearing.") 351 349 self.pinhole_smearer = wx.RadioButton(self, wx.ID_ANY, 352 350 'Custom Pinhole Smear') 353 # self.pinhole_smearer.SetToolTipString354 # ("Click to input custom resolution for pinhole smearing.")351 # self.pinhole_smearer.SetToolTipString 352 # ("Click to input custom resolution for pinhole smearing.") 355 353 self.slit_smearer = wx.RadioButton(self, wx.ID_ANY, 'Custom Slit Smear') 356 # self.slit_smearer.SetToolTipString357 # ("Click to input custom resolution for slit smearing.")354 # self.slit_smearer.SetToolTipString 355 # ("Click to input custom resolution for slit smearing.") 358 356 self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, 359 357 id=self.disable_smearer.GetId()) … … 378 376 self.Npts_fit = BGTextCtrl(self, wx.ID_ANY, "-", size=(75, 20), style=0) 379 377 self.Npts_fit.SetToolTipString( 380 378 " Npts : number of points selected for fitting") 381 379 self.Npts_total = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 382 style=wx.TE_PROCESS_ENTER,383 text_enter_callback=self._onQrangeEnter)380 style=wx.TE_PROCESS_ENTER, 381 text_enter_callback=self._onQrangeEnter) 384 382 self.Npts_total.SetValue(format_number(self.npts_x)) 385 self.Npts_total.SetToolTipString( \386 383 self.Npts_total.SetToolTipString( 384 " Total Npts : total number of data points") 387 385 388 386 # Update and Draw button … … 429 427 self.smear_description_2d_y = wx.StaticText(self, wx.ID_ANY, 430 428 smear_message_2d_y_title, style=wx.ALIGN_LEFT) 431 self.smear_description_2d_y.SetToolTipString( \429 self.smear_description_2d_y.SetToolTipString( 432 430 " dQs(perpendicular) in q_phi direction.") 433 431 self.smear_description_pin_min = wx.StaticText(self, wx.ID_ANY, … … 440 438 smear_message_slit_width_title, style=wx.ALIGN_LEFT) 441 439 442 # arrange sizers440 # arrange sizers 443 441 self.sizer_set_smearer.Add(sizer_smearer) 444 442 self.sizer_set_smearer.Add((10, 10)) 445 443 self.sizer_set_smearer.Add(self.smear_description_none, 446 444 0, wx.CENTER, 10) 447 445 self.sizer_set_smearer.Add(self.smear_description_dqdata, 448 446 0, wx.CENTER, 10) 449 447 self.sizer_set_smearer.Add(self.smear_description_2d, 450 448 0, wx.CENTER, 10) 451 449 self.sizer_new_smear.Add(self.smear_description_type, 452 450 0, wx.CENTER, 10) 453 451 self.sizer_new_smear.Add(self.smear_description_accuracy_type, 454 452 0, wx.CENTER, 10) 455 453 self.sizer_new_smear.Add(self.smear_accuracy) 456 454 self.sizer_new_smear.Add(self.smear_description_smear_type, 457 455 0, wx.CENTER, 10) 458 456 self.sizer_new_smear.Add((15, -1)) 459 self.sizer_new_smear.Add(self.smear_description_2d_x, 460 0, wx.CENTER, 10) 457 self.sizer_new_smear.Add(self.smear_description_2d_x, 0, wx.CENTER, 10) 461 458 self.sizer_new_smear.Add(self.smear_description_pin_min, 462 459 0, wx.CENTER, 10) 463 460 self.sizer_new_smear.Add(self.smear_description_slit_height, 464 0, wx.CENTER, 10) 465 466 self.sizer_new_smear.Add(self.smear_pinhole_min, 467 0, wx.CENTER, 10) 468 self.sizer_new_smear.Add(self.smear_slit_height, 469 0, wx.CENTER, 10) 470 self.sizer_new_smear.Add(self.smear_data_left, 471 0, wx.CENTER, 10) 461 0, wx.CENTER, 10) 462 463 self.sizer_new_smear.Add(self.smear_pinhole_min, 0, wx.CENTER, 10) 464 self.sizer_new_smear.Add(self.smear_slit_height, 0, wx.CENTER, 10) 465 self.sizer_new_smear.Add(self.smear_data_left, 0, wx.CENTER, 10) 472 466 self.sizer_new_smear.Add((20, -1)) 473 467 self.sizer_new_smear.Add(self.smear_description_2d_y, 474 468 0, wx.CENTER, 10) 475 469 self.sizer_new_smear.Add(self.smear_description_pin_max, 476 470 0, wx.CENTER, 10) 477 471 self.sizer_new_smear.Add(self.smear_description_slit_width, 478 472 0, wx.CENTER, 10) 479 473 480 474 self.sizer_new_smear.Add(self.smear_pinhole_max, 0, wx.CENTER, 10) … … 501 495 502 496 # Show only the relevant smear messages, etc 503 if self.current_smearer ==None:504 if not is_2 Ddata:497 if self.current_smearer is None: 498 if not is_2d_data: 505 499 self.smear_description_none.Show(True) 506 500 self.enable_smearer.Disable() … … 508 502 self.smear_description_none.Show(True) 509 503 self.slit_smearer.Disable() 510 if self.data ==None:504 if self.data is None: 511 505 self.slit_smearer.Disable() 512 506 self.pinhole_smearer.Disable() … … 515 509 self._show_smear_sizer() 516 510 boxsizer_range.Add(self.sizer_set_masking) 517 # 2D data? default518 is_2 Ddata = False519 520 # check if it is 2D data511 # 2D data? default 512 is_2d_data = False 513 514 # check if it is 2D data 521 515 if self.data.__class__.__name__ == "Data2D" or self.enable2D: 522 is_2 Ddata = True516 is_2d_data = True 523 517 524 518 self.sizer5.Clear(True) … … 568 562 sizer.Add(wx.StaticText(self, wx.ID_ANY, ' Max[1/A]')) 569 563 sizer.Add(self.EditMask_title) 570 sizer.Add((-1, 5))564 sizer.Add((-1, 5)) 571 565 572 566 sizer.Add(self.reset_qrange) … … 574 568 sizer.Add(self.qmax) 575 569 sizer.Add(self.btEditMask) 576 sizer.Add((-1, 5))577 578 sizer.AddMany(5*[(-1, 5)])570 sizer.Add((-1, 5)) 571 572 sizer.AddMany(5*[(-1, 5)]) 579 573 580 574 sizer.Add(box_description_1, 0, 0) … … 582 576 sizer.Add(self.points_sizer, 0, 0) 583 577 sizer.Add(self.draw_button, 0, 0) 584 sizer.Add((-1, 5))578 sizer.Add((-1, 5)) 585 579 586 580 sizer.Add(self.tcChi, 0, 0) … … 592 586 boxsizer_range.Add(sizer_chi2) 593 587 boxsizer_range.Add(sizer) 594 if is_2 Ddata:588 if is_2d_data: 595 589 self.btEditMask.Enable() 596 590 self.EditMask_title.Enable() … … 598 592 self.btEditMask.Disable() 599 593 self.EditMask_title.Disable() 600 # #save state594 # save state 601 595 self.save_current_state() 602 596 self.sizer5.Add(boxsizer_range, 0, wx.EXPAND | wx.ALL, 10) 603 597 self.sizer5.Layout() 604 598 605 606 599 def _set_sizer_dispersion(self): 607 600 """ … … 613 606 614 607 self.sizer4_4.Clear(True) 615 if self.model ==None:616 # #no model is selected608 if self.model is None: 609 # no model is selected 617 610 return 618 611 if not self.enable_disp.GetValue(): 619 # #the user didn't select dispersity display612 # the user didn't select dispersity display 620 613 return 621 614 622 615 self._reset_dispersity() 623 616 624 # #fill a sizer with the combobox to select dispersion type617 # fill a sizer with the combobox to select dispersion type 625 618 model_disp = wx.StaticText(self, wx.ID_ANY, 'Function') 626 619 CHECK_STATE = False … … 645 638 err_text = '' 646 639 self.text_disp_1 = wx.StaticText(self, wx.ID_ANY, err_text) 647 self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), \640 self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), 648 641 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 649 642 650 643 ix += 1 651 644 self.text_disp_min = wx.StaticText(self, wx.ID_ANY, 'Min') 652 self.sizer4_4.Add(self.text_disp_min, (iy, ix), (1, 1), \645 self.sizer4_4.Add(self.text_disp_min, (iy, ix), (1, 1), 653 646 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 654 647 … … 683 676 if item in self.model.magnetic_params: 684 677 continue 685 if not itemin self.model.orientation_params:686 if not itemin self.disp_cb_dict:678 if item not in self.model.orientation_params: 679 if item not in self.disp_cb_dict: 687 680 self.disp_cb_dict[item] = None 688 681 name0 = "Distribution of " + item … … 690 683 name2 = item + ".npts" 691 684 name3 = item + ".nsigmas" 692 if n ot name1in self.model.details:685 if name1 not in self.model.details: 693 686 self.model.details[name1] = ["", None, None] 694 687 … … 716 709 ctl1.SetValue(str(format_number(value, True))) 717 710 self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 718 # #text to show error sign711 # text to show error sign 719 712 ix = 2 720 713 text2 = wx.StaticText(self, wx.ID_ANY, '+/-') … … 776 769 Tct2.SetValue(str(format_number(value))) 777 770 self.sizer4_4.Add(Tct2, (iy, ix), (1, 1), 778 771 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 779 772 self.fixed_param.append([None, name3, Tct2, 780 773 None, None, None, … … 802 795 if item in self.model.magnetic_params: 803 796 continue 804 if 805 if not itemin self.disp_cb_dict:797 if item in self.model.orientation_params: 798 if item not in self.disp_cb_dict: 806 799 self.disp_cb_dict[item] = None 807 800 name0 = "Distribution of " + item … … 810 803 name3 = item + ".nsigmas" 811 804 812 if n ot name1in self.model.details:805 if name1 not in self.model.details: 813 806 self.model.details[name1] = ["", None, None] 814 807 … … 855 848 856 849 self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 857 # #text to show error sign850 # text to show error sign 858 851 ix = 2 859 852 text2 = wx.StaticText(self, wx.ID_ANY, '+/-') … … 968 961 969 962 self.state.model = self.model.clone() 970 # #save state into963 # save state into 971 964 self._copy_parameters_state(self.parameters, self.state.parameters) 972 965 self._copy_parameters_state(self.orientation_params_disp, … … 978 971 wx.PostEvent(self.parent, 979 972 StatusEvent(status=" Selected Distribution: Gaussian")) 980 # Fill the list of fittable parameters973 # Fill the list of fittable parameters 981 974 self.get_all_checked_params() 982 975 self.Layout() … … 986 979 Update and Draw the model 987 980 """ 988 if self.model ==None:981 if self.model is None: 989 982 msg = "Please select a Model first..." 990 983 wx.MessageBox(msg, 'Info') … … 996 989 self.create_default_data() 997 990 """ 998 flag, is_modified = self._update_paramv_on_fit()999 1000 wx.CallAfter(self._onparamEnter_helper, is_modified)991 flag, is_modified = self._update_paramv_on_fit() 992 993 wx.CallAfter(self._onparamEnter_helper, is_modified) 1001 994 if not flag: 1002 995 msg = "The parameters are invalid" … … 1008 1001 Allow to fit 1009 1002 """ 1010 if event !=None:1003 if event is not None: 1011 1004 event.Skip() 1012 1005 if self.fit_started: … … 1048 1041 return 1049 1042 1050 self.select_param( event=None)1043 self.select_param() 1051 1044 1052 1045 # Remove or do not allow fitting on the Q=0 point, especially … … 1059 1052 qmax=self.qmax_x) 1060 1053 1061 # single fit1062 # self._manager.onFit(uid=self.uid)1054 # single fit 1055 # self._manager.onFit(uid=self.uid) 1063 1056 self.fit_started = self._manager.onFit(uid=self.uid) 1064 1057 wx.CallAfter(self.set_fitbutton) … … 1073 1066 versions of Wx (before 2.9) and thus not the release version of 1074 1067 installers, the help comes up at the top level of the file as 1075 web browser does not pass anything past the # to the browser when it is1068 web browser does not pass anything past the # to the browser when it is 1076 1069 running "file:///...." 1077 1070 1078 :param evt: Triggers on clicking the help button1079 """1071 :param evt: Triggers on clicking the help button 1072 """ 1080 1073 1081 1074 _TreeLocation = "user/sasgui/perspectives/fitting/fitting_help.html" … … 1092 1085 versions of Wx (before 2.9) and thus not the release version of 1093 1086 installers, the help comes up at the top level of the file as 1094 web browser does not pass anything past the # to the browser when it is1087 web browser does not pass anything past the # to the browser when it is 1095 1088 running "file:///...." 1096 1089 1097 :param evt: Triggers on clicking the help button1098 """1090 :param evt: Triggers on clicking the help button 1091 """ 1099 1092 1100 1093 _TreeLocation = "user/sasgui/perspectives/fitting/sm_help.html" … … 1108 1101 """ 1109 1102 # Skip this feature if we are not on Windows 1110 # NOTE: the is_mac data member actually means "is no Windows".1103 # NOTE: the is_mac data member actually means "is no Windows". 1111 1104 if self.is_mac: 1112 1105 return … … 1118 1111 label = "Fit" 1119 1112 color = "black" 1120 # self.btFit.Enable(False)1113 # self.btFit.Enable(False) 1121 1114 self.btFit.SetLabel(label) 1122 1115 self.btFit.SetForegroundColour(color) … … 1149 1142 Stop fit 1150 1143 """ 1151 if event !=None:1144 if event is not None: 1152 1145 event.Skip() 1153 1146 self._manager.stop_fit(self.uid) … … 1169 1162 copy_flag = False 1170 1163 is_poly_enabled = None 1171 if event !=None:1172 if (event.GetEventObject() == self.formfactorbox \1164 if event is not None: 1165 if (event.GetEventObject() == self.formfactorbox 1173 1166 and self.structurebox.GetLabel() != 'None')\ 1174 1167 or event.GetEventObject() == self.structurebox\ … … 1183 1176 self._keep.Enable(False) 1184 1177 self._set_save_flag(False) 1185 # TODO: why do we have to variables for one flag??1186 1178 self.enable_disp.SetValue(False) 1187 1179 self.disable_disp.SetValue(True) … … 1213 1205 self._keep.Enable(not self.batch_on) 1214 1206 self._set_save_flag(True) 1207 self._set_smear(self.data) 1215 1208 1216 1209 # more disables for 2D … … 1226 1219 except: 1227 1220 raise 1228 # #error occured on chisqr computation1229 # pass1230 # #event to post model to fit to fitting plugins1221 # error occured on chisqr computation 1222 # pass 1223 # event to post model to fit to fitting plugins 1231 1224 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 1232 1225 1233 ## set smearing value whether or not 1234 # the data contain the smearing info 1226 # set smearing value whether or not data contain the smearing info 1235 1227 evt = ModelEventbox(model=self.model, 1236 1228 smearer=temp_smear, … … 1242 1234 1243 1235 self._manager._on_model_panel(evt=evt) 1244 self.mbox_description.SetLabel("Model [ %s ]" % str(self.model.name)) 1236 self.mbox_description.SetLabel("Model [ %s ]" % 1237 str(self.model.name)) 1245 1238 self.mbox_description.SetForegroundColour(wx.BLUE) 1246 1239 self.state.model = self.model.clone() 1247 1240 self.state.model.name = self.model.name 1248 1241 1249 if event !=None:1250 # #post state to fit panel1242 if event is not None: 1243 # post state to fit panel 1251 1244 new_event = PageInfoEvent(page=self) 1252 1245 wx.PostEvent(self.parent, new_event) 1253 # update list of plugins if new plugin is available1246 # update list of plugins if new plugin is available 1254 1247 custom_model = 'Customized Models' 1255 1248 mod_cat = self.categorybox.GetStringSelection() … … 1264 1257 self.formfactorbox.SetValue(current_val) 1265 1258 # when select a model only from guictr/button 1266 if is_poly_enabled !=None:1259 if is_poly_enabled is not None: 1267 1260 self.enable_disp.SetValue(is_poly_enabled) 1268 1261 self.disable_disp.SetValue(not is_poly_enabled) … … 1292 1285 when enter value on panel redraw model according to changed 1293 1286 """ 1294 if self.model ==None:1287 if self.model is None: 1295 1288 msg = "Please select a Model first..." 1296 1289 wx.MessageBox(msg, 'Info') 1297 1290 return 1298 1291 1299 # default flag1292 # default flag 1300 1293 flag = False 1301 1294 self.fitrange = True 1302 # get event object1295 # get event object 1303 1296 tcrtl = event.GetEventObject() 1304 # Clear msg if previously shown.1297 # Clear msg if previously shown. 1305 1298 msg = "" 1306 1299 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1313 1306 if not self.disable_smearer.GetValue(): 1314 1307 temp_smearer = self.current_smearer 1315 # # set smearing value whether or not1316 # the data contain thesmearing info1308 # set smearing value whether or not data contain the 1309 # smearing info 1317 1310 if self.slit_smearer.GetValue(): 1318 1311 flag1 = self.update_slit_smear() … … 1331 1324 enable_smearer=enable_smearer) 1332 1325 if flag: 1333 # self.compute_chisqr(smearer= temp_smearer)1334 1335 # #new state posted1326 # self.compute_chisqr(smearer= temp_smearer) 1327 1328 # new state posted 1336 1329 if self.state_change: 1337 # self._undo.Enable(True)1330 # self._undo.Enable(True) 1338 1331 event = PageInfoEvent(page=self) 1339 1332 wx.PostEvent(self.parent, event) … … 1345 1338 else: 1346 1339 self.save_current_state() 1347 msg = "Cannot Plot :Must enter a number!!! "1340 msg = "Cannot Plot: Must enter a number!!! " 1348 1341 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1349 1342 … … 1356 1349 """ 1357 1350 tcrtl = event.GetEventObject() 1358 # Clear msg if previously shown.1351 # Clear msg if previously shown. 1359 1352 msg = "" 1360 1353 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1374 1367 tcrtl.SetBackgroundColour(wx.WHITE) 1375 1368 1376 # self._undo.Enable(True)1369 # self._undo.Enable(True) 1377 1370 self.save_current_state() 1378 1371 event = PageInfoEvent(page=self) … … 1384 1377 ON Qrange focus 1385 1378 """ 1386 if event !=None:1379 if event is not None: 1387 1380 event.Skip() 1388 # tcrtl = event.GetEventObject()1381 # tcrtl = event.GetEventObject() 1389 1382 self._validate_qrange(self.qmin, self.qmax) 1390 1383 … … 1393 1386 On Qrange textctrl click, make the qrange lines in the plot 1394 1387 """ 1395 if event !=None:1388 if event is not None: 1396 1389 event.Skip() 1397 1390 if self.data.__class__.__name__ == "Data2D": … … 1411 1404 #On q range value updated. DO not combine with qrange_click(). 1412 1405 """ 1413 if event !=None:1406 if event is not None: 1414 1407 event.Skip() 1415 1408 if self.data.__class__.__name__ == "Data2D": … … 1439 1432 length = len(self.data.x) 1440 1433 indx = (numpy.abs(self.data.x - x_data)).argmin() 1441 # return array.flat[idx]1434 # return array.flat[idx] 1442 1435 if key == wx.WXK_PAGEUP or key == wx.WXK_NUMPAD_PAGEUP: 1443 1436 indx += 1 … … 1458 1451 """ 1459 1452 tcrtl = event.GetEventObject() 1460 # Clear msg if previously shown.1453 # Clear msg if previously shown. 1461 1454 msg = "" 1462 1455 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1488 1481 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1489 1482 return 1490 # Check if # of points for theory model are valid(>0).1483 # Check if # of points for theory model are valid(>0). 1491 1484 # check for 2d 1492 1485 if self.data.__class__.__name__ == "Data2D" or \ … … 1495 1488 radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + 1496 1489 self.data.qy_data * self.data.qy_data) 1497 index_data = ((self.qmin_x <= radius) & \ 1498 (radius <= self.qmax_x)) 1490 index_data = ((self.qmin_x <= radius) & (radius <= self.qmax_x)) 1499 1491 index_data = (index_data) & (self.data.mask) 1500 1492 index_data = (index_data) & (numpy.isfinite(self.data.data)) … … 1506 1498 return 1507 1499 else: 1508 # self.data.mask = index_data1509 # self.Npts_fit.SetValue(str(len(self.data.mask)))1500 # self.data.mask = index_data 1501 # self.Npts_fit.SetValue(str(len(self.data.mask))) 1510 1502 self.show_npts2fit() 1511 1503 else: 1512 index_data = ((self.qmin_x <= self.data.x) & \1504 index_data = ((self.qmin_x <= self.data.x) & 1513 1505 (self.data.x <= self.qmax_x)) 1514 1506 self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) … … 1543 1535 for item in self.parameters: 1544 1536 if item[0].IsShown(): 1545 # Skip the angle parameters if 1D data1537 # Skip the angle parameters if 1D data 1546 1538 if self.data.__class__.__name__ != "Data2D" and \ 1547 1539 not self.enable2D: … … 1550 1542 if item in self.param_toFit: 1551 1543 continue 1552 # #hide statictext +/-1544 # hide statictext +/- 1553 1545 if len(item) < 4: 1554 1546 continue 1555 if item[3] !=None and item[3].IsShown():1547 if item[3] is not None and item[3].IsShown(): 1556 1548 item[3].Hide() 1557 # #hide textcrtl for error after fit1558 if item[4] !=None and item[4].IsShown():1549 # hide textcrtl for error after fit 1550 if item[4] is not None and item[4].IsShown(): 1559 1551 item[4].Hide() 1560 1552 … … 1562 1554 for item in self.fittable_param: 1563 1555 if item[0].IsShown(): 1564 # Skip the angle parameters if 1D data1556 # Skip the angle parameters if 1D data 1565 1557 if self.data.__class__.__name__ != "Data2D" and \ 1566 1558 not self.enable2D: … … 1571 1563 if len(item) < 4: 1572 1564 continue 1573 # #hide statictext +/-1574 if item[3] !=None and item[3].IsShown():1565 # hide statictext +/- 1566 if item[3] is not None and item[3].IsShown(): 1575 1567 item[3].Hide() 1576 # #hide textcrtl for error after fit1577 if item[4] !=None and item[4].IsShown():1568 # hide textcrtl for error after fit 1569 if item[4] is not None and item[4].IsShown(): 1578 1570 item[4].Hide() 1579 1571 return … … 1584 1576 """ 1585 1577 # get the default values 1586 if self.dxl ==None:1578 if self.dxl is None: 1587 1579 self.dxl = 0.0 1588 if self.dxw ==None:1580 if self.dxw is None: 1589 1581 self.dxw = "" 1590 if self.dx_min ==None:1582 if self.dx_min is None: 1591 1583 self.dx_min = SMEAR_SIZE_L 1592 if self.dx_max ==None:1584 if self.dx_max is None: 1593 1585 self.dx_max = SMEAR_SIZE_H 1594 1586 … … 1611 1603 elif self.data.__class__.__name__ == "Data2D" or \ 1612 1604 self.enable2D: 1613 if data.dqx_data == None or data.dqy_data ==None:1605 if data.dqx_data is None or data.dqy_data is None: 1614 1606 return 1615 elif self.current_smearer !=None \1607 elif self.current_smearer is not None \ 1616 1608 and data.dqx_data.any() != 0 \ 1617 1609 and data.dqx_data.any() != 0: … … 1623 1615 return 1624 1616 # check if it is pinhole smear and get min max if it is. 1625 if data.dx != None and all(data.dx != 0):1617 if data.dx is not None and not numpy.any(data.dx): 1626 1618 self.smear_type = "Pinhole" 1627 1619 self.dq_l = data.dx[0] … … 1629 1621 1630 1622 # check if it is slit smear and get min max if it is. 1631 elif data.dxl != None or data.dxw !=None:1623 elif data.dxl is not None or data.dxw is not None: 1632 1624 self.smear_type = "Slit" 1633 if data.dxl != None and all(data.dxl !=0):1625 if data.dxl is not None and not numpy.all(data.dxl, 0): 1634 1626 self.dq_l = data.dxl[0] 1635 if data.dxw != None and all(data.dxw !=0):1627 if data.dxw is not None and not numpy.all(data.dxw, 0): 1636 1628 self.dq_r = data.dxw[0] 1637 # return self.smear_type,self.dq_l,self.dq_r1629 # return self.smear_type,self.dq_l,self.dq_r 1638 1630 1639 1631 def _show_smear_sizer(self): … … 1659 1651 1660 1652 self.smear_description_dqdata.Show(True) 1661 if self.smear_type !=None:1653 if self.smear_type is not None: 1662 1654 self.smear_description_smear_type.Show(True) 1663 1655 if self.smear_type == 'Slit': … … 1750 1742 Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low 1751 1743 """ 1752 # event.Skip()1744 # event.Skip() 1753 1745 # Check if the accuracy is same as before 1754 # self.smear2d_accuracy = event.GetEventObject().GetValue()1746 # self.smear2d_accuracy = event.GetEventObject().GetValue() 1755 1747 self.smear2d_accuracy = self.smear_accuracy.GetValue() 1756 1748 if self.pinhole_smearer.GetValue(): … … 1758 1750 else: 1759 1751 self.onSmear(event=None) 1760 if self.current_smearer !=None:1752 if self.current_smearer is not None: 1761 1753 self.current_smearer.set_accuracy(accuracy=\ 1762 1754 self.smear2d_accuracy) … … 1790 1782 Build a panel to allow to edit Mask 1791 1783 """ 1792 from sas.sasgui.guiframe.local_perspectives.plotting.masking \1793 importMaskPanel as MaskDialog1784 from sas.sasgui.guiframe.local_perspectives.plotting.masking import \ 1785 MaskPanel as MaskDialog 1794 1786 1795 1787 self.panel = MaskDialog(base=self, data=self.data, id=wx.NewId()) … … 1802 1794 is_valid_qrange = self._update_paramv_on_fit() 1803 1795 1804 if is_valid_qrange and self.model !=None:1796 if is_valid_qrange and self.model is not None: 1805 1797 self.panel.MakeModal(False) 1806 1798 event.Skip() … … 1808 1800 self._draw_model() 1809 1801 self.show_npts2fit() 1810 elif self.model ==None:1802 elif self.model is None: 1811 1803 self.panel.MakeModal(False) 1812 1804 event.Skip() … … 1875 1867 npts = len(data.x) 1876 1868 except: 1877 msg = "Unable to find min/max/length of \n data named %s" % 1869 msg = "Unable to find min/max/length of \n data named %s" %\ 1878 1870 data.filename 1879 1871 wx.PostEvent(self._manager.parent, StatusEvent(status=msg, … … 1892 1884 info="error")) 1893 1885 raise ValueError, msg 1894 # #Maximum value of data1886 # Maximum value of data 1895 1887 qmax = math.sqrt(x * x + y * y) 1896 1888 npts = len(data.data) … … 1904 1896 flag = False 1905 1897 is_data = False 1898 npts = 0 1906 1899 try: 1907 1900 old_id = self.data.id … … 1915 1908 flag = True 1916 1909 if data is not None: 1917 id = data.id1918 1910 if is_data: 1919 1911 self.graph_id = self.data.group_id … … 1930 1922 self._set_save_flag(False) 1931 1923 else: 1932 if self.model !=None:1924 if self.model is not None: 1933 1925 self._set_bookmark_flag(not self.batch_on) 1934 1926 self._keep.Enable(not self.batch_on) … … 1937 1929 self._set_preview_flag(True) 1938 1930 1939 self._set_smear(data)1940 1931 # more disables for 2D 1941 1932 if self.data.__class__.__name__ == "Data2D" or \ … … 1944 1935 self.pinhole_smearer.Enable(True) 1945 1936 self.default_mask = copy.deepcopy(self.data.mask) 1946 if self.data.err_data ==None or\1947 (self.data.err_data == 1).all() or\1948 (self.data.err_data == 0).all():1937 if self.data.err_data is None or\ 1938 numpy.all(err == 1 for err in self.data.err_data) or \ 1939 not numpy.any(self.data.err_data): 1949 1940 self.dI_didata.Enable(False) 1950 1941 self.dI_noweight.SetValue(True) … … 1957 1948 self.slit_smearer.Enable(True) 1958 1949 self.pinhole_smearer.Enable(True) 1959 if self.data.dy == None or\ 1960 (self.data.dy == 1).all() or\ 1961 (self.data.dy == 0).all(): 1950 1951 if self.data.dy is None or\ 1952 numpy.all(self.data.dy == 1) or\ 1953 not numpy.any(self.data.dy): 1962 1954 self.dI_didata.Enable(False) 1963 1955 self.dI_noweight.SetValue(True) … … 1967 1959 self.dI_didata.SetValue(True) 1968 1960 self.weightbt_string = self.dI_didata.GetLabelText() 1969 # Enable weighting radio uttons1961 # Enable weighting radio buttons 1970 1962 self.dI_noweight.Enable(True) 1971 1963 self.dI_sqrdata.Enable(True) … … 1976 1968 data_name = self.data.name 1977 1969 _, _, npts = self.compute_data_range(self.data) 1978 # set maximum range for x in linear scale1970 # set maximum range for x in linear scale 1979 1971 if not hasattr(self.data, "data"): # Display only for 1D data fit 1980 1972 self.btEditMask.Disable() … … 1985 1977 1986 1978 self.Npts_total.SetValue(str(npts)) 1987 # default:number of data points selected to fit1979 # default:number of data points selected to fit 1988 1980 self.Npts_fit.SetValue(str(npts)) 1989 1981 self.Npts_total.SetEditable(False) 1990 self.Npts_total.SetBackgroundColour( \1982 self.Npts_total.SetBackgroundColour( 1991 1983 self.GetParent().GetBackgroundColour()) 1992 1984 … … 1998 1990 # send graph_id to page_finder 1999 1991 self._manager.set_graph_id(uid=self.uid, graph_id=self.graph_id) 2000 # focus the page1992 # focus the page 2001 1993 if check_data_validity(data): 2002 1994 self.data_box_description.SetForegroundColour(wx.BLUE) … … 2010 2002 self.on_set_focus(None) 2011 2003 self.Refresh() 2012 # update model plot with new data information2004 # update model plot with new data information 2013 2005 if flag: 2014 #set model view button2015 self.onSmear(None)2016 2017 2006 if self.data.__class__.__name__ == "Data2D": 2018 2007 self.enable2D = True … … 2022 2011 self.model_view.SetLabel("1D Mode") 2023 2012 self.model_view.Disable() 2024 # replace data plot on combo box selection2025 # by removing the previous selected data2013 # replace data plot on combo box selection 2014 # by removing the previous selected data 2026 2015 try: 2027 2016 wx.PostEvent(self._manager.parent, … … 2030 2019 except: 2031 2020 pass 2032 # plot the current selected data2021 # plot the current selected data 2033 2022 wx.PostEvent(self._manager.parent, 2034 2023 NewPlotEvent(action="check", plot=self.data, … … 2050 2039 self.reset_page_helper(state) 2051 2040 2052 self.select_param( event=None)2053 # Save state_fit2041 self.select_param() 2042 # Save state_fit 2054 2043 self.save_current_state_fit() 2055 2044 except: … … 2090 2079 else: 2091 2080 for qx in self.data.x: 2092 if q x >= qmin and qx <= qmax:2081 if qmax >= qx >= qmin: 2093 2082 npts2fit += 1 2094 2083 return npts2fit … … 2119 2108 # make sure stop button to fit button all the time 2120 2109 self._on_fit_complete() 2121 if out ==None or not numpy.isfinite(chisqr):2110 if out is None or not numpy.isfinite(chisqr): 2122 2111 raise ValueError, "Fit error occured..." 2123 2112 … … 2126 2115 dispersity = '' 2127 2116 2128 # Hide textctrl boxes of errors.2117 # Hide textctrl boxes of errors. 2129 2118 self._clear_Err_on_Fit() 2130 2119 2131 # Check if chi2 is finite2132 if chisqr !=None and numpy.isfinite(chisqr):2133 # format chi22120 # Check if chi2 is finite 2121 if chisqr is not None and numpy.isfinite(chisqr): 2122 # format chi2 2134 2123 chi2 = format_number(chisqr, True) 2135 2124 self.tcChi.SetValue(chi2) … … 2138 2127 self.tcChi.SetValue("-") 2139 2128 2140 # Hide error title2129 # Hide error title 2141 2130 if self.text2_3.IsShown() and not self.is_mac: 2142 2131 self.text2_3.Hide() … … 2145 2134 if self.enable_disp.GetValue(): 2146 2135 if hasattr(self, "text_disp_1"): 2147 if self.text_disp_1 !=None and not self.is_mac:2136 if self.text_disp_1 is not None and not self.is_mac: 2148 2137 self.text_disp_1.Hide() 2149 2138 except: … … 2152 2141 2153 2142 i = 0 2154 # Set the panel when fit result are list2143 # Set the panel when fit result are list 2155 2144 2156 2145 for item in self.param_toFit: 2157 if len(item) > 5 and item !=None:2146 if len(item) > 5 and item is not None: 2158 2147 2159 2148 if item[0].IsShown(): 2160 # #reset error value to initial state2149 # reset error value to initial state 2161 2150 if not self.is_mac: 2162 2151 item[3].Hide() … … 2165 2154 if item[1] == p_name[ind]: 2166 2155 break 2167 if len(out) > 0 and out[ind] !=None:2156 if len(out) > 0 and out[ind] is not None: 2168 2157 val_out = format_number(out[ind], True) 2169 2158 item[2].SetValue(val_out) 2170 2159 2171 if(cov !=None and len(cov) == len(out)):2160 if(cov is not None and len(cov) == len(out)): 2172 2161 try: 2173 if dispersity !=None:2162 if dispersity is not None: 2174 2163 if self.enable_disp.GetValue(): 2175 2164 if hasattr(self, "text_disp_1"): 2176 if self.text_disp_1 !=None:2165 if self.text_disp_1 is not None: 2177 2166 if not self.text_disp_1.IsShown()\ 2178 and not self.is_mac:2167 and not self.is_mac: 2179 2168 self.text_disp_1.Show(True) 2180 2169 except: 2181 2170 pass 2182 2171 2183 if cov[ind] !=None:2172 if cov[ind] is not None: 2184 2173 if numpy.isfinite(float(cov[ind])): 2185 2174 val_err = format_number(cov[ind], True) 2186 2175 item[4].SetForegroundColour(wx.BLACK) 2187 2176 else: 2188 2177 val_err = 'NaN' … … 2196 2185 else: 2197 2186 raise ValueError, "onsetValues: Invalid parameters..." 2198 # Show error title when any errors displayed2187 # Show error title when any errors displayed 2199 2188 if has_error: 2200 2189 if not self.text2_3.IsShown(): 2201 2190 self.text2_3.Show(True) 2202 # #save current state2191 # save current state 2203 2192 self.save_current_state() 2204 2193 … … 2207 2196 self.Refresh() 2208 2197 self._mac_sleep(0.1) 2209 # plot model ( when drawing, do not update chisqr value again)2198 # plot model ( when drawing, do not update chisqr value again) 2210 2199 self._draw_model(update_chisqr=False, source='fit') 2211 2200 … … 2223 2212 # compute weight for the current data 2224 2213 flag_weight = self.get_weight_flag() 2225 if is_2D ==None:2214 if is_2D is None: 2226 2215 is_2D = self._is_2D() 2227 2216 self._manager.set_fit_weight(uid=self.uid, … … 2242 2231 self._update_paramv_on_fit() 2243 2232 2244 if event !=None:2233 if event is not None: 2245 2234 tcrtl = event.GetEventObject() 2246 2235 # event case of radio button 2247 if tcrtl.GetValue() == True:2236 if tcrtl.GetValue(): 2248 2237 self.dx_min = 0.0 2249 2238 self.dx_max = 0.0 … … 2263 2252 2264 2253 self.sizer_set_smearer.Layout() 2265 # #we need FitInside here not just self.Layout to ensure all the sizers2266 # #end up with the necessasary space to in the scroll panel. In2267 # #particular the compute and fit buttons end up on top of each other2268 # # PDB Nov 28 2015.2254 # we need FitInside here not just self.Layout to ensure all the sizers 2255 # end up with the necessasary space to in the scroll panel. In 2256 # particular the compute and fit buttons end up on top of each other 2257 # PDB Nov 28 2015. 2269 2258 self.FitInside() 2270 2259 2271 if event !=None:2260 if event is not None: 2272 2261 event.Skip() 2273 # self._undo.Enable(True)2262 # self._undo.Enable(True) 2274 2263 self.save_current_state() 2275 2264 event = PageInfoEvent(page=self) … … 2346 2335 get_pin_max.SetBackgroundColour("pink") 2347 2336 msg = "Model Error:This value can not be negative!!!" 2348 elif self.dx_min != None and self.dx_max !=None:2337 elif self.dx_min is not None and self.dx_max is not None: 2349 2338 if self._is_2D(): 2350 2339 data.dqx_data[data.dqx_data == 0] = self.dx_min … … 2357 2346 self.dx_max + step / 1.1, 2358 2347 step) 2359 elif self.dx_min !=None:2348 elif self.dx_min is not None: 2360 2349 if self._is_2D(): 2361 2350 data.dqx_data[data.dqx_data == 0] = self.dx_min 2362 2351 else: 2363 2352 data.dx[data.dx == 0] = self.dx_min 2364 elif self.dx_max !=None:2353 elif self.dx_max is not None: 2365 2354 if self._is_2D(): 2366 2355 data.dqy_data[data.dqy_data == 0] = self.dx_max … … 2370 2359 # 2D need to set accuracy 2371 2360 if self._is_2D(): 2372 self.current_smearer.set_accuracy( accuracy=\2373 2374 2375 if msg !=None:2361 self.current_smearer.set_accuracy( 2362 accuracy=self.smear2d_accuracy) 2363 2364 if msg is not None: 2376 2365 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2377 2366 else: 2378 2367 get_pin_min.SetBackgroundColour("white") 2379 2368 get_pin_max.SetBackgroundColour("white") 2380 # #set smearing value whether or not the data contain the smearing info2369 # set smearing value whether or not the data contain the smearing info 2381 2370 2382 2371 enable_smearer = not self.disable_smearer.GetValue() … … 2404 2393 wx.CallAfter(self.save_current_state) 2405 2394 2406 if msg !=None:2395 if msg is not None: 2407 2396 return False 2408 2397 else: … … 2420 2409 msg = None 2421 2410 # for event given 2422 if event !=None:2411 if event is not None: 2423 2412 tcrtl = event.GetEventObject() 2424 2413 # event case of radio button … … 2441 2430 self._show_smear_sizer() 2442 2431 self.sizer_set_smearer.Layout() 2443 # #we need FitInside here not just self.Layout to ensure all the sizers2444 # #end up with the necessasary space to in the scroll panel. In2445 # #particular the compute and fit buttons end up on top of each other2446 # # PDB Nov 28 2015.2432 # we need FitInside here not just self.Layout to ensure all the sizers 2433 # end up with the necessasary space to in the scroll panel. In 2434 # particular the compute and fit buttons end up on top of each other 2435 # PDB Nov 28 2015. 2447 2436 self.FitInside() 2448 2437 2449 if event !=None:2438 if event is not None: 2450 2439 event.Skip() 2451 2440 self.save_current_state() 2452 2441 event = PageInfoEvent(page=self) 2453 2442 wx.PostEvent(self.parent, event) 2454 if msg !=None:2443 if msg is not None: 2455 2444 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2456 2445 … … 2541 2530 2542 2531 self.current_smearer = smear_selection(data, self.model) 2543 # #set smearing value whether or not the data contain the smearing info2532 # set smearing value whether or not the data contain the smearing info 2544 2533 enable_smearer = not self.disable_smearer.GetValue() 2545 2534 self._manager.set_smearer(smearer=self.current_smearer, … … 2564 2553 if self._is_changed_slit(): 2565 2554 msg = self._set_slit_smear() 2566 # self._undo.Enable(True)2555 # self._undo.Enable(True) 2567 2556 self.save_current_state() 2568 2557 2569 if msg !=None:2558 if msg is not None: 2570 2559 return False 2571 2560 else: … … 2577 2566 are computed when fitting 2578 2567 """ 2579 if event !=None:2568 if event is not None: 2580 2569 event.Skip() 2581 2570 if self.data is None: … … 2590 2579 2591 2580 self.sizer_set_smearer.Layout() 2592 # #we need FitInside here not just self.Layout to ensure all the sizers2593 # #end up with the necessasary space to in the scroll panel. In2594 # #particular the compute and fit buttons end up on top of each other2595 # # PDB Nov 28 2015.2581 # we need FitInside here not just self.Layout to ensure all the sizers 2582 # end up with the necessasary space to in the scroll panel. In 2583 # particular the compute and fit buttons end up on top of each other 2584 # PDB Nov 28 2015. 2596 2585 self.FitInside() 2597 2586 self._set_weight() 2598 2587 2599 # #set smearing value whether or not the data contain the smearing info2588 # set smearing value whether or not the data contain the smearing info 2600 2589 enable_smearer = not self.disable_smearer.GetValue() 2601 2590 wx.CallAfter(self._manager.set_smearer, uid=self.uid, … … 2618 2607 """ 2619 2608 self._get_smear_info() 2620 # renew smear sizer2609 # renew smear sizer 2621 2610 if self.smear_type is not None: 2622 2611 self.smear_description_smear_type.SetValue(str(self.smear_type)) … … 2658 2647 """ 2659 2648 try: 2660 if event ==None:2649 if event is None: 2661 2650 output = "-" 2662 2651 elif not numpy.isfinite(event.output): … … 2693 2682 self._manager.set_param2fit(self.uid, param2fit) 2694 2683 2695 def select_param(self, event ):2684 def select_param(self, event=None): 2696 2685 """ 2697 2686 Select TextCtrl checked for fitting purpose and stores them … … 2700 2689 self.param_toFit = [] 2701 2690 for item in self.parameters: 2702 # Skip t ifhe angle parameters if 1D data2691 # Skip t ifhe angle parameters if 1D data 2703 2692 if self.data.__class__.__name__ != "Data2D" and\ 2704 2693 not self.enable2D: 2705 2694 if item in self.orientation_params: 2706 2695 continue 2707 # Select parameters to fit for list of primary parameters2696 # Select parameters to fit for list of primary parameters 2708 2697 if item[0].GetValue() and item[0].IsShown(): 2709 2698 if not (item in self.param_toFit): … … 2714 2703 self.param_toFit.remove(item) 2715 2704 2716 # Select parameters to fit for list of fittable parameters2705 # Select parameters to fit for list of fittable parameters 2717 2706 # with dispersion 2718 2707 for item in self.fittable_param: 2719 # Skip t ifhe angle parameters if 1D data2708 # Skip t ifhe angle parameters if 1D data 2720 2709 if self.data.__class__.__name__ != "Data2D" and\ 2721 2710 not self.enable2D: … … 2726 2715 self.param_toFit.append(item) 2727 2716 else: 2728 # remove parameters from the fitting list2717 # remove parameters from the fitting list 2729 2718 if item in self.param_toFit: 2730 2719 self.param_toFit.remove(item) 2731 2720 2732 # Calculate num. of angle parameters2721 # Calculate num. of angle parameters 2733 2722 if self.data.__class__.__name__ == "Data2D" or \ 2734 2723 self.enable2D: … … 2736 2725 else: 2737 2726 len_orient_para = len(self.orientation_params) # assume even len 2738 # Total num. of angle parameters2727 # Total num. of angle parameters 2739 2728 if len(self.fittable_param) > 0: 2740 2729 len_orient_para *= 2 2741 2730 2742 2731 self.save_current_state_fit() 2743 if event !=None:2744 # #post state to fit panel2732 if event is not None: 2733 # post state to fit panel 2745 2734 event = PageInfoEvent(page=self) 2746 2735 wx.PostEvent(self.parent, event) … … 2768 2757 self.orientation_params_disp = [] 2769 2758 2770 if model ==None:2759 if model is None: 2771 2760 self.sizer3.Layout() 2772 2761 self.SetupScrolling() … … 2776 2765 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 2777 2766 sizer = wx.GridBagSizer(5, 5) 2778 # #save the current model2767 # save the current model 2779 2768 self.model = model 2780 2769 2781 2770 keys = self.model.getParamList() 2782 2771 2783 # list of dispersion parameters2772 # list of dispersion parameters 2784 2773 self.disp_list = self.model.getDispParamList() 2785 2774 … … 2814 2803 return -1 2815 2804 # both have a number 2816 if num_a != None and num_b !=None:2805 if num_a is not None and num_b is not None: 2817 2806 if num_a > num_b: 2818 2807 return -1 … … 2827 2816 return 1 2828 2817 # one of them has a number 2829 elif num_a !=None:2818 elif num_a is not None: 2830 2819 return 1 2831 elif num_b !=None:2820 elif num_b is not None: 2832 2821 return -1 2833 2822 # no numbers … … 2835 2824 return cmp(a.lower(), b.lower()) 2836 2825 2837 # keys obtained now from ordered dict, so commenting alphabetical ordering2838 # keys.sort(custom_compare)2826 # keys obtained now from ordered dict, so commenting alphabetical 2827 # ordering keys.sort(custom_compare) 2839 2828 2840 2829 iy = 0 … … 2844 2833 ix += 1 2845 2834 self.text2_2 = wx.StaticText(self, wx.ID_ANY, 'Value') 2846 sizer.Add(self.text2_2, (iy, ix), (1, 1), \2835 sizer.Add(self.text2_2, (iy, ix), (1, 1), 2847 2836 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2848 2837 ix += 2 2849 2838 self.text2_3 = wx.StaticText(self, wx.ID_ANY, 'Error') 2850 sizer.Add(self.text2_3, (iy, ix), (1, 1), \2851 2839 sizer.Add(self.text2_3, (iy, ix), (1, 1), 2840 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2852 2841 if not self.is_mac: 2853 2842 self.text2_3.Hide() 2854 2843 ix += 1 2855 2844 self.text2_min = wx.StaticText(self, wx.ID_ANY, 'Min') 2856 sizer.Add(self.text2_min, (iy, ix), (1, 1), \2857 2858 # self.text2_min.Hide()2845 sizer.Add(self.text2_min, (iy, ix), (1, 1), 2846 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2847 # self.text2_min.Hide() 2859 2848 ix += 1 2860 2849 self.text2_max = wx.StaticText(self, wx.ID_ANY, 'Max') 2861 sizer.Add(self.text2_max, (iy, ix), (1, 1), \2862 2863 # self.text2_max.Hide()2850 sizer.Add(self.text2_max, (iy, ix), (1, 1), 2851 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2852 # self.text2_max.Hide() 2864 2853 ix += 1 2865 2854 self.text2_4 = wx.StaticText(self, wx.ID_ANY, '[Units]') 2866 sizer.Add(self.text2_4, (iy, ix), (1, 1), \2867 2855 sizer.Add(self.text2_4, (iy, ix), (1, 1), 2856 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2868 2857 self.text2_4.Hide() 2869 2858 … … 2871 2860 for item in keys: 2872 2861 2873 if not itemin self.disp_list and not item in \2862 if item not in self.disp_list and not item in \ 2874 2863 self.model.orientation_params: 2875 2864 2876 # #prepare a spot to store errors2877 if not itemin self.model.details:2865 # prepare a spot to store errors 2866 if item not in self.model.details: 2878 2867 self.model.details[item] = ["", None, None] 2879 2868 2880 2869 iy += 1 2881 2870 ix = 0 2882 if (self.model.__class__ in \2883 self.model_list_box["Multi-Functions"] or \2871 if (self.model.__class__ in 2872 self.model_list_box["Multi-Functions"] or 2884 2873 self.temp_multi_functional)\ 2885 2874 and (item in self.model.non_fittable): 2886 2875 non_fittable_name = wx.StaticText(self, wx.ID_ANY, item) 2887 sizer.Add(non_fittable_name, (iy, ix), (1, 1), \2876 sizer.Add(non_fittable_name, (iy, ix), (1, 1), 2888 2877 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 21) 2889 # #add parameter value2878 # add parameter value 2890 2879 ix += 1 2891 2880 value = self.model.getParam(item) 2892 2881 if len(self.model.fun_list) > 0: 2893 # num = item.split('_')[1][5:7]2882 # num = item.split('_')[1][5:7] 2894 2883 fun_box = wx.ComboBox(self, wx.ID_ANY, size=(100, -1), 2895 2884 style=wx.CB_READONLY, name='%s' % item) 2896 2885 self._set_fun_box_list(fun_box) 2897 2886 fun_box.SetSelection(0) 2898 # self.fun_box.SetToolTipString("A function2887 # self.fun_box.SetToolTipString("A function 2899 2888 # describing the interface") 2900 2889 wx.EVT_COMBOBOX(fun_box, wx.ID_ANY, self._on_fun_box) … … 2903 2892 size=(_BOX_WIDTH, 20), 2904 2893 style=wx.TE_PROCESS_ENTER, name='%s' % item) 2905 fun_box.SetToolTipString( \2894 fun_box.SetToolTipString( 2906 2895 "Hit 'Enter' after typing to update the plot.") 2907 2896 fun_box.SetValue(format_number(value, True)) … … 2911 2900 None, None]) 2912 2901 else: 2913 # #add parameters name with checkbox for selecting to fit2902 # add parameters name with checkbox for selecting to fit 2914 2903 cb = wx.CheckBox(self, wx.ID_ANY, item) 2915 2904 cb.SetValue(CHECK_STATE) 2916 2905 cb.SetToolTipString(" Check mark to fit.") 2917 # cb.SetValue(True)2906 # cb.SetValue(True) 2918 2907 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 2919 2908 … … 2921 2910 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 2922 2911 2923 # #add parameter value2912 # add parameter value 2924 2913 ix += 1 2925 2914 value = self.model.getParam(item) 2926 2915 ctl1 = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 2927 2916 style=wx.TE_PROCESS_ENTER) 2928 ctl1.SetToolTipString( \2917 ctl1.SetToolTipString( 2929 2918 "Hit 'Enter' after typing to update the plot.") 2930 2919 ctl1.SetValue(format_number(value, True)) 2931 2920 sizer.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 2932 # #text to show error sign2921 # text to show error sign 2933 2922 ix += 1 2934 2923 text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 2935 sizer.Add(text2, (iy, ix), (1, 1), \2924 sizer.Add(text2, (iy, ix), (1, 1), 2936 2925 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2937 2926 if not self.is_mac: … … 2994 2983 iy += 1 2995 2984 ix = 0 2996 # Add tile for orientational angle2985 # Add tile for orientational angle 2997 2986 for item in keys: 2998 2987 if item in self.model.orientation_params: … … 3001 2990 mag_on_button.SetToolTipString("Turn Pol Beam/Mag scatt on/off") 3002 2991 mag_on_button.Bind(wx.EVT_BUTTON, self._on_mag_on) 3003 mag_angle_help_button = wx.Button(self, wx.ID_ANY, "Magnetic angles?") 2992 mag_angle_help_button = wx.Button(self, wx.ID_ANY, 2993 "Magnetic angles?") 3004 2994 mag_angle_help_button.SetToolTipString("see angle definitions") 3005 2995 mag_help_button = wx.Button(self, wx.ID_ANY, "Mag HELP") 3006 2996 mag_help_button.SetToolTipString("Help on pol beam/mag fitting") 3007 2997 mag_help_button.Bind(wx.EVT_BUTTON, self._on_mag_help) 3008 mag_angle_help_button.Bind(wx.EVT_BUTTON, \2998 mag_angle_help_button.Bind(wx.EVT_BUTTON, 3009 2999 self._on_mag_angle_help) 3010 3000 sizer.Add(orient_angle, (iy, ix), (1, 1), … … 3019 3009 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 3020 3010 3021 # handle the magnetic buttons3022 # clean this up so that assume mag is off then turn3023 # all buttons on IF mag has mag and has 2D3011 # handle the magnetic buttons 3012 # clean this up so that assume mag is off then turn 3013 # all buttons on IF mag has mag and has 2D 3024 3014 if not self._has_magnetic: 3025 3015 mag_on_button.Show(False) … … 3047 3037 break 3048 3038 3049 # For Gaussian only3039 # For Gaussian only 3050 3040 if type.lower() != "array": 3051 3041 for item in self.model.orientation_params: … … 3053 3043 if item in self.model.magnetic_params: 3054 3044 continue 3055 if not itemin self.disp_list:3056 # #prepare a spot to store min max3057 if not itemin self.model.details:3045 if item not in self.disp_list: 3046 # prepare a spot to store min max 3047 if item not in self.model.details: 3058 3048 self.model.details[item] = ["", None, None] 3059 3049 3060 3050 iy += 1 3061 3051 ix = 0 3062 # #add parameters name with checkbox for selecting to fit3052 # add parameters name with checkbox for selecting to fit 3063 3053 cb = wx.CheckBox(self, wx.ID_ANY, item) 3064 3054 cb.SetValue(CHECK_STATE) … … 3073 3063 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 3074 3064 3075 # #add parameter value3065 # add parameter value 3076 3066 ix += 1 3077 3067 value = self.model.getParam(item) 3078 3068 ctl1 = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 3079 3069 style=wx.TE_PROCESS_ENTER) 3080 ctl1.SetToolTipString( \3070 ctl1.SetToolTipString( 3081 3071 "Hit 'Enter' after typing to update the plot.") 3082 3072 ctl1.SetValue(format_number(value, True)) … … 3087 3077 ctl1.Hide() 3088 3078 sizer.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 3089 # #text to show error sign3079 # text to show error sign 3090 3080 ix += 1 3091 3081 text2 = wx.StaticText(self, -1, '+/-') 3092 sizer.Add(text2, (iy, ix), (1, 1), \3082 sizer.Add(text2, (iy, ix), (1, 1), 3093 3083 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 3094 3084 … … 3155 3145 iy += 1 3156 3146 box_description.SetForegroundColour(wx.BLUE) 3157 # Display units text on panel3147 # Display units text on panel 3158 3148 for item in keys: 3159 3149 if item in self.model.details: 3160 3150 self.text2_4.Show() 3161 # Fill the list of fittable parameters3151 # Fill the list of fittable parameters 3162 3152 self.get_all_checked_params() 3163 3153 self.save_current_state_fit() … … 3171 3161 Get key stroke event 3172 3162 """ 3173 if self.data ==None:3163 if self.data is None: 3174 3164 return 3175 3165 # Figuring out key combo: Cmd for copy, Alt for paste -
src/sas/sasgui/perspectives/fitting/fitpanel.py
re6de6b8 rc8e1996 187 187 """ 188 188 189 # get number of pages190 nop = self.GetPageCount()191 189 # use while-loop, for-loop will not do the job well. 192 while ( nop> 0):190 while (self.GetPageCount() > 0): 193 191 # delete the first page until no page exists 194 192 page = self.GetPage(0) … … 197 195 self._close_helper(selected_page=page) 198 196 self.DeletePage(0) 199 nop = self.GetPageCount()200 197 # Clear list of names 201 198 self.fit_page_name = {} … … 240 237 # close all panels only when svs file opened 241 238 self.close_all() 242 self._manager.mypanels = []243 239 self.sim_page = None 244 240 self.batch_page = None … … 248 244 close page and remove all references to the closed page 249 245 """ 250 nbr_page = self.GetPageCount()251 246 selected_page = self.GetPage(self.GetSelection()) 252 if nbr_page== 1:247 if self.GetPageCount() == 1: 253 248 if selected_page.get_data() is not None: 254 249 if event is not None: … … 293 288 copy a dictionary of model into its own dictionary 294 289 295 :param m_dict: dictionnary made of model name as key and model class290 :param dict: dictionnary made of model name as key and model class 296 291 as value 297 292 """ … … 320 315 if caption == "Const & Simul Fit": 321 316 self.sim_page = SimultaneousFitPage(self, page_finder=page_finder, 322 id= 317 id=wx.ID_ANY, batch_on=False) 323 318 self.sim_page.window_caption = caption 324 319 self.sim_page.window_name = caption … … 397 392 raise ValueError, "Fitpanel delete_data expect list of id" 398 393 else: 399 n = self.GetPageCount()400 394 for page in self.opened_pages.values(): 401 395 pos = self.GetPageIndex(page) … … 441 435 if data_1d_list and data_2d_list: 442 436 # need to warning the user that this batch is a special case 443 from sas.sasgui.perspectives.fitting.fitting_widgets import BatchDataDialog 437 from sas.sasgui.perspectives.fitting.fitting_widgets import \ 438 BatchDataDialog 444 439 dlg = BatchDataDialog(self) 445 440 if dlg.ShowModal() == wx.ID_OK: … … 461 456 page = self.add_empty_page() 462 457 if data_1d_list and not data_2d_list: 463 # only on type of data458 # only on type of data 464 459 page.fill_data_combobox(data_1d_list) 465 460 elif not data_1d_list and data_2d_list: … … 477 472 Add a fitting page on the notebook contained by fitpanel 478 473 479 :param data : data to fit474 :param data_list: data to fit 480 475 481 476 :return panel : page just added for further used. -
src/sas/sasgui/perspectives/fitting/pagestate.py
r467202f rc8e1996 46 46 ["npts", "npts", "float"], 47 47 ["categorycombobox", "categorycombobox", "string"], 48 ["formfactorcombobox", "formfactorcombobox", "string"], 49 ["structurecombobox", "structurecombobox", "string"], 48 ["formfactorcombobox", "formfactorcombobox", 49 "string"], 50 ["structurecombobox", "structurecombobox", 51 "string"], 50 52 ["multi_factor", "multi_factor", "float"], 51 53 ["magnetic_on", "magnetic_on", "bool"], … … 65 67 ["smearer", "smearer", "float"], 66 68 ["smear_type", "smear_type", "string"], 67 ["dq_l", "dq_l", " string"],68 ["dq_r", "dq_r", " string"],69 ["dq_l", "dq_l", "float"], 70 ["dq_r", "dq_r", "float"], 69 71 ["dx_max", "dx_max", "float"], 70 72 ["dx_min", "dx_min", "float"], … … 80 82 ["str_parameters", "str_parameters"], 81 83 ["orientation_parameters", "orientation_params"], 82 ["dispersity_parameters", "orientation_params_disp"], 84 ["dispersity_parameters", 85 "orientation_params_disp"], 83 86 ["fixed_param", "fixed_param"], 84 87 ["fittable_param", "fittable_param"]] … … 120 123 try: 121 124 return node.get(item[0]).strip() == "True" 122 except :125 except Exception: 123 126 return None 124 127 else: 125 128 try: 126 129 return float(node.get(item[0])) 127 except :130 except Exception: 128 131 return None 129 132 … … 188 191 # page name 189 192 self.page_name = "" 190 # Contains link between model, allits parameters, and panel organization193 # Contains link between model, its parameters, and panel organization 191 194 self.parameters = [] 192 195 # String parameter list that can not be fitted … … 305 308 obj.fittable_param = copy.deepcopy(self.fittable_param) 306 309 obj.orientation_params = copy.deepcopy(self.orientation_params) 307 obj.orientation_params_disp = copy.deepcopy(self.orientation_params_disp) 310 obj.orientation_params_disp = \ 311 copy.deepcopy(self.orientation_params_disp) 308 312 obj.enable_disp = copy.deepcopy(self.enable_disp) 309 313 obj.disable_disp = copy.deepcopy(self.disable_disp) … … 397 401 rep += "data : %s\n" % str(self.data) 398 402 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % \ 399 (str(self.qmin), str(self.qmax), str(self.npts))403 (str(self.qmin), str(self.qmax), str(self.npts)) 400 404 rep += "Dispersion selection : %s\n" % str(self.disp_box) 401 405 rep += "Smearing enable : %s\n" % str(self.enable_smearer) … … 413 417 414 418 rep += "2D enable : %s\n" % str(self.enable2D) 415 rep += "All parameters checkbox selected: %s\n" % s tr(self.cb1)419 rep += "All parameters checkbox selected: %s\n" % self.cb1 416 420 rep += "Value of Chisqr : %s\n" % str(self.tcChi) 417 rep += "Smear object : %s\n" % s tr(self.smearer)418 rep += "Smear type : %s\n" % s tr(self.smear_type)421 rep += "Smear object : %s\n" % self.smearer 422 rep += "Smear type : %s\n" % self.smear_type 419 423 rep += "dq_l : %s\n" % self.dq_l 420 424 rep += "dq_r : %s\n" % self.dq_r … … 478 482 value = content[1] 479 483 except Exception: 480 msg = "Report string expected 'name: value' but got %r" %line484 msg = "Report string expected 'name: value' but got %r" % line 481 485 logging.error(msg) 482 486 if name.count("State created"): … … 493 497 if name == "value": 494 498 param_string += value + ',' 499 fixed_parameter = False 495 500 if name == "selected": 496 501 if value == u' False': 497 502 fixed_parameter = True 498 else:499 fixed_parameter = False500 503 if name == "error value": 501 504 if fixed_parameter: … … 617 620 dialog.Show() 618 621 619 def _to XML_helper(self, thelist, element, newdoc):622 def _to_xml_helper(self, thelist, element, newdoc): 620 623 """ 621 624 Helper method to create xml file for saving state … … 635 638 element.appendChild(sub_element) 636 639 637 def to XML(self, file="fitting_state.fitv", doc=None,638 entry_node=None, batch_fit_state=None):640 def to_xml(self, file="fitting_state.fitv", doc=None, 641 entry_node=None, batch_fit_state=None): 639 642 """ 640 643 Writes the state of the fit panel to file, as XML. … … 648 651 :param entry_node: XML node within the XML document at which we 649 652 will append the data [optional] 653 :param batch_fit_state: simultaneous fit state 650 654 """ 651 655 from xml.dom.minidom import getDOMImplementation … … 746 750 for item in LIST_OF_STATE_PARAMETERS: 747 751 element = newdoc.createElement(item[0]) 748 self._to XML_helper(thelist=getattr(self, item[1]),749 element=element, newdoc=newdoc)752 self._to_xml_helper(thelist=getattr(self, item[1]), 753 element=element, newdoc=newdoc) 750 754 inputs.appendChild(element) 751 755 … … 765 769 for constraint in batch_fit_state.constraints_list: 766 770 if constraint.model_cbox.GetValue() != "": 767 # model_cbox, param_cbox, egal_txt, constraint, btRemove, sizer 771 # model_cbox, param_cbox, egal_txt, constraint, 772 # btRemove, sizer 768 773 doc_cons = newdoc.createElement('constraint') 769 774 doc_cons.setAttribute('model_cbox', … … 808 813 return newdoc 809 814 810 def _from XML_helper(self, node, list):815 def _from_xml_helper(self, node, list): 811 816 """ 812 817 Helper function to write state to xml … … 858 863 [maximum_displayed, maximum_value], unit]) 859 864 860 def from XML(self, file=None, node=None):865 def from_xml(self, file=None, node=None): 861 866 """ 862 867 Load fitting state from a file … … 887 892 logging.error(msg) 888 893 889 # Parse fitting attributes890 entry = get_content('ns:Attributes', node)891 for item in LIST_OF_DATA_ATTRIBUTES:892 node = get_content('ns:%s' % item[0], entry)893 setattr(self, item[0], parse_entry_helper(node, item))894 895 894 if entry is not None: 895 # Parse fitting attributes 896 entry = get_content('ns:Attributes', node) 897 for item in LIST_OF_DATA_ATTRIBUTES: 898 node = get_content('ns:%s' % item[0], entry) 899 setattr(self, item[0], parse_entry_helper(node, item)) 900 896 901 for item in LIST_OF_STATE_ATTRIBUTES: 897 902 node = get_content('ns:%s' % item[0], entry) … … 900 905 for item in LIST_OF_STATE_PARAMETERS: 901 906 node = get_content("ns:%s" % item[0], entry) 902 self._fromXML_helper(node=node, list=getattr(self, item[1])) 907 self._from_xml_helper(node=node, 908 list=getattr(self, item[1])) 903 909 904 910 # Recover _disp_obj_dict from xml file … … 950 956 """ 951 957 images = [] 952 # some imports953 import wx954 958 955 959 # Reset memory … … 958 962 959 963 # For no figures in the list, prepare empty plot 960 if figs ==None or len(figs) == 0:964 if figs is None or len(figs) == 0: 961 965 figs = [None] 962 966 … … 965 969 self.imgRAM = wx.MemoryFSHandler() 966 970 for fig in figs: 967 if fig s !=None:971 if fig is not None: 968 972 ind = figs.index(fig) 969 973 canvas = canvases[ind] 970 974 971 # store the image in wx.FileSystem Object975 # store the image in wx.FileSystem Object 972 976 wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 973 977 … … 975 979 ind = figs.index(fig) 976 980 977 # AddFile, image can be retrieved with 'memory:filename'981 # AddFile, image can be retrieved with 'memory:filename' 978 982 self.imgRAM.AddFile('img_fit%s.png' % ind, 979 983 canvas.bitmap, wx.BITMAP_TYPE_PNG) 980 984 981 # append figs985 # append figs 982 986 images.append(fig) 983 987 … … 989 993 Class to load a .fitv fitting file 990 994 """ 991 # #File type995 # File type 992 996 type_name = "Fitting" 993 997 994 # #Wildcards998 # Wildcards 995 999 type = ["Fitting files (*.fitv)|*.fitv" 996 1000 "SASView file (*.svs)|*.svs"] 997 # #List of allowed extensions1001 # List of allowed extensions 998 1002 ext = ['.fitv', '.FITV', '.svs', 'SVS'] 999 1003 … … 1009 1013 1010 1014 """ 1011 # #Call back method to be executed after a file is read1015 # Call back method to be executed after a file is read 1012 1016 self.call_back = call_back 1013 # #CanSAS format flag1017 # CanSAS format flag 1014 1018 self.cansas = cansas 1015 1019 self.state = None … … 1027 1031 1028 1032 """ 1029 if self.cansas == True:1033 if self.cansas: 1030 1034 return self._read_cansas(path) 1031 1035 … … 1061 1065 for item in datainfo.run: 1062 1066 runname = {} 1063 if datainfo.run_name.has_key(item)and \1067 if item in datainfo.run_name and \ 1064 1068 len(str(datainfo.run_name[item])) > 1: 1065 1069 runname = {'name': datainfo.run_name[item]} … … 1076 1080 root_node = doc.createElement(item[0]) 1077 1081 new_node.appendChild(root_node) 1078 temp_list = None1079 1082 temp_list = getattr(datainfo, item[1]) 1080 1083 … … 1113 1116 datainfo.sample.position.z, 1114 1117 {"unit": datainfo.sample.position_unit}) 1115 if written == True:1118 if written: 1116 1119 sample.appendChild(pos) 1117 1120 … … 1121 1124 written = written | write_node(doc, ori, "pitch", 1122 1125 datainfo.sample.orientation.y, 1123 {"unit": datainfo.sample.orientation_unit}) 1126 {"unit": 1127 datainfo.sample.orientation_unit}) 1124 1128 written = written | write_node(doc, ori, "yaw", 1125 1129 datainfo.sample.orientation.z, 1126 {"unit": datainfo.sample.orientation_unit}) 1127 if written == True: 1130 {"unit": 1131 datainfo.sample.orientation_unit}) 1132 if written: 1128 1133 sample.appendChild(ori) 1129 1134 … … 1153 1158 datainfo.source.beam_size.z, 1154 1159 {"unit": datainfo.source.beam_size_unit}) 1155 if written == True:1160 if written: 1156 1161 source.appendChild(size) 1157 1162 … … 1198 1203 written = written | write_node(doc, size, "z", apert.size.z, 1199 1204 {"unit": apert.size_unit}) 1200 if written == True:1205 if written: 1201 1206 ap.appendChild(size) 1202 1207 … … 1210 1215 item.slit_length, 1211 1216 {"unit": item.slit_length_unit}) 1212 if written == True:1217 if written: 1213 1218 instr.appendChild(det) 1214 1219 … … 1220 1225 written = written | write_node(doc, off, "z", item.offset.z, 1221 1226 {"unit": item.offset_unit}) 1222 if written == True:1227 if written: 1223 1228 det.appendChild(off) 1224 1229 … … 1232 1237 item.beam_center.z, 1233 1238 {"unit": item.beam_center_unit}) 1234 if written == True:1239 if written: 1235 1240 det.appendChild(center) 1236 1241 … … 1242 1247 written = written | write_node(doc, pix, "z", item.pixel_size.z, 1243 1248 {"unit": item.pixel_size_unit}) 1244 if written == True:1249 if written: 1245 1250 det.appendChild(pix) 1246 1251 … … 1253 1258 written = written | write_node(doc, ori, "yaw", item.orientation.z, 1254 1259 {"unit": item.orientation_unit}) 1255 if written == True:1260 if written: 1256 1261 det.appendChild(ori) 1257 1262 … … 1290 1295 # Create an empty state 1291 1296 state = PageState() 1292 state.from XML(node=nodes[0])1297 state.from_xml(node=nodes[0]) 1293 1298 1294 1299 except: … … 1314 1319 simfitstate_0 = simfitstate[0] 1315 1320 all = simfitstate_0.xpath('ns:select_all', 1316 namespaces={'ns': CANSAS_NS})1321 namespaces={'ns': CANSAS_NS}) 1317 1322 atts = all[0].attrib 1318 1323 checked = atts.get('checked') 1319 1324 sim_fit_state.select_all = bool(checked) 1320 1325 model_list = simfitstate_0.xpath('ns:model_list', 1321 namespaces={'ns': CANSAS_NS})1326 namespaces={'ns': CANSAS_NS}) 1322 1327 model_list_items = model_list[0].xpath('ns:model_list_item', 1323 namespaces={'ns': CANSAS_NS}) 1328 namespaces={'ns': 1329 CANSAS_NS}) 1324 1330 for model in model_list_items: 1325 1331 attrs = model.attrib … … 1368 1374 return return_value, _ 1369 1375 1370 # Parse 2D1376 # Parse 2D 1371 1377 data_info = Data2D() 1372 1378 … … 1590 1596 for entry in nodes: 1591 1597 for item in LIST_OF_DATA_2D_ATTR: 1592 # get node1598 # get node 1593 1599 node = get_content('ns:%s' % item[0], entry) 1594 1600 setattr(data_info, item[1], parse_entry_helper(node, item)) … … 1633 1639 entry_list = root.xpath('ns:SASentry', 1634 1640 namespaces={'ns': CANSAS_NS}) 1635 name_map = {}1636 1641 for entry in entry_list: 1637 1642 try: … … 1679 1684 state.data.is_data = state.is_data 1680 1685 if output[ind].run_name is not None\ 1681 and len(output[ind].run_name) != 0:1686 and len(output[ind].run_name) != 0: 1682 1687 if isinstance(output[ind].run_name, dict): 1683 1688 name = output[ind].run_name.keys()[0] … … 1715 1720 # Write the XML document 1716 1721 else: 1717 doc = fitstate.to XML(file=filename)1722 doc = fitstate.to_xml(file=filename) 1718 1723 1719 1724 # Save the document no matter the type … … 1749 1754 1750 1755 if state is not None: 1751 doc = state.to XML(doc=doc, file=data.filename, entry_node=sasentry,1752 batch_fit_state=self.batchfit_params)1756 doc = state.to_xml(doc=doc, file=data.filename, entry_node=sasentry, 1757 batch_fit_state=self.batchfit_params) 1753 1758 1754 1759 return doc
Note: See TracChangeset
for help on using the changeset viewer.