Changeset f668101 in sasview for src/sas/sasgui/perspectives/fitting/fitpage.py
- Timestamp:
- Dec 7, 2016 7:16:33 AM (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:
- c6728e1
- Parents:
- 1cad8a4 (diff), 5231948 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitpage.py
r55db501 rf668101 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 … … 186 185 187 186 :return: True or False 188 189 187 """ 190 188 if self.data.__class__.__name__ == "Data2D" or \ … … 200 198 buttons, xi^2, number of points etc. 201 199 """ 202 is_2 Ddata = False200 is_2d_data = False 203 201 204 202 # Check if data is 2D 205 203 if self.data.__class__.__name__ == "Data2D" or \ 206 204 self.enable2D: 207 is_2 Ddata = True205 is_2d_data = True 208 206 209 207 title = "Fitting" 210 # smear messages & titles208 # smear messages & titles 211 209 smear_message_none = "No smearing is selected..." 212 210 smear_message_dqdata = "The dQ data is being used for smearing..." … … 226 224 self._get_smear_info() 227 225 228 # Sizers226 # Sizers 229 227 box_description_range = wx.StaticBox(self, wx.ID_ANY, str(title)) 230 228 box_description_range.SetForegroundColour(wx.BLUE) … … 245 243 sizer_weighting = wx.BoxSizer(wx.HORIZONTAL) 246 244 weighting_box.SetMinSize((_DATA_BOX_WIDTH, 40)) 247 # Filling the sizer containing weighting info.245 # Filling the sizer containing weighting info. 248 246 self.dI_noweight = wx.RadioButton(self, wx.ID_ANY, 249 247 'No Weighting', style=wx.RB_GROUP) … … 287 285 self._on_select_accuracy) 288 286 289 # Fit button287 # Fit button 290 288 self.btFit = wx.Button(self, self._ids.next(), 'Fit') 291 289 self.default_bt_colour = self.btFit.GetDefaultAttributes() … … 293 291 self.btFit.SetToolTipString("Start fitting.") 294 292 295 # General Help button293 # General Help button 296 294 self.btFitHelp = wx.Button(self, wx.ID_ANY, 'Help') 297 295 self.btFitHelp.SetToolTipString("General fitting help.") 298 296 self.btFitHelp.Bind(wx.EVT_BUTTON, self._onFitHelp) 299 297 300 # Resolution Smearing Help button (for now use same technique as301 # used for dI help to get tiniest possible button that works302 # both on MAC and PC. Should completely rewrite the fitting sizer303 # in future. This is minimum to get out release 3.1298 # Resolution Smearing Help button (for now use same technique as 299 # used for dI help to get tiniest possible button that works 300 # both on MAC and PC. Should completely rewrite the fitting sizer 301 # in future. This is minimum to get out release 3.1 304 302 # comment June 14, 2015 --- PDB 305 303 if sys.platform.count("win32") > 0: 306 size_q = (20, 15) # on PC304 size_q = (20, 15) # on PC 307 305 else: 308 size_q = (30, 20) # on MAC306 size_q = (30, 20) # on MAC 309 307 self.btSmearHelp = wx.Button(self, wx.ID_ANY, '?', 310 308 style=wx.BU_EXACTFIT, size=size_q) … … 312 310 self.btSmearHelp.Bind(wx.EVT_BUTTON, self._onSmearHelp) 313 311 314 # textcntrl for custom resolution312 # textcntrl for custom resolution 315 313 self.smear_pinhole_max = ModelTextCtrl(self, wx.ID_ANY, 316 314 size=(_BOX_WIDTH - 25, 20), … … 330 328 text_enter_callback=self.onSlitSmear) 331 329 332 # #smear330 # smear 333 331 self.smear_data_left = BGTextCtrl(self, wx.ID_ANY, 334 332 size=(_BOX_WIDTH - 25, 20), style=0) … … 338 336 self.smear_data_right.SetValue(str(self.dq_r)) 339 337 340 # set default values for smear338 # set default values for smear 341 339 self.smear_pinhole_max.SetValue(str(self.dx_max)) 342 340 self.smear_pinhole_min.SetValue(str(self.dx_min)) … … 344 342 self.smear_slit_width.SetValue(str(self.dxw)) 345 343 346 # Filling the sizer containing instruments smearing info.344 # Filling the sizer containing instruments smearing info. 347 345 self.disable_smearer = wx.RadioButton(self, wx.ID_ANY, 348 346 'None', style=wx.RB_GROUP) 349 347 self.enable_smearer = wx.RadioButton(self, wx.ID_ANY, 'Use dQ Data') 350 # self.enable_smearer.SetToolTipString(351 # "Click to use the loaded dQ data for smearing.")348 # self.enable_smearer.SetToolTipString( 349 # "Click to use the loaded dQ data for smearing.") 352 350 self.pinhole_smearer = wx.RadioButton(self, wx.ID_ANY, 353 351 'Custom Pinhole Smear') 354 # self.pinhole_smearer.SetToolTipString355 # ("Click to input custom resolution for pinhole smearing.")352 # self.pinhole_smearer.SetToolTipString 353 # ("Click to input custom resolution for pinhole smearing.") 356 354 self.slit_smearer = wx.RadioButton(self, wx.ID_ANY, 'Custom Slit Smear') 357 # self.slit_smearer.SetToolTipString358 # ("Click to input custom resolution for slit smearing.")355 # self.slit_smearer.SetToolTipString 356 # ("Click to input custom resolution for slit smearing.") 359 357 self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, 360 358 id=self.disable_smearer.GetId()) … … 379 377 self.Npts_fit = BGTextCtrl(self, wx.ID_ANY, "-", size=(75, 20), style=0) 380 378 self.Npts_fit.SetToolTipString( 381 379 " Npts : number of points selected for fitting") 382 380 self.Npts_total = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 383 style=wx.TE_PROCESS_ENTER,384 text_enter_callback=self._onQrangeEnter)381 style=wx.TE_PROCESS_ENTER, 382 text_enter_callback=self._onQrangeEnter) 385 383 self.Npts_total.SetValue(format_number(self.npts_x)) 386 self.Npts_total.SetToolTipString( \387 384 self.Npts_total.SetToolTipString( 385 " Total Npts : total number of data points") 388 386 389 387 # Update and Draw button … … 430 428 self.smear_description_2d_y = wx.StaticText(self, wx.ID_ANY, 431 429 smear_message_2d_y_title, style=wx.ALIGN_LEFT) 432 self.smear_description_2d_y.SetToolTipString( \430 self.smear_description_2d_y.SetToolTipString( 433 431 " dQs(perpendicular) in q_phi direction.") 434 432 self.smear_description_pin_min = wx.StaticText(self, wx.ID_ANY, … … 441 439 smear_message_slit_width_title, style=wx.ALIGN_LEFT) 442 440 443 # arrange sizers441 # arrange sizers 444 442 self.sizer_set_smearer.Add(sizer_smearer) 445 443 self.sizer_set_smearer.Add((10, 10)) 446 444 self.sizer_set_smearer.Add(self.smear_description_none, 447 445 0, wx.CENTER, 10) 448 446 self.sizer_set_smearer.Add(self.smear_description_dqdata, 449 447 0, wx.CENTER, 10) 450 448 self.sizer_set_smearer.Add(self.smear_description_2d, 451 449 0, wx.CENTER, 10) 452 450 self.sizer_new_smear.Add(self.smear_description_type, 453 451 0, wx.CENTER, 10) 454 452 self.sizer_new_smear.Add(self.smear_description_accuracy_type, 455 453 0, wx.CENTER, 10) 456 454 self.sizer_new_smear.Add(self.smear_accuracy) 457 455 self.sizer_new_smear.Add(self.smear_description_smear_type, 458 456 0, wx.CENTER, 10) 459 457 self.sizer_new_smear.Add((15, -1)) 460 self.sizer_new_smear.Add(self.smear_description_2d_x, 461 0, wx.CENTER, 10) 458 self.sizer_new_smear.Add(self.smear_description_2d_x, 0, wx.CENTER, 10) 462 459 self.sizer_new_smear.Add(self.smear_description_pin_min, 463 460 0, wx.CENTER, 10) 464 461 self.sizer_new_smear.Add(self.smear_description_slit_height, 465 0, wx.CENTER, 10) 466 467 self.sizer_new_smear.Add(self.smear_pinhole_min, 468 0, wx.CENTER, 10) 469 self.sizer_new_smear.Add(self.smear_slit_height, 470 0, wx.CENTER, 10) 471 self.sizer_new_smear.Add(self.smear_data_left, 472 0, wx.CENTER, 10) 462 0, wx.CENTER, 10) 463 464 self.sizer_new_smear.Add(self.smear_pinhole_min, 0, wx.CENTER, 10) 465 self.sizer_new_smear.Add(self.smear_slit_height, 0, wx.CENTER, 10) 466 self.sizer_new_smear.Add(self.smear_data_left, 0, wx.CENTER, 10) 473 467 self.sizer_new_smear.Add((20, -1)) 474 468 self.sizer_new_smear.Add(self.smear_description_2d_y, 475 469 0, wx.CENTER, 10) 476 470 self.sizer_new_smear.Add(self.smear_description_pin_max, 477 471 0, wx.CENTER, 10) 478 472 self.sizer_new_smear.Add(self.smear_description_slit_width, 479 473 0, wx.CENTER, 10) 480 474 481 475 self.sizer_new_smear.Add(self.smear_pinhole_max, 0, wx.CENTER, 10) … … 502 496 503 497 # Show only the relevant smear messages, etc 504 if self.current_smearer ==None:505 if not is_2 Ddata:498 if self.current_smearer is None: 499 if not is_2d_data: 506 500 self.smear_description_none.Show(True) 507 501 self.enable_smearer.Disable() … … 509 503 self.smear_description_none.Show(True) 510 504 self.slit_smearer.Disable() 511 if self.data ==None:505 if self.data is None: 512 506 self.slit_smearer.Disable() 513 507 self.pinhole_smearer.Disable() … … 516 510 self._show_smear_sizer() 517 511 boxsizer_range.Add(self.sizer_set_masking) 518 # 2D data? default519 is_2 Ddata = False520 521 # check if it is 2D data512 # 2D data? default 513 is_2d_data = False 514 515 # check if it is 2D data 522 516 if self.data.__class__.__name__ == "Data2D" or self.enable2D: 523 is_2 Ddata = True517 is_2d_data = True 524 518 525 519 self.sizer5.Clear(True) … … 569 563 sizer.Add(wx.StaticText(self, wx.ID_ANY, ' Max[1/A]')) 570 564 sizer.Add(self.EditMask_title) 571 sizer.Add((-1, 5))565 sizer.Add((-1, 5)) 572 566 573 567 sizer.Add(self.reset_qrange) … … 575 569 sizer.Add(self.qmax) 576 570 sizer.Add(self.btEditMask) 577 sizer.Add((-1, 5))578 579 sizer.AddMany(5*[(-1, 5)])571 sizer.Add((-1, 5)) 572 573 sizer.AddMany(5*[(-1, 5)]) 580 574 581 575 sizer.Add(box_description_1, 0, 0) … … 583 577 sizer.Add(self.points_sizer, 0, 0) 584 578 sizer.Add(self.draw_button, 0, 0) 585 sizer.Add((-1, 5))579 sizer.Add((-1, 5)) 586 580 587 581 sizer.Add(self.tcChi, 0, 0) … … 593 587 boxsizer_range.Add(sizer_chi2) 594 588 boxsizer_range.Add(sizer) 595 if is_2 Ddata:589 if is_2d_data: 596 590 self.btEditMask.Enable() 597 591 self.EditMask_title.Enable() … … 599 593 self.btEditMask.Disable() 600 594 self.EditMask_title.Disable() 601 # #save state595 # save state 602 596 self.save_current_state() 603 597 self.sizer5.Add(boxsizer_range, 0, wx.EXPAND | wx.ALL, 10) 604 598 self.sizer5.Layout() 605 599 606 607 600 def _set_sizer_dispersion(self): 608 601 """ … … 614 607 615 608 self.sizer4_4.Clear(True) 616 if self.model ==None:617 # #no model is selected609 if self.model is None: 610 # no model is selected 618 611 return 619 612 if not self.enable_disp.GetValue(): 620 # #the user didn't select dispersity display613 # the user didn't select dispersity display 621 614 return 622 615 623 616 self._reset_dispersity() 624 617 625 # #fill a sizer with the combobox to select dispersion type618 # fill a sizer with the combobox to select dispersion type 626 619 model_disp = wx.StaticText(self, wx.ID_ANY, 'Function') 627 620 CHECK_STATE = self.cb1.GetValue() … … 646 639 err_text = '' 647 640 self.text_disp_1 = wx.StaticText(self, wx.ID_ANY, err_text) 648 self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), \641 self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), 649 642 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 650 643 651 644 ix += 1 652 645 self.text_disp_min = wx.StaticText(self, wx.ID_ANY, 'Min') 653 self.sizer4_4.Add(self.text_disp_min, (iy, ix), (1, 1), \646 self.sizer4_4.Add(self.text_disp_min, (iy, ix), (1, 1), 654 647 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 655 648 … … 684 677 if item in self.model.magnetic_params: 685 678 continue 686 if not itemin self.model.orientation_params:687 if not itemin self.disp_cb_dict:679 if item not in self.model.orientation_params: 680 if item not in self.disp_cb_dict: 688 681 self.disp_cb_dict[item] = None 689 682 name0 = "Distribution of " + item … … 691 684 name2 = item + ".npts" 692 685 name3 = item + ".nsigmas" 693 if n ot name1in self.model.details:686 if name1 not in self.model.details: 694 687 self.model.details[name1] = ["", None, None] 695 688 … … 717 710 ctl1.SetValue(str(format_number(value, True))) 718 711 self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 719 # #text to show error sign712 # text to show error sign 720 713 ix = 2 721 714 text2 = wx.StaticText(self, wx.ID_ANY, '+/-') … … 777 770 Tct2.SetValue(str(format_number(value))) 778 771 self.sizer4_4.Add(Tct2, (iy, ix), (1, 1), 779 772 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 780 773 self.fixed_param.append([None, name3, Tct2, 781 774 None, None, None, … … 803 796 if item in self.model.magnetic_params: 804 797 continue 805 if 806 if not itemin self.disp_cb_dict:798 if item in self.model.orientation_params: 799 if item not in self.disp_cb_dict: 807 800 self.disp_cb_dict[item] = None 808 801 name0 = "Distribution of " + item … … 811 804 name3 = item + ".nsigmas" 812 805 813 if n ot name1in self.model.details:806 if name1 not in self.model.details: 814 807 self.model.details[name1] = ["", None, None] 815 808 … … 856 849 857 850 self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 858 # #text to show error sign851 # text to show error sign 859 852 ix = 2 860 853 text2 = wx.StaticText(self, wx.ID_ANY, '+/-') … … 969 962 970 963 self.state.model = self.model.clone() 971 ## save state into 972 self.state.cb1 = self.cb1.GetValue()964 965 # save state into 973 966 self._copy_parameters_state(self.parameters, self.state.parameters) 974 967 self._copy_parameters_state(self.orientation_params_disp, … … 980 973 wx.PostEvent(self.parent, 981 974 StatusEvent(status=" Selected Distribution: Gaussian")) 982 #Fill the list of fittable parameters 983 # self.select_all_param(event=None)975 976 # Fill the list of fittable parameters 984 977 self.get_all_checked_params() 985 978 self.Layout() … … 989 982 Update and Draw the model 990 983 """ 991 if self.model ==None:984 if self.model is None: 992 985 msg = "Please select a Model first..." 993 986 wx.MessageBox(msg, 'Info') … … 999 992 self.create_default_data() 1000 993 """ 1001 flag, is_modified = self._update_paramv_on_fit()1002 1003 wx.CallAfter(self._onparamEnter_helper, is_modified)994 flag, is_modified = self._update_paramv_on_fit() 995 996 wx.CallAfter(self._onparamEnter_helper, is_modified) 1004 997 if not flag: 1005 998 msg = "The parameters are invalid" … … 1011 1004 Allow to fit 1012 1005 """ 1013 if event !=None:1006 if event is not None: 1014 1007 event.Skip() 1015 1008 if self.fit_started: … … 1051 1044 return 1052 1045 1053 self.select_param( event=None)1046 self.select_param() 1054 1047 1055 1048 # Remove or do not allow fitting on the Q=0 point, especially … … 1062 1055 qmax=self.qmax_x) 1063 1056 1064 # single fit1065 # self._manager.onFit(uid=self.uid)1057 # single fit 1058 # self._manager.onFit(uid=self.uid) 1066 1059 self.fit_started = self._manager.onFit(uid=self.uid) 1067 1060 wx.CallAfter(self.set_fitbutton) … … 1076 1069 versions of Wx (before 2.9) and thus not the release version of 1077 1070 installers, the help comes up at the top level of the file as 1078 web browser does not pass anything past the # to the browser when it is1071 web browser does not pass anything past the # to the browser when it is 1079 1072 running "file:///...." 1080 1073 1081 :param evt: Triggers on clicking the help button1082 """1074 :param evt: Triggers on clicking the help button 1075 """ 1083 1076 1084 1077 _TreeLocation = "user/sasgui/perspectives/fitting/fitting_help.html" … … 1095 1088 versions of Wx (before 2.9) and thus not the release version of 1096 1089 installers, the help comes up at the top level of the file as 1097 web browser does not pass anything past the # to the browser when it is1090 web browser does not pass anything past the # to the browser when it is 1098 1091 running "file:///...." 1099 1092 1100 :param evt: Triggers on clicking the help button1101 """1093 :param evt: Triggers on clicking the help button 1094 """ 1102 1095 1103 1096 _TreeLocation = "user/sasgui/perspectives/fitting/sm_help.html" … … 1111 1104 """ 1112 1105 # Skip this feature if we are not on Windows 1113 # NOTE: the is_mac data member actually means "is no Windows".1106 # NOTE: the is_mac data member actually means "is no Windows". 1114 1107 if self.is_mac: 1115 1108 return … … 1121 1114 label = "Fit" 1122 1115 color = "black" 1123 # self.btFit.Enable(False)1116 # self.btFit.Enable(False) 1124 1117 self.btFit.SetLabel(label) 1125 1118 self.btFit.SetForegroundColour(color) … … 1152 1145 Stop fit 1153 1146 """ 1154 if event !=None:1147 if event is not None: 1155 1148 event.Skip() 1156 1149 self._manager.stop_fit(self.uid) … … 1172 1165 copy_flag = False 1173 1166 is_poly_enabled = None 1174 if event !=None:1175 if (event.GetEventObject() == self.formfactorbox \1167 if event is not None: 1168 if (event.GetEventObject() == self.formfactorbox 1176 1169 and self.structurebox.GetLabel() != 'None')\ 1177 1170 or event.GetEventObject() == self.structurebox\ … … 1186 1179 self._keep.Enable(False) 1187 1180 self._set_save_flag(False) 1188 # TODO: why do we have to variables for one flag??1189 1181 self.enable_disp.SetValue(False) 1190 1182 self.disable_disp.SetValue(True) … … 1216 1208 self._keep.Enable(not self.batch_on) 1217 1209 self._set_save_flag(True) 1210 self._set_smear(self.data) 1218 1211 1219 1212 # more disables for 2D … … 1229 1222 except: 1230 1223 raise 1231 # #error occured on chisqr computation1232 # pass1233 # #event to post model to fit to fitting plugins1224 # error occured on chisqr computation 1225 # pass 1226 # event to post model to fit to fitting plugins 1234 1227 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 1235 1228 1236 ## set smearing value whether or not 1237 # the data contain the smearing info 1229 # set smearing value whether or not data contain the smearing info 1238 1230 evt = ModelEventbox(model=self.model, 1239 1231 smearer=temp_smear, … … 1245 1237 1246 1238 self._manager._on_model_panel(evt=evt) 1247 self.mbox_description.SetLabel("Model [ %s ]" % str(self.model.name)) 1239 self.mbox_description.SetLabel("Model [ %s ]" % 1240 str(self.model.name)) 1248 1241 self.mbox_description.SetForegroundColour(wx.BLUE) 1249 1242 self.state.model = self.model.clone() 1250 1243 self.state.model.name = self.model.name 1251 1244 1252 if event !=None:1253 # #post state to fit panel1245 if event is not None: 1246 # post state to fit panel 1254 1247 new_event = PageInfoEvent(page=self) 1255 1248 wx.PostEvent(self.parent, new_event) 1256 # update list of plugins if new plugin is available1249 # update list of plugins if new plugin is available 1257 1250 custom_model = 'Customized Models' 1258 1251 mod_cat = self.categorybox.GetStringSelection() … … 1267 1260 self.formfactorbox.SetValue(current_val) 1268 1261 # when select a model only from guictr/button 1269 if is_poly_enabled !=None:1262 if is_poly_enabled is not None: 1270 1263 self.enable_disp.SetValue(is_poly_enabled) 1271 1264 self.disable_disp.SetValue(not is_poly_enabled) … … 1295 1288 when enter value on panel redraw model according to changed 1296 1289 """ 1297 if self.model ==None:1290 if self.model is None: 1298 1291 msg = "Please select a Model first..." 1299 1292 wx.MessageBox(msg, 'Info') 1300 1293 return 1301 1294 1302 # default flag1295 # default flag 1303 1296 flag = False 1304 1297 self.fitrange = True 1305 # get event object1298 # get event object 1306 1299 tcrtl = event.GetEventObject() 1307 # Clear msg if previously shown.1300 # Clear msg if previously shown. 1308 1301 msg = "" 1309 1302 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1316 1309 if not self.disable_smearer.GetValue(): 1317 1310 temp_smearer = self.current_smearer 1318 # # set smearing value whether or not1319 # the data contain thesmearing info1311 # set smearing value whether or not data contain the 1312 # smearing info 1320 1313 if self.slit_smearer.GetValue(): 1321 1314 flag1 = self.update_slit_smear() … … 1334 1327 enable_smearer=enable_smearer) 1335 1328 if flag: 1336 # self.compute_chisqr(smearer= temp_smearer)1337 1338 # #new state posted1329 # self.compute_chisqr(smearer= temp_smearer) 1330 1331 # new state posted 1339 1332 if self.state_change: 1340 # self._undo.Enable(True)1333 # self._undo.Enable(True) 1341 1334 event = PageInfoEvent(page=self) 1342 1335 wx.PostEvent(self.parent, event) … … 1348 1341 else: 1349 1342 self.save_current_state() 1350 msg = "Cannot Plot :Must enter a number!!! "1343 msg = "Cannot Plot: Must enter a number!!! " 1351 1344 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1352 1345 … … 1359 1352 """ 1360 1353 tcrtl = event.GetEventObject() 1361 # Clear msg if previously shown.1354 # Clear msg if previously shown. 1362 1355 msg = "" 1363 1356 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1377 1370 tcrtl.SetBackgroundColour(wx.WHITE) 1378 1371 1379 # self._undo.Enable(True)1372 # self._undo.Enable(True) 1380 1373 self.save_current_state() 1381 1374 event = PageInfoEvent(page=self) … … 1387 1380 ON Qrange focus 1388 1381 """ 1389 if event !=None:1382 if event is not None: 1390 1383 event.Skip() 1391 # tcrtl = event.GetEventObject()1384 # tcrtl = event.GetEventObject() 1392 1385 self._validate_qrange(self.qmin, self.qmax) 1393 1386 … … 1396 1389 On Qrange textctrl click, make the qrange lines in the plot 1397 1390 """ 1398 if event !=None:1391 if event is not None: 1399 1392 event.Skip() 1400 1393 if self.data.__class__.__name__ == "Data2D": … … 1414 1407 #On q range value updated. DO not combine with qrange_click(). 1415 1408 """ 1416 if event !=None:1409 if event is not None: 1417 1410 event.Skip() 1418 1411 if self.data.__class__.__name__ == "Data2D": … … 1442 1435 length = len(self.data.x) 1443 1436 indx = (numpy.abs(self.data.x - x_data)).argmin() 1444 # return array.flat[idx]1437 # return array.flat[idx] 1445 1438 if key == wx.WXK_PAGEUP or key == wx.WXK_NUMPAD_PAGEUP: 1446 1439 indx += 1 … … 1461 1454 """ 1462 1455 tcrtl = event.GetEventObject() 1463 # Clear msg if previously shown.1456 # Clear msg if previously shown. 1464 1457 msg = "" 1465 1458 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1491 1484 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1492 1485 return 1493 # Check if # of points for theory model are valid(>0).1486 # Check if # of points for theory model are valid(>0). 1494 1487 # check for 2d 1495 1488 if self.data.__class__.__name__ == "Data2D" or \ … … 1498 1491 radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + 1499 1492 self.data.qy_data * self.data.qy_data) 1500 index_data = ((self.qmin_x <= radius) & \ 1501 (radius <= self.qmax_x)) 1493 index_data = ((self.qmin_x <= radius) & (radius <= self.qmax_x)) 1502 1494 index_data = (index_data) & (self.data.mask) 1503 1495 index_data = (index_data) & (numpy.isfinite(self.data.data)) … … 1509 1501 return 1510 1502 else: 1511 # self.data.mask = index_data1512 # self.Npts_fit.SetValue(str(len(self.data.mask)))1503 # self.data.mask = index_data 1504 # self.Npts_fit.SetValue(str(len(self.data.mask))) 1513 1505 self.show_npts2fit() 1514 1506 else: 1515 index_data = ((self.qmin_x <= self.data.x) & \1507 index_data = ((self.qmin_x <= self.data.x) & 1516 1508 (self.data.x <= self.qmax_x)) 1517 1509 self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) … … 1546 1538 for item in self.parameters: 1547 1539 if item[0].IsShown(): 1548 # Skip the angle parameters if 1D data1540 # Skip the angle parameters if 1D data 1549 1541 if self.data.__class__.__name__ != "Data2D" and \ 1550 1542 not self.enable2D: … … 1553 1545 if item in self.param_toFit: 1554 1546 continue 1555 # #hide statictext +/-1547 # hide statictext +/- 1556 1548 if len(item) < 4: 1557 1549 continue 1558 if item[3] !=None and item[3].IsShown():1550 if item[3] is not None and item[3].IsShown(): 1559 1551 item[3].Hide() 1560 # #hide textcrtl for error after fit1561 if item[4] !=None and item[4].IsShown():1552 # hide textcrtl for error after fit 1553 if item[4] is not None and item[4].IsShown(): 1562 1554 item[4].Hide() 1563 1555 … … 1565 1557 for item in self.fittable_param: 1566 1558 if item[0].IsShown(): 1567 # Skip the angle parameters if 1D data1559 # Skip the angle parameters if 1D data 1568 1560 if self.data.__class__.__name__ != "Data2D" and \ 1569 1561 not self.enable2D: … … 1574 1566 if len(item) < 4: 1575 1567 continue 1576 # #hide statictext +/-1577 if item[3] !=None and item[3].IsShown():1568 # hide statictext +/- 1569 if item[3] is not None and item[3].IsShown(): 1578 1570 item[3].Hide() 1579 # #hide textcrtl for error after fit1580 if item[4] !=None and item[4].IsShown():1571 # hide textcrtl for error after fit 1572 if item[4] is not None and item[4].IsShown(): 1581 1573 item[4].Hide() 1582 1574 return … … 1587 1579 """ 1588 1580 # get the default values 1589 if self.dxl ==None:1581 if self.dxl is None: 1590 1582 self.dxl = 0.0 1591 if self.dxw ==None:1583 if self.dxw is None: 1592 1584 self.dxw = "" 1593 if self.dx_min ==None:1585 if self.dx_min is None: 1594 1586 self.dx_min = SMEAR_SIZE_L 1595 if self.dx_max ==None:1587 if self.dx_max is None: 1596 1588 self.dx_max = SMEAR_SIZE_H 1597 1589 … … 1614 1606 elif self.data.__class__.__name__ == "Data2D" or \ 1615 1607 self.enable2D: 1616 if data.dqx_data == None or data.dqy_data ==None:1608 if data.dqx_data is None or data.dqy_data is None: 1617 1609 return 1618 elif self.current_smearer !=None \1610 elif self.current_smearer is not None \ 1619 1611 and data.dqx_data.any() != 0 \ 1620 1612 and data.dqx_data.any() != 0: … … 1626 1618 return 1627 1619 # check if it is pinhole smear and get min max if it is. 1628 if data.dx != None and all(data.dx != 0):1620 if data.dx is not None and not numpy.any(data.dx): 1629 1621 self.smear_type = "Pinhole" 1630 1622 self.dq_l = data.dx[0] … … 1632 1624 1633 1625 # check if it is slit smear and get min max if it is. 1634 elif data.dxl != None or data.dxw !=None:1626 elif data.dxl is not None or data.dxw is not None: 1635 1627 self.smear_type = "Slit" 1636 if data.dxl != None and all(data.dxl !=0):1628 if data.dxl is not None and not numpy.all(data.dxl, 0): 1637 1629 self.dq_l = data.dxl[0] 1638 if data.dxw != None and all(data.dxw !=0):1630 if data.dxw is not None and not numpy.all(data.dxw, 0): 1639 1631 self.dq_r = data.dxw[0] 1640 # return self.smear_type,self.dq_l,self.dq_r1632 # return self.smear_type,self.dq_l,self.dq_r 1641 1633 1642 1634 def _show_smear_sizer(self): … … 1662 1654 1663 1655 self.smear_description_dqdata.Show(True) 1664 if self.smear_type !=None:1656 if self.smear_type is not None: 1665 1657 self.smear_description_smear_type.Show(True) 1666 1658 if self.smear_type == 'Slit': … … 1753 1745 Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low 1754 1746 """ 1755 # event.Skip()1747 # event.Skip() 1756 1748 # Check if the accuracy is same as before 1757 # self.smear2d_accuracy = event.GetEventObject().GetValue()1749 # self.smear2d_accuracy = event.GetEventObject().GetValue() 1758 1750 self.smear2d_accuracy = self.smear_accuracy.GetValue() 1759 1751 if self.pinhole_smearer.GetValue(): … … 1761 1753 else: 1762 1754 self.onSmear(event=None) 1763 if self.current_smearer !=None:1755 if self.current_smearer is not None: 1764 1756 self.current_smearer.set_accuracy(accuracy=\ 1765 1757 self.smear2d_accuracy) … … 1793 1785 Build a panel to allow to edit Mask 1794 1786 """ 1795 from sas.sasgui.guiframe.local_perspectives.plotting.masking \1796 importMaskPanel as MaskDialog1787 from sas.sasgui.guiframe.local_perspectives.plotting.masking import \ 1788 MaskPanel as MaskDialog 1797 1789 1798 1790 self.panel = MaskDialog(base=self, data=self.data, id=wx.NewId()) … … 1805 1797 is_valid_qrange = self._update_paramv_on_fit() 1806 1798 1807 if is_valid_qrange and self.model !=None:1799 if is_valid_qrange and self.model is not None: 1808 1800 self.panel.MakeModal(False) 1809 1801 event.Skip() … … 1811 1803 self._draw_model() 1812 1804 self.show_npts2fit() 1813 elif self.model ==None:1805 elif self.model is None: 1814 1806 self.panel.MakeModal(False) 1815 1807 event.Skip() … … 1878 1870 npts = len(data.x) 1879 1871 except: 1880 msg = "Unable to find min/max/length of \n data named %s" % 1872 msg = "Unable to find min/max/length of \n data named %s" %\ 1881 1873 data.filename 1882 1874 wx.PostEvent(self._manager.parent, StatusEvent(status=msg, … … 1895 1887 info="error")) 1896 1888 raise ValueError, msg 1897 # #Maximum value of data1889 # Maximum value of data 1898 1890 qmax = math.sqrt(x * x + y * y) 1899 1891 npts = len(data.data) … … 1907 1899 flag = False 1908 1900 is_data = False 1901 npts = 0 1909 1902 try: 1910 1903 old_id = self.data.id … … 1918 1911 flag = True 1919 1912 if data is not None: 1920 id = data.id1921 1913 if is_data: 1922 1914 self.graph_id = self.data.group_id … … 1933 1925 self._set_save_flag(False) 1934 1926 else: 1935 if self.model !=None:1927 if self.model is not None: 1936 1928 self._set_bookmark_flag(not self.batch_on) 1937 1929 self._keep.Enable(not self.batch_on) … … 1940 1932 self._set_preview_flag(True) 1941 1933 1942 self._set_smear(data)1943 1934 # more disables for 2D 1944 1935 if self.data.__class__.__name__ == "Data2D" or \ … … 1947 1938 self.pinhole_smearer.Enable(True) 1948 1939 self.default_mask = copy.deepcopy(self.data.mask) 1949 if self.data.err_data ==None or\1950 (self.data.err_data == 1).all() or\1951 (self.data.err_data == 0).all():1940 if self.data.err_data is None or\ 1941 numpy.all(err == 1 for err in self.data.err_data) or \ 1942 not numpy.any(self.data.err_data): 1952 1943 self.dI_didata.Enable(False) 1953 1944 self.dI_noweight.SetValue(True) … … 1960 1951 self.slit_smearer.Enable(True) 1961 1952 self.pinhole_smearer.Enable(True) 1962 if self.data.dy == None or\ 1963 (self.data.dy == 1).all() or\ 1964 (self.data.dy == 0).all(): 1953 1954 if self.data.dy is None or\ 1955 numpy.all(self.data.dy == 1) or\ 1956 not numpy.any(self.data.dy): 1965 1957 self.dI_didata.Enable(False) 1966 1958 self.dI_noweight.SetValue(True) … … 1970 1962 self.dI_didata.SetValue(True) 1971 1963 self.weightbt_string = self.dI_didata.GetLabelText() 1972 # Enable weighting radio uttons1964 # Enable weighting radio buttons 1973 1965 self.dI_noweight.Enable(True) 1974 1966 self.dI_sqrdata.Enable(True) … … 1979 1971 data_name = self.data.name 1980 1972 _, _, npts = self.compute_data_range(self.data) 1981 # set maximum range for x in linear scale1973 # set maximum range for x in linear scale 1982 1974 if not hasattr(self.data, "data"): # Display only for 1D data fit 1983 1975 self.btEditMask.Disable() … … 1988 1980 1989 1981 self.Npts_total.SetValue(str(npts)) 1990 # default:number of data points selected to fit1982 # default:number of data points selected to fit 1991 1983 self.Npts_fit.SetValue(str(npts)) 1992 1984 self.Npts_total.SetEditable(False) 1993 self.Npts_total.SetBackgroundColour( \1985 self.Npts_total.SetBackgroundColour( 1994 1986 self.GetParent().GetBackgroundColour()) 1995 1987 … … 2001 1993 # send graph_id to page_finder 2002 1994 self._manager.set_graph_id(uid=self.uid, graph_id=self.graph_id) 2003 # focus the page1995 # focus the page 2004 1996 if check_data_validity(data): 2005 1997 self.data_box_description.SetForegroundColour(wx.BLUE) … … 2013 2005 self.on_set_focus(None) 2014 2006 self.Refresh() 2015 # update model plot with new data information2007 # update model plot with new data information 2016 2008 if flag: 2017 #set model view button2018 self.onSmear(None)2019 2020 2009 if self.data.__class__.__name__ == "Data2D": 2021 2010 self.enable2D = True … … 2025 2014 self.model_view.SetLabel("1D Mode") 2026 2015 self.model_view.Disable() 2027 # replace data plot on combo box selection2028 # by removing the previous selected data2016 # replace data plot on combo box selection 2017 # by removing the previous selected data 2029 2018 try: 2030 2019 wx.PostEvent(self._manager.parent, … … 2033 2022 except: 2034 2023 pass 2035 # plot the current selected data2024 # plot the current selected data 2036 2025 wx.PostEvent(self._manager.parent, 2037 2026 NewPlotEvent(action="check", plot=self.data, … … 2053 2042 self.reset_page_helper(state) 2054 2043 2055 self.select_param( event=None)2056 # Save state_fit2044 self.select_param() 2045 # Save state_fit 2057 2046 self.save_current_state_fit() 2058 2047 except: … … 2093 2082 else: 2094 2083 for qx in self.data.x: 2095 if q x >= qmin and qx <= qmax:2084 if qmax >= qx >= qmin: 2096 2085 npts2fit += 1 2097 2086 return npts2fit … … 2122 2111 # make sure stop button to fit button all the time 2123 2112 self._on_fit_complete() 2124 if out ==None or not numpy.isfinite(chisqr):2113 if out is None or not numpy.isfinite(chisqr): 2125 2114 raise ValueError, "Fit error occured..." 2126 2115 … … 2129 2118 dispersity = '' 2130 2119 2131 # Hide textctrl boxes of errors.2120 # Hide textctrl boxes of errors. 2132 2121 self._clear_Err_on_Fit() 2133 2122 2134 # Check if chi2 is finite2135 if chisqr !=None and numpy.isfinite(chisqr):2136 # format chi22123 # Check if chi2 is finite 2124 if chisqr is not None and numpy.isfinite(chisqr): 2125 # format chi2 2137 2126 chi2 = format_number(chisqr, True) 2138 2127 self.tcChi.SetValue(chi2) … … 2141 2130 self.tcChi.SetValue("-") 2142 2131 2143 # Hide error title2132 # Hide error title 2144 2133 if self.text2_3.IsShown() and not self.is_mac: 2145 2134 self.text2_3.Hide() … … 2148 2137 if self.enable_disp.GetValue(): 2149 2138 if hasattr(self, "text_disp_1"): 2150 if self.text_disp_1 !=None and not self.is_mac:2139 if self.text_disp_1 is not None and not self.is_mac: 2151 2140 self.text_disp_1.Hide() 2152 2141 except: … … 2155 2144 2156 2145 i = 0 2157 # Set the panel when fit result are list2146 # Set the panel when fit result are list 2158 2147 2159 2148 for item in self.param_toFit: 2160 if len(item) > 5 and item !=None:2149 if len(item) > 5 and item is not None: 2161 2150 2162 2151 if item[0].IsShown(): 2163 # #reset error value to initial state2152 # reset error value to initial state 2164 2153 if not self.is_mac: 2165 2154 item[3].Hide() … … 2168 2157 if item[1] == p_name[ind]: 2169 2158 break 2170 if len(out) > 0 and out[ind] !=None:2159 if len(out) > 0 and out[ind] is not None: 2171 2160 val_out = format_number(out[ind], True) 2172 2161 item[2].SetValue(val_out) 2173 2162 2174 if(cov !=None and len(cov) == len(out)):2163 if(cov is not None and len(cov) == len(out)): 2175 2164 try: 2176 if dispersity !=None:2165 if dispersity is not None: 2177 2166 if self.enable_disp.GetValue(): 2178 2167 if hasattr(self, "text_disp_1"): 2179 if self.text_disp_1 !=None:2168 if self.text_disp_1 is not None: 2180 2169 if not self.text_disp_1.IsShown()\ 2181 and not self.is_mac:2170 and not self.is_mac: 2182 2171 self.text_disp_1.Show(True) 2183 2172 except: 2184 2173 pass 2185 2174 2186 if cov[ind] !=None:2175 if cov[ind] is not None: 2187 2176 if numpy.isfinite(float(cov[ind])): 2188 2177 val_err = format_number(cov[ind], True) 2189 2178 item[4].SetForegroundColour(wx.BLACK) 2190 2179 else: 2191 2180 val_err = 'NaN' … … 2199 2188 else: 2200 2189 raise ValueError, "onsetValues: Invalid parameters..." 2201 # Show error title when any errors displayed2190 # Show error title when any errors displayed 2202 2191 if has_error: 2203 2192 if not self.text2_3.IsShown(): 2204 2193 self.text2_3.Show(True) 2205 # #save current state2194 # save current state 2206 2195 self.save_current_state() 2207 2196 … … 2210 2199 self.Refresh() 2211 2200 self._mac_sleep(0.1) 2212 # plot model ( when drawing, do not update chisqr value again)2201 # plot model ( when drawing, do not update chisqr value again) 2213 2202 self._draw_model(update_chisqr=False, source='fit') 2214 2203 … … 2226 2215 # compute weight for the current data 2227 2216 flag_weight = self.get_weight_flag() 2228 if is_2D ==None:2217 if is_2D is None: 2229 2218 is_2D = self._is_2D() 2230 2219 self._manager.set_fit_weight(uid=self.uid, … … 2245 2234 self._update_paramv_on_fit() 2246 2235 2247 if event !=None:2236 if event is not None: 2248 2237 tcrtl = event.GetEventObject() 2249 2238 # event case of radio button 2250 if tcrtl.GetValue() == True:2239 if tcrtl.GetValue(): 2251 2240 self.dx_min = 0.0 2252 2241 self.dx_max = 0.0 … … 2266 2255 2267 2256 self.sizer_set_smearer.Layout() 2268 # #we need FitInside here not just self.Layout to ensure all the sizers2269 # #end up with the necessasary space to in the scroll panel. In2270 # #particular the compute and fit buttons end up on top of each other2271 # # PDB Nov 28 2015.2257 # we need FitInside here not just self.Layout to ensure all the sizers 2258 # end up with the necessasary space to in the scroll panel. In 2259 # particular the compute and fit buttons end up on top of each other 2260 # PDB Nov 28 2015. 2272 2261 self.FitInside() 2273 2262 2274 if event !=None:2263 if event is not None: 2275 2264 event.Skip() 2276 # self._undo.Enable(True)2265 # self._undo.Enable(True) 2277 2266 self.save_current_state() 2278 2267 event = PageInfoEvent(page=self) … … 2349 2338 get_pin_max.SetBackgroundColour("pink") 2350 2339 msg = "Model Error:This value can not be negative!!!" 2351 elif self.dx_min != None and self.dx_max !=None:2340 elif self.dx_min is not None and self.dx_max is not None: 2352 2341 if self._is_2D(): 2353 2342 data.dqx_data[data.dqx_data == 0] = self.dx_min … … 2360 2349 self.dx_max + step / 1.1, 2361 2350 step) 2362 elif self.dx_min !=None:2351 elif self.dx_min is not None: 2363 2352 if self._is_2D(): 2364 2353 data.dqx_data[data.dqx_data == 0] = self.dx_min 2365 2354 else: 2366 2355 data.dx[data.dx == 0] = self.dx_min 2367 elif self.dx_max !=None:2356 elif self.dx_max is not None: 2368 2357 if self._is_2D(): 2369 2358 data.dqy_data[data.dqy_data == 0] = self.dx_max … … 2373 2362 # 2D need to set accuracy 2374 2363 if self._is_2D(): 2375 self.current_smearer.set_accuracy( accuracy=\2376 2377 2378 if msg !=None:2364 self.current_smearer.set_accuracy( 2365 accuracy=self.smear2d_accuracy) 2366 2367 if msg is not None: 2379 2368 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2380 2369 else: 2381 2370 get_pin_min.SetBackgroundColour("white") 2382 2371 get_pin_max.SetBackgroundColour("white") 2383 # #set smearing value whether or not the data contain the smearing info2372 # set smearing value whether or not the data contain the smearing info 2384 2373 2385 2374 enable_smearer = not self.disable_smearer.GetValue() … … 2407 2396 wx.CallAfter(self.save_current_state) 2408 2397 2409 if msg !=None:2398 if msg is not None: 2410 2399 return False 2411 2400 else: … … 2423 2412 msg = None 2424 2413 # for event given 2425 if event !=None:2414 if event is not None: 2426 2415 tcrtl = event.GetEventObject() 2427 2416 # event case of radio button … … 2444 2433 self._show_smear_sizer() 2445 2434 self.sizer_set_smearer.Layout() 2446 # #we need FitInside here not just self.Layout to ensure all the sizers2447 # #end up with the necessasary space to in the scroll panel. In2448 # #particular the compute and fit buttons end up on top of each other2449 # # PDB Nov 28 2015.2435 # we need FitInside here not just self.Layout to ensure all the sizers 2436 # end up with the necessasary space to in the scroll panel. In 2437 # particular the compute and fit buttons end up on top of each other 2438 # PDB Nov 28 2015. 2450 2439 self.FitInside() 2451 2440 2452 if event !=None:2441 if event is not None: 2453 2442 event.Skip() 2454 2443 self.save_current_state() 2455 2444 event = PageInfoEvent(page=self) 2456 2445 wx.PostEvent(self.parent, event) 2457 if msg !=None:2446 if msg is not None: 2458 2447 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2459 2448 … … 2544 2533 2545 2534 self.current_smearer = smear_selection(data, self.model) 2546 # #set smearing value whether or not the data contain the smearing info2535 # set smearing value whether or not the data contain the smearing info 2547 2536 enable_smearer = not self.disable_smearer.GetValue() 2548 2537 self._manager.set_smearer(smearer=self.current_smearer, … … 2567 2556 if self._is_changed_slit(): 2568 2557 msg = self._set_slit_smear() 2569 # self._undo.Enable(True)2558 # self._undo.Enable(True) 2570 2559 self.save_current_state() 2571 2560 2572 if msg !=None:2561 if msg is not None: 2573 2562 return False 2574 2563 else: … … 2580 2569 are computed when fitting 2581 2570 """ 2582 if event !=None:2571 if event is not None: 2583 2572 event.Skip() 2584 2573 if self.data is None: … … 2593 2582 2594 2583 self.sizer_set_smearer.Layout() 2595 # #we need FitInside here not just self.Layout to ensure all the sizers2596 # #end up with the necessasary space to in the scroll panel. In2597 # #particular the compute and fit buttons end up on top of each other2598 # # PDB Nov 28 2015.2584 # we need FitInside here not just self.Layout to ensure all the sizers 2585 # end up with the necessasary space to in the scroll panel. In 2586 # particular the compute and fit buttons end up on top of each other 2587 # PDB Nov 28 2015. 2599 2588 self.FitInside() 2600 2589 self._set_weight() 2601 2590 2602 # #set smearing value whether or not the data contain the smearing info2591 # set smearing value whether or not the data contain the smearing info 2603 2592 enable_smearer = not self.disable_smearer.GetValue() 2604 2593 wx.CallAfter(self._manager.set_smearer, uid=self.uid, … … 2621 2610 """ 2622 2611 self._get_smear_info() 2623 # renew smear sizer2612 # renew smear sizer 2624 2613 if self.smear_type is not None: 2625 2614 self.smear_description_smear_type.SetValue(str(self.smear_type)) … … 2661 2650 """ 2662 2651 try: 2663 if event ==None:2652 if event is None: 2664 2653 output = "-" 2665 2654 elif not numpy.isfinite(event.output): … … 2696 2685 self._manager.set_param2fit(self.uid, param2fit) 2697 2686 2698 def select_all_param(self, event): 2699 """ 2700 set to true or false all checkBox given the main checkbox value cb1 2701 """ 2702 self.param_toFit = [] 2703 if self.parameters != []: 2704 if self.cb1.GetValue(): 2705 for item in self.parameters: 2706 if item[0].IsShown(): 2707 ## for data2D select all to fit 2708 if self.data.__class__.__name__ == "Data2D" or \ 2709 self.enable2D: 2710 item[0].SetValue(True) 2711 self.param_toFit.append(item) 2712 else: 2713 ## for 1D all parameters except orientation 2714 if not item in self.orientation_params: 2715 item[0].SetValue(True) 2716 self.param_toFit.append(item) 2717 else: 2718 item[0].SetValue(False) 2719 #if len(self.fittable_param)>0: 2720 for item in self.fittable_param: 2721 if item[0].IsShown(): 2722 if self.data.__class__.__name__ == "Data2D" or \ 2723 self.enable2D: 2724 item[0].SetValue(True) 2725 self.param_toFit.append(item) 2726 try: 2727 if len(self.values[item[1]]) > 0: 2728 item[0].SetValue(False) 2729 except: 2730 pass 2731 2732 else: 2733 ## for 1D all parameters except orientation 2734 if not item in self.orientation_params_disp: 2735 item[0].SetValue(True) 2736 self.param_toFit.append(item) 2737 try: 2738 if len(self.values[item[1]]) > 0: 2739 item[0].SetValue(False) 2740 except: 2741 pass 2742 else: 2743 item[0].SetValue(False) 2744 2745 else: 2746 for item in self.parameters: 2747 item[0].SetValue(False) 2748 for item in self.fittable_param: 2749 item[0].SetValue(False) 2750 self.param_toFit = [] 2751 2752 self.save_current_state_fit() 2753 2754 if event != None: 2755 #self._undo.Enable(True) 2756 ## post state to fit panel 2757 event = PageInfoEvent(page=self) 2758 wx.PostEvent(self.parent, event) 2759 param2fit = [] 2760 for item in self.param_toFit: 2761 if item[0] and item[0].IsShown(): 2762 param2fit.append(item[1]) 2763 self.parent._manager.set_param2fit(self.uid, param2fit) 2764 2765 def select_param(self, event): 2687 2688 def select_param(self, event=None): 2766 2689 """ 2767 2690 Select TextCtrl checked for fitting purpose and stores them … … 2770 2693 self.param_toFit = [] 2771 2694 for item in self.parameters: 2772 # Skip t ifhe angle parameters if 1D data2695 # Skip t ifhe angle parameters if 1D data 2773 2696 if self.data.__class__.__name__ != "Data2D" and\ 2774 2697 not self.enable2D: 2775 2698 if item in self.orientation_params: 2776 2699 continue 2777 # Select parameters to fit for list of primary parameters2700 # Select parameters to fit for list of primary parameters 2778 2701 if item[0].GetValue() and item[0].IsShown(): 2779 2702 if not (item in self.param_toFit): … … 2784 2707 self.param_toFit.remove(item) 2785 2708 2786 # Select parameters to fit for list of fittable parameters2709 # Select parameters to fit for list of fittable parameters 2787 2710 # with dispersion 2788 2711 for item in self.fittable_param: 2789 # Skip t ifhe angle parameters if 1D data2712 # Skip t ifhe angle parameters if 1D data 2790 2713 if self.data.__class__.__name__ != "Data2D" and\ 2791 2714 not self.enable2D: … … 2796 2719 self.param_toFit.append(item) 2797 2720 else: 2798 # remove parameters from the fitting list2721 # remove parameters from the fitting list 2799 2722 if item in self.param_toFit: 2800 2723 self.param_toFit.remove(item) 2801 2724 2802 # Calculate num. of angle parameters2725 # Calculate num. of angle parameters 2803 2726 if self.data.__class__.__name__ == "Data2D" or \ 2804 2727 self.enable2D: … … 2806 2729 else: 2807 2730 len_orient_para = len(self.orientation_params) # assume even len 2808 # Total num. of angle parameters2731 # Total num. of angle parameters 2809 2732 if len(self.fittable_param) > 0: 2810 2733 len_orient_para *= 2 … … 2817 2740 2818 2741 self.save_current_state_fit() 2819 if event !=None:2820 # #post state to fit panel2742 if event is not None: 2743 # post state to fit panel 2821 2744 event = PageInfoEvent(page=self) 2822 2745 wx.PostEvent(self.parent, event) … … 2844 2767 self.orientation_params_disp = [] 2845 2768 2846 if model ==None:2769 if model is None: 2847 2770 self.sizer3.Layout() 2848 2771 self.SetupScrolling() … … 2852 2775 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 2853 2776 sizer = wx.GridBagSizer(5, 5) 2854 # #save the current model2777 # save the current model 2855 2778 self.model = model 2856 2779 2857 2780 keys = self.model.getParamList() 2858 2781 2859 # list of dispersion parameters2782 # list of dispersion parameters 2860 2783 self.disp_list = self.model.getDispParamList() 2861 2784 … … 2890 2813 return -1 2891 2814 # both have a number 2892 if num_a != None and num_b !=None:2815 if num_a is not None and num_b is not None: 2893 2816 if num_a > num_b: 2894 2817 return -1 … … 2903 2826 return 1 2904 2827 # one of them has a number 2905 elif num_a !=None:2828 elif num_a is not None: 2906 2829 return 1 2907 elif num_b !=None:2830 elif num_b is not None: 2908 2831 return -1 2909 2832 # no numbers … … 2911 2834 return cmp(a.lower(), b.lower()) 2912 2835 2913 # keys obtained now from ordered dict, so commenting alphabetical ordering2914 # keys.sort(custom_compare)2836 # keys obtained now from ordered dict, so commenting alphabetical 2837 # ordering keys.sort(custom_compare) 2915 2838 2916 2839 iy = 0 … … 2926 2849 ix += 1 2927 2850 self.text2_2 = wx.StaticText(self, wx.ID_ANY, 'Value') 2928 sizer.Add(self.text2_2, (iy, ix), (1, 1), \2851 sizer.Add(self.text2_2, (iy, ix), (1, 1), 2929 2852 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2930 2853 ix += 2 2931 2854 self.text2_3 = wx.StaticText(self, wx.ID_ANY, 'Error') 2932 sizer.Add(self.text2_3, (iy, ix), (1, 1), \2933 2855 sizer.Add(self.text2_3, (iy, ix), (1, 1), 2856 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2934 2857 if not self.is_mac: 2935 2858 self.text2_3.Hide() 2936 2859 ix += 1 2937 2860 self.text2_min = wx.StaticText(self, wx.ID_ANY, 'Min') 2938 sizer.Add(self.text2_min, (iy, ix), (1, 1), \2939 2940 # self.text2_min.Hide()2861 sizer.Add(self.text2_min, (iy, ix), (1, 1), 2862 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2863 # self.text2_min.Hide() 2941 2864 ix += 1 2942 2865 self.text2_max = wx.StaticText(self, wx.ID_ANY, 'Max') 2943 sizer.Add(self.text2_max, (iy, ix), (1, 1), \2944 2945 # self.text2_max.Hide()2866 sizer.Add(self.text2_max, (iy, ix), (1, 1), 2867 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2868 # self.text2_max.Hide() 2946 2869 ix += 1 2947 2870 self.text2_4 = wx.StaticText(self, wx.ID_ANY, '[Units]') 2948 sizer.Add(self.text2_4, (iy, ix), (1, 1), \2949 2871 sizer.Add(self.text2_4, (iy, ix), (1, 1), 2872 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2950 2873 self.text2_4.Hide() 2951 2874 … … 2953 2876 for item in keys: 2954 2877 2955 if not itemin self.disp_list and not item in \2878 if item not in self.disp_list and not item in \ 2956 2879 self.model.orientation_params: 2957 2880 2958 # #prepare a spot to store errors2959 if not itemin self.model.details:2881 # prepare a spot to store errors 2882 if item not in self.model.details: 2960 2883 self.model.details[item] = ["", None, None] 2961 2884 2962 2885 iy += 1 2963 2886 ix = 0 2964 if (self.model.__class__ in \2965 self.model_list_box["Multi-Functions"] or \2887 if (self.model.__class__ in 2888 self.model_list_box["Multi-Functions"] or 2966 2889 self.temp_multi_functional)\ 2967 2890 and (item in self.model.non_fittable): 2968 2891 non_fittable_name = wx.StaticText(self, wx.ID_ANY, item) 2969 sizer.Add(non_fittable_name, (iy, ix), (1, 1), \2892 sizer.Add(non_fittable_name, (iy, ix), (1, 1), 2970 2893 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 21) 2971 # #add parameter value2894 # add parameter value 2972 2895 ix += 1 2973 2896 value = self.model.getParam(item) 2974 2897 if len(self.model.fun_list) > 0: 2975 # num = item.split('_')[1][5:7]2898 # num = item.split('_')[1][5:7] 2976 2899 fun_box = wx.ComboBox(self, wx.ID_ANY, size=(100, -1), 2977 2900 style=wx.CB_READONLY, name='%s' % item) 2978 2901 self._set_fun_box_list(fun_box) 2979 2902 fun_box.SetSelection(0) 2980 # self.fun_box.SetToolTipString("A function2903 # self.fun_box.SetToolTipString("A function 2981 2904 # describing the interface") 2982 2905 wx.EVT_COMBOBOX(fun_box, wx.ID_ANY, self._on_fun_box) … … 2985 2908 size=(_BOX_WIDTH, 20), 2986 2909 style=wx.TE_PROCESS_ENTER, name='%s' % item) 2987 fun_box.SetToolTipString( \2910 fun_box.SetToolTipString( 2988 2911 "Hit 'Enter' after typing to update the plot.") 2989 2912 fun_box.SetValue(format_number(value, True)) … … 2993 2916 None, None]) 2994 2917 else: 2995 # #add parameters name with checkbox for selecting to fit2918 # add parameters name with checkbox for selecting to fit 2996 2919 cb = wx.CheckBox(self, wx.ID_ANY, item) 2997 2920 cb.SetValue(CHECK_STATE) 2998 2921 cb.SetToolTipString(" Check mark to fit.") 2999 # cb.SetValue(True)2922 # cb.SetValue(True) 3000 2923 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 3001 2924 … … 3003 2926 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 3004 2927 3005 # #add parameter value2928 # add parameter value 3006 2929 ix += 1 3007 2930 value = self.model.getParam(item) 3008 2931 ctl1 = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 3009 2932 style=wx.TE_PROCESS_ENTER) 3010 ctl1.SetToolTipString( \2933 ctl1.SetToolTipString( 3011 2934 "Hit 'Enter' after typing to update the plot.") 3012 2935 ctl1.SetValue(format_number(value, True)) 3013 2936 sizer.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 3014 # #text to show error sign2937 # text to show error sign 3015 2938 ix += 1 3016 2939 text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 3017 sizer.Add(text2, (iy, ix), (1, 1), \2940 sizer.Add(text2, (iy, ix), (1, 1), 3018 2941 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 3019 2942 if not self.is_mac: … … 3076 2999 iy += 1 3077 3000 ix = 0 3078 # Add tile for orientational angle3001 # Add tile for orientational angle 3079 3002 for item in keys: 3080 3003 if item in self.model.orientation_params: … … 3083 3006 mag_on_button.SetToolTipString("Turn Pol Beam/Mag scatt on/off") 3084 3007 mag_on_button.Bind(wx.EVT_BUTTON, self._on_mag_on) 3085 mag_angle_help_button = wx.Button(self, wx.ID_ANY, "Magnetic angles?") 3008 mag_angle_help_button = wx.Button(self, wx.ID_ANY, 3009 "Magnetic angles?") 3086 3010 mag_angle_help_button.SetToolTipString("see angle definitions") 3087 3011 mag_help_button = wx.Button(self, wx.ID_ANY, "Mag HELP") 3088 3012 mag_help_button.SetToolTipString("Help on pol beam/mag fitting") 3089 3013 mag_help_button.Bind(wx.EVT_BUTTON, self._on_mag_help) 3090 mag_angle_help_button.Bind(wx.EVT_BUTTON, \3014 mag_angle_help_button.Bind(wx.EVT_BUTTON, 3091 3015 self._on_mag_angle_help) 3092 3016 sizer.Add(orient_angle, (iy, ix), (1, 1), … … 3101 3025 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 3102 3026 3103 # handle the magnetic buttons3104 # clean this up so that assume mag is off then turn3105 # all buttons on IF mag has mag and has 2D3027 # handle the magnetic buttons 3028 # clean this up so that assume mag is off then turn 3029 # all buttons on IF mag has mag and has 2D 3106 3030 if not self._has_magnetic: 3107 3031 mag_on_button.Show(False) … … 3129 3053 break 3130 3054 3131 # For Gaussian only3055 # For Gaussian only 3132 3056 if type.lower() != "array": 3133 3057 for item in self.model.orientation_params: … … 3135 3059 if item in self.model.magnetic_params: 3136 3060 continue 3137 if not itemin self.disp_list:3138 # #prepare a spot to store min max3139 if not itemin self.model.details:3061 if item not in self.disp_list: 3062 # prepare a spot to store min max 3063 if item not in self.model.details: 3140 3064 self.model.details[item] = ["", None, None] 3141 3065 3142 3066 iy += 1 3143 3067 ix = 0 3144 # #add parameters name with checkbox for selecting to fit3068 # add parameters name with checkbox for selecting to fit 3145 3069 cb = wx.CheckBox(self, wx.ID_ANY, item) 3146 3070 cb.SetValue(CHECK_STATE) … … 3155 3079 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 3156 3080 3157 # #add parameter value3081 # add parameter value 3158 3082 ix += 1 3159 3083 value = self.model.getParam(item) 3160 3084 ctl1 = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 3161 3085 style=wx.TE_PROCESS_ENTER) 3162 ctl1.SetToolTipString( \3086 ctl1.SetToolTipString( 3163 3087 "Hit 'Enter' after typing to update the plot.") 3164 3088 ctl1.SetValue(format_number(value, True)) … … 3169 3093 ctl1.Hide() 3170 3094 sizer.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 3171 # #text to show error sign3095 # text to show error sign 3172 3096 ix += 1 3173 3097 text2 = wx.StaticText(self, -1, '+/-') 3174 sizer.Add(text2, (iy, ix), (1, 1), \3098 sizer.Add(text2, (iy, ix), (1, 1), 3175 3099 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 3176 3100 … … 3237 3161 iy += 1 3238 3162 box_description.SetForegroundColour(wx.BLUE) 3239 # Display units text on panel3163 # Display units text on panel 3240 3164 for item in keys: 3241 3165 if item in self.model.details: 3242 3166 self.text2_4.Show() 3243 # Fill the list of fittable parameters3167 # Fill the list of fittable parameters 3244 3168 self.get_all_checked_params() 3245 3169 self.save_current_state_fit() … … 3253 3177 Get key stroke event 3254 3178 """ 3255 if self.data ==None:3179 if self.data is None: 3256 3180 return 3257 3181 # Figuring out key combo: Cmd for copy, Alt for paste
Note: See TracChangeset
for help on using the changeset viewer.