Changeset c8e1996 in sasview for src/sas/sasgui/perspectives/fitting/fitpage.py
- Timestamp:
- Oct 20, 2016 3:54:06 PM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 880e845, cf1910f
- Parents:
- 8b645cc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/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
Note: See TracChangeset
for help on using the changeset viewer.