Changes in src/sas/perspectives/fitting/basepage.py [1c2bf90:f0d720b] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/fitting/basepage.py
r1c2bf90 rf0d720b 15 15 from wx.lib.scrolledpanel import ScrolledPanel 16 16 from sas.guiframe.panel_base import PanelBase 17 from sas.guiframe.utils import format_number, check_float , IdList17 from sas.guiframe.utils import format_number, check_float 18 18 from sas.guiframe.events import PanelOnFocusEvent 19 19 from sas.guiframe.events import StatusEvent … … 57 57 ## Title to appear on top of the window 58 58 window_caption = "Fit Page " 59 # These two buttons have specific IDs since they seem to be created more 60 # frequently than they need to. In particular, set_dispers_sizer() is 61 # called by _on_select_model 62 ID_BOOKMARK = wx.NewId() 63 ID_DISPERSER_HELP = wx.NewId() 64 _id_pool = IdList() 65 59 66 60 def __init__(self, parent, color='blue', **kwargs): 67 61 """ … … 72 66 #Set window's font size 73 67 self.SetWindowVariant(variant=FONT_VARIANT) 68 74 69 self.SetBackgroundColour(color) 75 76 self._ids = iter(self._id_pool)77 70 ## parent of the page 78 71 self.parent = parent … … 133 126 self.Npts_fit = None 134 127 self.Npts_total = None 135 self.theory_qmin = None 128 self.theory_qmin = None 136 129 self.theory_qmax = None 137 130 self.theory_qmin_x = None … … 142 135 self.sld_axes = None 143 136 self.multi_factor = None 144 137 145 138 self.disp_cb_dict = {} 146 139 147 140 #self.state = PageState(parent=parent) 148 141 ## dictionary containing list of models 149 142 self.model_list_box = {} 150 143 151 144 ## Data member to store the dispersion object created 152 145 self._disp_obj_dict = {} … … 176 169 self.disp_list = [] 177 170 self.disp_name = "" 178 171 179 172 ## list of orientation parameters 180 173 self.orientation_params = [] 181 174 self.orientation_params_disp = [] 182 # Self.model should ALWAYS be None here. It was set to none above in 175 # Self.model should ALWAYS be None here. It was set to none above in 183 176 # this long init setting. no obvious function call in between setting 184 # and this - commenting out on 4/8/2014 by PDB. Remove once clear 177 # and this - commenting out on 4/8/2014 by PDB. Remove once clear 185 178 # it is pointless. 186 179 # if self.model != None: … … 205 198 ## Create context menu for page 206 199 self.popUpMenu = wx.Menu() 207 208 wx_id = self._ids.next()209 self._keep = wx.MenuItem(self.popUpMenu, wx_id, "Add bookmark",200 201 id = wx.NewId() 202 self._keep = wx.MenuItem(self.popUpMenu, id, "Add bookmark", 210 203 " Keep the panel status to recall it later") 211 204 self.popUpMenu.AppendItem(self._keep) … … 213 206 self._set_bookmark_flag(False) 214 207 self._set_save_flag(False) 215 wx.EVT_MENU(self, wx_id, self.on_bookmark)208 wx.EVT_MENU(self, id, self.on_bookmark) 216 209 self.popUpMenu.AppendSeparator() 217 210 218 211 ## Default locations 219 212 self._default_save_location = os.getcwd() … … 221 214 #self.onSave(event=None) 222 215 self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 223 216 224 217 # bind key event 225 218 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) 226 219 227 220 ## create the basic structure of the panel with empty sizer 228 221 self.define_page_structure() 229 222 ## drawing Initial dispersion parameters sizer 230 223 self.set_dispers_sizer() 231 224 232 225 ## layout 233 226 self.set_layout() 234 227 235 228 def set_index_model(self, index): 236 229 """ … … 238 231 """ 239 232 self.index_model = index 240 233 241 234 def create_default_data(self): 242 235 """ … … 255 248 else: 256 249 self._create_default_1d_data() 257 250 258 251 if self.model != None: 259 252 if not self.data.is_data: … … 265 258 self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 266 259 self.state.slit_smearer = self.slit_smearer.GetValue() 267 260 268 261 def _create_default_1d_data(self): 269 262 """ … … 271 264 Only when the page is on theory mode. 272 265 :warning: This data is never plotted. 273 266 274 267 """ 275 268 x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, … … 281 274 self.data.id = str(self.uid) + " data" 282 275 self.data.group_id = str(self.uid) + " Model1D" 283 276 284 277 def _create_log_1d_data(self): 285 278 """ … … 287 280 Only when the page is on theory mode. 288 281 :warning: This data is never plotted. 289 282 290 283 """ 291 284 if self.qmin_x >= 1.e-10: 292 285 qmin = numpy.log10(self.qmin_x) 293 286 else: 294 qmin = -10. 295 287 qmin = -10. 288 296 289 if self.qmax_x <= 1.e10: 297 290 qmax = numpy.log10(self.qmax_x) 298 291 else: 299 qmax = 10. 300 292 qmax = 10. 293 301 294 x = numpy.logspace(start=qmin, stop=qmax, 302 295 num=self.npts_x, endpoint=True, base=10.0) … … 307 300 self.data.id = str(self.uid) + " data" 308 301 self.data.group_id = str(self.uid) + " Model1D" 309 302 310 303 def _create_default_2d_data(self): 311 304 """ … … 365 358 #xstep = x_size / len(x_bins - 1) 366 359 #ystep = y_size / len(y_bins - 1) 367 360 368 361 self.data.source = Source() 369 362 self.data.data = numpy.ones(len(mask)) … … 388 381 wx.PostEvent(self._manager.parent, PanelOnFocusEvent(panel=self)) 389 382 self.on_tap_focus() 390 383 391 384 def on_tap_focus(self): 392 385 """ … … 404 397 self._manager.menu1.FindItemById(self._manager.id_batchfit) 405 398 batch_menu.Enable(self.batch_on and flag) 406 399 407 400 def set_page_info(self, page_info): 408 401 """ 409 402 set some page important information at once 410 403 """ 411 # THIS METHOD/FUNCTION NO LONGE APPEARS TO BE CALLED. Started up program 404 # THIS METHOD/FUNCTION NO LONGE APPEARS TO BE CALLED. Started up program 412 405 # and started new fit window and PR and Invariant and a fit in fitting 413 406 # but never entered this routine which should be an initialization 414 # routine. Leave for a while but probably something to clean up at 407 # routine. Leave for a while but probably something to clean up at 415 408 # some point? 416 409 # … … 433 426 ## Data member to store the dispersion object created 434 427 self.populate_box(model_dict=self.model_list_box) 435 428 436 429 def onContextMenu(self, event): 437 430 """ … … 440 433 # Skipping the save state functionality for release 0.9.0 441 434 #return 442 435 443 436 pos = event.GetPosition() 444 437 pos = self.ScreenToClient(pos) 445 438 446 439 self.PopupMenu(self.popUpMenu, pos) 447 440 448 441 def onUndo(self, event): 449 442 """ … … 452 445 event = PreviousStateEvent(page=self) 453 446 wx.PostEvent(self.parent, event) 454 447 455 448 def onRedo(self, event): 456 449 """ … … 459 452 event = NextStateEvent(page=self) 460 453 wx.PostEvent(self.parent, event) 461 454 462 455 def define_page_structure(self): 463 456 """ … … 472 465 self.sizer5 = wx.BoxSizer(wx.VERTICAL) 473 466 self.sizer6 = wx.BoxSizer(wx.VERTICAL) 474 467 475 468 self.sizer0.SetMinSize((PANEL_WIDTH, -1)) 476 469 self.sizer1.SetMinSize((PANEL_WIDTH, -1)) … … 480 473 self.sizer5.SetMinSize((PANEL_WIDTH, -1)) 481 474 self.sizer6.SetMinSize((PANEL_WIDTH, -1)) 482 475 483 476 self.vbox.Add(self.sizer0) 484 477 self.vbox.Add(self.sizer1) … … 488 481 self.vbox.Add(self.sizer5) 489 482 self.vbox.Add(self.sizer6) 490 483 491 484 def set_layout(self): 492 485 """ … … 497 490 self.SetSizer(self.vbox) 498 491 self.Centre() 499 492 500 493 def set_owner(self, owner): 501 494 """ 502 495 set owner of fitpage 503 496 504 497 :param owner: the class responsible of plotting 505 498 506 499 """ 507 500 self.event_owner = owner 508 501 self.state.event_owner = owner 509 502 510 503 def get_state(self): 511 504 """ … … 513 506 """ 514 507 return self.state 515 508 516 509 def get_data(self): 517 510 """ … … 519 512 """ 520 513 return self.data 521 514 522 515 def get_data_list(self): 523 516 """ … … 525 518 """ 526 519 return self.data_list 527 520 528 521 def set_manager(self, manager): 529 522 """ 530 523 set panel manager 531 524 532 525 :param manager: instance of plugin fitting 533 526 534 527 """ 535 528 self._manager = manager 536 529 self.state.manager = manager 537 530 538 531 def populate_box(self, model_dict): 539 532 """ 540 533 Store list of model 541 534 542 535 :param model_dict: dictionary containing list of models 543 536 544 537 """ 545 538 self.model_list_box = model_dict 546 539 self.state.model_list_box = self.model_list_box 547 540 self.initialize_combox() 548 541 549 542 def set_model_dictionary(self, model_dict): 550 543 """ … … 558 551 """ 559 552 put default value in the combobox 560 """ 553 """ 561 554 ## fill combox box 562 555 if self.model_list_box is None: … … 567 560 ## These are called for first time by formfactor_combo_init 568 561 ## itself called from fitpanel only. If we find that I'm wrong and 569 ## we DO need to initialize somehow here - do it by a call to 570 ## formfactor_combo_init 562 ## we DO need to initialize somehow here - do it by a call to 563 ## formfactor_combo_init 571 564 ## self.formfator_combo_init() 572 ## BUT NOT HERE -- make it last line of this 565 ## BUT NOT HERE -- make it last line of this 573 566 ## method so that structure box is populated before _show_comboox_helper 574 567 ## is called. Otherwise wx will complain mightily:-) … … 582 575 # self.model_list_box["Shapes"]) 583 576 self._populate_box(self.structurebox, 584 self.model_list_box["Structure Factors"])577 self.model_list_box["Structure Factors"]) 585 578 self.structurebox.Insert("None", 0, None) 586 579 self.structurebox.SetSelection(0) … … 589 582 self.structurebox.Disable() 590 583 self.text2.Disable() 591 584 592 585 if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: 593 586 self.structurebox.Show() … … 596 589 self.text2.Enable() 597 590 598 591 599 592 def set_dispers_sizer(self): 600 593 """ 601 594 fill sizer containing dispersity info 602 595 """ 603 #print "==== entering set_dispers_sizer ==="604 596 self.sizer4.Clear(True) 605 597 name = "Polydispersity and Orientational Distribution" 606 box_description = wx.StaticBox(self, wx.ID_ANY, name)598 box_description = wx.StaticBox(self, -1, name) 607 599 box_description.SetForegroundColour(wx.BLUE) 608 600 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 609 601 #---------------------------------------------------- 610 self.disable_disp = wx.RadioButton(self, wx.ID_ANY, 'Off', (10, 10),611 style=wx.RB_GROUP)612 self.enable_disp = wx.RadioButton(self, wx.ID_ANY, 'On', (10, 30))602 self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), 603 style=wx.RB_GROUP) 604 self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 613 605 # best size for MAC and PC 614 606 if ON_MAC: … … 616 608 else: 617 609 size_q = (20, 15) 618 self.disp_help_bt = wx.Button(self, self.ID_DISPERSER_HELP, '?',610 self.disp_help_bt = wx.Button(self, wx.NewId(), '?', 619 611 style=wx.BU_EXACTFIT, 620 612 size=size_q) … … 622 614 id=self.disp_help_bt.GetId()) 623 615 self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") 624 616 625 617 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 626 id=self.disable_disp.GetId())618 id=self.disable_disp.GetId()) 627 619 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 628 id=self.enable_disp.GetId())620 id=self.enable_disp.GetId()) 629 621 #MAC needs SetValue 630 622 self.disable_disp.SetValue(True) … … 632 624 sizer_dispersion.Add((20, 20)) 633 625 name = "" # Polydispersity and \nOrientational Distribution " 634 sizer_dispersion.Add(wx.StaticText(self, wx.ID_ANY, name))626 sizer_dispersion.Add(wx.StaticText(self, -1, name)) 635 627 sizer_dispersion.Add(self.enable_disp) 636 628 sizer_dispersion.Add((20, 20)) … … 638 630 sizer_dispersion.Add((25, 20)) 639 631 sizer_dispersion.Add(self.disp_help_bt) 640 632 641 633 ## fill a sizer for dispersion 642 634 boxsizer1.Add(sizer_dispersion, 0, 643 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,644 635 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 636 border=5) 645 637 self.sizer4_4 = wx.GridBagSizer(6, 5) 646 638 … … 651 643 self.sizer4.Layout() 652 644 self.Layout() 653 645 654 646 self.Refresh() 655 647 ## saving the state of enable dispersity button … … 657 649 self.state.disable_disp = self.disable_disp.GetValue() 658 650 self.SetupScrolling() 659 651 660 652 def onResetModel(self, event): 661 653 """ … … 675 667 previous_state = self.saved_states[name] 676 668 ## reset state of checkbox,textcrtl and regular parameters value 677 669 678 670 self.reset_page(previous_state) 679 671 self.state.m_name = self.m_name 680 672 self.Show(True) 681 673 682 674 def on_preview(self, event): 683 675 """ … … 688 680 # get the report dialog 689 681 self.state.report(images, canvases) 690 682 691 683 def on_save(self, event): 692 684 """ … … 701 693 self._manager.parent._default_save_location 702 694 dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, 703 self.window_caption, "*.fitv", wx.SAVE)695 self.window_caption, "*.fitv", wx.SAVE) 704 696 705 697 if dlg.ShowModal() == wx.ID_OK: 706 698 path = dlg.GetPath() 707 699 self._default_save_location = os.path.dirname(path) 708 self._manager.parent._default_save_location = 709 self._default_save_location700 self._manager.parent._default_save_location =\ 701 self._default_save_location 710 702 else: 711 703 return None … … 717 709 self._manager.save_fit_state(filepath=fName, fitstate=new_state) 718 710 return new_state 719 711 720 712 def on_copy(self, event): 721 713 """ … … 734 726 wx.CallAfter(self.get_copy) 735 727 736 728 737 729 def on_paste(self, event): 738 730 """ … … 746 738 # messages depending on the flag 747 739 #self._copy_info(True) 748 740 749 741 def _copy_info(self, flag): 750 742 """ 751 743 Send event dpemding on flag 752 744 753 745 : Param flag: flag that distinguish event 754 746 """ … … 766 758 # inform msg to wx 767 759 wx.PostEvent(self._manager.parent, 768 769 760 StatusEvent(status=msg, info=infor)) 761 770 762 def _get_time_stamp(self): 771 763 """ … … 777 769 current_date = str(month) + "/" + str(day) + "/" + str(year) 778 770 return current_time, current_date 779 771 780 772 def on_bookmark(self, event): 781 773 """ … … 796 788 name += "bookmarked at %s on %s" % (current_time, current_date) 797 789 self.saved_states[name] = new_state 798 790 799 791 ## Add item in the context menu 800 792 msg = "Model saved at %s on %s" % (current_time, current_date) … … 802 794 msg += " Saved! right click on this page to retrieve this model" 803 795 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 804 805 self.popUpMenu.Append(self.ID_BOOKMARK, name, str(msg)) 806 wx.EVT_MENU(self, self.ID_BOOKMARK, self.onResetModel) 796 797 id = wx.NewId() 798 self.popUpMenu.Append(id, name, str(msg)) 799 wx.EVT_MENU(self, id, self.onResetModel) 807 800 wx.PostEvent(self._manager.parent, 808 801 AppendBookmarkEvent(title=name, 809 802 hint=str(msg), 810 803 handler=self._back_to_bookmark)) 811 804 812 805 def _back_to_bookmark(self, event): 813 806 """ … … 817 810 self.onResetModel(event) 818 811 self._draw_model() 819 812 820 813 def onSetFocus(self, evt): 821 814 """ … … 824 817 """ 825 818 return 826 819 827 820 def read_file(self, path): 828 821 """ 829 822 Read two columns file 830 823 831 824 :param path: the path to the file to read 832 825 833 826 """ 834 827 try: … … 863 856 """ 864 857 return self.state.clone() 865 858 866 859 def save_current_state(self): 867 860 """ … … 873 866 self.state.disp_list = copy.deepcopy(self.disp_list) 874 867 self.state.model = self.model.clone() 875 868 876 869 #model combobox: complex code because of mac's silent error 877 870 if self.structurebox != None: … … 892 885 self.state.categorycombobox = self.categorybox.\ 893 886 GetString(cb_select) 894 887 895 888 self.state.enable2D = copy.deepcopy(self.enable2D) 896 889 self.state.values = copy.deepcopy(self.values) … … 909 902 self.state.enable_disp = self.enable_disp.GetValue() 910 903 self.state.disable_disp = self.disable_disp.GetValue() 911 904 912 905 self.state.smearer = copy.deepcopy(self.current_smearer) 913 906 if hasattr(self, "enable_smearer"): … … 924 917 self.state.dxw = copy.deepcopy(self.dxw) 925 918 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 926 919 927 920 if len(self._disp_obj_dict) > 0: 928 921 for k, v in self._disp_obj_dict.iteritems(): … … 933 926 ## save plotting range 934 927 self._save_plotting_range() 935 928 936 929 self.state.orientation_params = [] 937 930 self.state.orientation_params_disp = [] … … 948 941 self._copy_parameters_state(self.orientation_params_disp, 949 942 self.state.orientation_params_disp) 950 943 951 944 self._copy_parameters_state(self.parameters, self.state.parameters) 952 945 self._copy_parameters_state(self.fittable_param, … … 955 948 #save chisqr 956 949 self.state.tcChi = self.tcChi.GetValue() 957 950 958 951 def save_current_state_fit(self): 959 952 """ … … 965 958 self.state.disp_list = copy.deepcopy(self.disp_list) 966 959 self.state.model = self.model.clone() 967 960 968 961 self.state.enable2D = copy.deepcopy(self.enable2D) 969 962 self.state.values = copy.deepcopy(self.values) … … 971 964 ## save data 972 965 self.state.data = copy.deepcopy(self.data) 973 966 974 967 if hasattr(self, "enable_disp"): 975 968 self.state.enable_disp = self.enable_disp.GetValue() 976 969 self.state.disable_disp = self.disable_disp.GetValue() 977 970 978 971 self.state.smearer = copy.deepcopy(self.current_smearer) 979 972 if hasattr(self, "enable_smearer"): … … 982 975 self.state.disable_smearer = \ 983 976 copy.deepcopy(self.disable_smearer.GetValue()) 984 977 985 978 self.state.pinhole_smearer = \ 986 979 copy.deepcopy(self.pinhole_smearer.GetValue()) … … 1005 998 for k, v in self._disp_obj_dict.iteritems(): 1006 999 self.state._disp_obj_dict[k] = v 1007 1000 1008 1001 self.state.values = copy.deepcopy(self.values) 1009 1002 self.state.weights = copy.deepcopy(self.weights) 1010 1003 1011 1004 ## save plotting range 1012 1005 self._save_plotting_range() 1013 1006 1014 1007 ## save checkbutton state and txtcrtl values 1015 1008 self._copy_parameters_state(self.orientation_params, 1016 self.state.orientation_params)1009 self.state.orientation_params) 1017 1010 self._copy_parameters_state(self.orientation_params_disp, 1018 self.state.orientation_params_disp)1011 self.state.orientation_params_disp) 1019 1012 self._copy_parameters_state(self.parameters, self.state.parameters) 1020 1013 self._copy_parameters_state(self.fittable_param, 1021 self.state.fittable_param)1014 self.state.fittable_param) 1022 1015 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 1023 1016 1024 1017 def check_invalid_panel(self): 1025 1018 """ … … 1032 1025 wx.MessageBox(msg, 'Info') 1033 1026 return True 1034 1027 1035 1028 def set_model_state(self, state): 1036 1029 """ … … 1039 1032 self.disp_cb_dict = state.disp_cb_dict 1040 1033 self.disp_list = state.disp_list 1041 1034 1042 1035 ## set the state of the radio box 1043 1036 #self.shape_rbutton.SetValue(state.shape_rbutton) … … 1045 1038 #self.struct_rbutton.SetValue(state.struct_rbutton) 1046 1039 #self.plugin_rbutton.SetValue(state.plugin_rbutton) 1047 1040 1048 1041 ## fill model combobox 1049 1042 self._show_combox_helper() … … 1059 1052 category_pos = int(ind_cat) 1060 1053 break 1061 1054 1062 1055 self.categorybox.Select(category_pos) 1063 1056 try: … … 1071 1064 formfactor_pos = int(ind_form) 1072 1065 break 1073 1066 1074 1067 self.formfactorbox.Select(formfactor_pos) 1075 1068 1076 1069 try: 1077 1070 # to support older version … … 1084 1077 structfactor_pos = int(ind_struct) 1085 1078 break 1086 1079 1087 1080 self.structurebox.SetSelection(structfactor_pos) 1088 1081 1089 1082 if state.multi_factor != None: 1090 1083 self.multifactorbox.SetSelection(state.multi_factor) 1091 1084 1092 1085 ## reset state of checkbox,textcrtl and regular parameters value 1093 1086 self._reset_parameters_state(self.orientation_params_disp, … … 1101 1094 self.enable_disp.SetValue(state.enable_disp) 1102 1095 self.disable_disp.SetValue(state.disable_disp) 1103 1096 1104 1097 if hasattr(self, "disp_box") and self.disp_box != None: 1105 1098 self.disp_box.SetSelection(state.disp_box) … … 1109 1102 1110 1103 self._set_dipers_Param(event=None) 1111 1104 1112 1105 if name == "ArrayDispersion": 1113 1106 1114 1107 for item in self.disp_cb_dict.keys(): 1115 1108 1116 1109 if hasattr(self.disp_cb_dict[item], "SetValue"): 1117 1110 self.disp_cb_dict[item].SetValue(\ 1118 1111 state.disp_cb_dict[item]) 1119 1112 # Create the dispersion objects 1120 from sas.models.dispersion_models import ArrayDispersion 1113 #from sas.models.dispersion_models import ArrayDispersion 1114 from sasmodels.weights import ArrayDispersion 1121 1115 disp_model = ArrayDispersion() 1122 1116 if hasattr(state, "values") and \ … … 1129 1123 else: 1130 1124 self._reset_dispersity() 1131 1125 1132 1126 self._disp_obj_dict[item] = disp_model 1133 1127 # Set the new model as the dispersion object 1134 1128 #for the selected parameter 1135 1129 self.model.set_dispersion(item, disp_model) 1136 1130 1137 1131 self.model._persistency_dict[item] = \ 1138 1132 [state.values, state.weights] 1139 1133 1140 1134 else: 1141 1135 keys = self.model.getParamList() … … 1155 1149 self.pinhole_smearer.SetValue(state.pinhole_smearer) 1156 1150 self.slit_smearer.SetValue(state.slit_smearer) 1157 1151 1158 1152 self.dI_noweight.SetValue(state.dI_noweight) 1159 1153 self.dI_didata.SetValue(state.dI_didata) 1160 1154 self.dI_sqrdata.SetValue(state.dI_sqrdata) 1161 1155 self.dI_idata.SetValue(state.dI_idata) 1162 1156 1163 1157 ## we have two more options for smearing 1164 1158 if self.pinhole_smearer.GetValue(): … … 1166 1160 elif self.slit_smearer.GetValue(): 1167 1161 self.onSlitSmear(event=None) 1168 1162 1169 1163 ## reset state of checkbox,textcrtl and dispersity parameters value 1170 1164 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1171 1165 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1172 1166 1173 1167 ## draw the model with previous parameters value 1174 1168 self._onparamEnter_helper() … … 1178 1172 self._lay_out() 1179 1173 self.Refresh() 1180 1174 1181 1175 def reset_page_helper(self, state): 1182 1176 """ 1183 1177 Use page_state and change the state of existing page 1184 1178 1185 1179 :precondition: the page is already drawn or created 1186 1180 1187 1181 :postcondition: the state of the underlying data change as well as the 1188 1182 state of the graphic interface … … 1210 1204 else: 1211 1205 self.set_data(data) 1212 1206 1213 1207 self.enable2D = state.enable2D 1214 1208 try: … … 1220 1214 self.disp_cb_dict = state.disp_cb_dict 1221 1215 self.disp_list = state.disp_list 1222 1216 1223 1217 ## set the state of the radio box 1224 1218 #self.shape_rbutton.SetValue(state.shape_rbutton) … … 1226 1220 #self.struct_rbutton.SetValue(state.struct_rbutton) 1227 1221 #self.plugin_rbutton.SetValue(state.plugin_rbutton) 1228 1222 1229 1223 ## fill model combobox 1230 1224 self._show_combox_helper() … … 1240 1234 category_pos = int(ind_cat) 1241 1235 break 1242 1236 1243 1237 self.categorybox.Select(category_pos) 1244 1238 self._show_combox(None) … … 1253 1247 formfactor_pos = int(ind_form) 1254 1248 break 1255 1249 1256 1250 self.formfactorbox.Select(formfactor_pos) 1257 1251 1258 1252 try: 1259 1253 # to support older version … … 1266 1260 structfactor_pos = int(ind_struct) 1267 1261 break 1268 1262 1269 1263 self.structurebox.SetSelection(structfactor_pos) 1270 1264 … … 1274 1268 #draw the panel according to the new model parameter 1275 1269 self._on_select_model(event=None) 1276 1270 1277 1271 # take care of 2D button 1278 1272 if data == None and self.model_view.IsEnabled(): … … 1281 1275 else: 1282 1276 self.model_view.SetLabel("1D Mode") 1283 1277 1284 1278 ## set the select all check box to the a given state 1285 1279 self.cb1.SetValue(state.cb1) 1286 1280 1287 1281 ## reset state of checkbox,textcrtl and regular parameters value 1288 1282 self._reset_parameters_state(self.orientation_params_disp, … … 1323 1317 self.dI_sqrdata.SetValue(False) 1324 1318 self.dI_idata.SetValue(False) 1325 1319 1326 1320 ## we have two more options for smearing 1327 1321 if self.pinhole_smearer.GetValue(): … … 1339 1333 self.smear_slit_height.SetValue(str(self.dxl)) 1340 1334 if self.dxw != None: 1341 self.smear_slit_width.SetValue(str(self.dxw)) 1335 self.smear_slit_width.SetValue(str(self.dxw)) 1342 1336 else: 1343 self.smear_slit_width.SetValue('') 1337 self.smear_slit_width.SetValue('') 1344 1338 self.onSlitSmear(event=None) 1345 1339 1346 1340 ## reset state of checkbox,textcrtl and dispersity parameters value 1347 1341 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1348 1342 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1349 1343 1350 1344 ## draw the model with previous parameters value 1351 1345 self._onparamEnter_helper() … … 1354 1348 ## reset context menu items 1355 1349 self._reset_context_menu() 1356 1350 1357 1351 ## set the value of the current state to the state given as parameter 1358 1352 self.state = state.clone() 1359 1353 self.state.m_name = self.m_name 1360 1354 1361 1355 def _reset_page_disp_helper(self, state): 1362 1356 """ … … 1373 1367 self.values = copy.deepcopy(state.values) 1374 1368 self.weights = copy.deepcopy(state.weights) 1375 1369 1376 1370 for key, disp in state._disp_obj_dict.iteritems(): 1377 1371 # From saved file, disp_model can not be sent in model obj. … … 1379 1373 if disp.__class__.__name__ == 'str': 1380 1374 disp_model = None 1381 com_str = "from sas.models.dispersion_models " 1375 #com_str = "from sas.models.dispersion_models " 1376 com_str = "from sasmodels.weights " 1382 1377 com_str += "import %s as disp_func \ndisp_model = disp_func()" 1383 1378 exec com_str % disp … … 1420 1415 except: 1421 1416 logging.error(sys.exc_info()[1]) 1422 1417 1423 1418 # Make sure the check box updated when all checked 1424 1419 if self.cb1.GetValue(): 1425 1420 self.select_all_param(None) 1426 1421 1427 1422 def _selectDlg(self): 1428 1423 """ 1429 open a dialog file to selected the customized dispersity 1424 open a dialog file to selected the customized dispersity 1430 1425 """ 1431 1426 if self.parent != None: … … 1433 1428 self._manager.parent.get_save_location() 1434 1429 dlg = wx.FileDialog(self, "Choose a weight file", 1435 self._default_save_location, "",1436 "*.*", wx.OPEN)1430 self._default_save_location, "", 1431 "*.*", wx.OPEN) 1437 1432 path = None 1438 1433 if dlg.ShowModal() == wx.ID_OK: … … 1445 1440 reset the context menu 1446 1441 """ 1447 ids = iter(self._id_pool) # Reusing ids for context menu1448 1442 for name, _ in self.state.saved_states.iteritems(): 1449 1443 self.number_saved_state += 1 1450 1444 ## Add item in the context menu 1451 wx_id = ids.next()1445 id = wx.NewId() 1452 1446 msg = 'Save model and state %g' % self.number_saved_state 1453 self.popUpMenu.Append( wx_id, name, msg)1454 wx.EVT_MENU(self, wx_id, self.onResetModel)1455 1447 self.popUpMenu.Append(id, name, msg) 1448 wx.EVT_MENU(self, id, self.onResetModel) 1449 1456 1450 def _reset_plotting_range(self, state): 1457 1451 """ … … 1472 1466 self.state.formfactorcombobox = self.formfactorbox.GetLabel() 1473 1467 self.state.categorycombobox = self.categorybox.GetLabel() 1474 1468 1475 1469 ## post state to fit panel 1476 1470 event = PageInfoEvent(page=self) 1477 1471 wx.PostEvent(self.parent, event) 1478 1472 1479 1473 def _save_plotting_range(self): 1480 1474 """ … … 1484 1478 self.state.qmax = self.qmax_x 1485 1479 self.state.npts = self.npts_x 1486 1480 1487 1481 def _onparamEnter_helper(self): 1488 1482 """ … … 1501 1495 try: 1502 1496 is_modified = self._check_value_enter(self.fittable_param, 1503 1497 is_modified) 1504 1498 is_modified = self._check_value_enter(self.fixed_param, 1505 1499 is_modified) … … 1521 1515 self.qmax_x = tempmax 1522 1516 is_modified = True 1523 1517 1524 1518 if is_2Ddata: 1525 1519 # set mask 1526 1520 is_modified = self._validate_Npts() 1527 1521 1528 1522 else: 1529 1523 self.fitrange = False 1530 1524 1531 1525 if not self.data.is_data: 1532 1526 is_modified = True … … 1548 1542 self.Refresh() 1549 1543 return is_modified 1550 1544 1551 1545 def _update_paramv_on_fit(self): 1552 1546 """ … … 1573 1567 self._check_value_enter(self.parameters, is_modified) 1574 1568 1575 # If qmin and qmax have been modified, update qmin and qmax and 1569 # If qmin and qmax have been modified, update qmin and qmax and 1576 1570 # Here we should check whether the boundaries have been modified. 1577 # If qmin and qmax have been modified, update qmin and qmax and 1571 # If qmin and qmax have been modified, update qmin and qmax and 1578 1572 # set the is_modified flag to True 1579 1573 self.fitrange = self._validate_qrange(self.qmin, self.qmax) … … 1602 1596 qmax=float(self.qmax_x), 1603 1597 enable_smearer=enable_smearer, 1604 draw=False)1598 draw=False) 1605 1599 elif not self._is_2D(): 1606 1600 enable_smearer = not self.disable_smearer.GetValue() … … 1611 1605 qmax=float(self.qmax_x), 1612 1606 enable_smearer=enable_smearer, 1613 draw=False)1607 draw=False) 1614 1608 if self.data != None: 1615 1609 index_data = ((self.qmin_x <= self.data.x) & \ … … 1647 1641 msg += " model or Fitting range is not valid!!! " 1648 1642 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1649 1643 1650 1644 try: 1651 1645 self.save_current_state() 1652 1646 except: 1653 1647 logging.error(sys.exc_info()[1]) 1654 1648 1655 1649 return flag 1656 1650 1657 1651 def _is_modified(self, is_modified): 1658 1652 """ … … 1660 1654 """ 1661 1655 return is_modified 1662 1656 1663 1657 def _reset_parameters_state(self, listtorestore, statelist): 1664 1658 """ … … 1699 1693 item_page[5].Show(item_page_info[5][0]) 1700 1694 item_page[5].SetValue(item_page_info[5][1]) 1701 1695 1702 1696 if item_page[6] != None: 1703 1697 ## show of hide the text crtl for fitting error 1704 1698 item_page[6].Show(item_page_info[6][0]) 1705 1699 item_page[6].SetValue(item_page_info[6][1]) 1706 1700 1707 1701 def _reset_strparam_state(self, listtorestore, statelist): 1708 1702 """ … … 1713 1707 1714 1708 listtorestore = copy.deepcopy(statelist) 1715 1709 1716 1710 for j in range(len(listtorestore)): 1717 1711 item_page = listtorestore[j] 1718 1712 item_page_info = statelist[j] 1719 1713 ##change the state of the check box for simple parameters 1720 1714 1721 1715 if item_page[0] != None: 1722 1716 item_page[0].SetValue(format_number(item_page_info[0], True)) … … 1730 1724 item_page[2].SetValue(selection) 1731 1725 self.model.setParam(param_name, selection) 1732 1726 1733 1727 def _copy_parameters_state(self, listtocopy, statelist): 1734 1728 """ 1735 1729 copy the state of button 1736 1730 1737 1731 :param listtocopy: the list of check button to copy 1738 1732 :param statelist: list of state object to store the current state 1739 1733 1740 1734 """ 1741 1735 if len(listtocopy) == 0: 1742 1736 return 1743 1737 1744 1738 for item in listtocopy: 1745 1739 1746 1740 checkbox_state = None 1747 1741 if item[0] != None: … … 1759 1753 error_value = item[4].GetValue() 1760 1754 error_state = item[4].IsShown() 1761 1755 1762 1756 min_value = None 1763 1757 min_state = None … … 1765 1759 min_value = item[5].GetValue() 1766 1760 min_state = item[5].IsShown() 1767 1761 1768 1762 max_value = None 1769 1763 max_state = None … … 1774 1768 if item[7] != None: 1775 1769 unit = item[7].GetLabel() 1776 1770 1777 1771 statelist.append([checkbox_state, parameter_name, parameter_value, 1778 1772 static_text, [error_state, error_value], 1779 1773 [min_state, min_value], 1780 1774 [max_state, max_value], unit]) 1781 1782 1775 1776 1783 1777 def _draw_model(self, update_chisqr=True, source='model'): 1784 1778 """ … … 1786 1780 The method will use the data member from the model page 1787 1781 to build a call to the fitting perspective manager. 1788 1782 1789 1783 :param chisqr: update chisqr value [bool] 1790 1784 """ 1791 1785 wx.CallAfter(self._draw_model_after, update_chisqr, source) 1792 1786 1793 1787 def _draw_model_after(self, update_chisqr=True, source='model'): 1794 1788 """ … … 1796 1790 The method will use the data member from the model page 1797 1791 to build a call to the fitting perspective manager. 1798 1792 1799 1793 :param chisqr: update chisqr value [bool] 1800 1794 """ … … 1824 1818 source='model', 1825 1819 weight=weight) 1826 1820 1827 1821 def _on_show_sld(self, event=None): 1828 1822 """ … … 1839 1833 sld_data.name = 'SLD' 1840 1834 sld_data.axes = self.sld_axes 1841 self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, 1842 id=wx.ID_ANY) 1835 self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id=-1) 1843 1836 self.panel.ShowModal() 1844 1837 1845 1838 def _set_multfactor_combobox(self, multiplicity=10): 1846 1839 """ … … 1852 1845 self.multifactorbox.Append(str(idx), int(idx)) 1853 1846 self._hide_multfactor_combobox() 1854 1847 1855 1848 def _show_multfactor_combobox(self): 1856 1849 """ … … 1862 1855 if not self.multifactorbox.IsShown(): 1863 1856 self.multifactorbox.Show(True) 1864 1857 1865 1858 def _hide_multfactor_combobox(self): 1866 1859 """ … … 1872 1865 if self.multifactorbox.IsShown(): 1873 1866 self.multifactorbox.Hide() 1874 1867 1875 1868 def formfactor_combo_init(self): 1876 1869 """ … … 1878 1871 """ 1879 1872 self._show_combox(None) 1880 1873 1881 1874 def _show_combox_helper(self): 1882 1875 """ … … 1911 1904 StatusEvent(status=msg, info="error")) 1912 1905 self._populate_box(self.formfactorbox, m_list) 1913 1914 def _on_modify_cat(self, event=None): 1906 1907 def _on_modify_cat(self, event=None): 1915 1908 """ 1916 1909 Called when category manager is opened 1917 1910 """ 1918 self._manager.parent.on_category_panel(event) 1919 1911 self._manager.parent.on_category_panel(event) 1912 1920 1913 def _show_combox(self, event=None): 1921 1914 """ … … 1931 1924 self.Layout() 1932 1925 self.Refresh() 1933 1926 1934 1927 def _populate_box(self, combobox, list): 1935 1928 """ 1936 1929 fill combox box with dict item 1937 1930 1938 1931 :param list: contains item to fill the combox 1939 1932 item must model class … … 1944 1937 name = model.__class__.__name__ 1945 1938 if models.__name__ != "NoStructure": 1946 if hasattr(model, "name"): 1939 if hasattr(model, "oldname"): 1940 name = model.oldname 1941 elif hasattr(model, "name"): 1947 1942 name = model.name 1948 1943 mlist.append((name, models)) 1949 1944 1950 1945 # Sort the models 1951 1946 mlist_sorted = sorted(mlist) … … 1953 1948 combobox.Append(item[0], item[1]) 1954 1949 return 0 1955 1950 1956 1951 def _onQrangeEnter(self, event): 1957 1952 """ 1958 1953 Check validity of value enter in the Q range field 1959 1954 1960 1955 """ 1961 1956 tcrtl = event.GetEventObject() … … 2010 2005 self.create_default_data() 2011 2006 self._draw_model() 2012 2007 2013 2008 def _theory_qrange_enter(self, event): 2014 2009 """ 2015 2010 Check validity of value enter in the Q range field 2016 2011 """ 2017 2012 2018 2013 tcrtl = event.GetEventObject() 2019 2014 #Clear msg if previously shown. … … 2067 2062 self.create_default_data() 2068 2063 self._draw_model() 2069 2064 2070 2065 def _on_select_model_helper(self): 2071 2066 """ … … 2093 2088 self.structurebox.Enable() 2094 2089 self.text2.Enable() 2095 2090 2096 2091 if form_factor != None: 2097 2092 # set multifactor for Mutifunctional models … … 2110 2105 # default value 2111 2106 m_id = 1 2112 2107 2113 2108 self.multi_factor = self.multifactorbox.GetClientData(m_id) 2114 2109 if self.multi_factor == None: … … 2138 2133 self.show_sld_button.Hide() 2139 2134 self.multi_factor = None 2140 2135 2141 2136 s_id = self.structurebox.GetCurrentSelection() 2142 2137 struct_factor = self.structurebox.GetClientData(s_id) 2143 2138 2144 2139 if struct_factor != None: 2145 2140 from sas.models.MultiplicationModel import MultiplicationModel … … 2156 2151 # check if model has magnetic parameters 2157 2152 if len(self.model.magnetic_params) > 0: 2158 self._has_magnetic = True 2153 self._has_magnetic = True 2159 2154 else: 2160 self._has_magnetic = False 2155 self._has_magnetic = False 2161 2156 ## post state to fit panel 2162 2157 self.state.parameters = [] … … 2168 2163 self.on_set_focus(None) 2169 2164 self.Layout() 2170 2165 2171 2166 def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 2172 2167 """ 2173 2168 Verify that the Q range controls have valid values 2174 2169 and that Qmin < Qmax. 2175 2170 2176 2171 :param qmin_ctrl: text control for Qmin 2177 2172 :param qmax_ctrl: text control for Qmax 2178 2173 2179 2174 :return: True is the Q range is value, False otherwise 2180 2175 2181 2176 """ 2182 2177 qmin_validity = check_float(qmin_ctrl) … … 2202 2197 return False 2203 2198 return True 2204 2199 2205 2200 def _validate_Npts(self): 2206 2201 """ … … 2237 2232 self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 2238 2233 self.fitrange = True 2239 2234 2240 2235 return flag 2241 2236 … … 2272 2267 self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 2273 2268 self.fitrange = True 2274 2269 2275 2270 return flag 2276 2271 2277 2272 def _check_value_enter(self, list, modified): 2278 2273 """ … … 2296 2291 #try: 2297 2292 name = str(item[1]) 2298 2293 2299 2294 if string.find(name, ".npts") == -1 and \ 2300 2295 string.find(name, ".nsigmas") == -1: … … 2302 2297 param_min = None 2303 2298 param_max = None 2304 2299 2305 2300 ## check minimun value 2306 2301 if item[5] != None and item[5] != "": … … 2311 2306 if numpy.isfinite(param_min): 2312 2307 item[2].SetValue(format_number(param_min)) 2313 2308 2314 2309 item[5].SetBackgroundColour(wx.WHITE) 2315 2310 item[2].SetBackgroundColour(wx.WHITE) 2316 2311 2317 2312 except: 2318 2313 msg = "Wrong fit parameter range entered" … … 2329 2324 if numpy.isfinite(param_max): 2330 2325 item[2].SetValue(format_number(param_max)) 2331 2326 2332 2327 item[6].SetBackgroundColour(wx.WHITE) 2333 2328 item[2].SetBackgroundColour(wx.WHITE) … … 2338 2333 raise ValueError, msg 2339 2334 is_modified = True 2340 2335 2341 2336 if param_min != None and param_max != None: 2342 2337 if not self._validate_qrange(item[5], item[6]): … … 2345 2340 wx.PostEvent(self._manager.parent, 2346 2341 StatusEvent(status=msg)) 2347 2342 2348 2343 if name in self.model.details.keys(): 2349 2344 self.model.details[name][1:3] = param_min, param_max … … 2366 2361 msg = "Wrong Fit parameter value entered " 2367 2362 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2368 2363 2369 2364 return is_modified 2370 2365 2371 2366 def _set_dipers_Param(self, event): 2372 2367 """ … … 2387 2382 2388 2383 self._reset_dispersity() 2389 2384 2390 2385 if self.model == None: 2391 2386 self.model_disp.Hide() … … 2395 2390 if self.enable_disp.GetValue(): 2396 2391 ## layout for model containing no dispersity parameters 2397 2392 2398 2393 self.disp_list = self.model.getDispParamList() 2399 2394 2400 2395 if len(self.disp_list) == 0 and len(self.disp_cb_dict) == 0: 2401 2396 self._layout_sizer_noDipers() … … 2405 2400 else: 2406 2401 self.sizer4_4.Clear(True) 2407 2402 2408 2403 ## post state to fit panel 2409 2404 self.save_current_state() … … 2413 2408 #draw the model with the current dispersity 2414 2409 self._draw_model() 2415 ## Need to use FitInside again here to replace the next four lines. 2416 ## Otherwised polydispersity off does not resize the scrollwindow. 2417 ## PDB Nov 28, 2015 2418 self.FitInside() 2419 # self.sizer4_4.Layout() 2420 # self.sizer5.Layout() 2421 # self.Layout() 2422 # self.Refresh() 2423 2410 self.sizer4_4.Layout() 2411 self.sizer5.Layout() 2412 self.Layout() 2413 self.Refresh() 2414 2424 2415 def _layout_sizer_noDipers(self): 2425 2416 """ … … 2431 2422 self.fixed_param = [] 2432 2423 self.orientation_params_disp = [] 2433 2424 2434 2425 self.sizer4_4.Clear(True) 2435 2426 text = "No polydispersity available for this model" 2436 model_disp = wx.StaticText(self, wx.ID_ANY, text)2427 model_disp = wx.StaticText(self, -1, text) 2437 2428 self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), 2438 2429 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 2439 2430 self.sizer4_4.Layout() 2440 2431 self.sizer4.Layout() 2441 2432 2442 2433 def _reset_dispersity(self): 2443 2434 """ … … 2452 2443 if item in self.param_toFit: 2453 2444 self.param_toFit.remove(item) 2454 2445 2455 2446 self.fittable_param = [] 2456 2447 self.fixed_param = [] … … 2458 2449 self.values = {} 2459 2450 self.weights = {} 2460 2461 from sas.models.dispersion_models import GaussianDispersion 2451 2452 #from sas.models.dispersion_models import GaussianDispersion 2453 from sasmodels.weights import GaussianDispersion 2462 2454 if len(self.disp_cb_dict) == 0: 2463 2455 self.save_current_state() … … 2470 2462 # Go back to Gaussian model (with 0 pts) 2471 2463 disp_model = GaussianDispersion() 2472 2464 2473 2465 self._disp_obj_dict[p] = disp_model 2474 2466 # Set the new model as the dispersion object … … 2483 2475 self.Layout() 2484 2476 self.Refresh() 2485 2477 2486 2478 def _on_select_Disp(self, event): 2487 2479 """ … … 2496 2488 event = PageInfoEvent(page=self) 2497 2489 wx.PostEvent(self.parent, event) 2498 2490 2499 2491 self.sizer4_4.Layout() 2500 2492 self.sizer4.Layout() 2501 2493 self.SetupScrolling() 2502 2494 2503 2495 def _on_disp_func(self, event=None): 2504 2496 """ 2505 2497 Select a distribution function for the polydispersion 2506 2498 2507 2499 :Param event: ComboBox event 2508 2500 """ … … 2520 2512 disp_name = disp_box.GetValue() 2521 2513 dispersity = disp_box.GetClientData(selection) 2522 2514 2523 2515 #disp_model = GaussianDispersion() 2524 2516 disp_model = dispersity() … … 2538 2530 self.model.set_dispersion(param_name, disp_model) 2539 2531 self.state._disp_obj_dict[name1] = disp_model 2540 2532 2541 2533 value1 = str(format_number(self.model.getParam(name1), True)) 2542 2534 value2 = str(format_number(self.model.getParam(name2))) … … 2566 2558 for item in self.fixed_param: 2567 2559 if item[1] == name2: 2568 item[2].SetValue(value2) 2560 item[2].SetValue(value2) 2569 2561 # Disable Npts for array 2570 2562 if disp_name.lower() == "array": … … 2579 2571 else: 2580 2572 item[2].Enable() 2581 2573 2582 2574 # Make sure the check box updated when all checked 2583 2575 if self.cb1.GetValue(): … … 2600 2592 wx.PostEvent(self._manager.parent, 2601 2593 StatusEvent(status=msg, info="error")) 2602 2594 2603 2595 def _set_array_disp(self, name=None, disp=None): 2604 2596 """ 2605 2597 Set array dispersion 2606 2598 2607 2599 :param name: name of the parameter for the dispersion to be set 2608 2600 :param disp: the polydisperion object … … 2621 2613 self._default_save_location = os.path.dirname(path) 2622 2614 if self._manager != None: 2623 self._manager.parent._default_save_location = 2615 self._manager.parent._default_save_location =\ 2624 2616 self._default_save_location 2625 2617 2626 2618 basename = os.path.basename(path) 2627 2619 values, weights = self.read_file(path) 2628 2620 2629 2621 # If any of the two arrays is empty, notify the user that we won't 2630 2622 # proceed … … 2639 2631 values=values, weights=weights) 2640 2632 return basename 2641 2633 2642 2634 def _set_array_disp_model(self, name=None, disp=None, 2643 2635 values=[], weights=[]): 2644 2636 """ 2645 2637 Set array dispersion model 2646 2638 2647 2639 :param name: name of the parameter for the dispersion to be set 2648 2640 :param disp: the polydisperion object … … 2673 2665 self.state.model._persistency_dict[name.split('.')[0]] = \ 2674 2666 [values, weights] 2675 2667 2676 2668 def _del_array_values(self, name=None): 2677 2669 """ 2678 2670 Reset array dispersion 2679 2671 2680 2672 :param name: name of the parameter for the dispersion to be set 2681 2673 """ … … 2691 2683 except: 2692 2684 logging.error(sys.exc_info()[1]) 2693 2685 2694 2686 def _lay_out(self): 2695 2687 """ 2696 2688 returns self.Layout 2697 2689 2698 2690 :Note: Mac seems to like this better when self. 2699 2691 Layout is called after fitting. … … 2702 2694 self.Layout() 2703 2695 return 2704 2696 2705 2697 def _sleep4sec(self): 2706 2698 """ … … 2711 2703 if ON_MAC == True: 2712 2704 time.sleep(1) 2713 2705 2714 2706 def _find_polyfunc_selection(self, disp_func=None): 2715 2707 """ 2716 2708 FInd Comboox selection from disp_func 2717 2709 2718 2710 :param disp_function: dispersion distr. function 2719 2711 """ … … 2729 2721 except: 2730 2722 return 3 2731 2723 2732 2724 def on_reset_clicked(self, event): 2733 2725 """ … … 2741 2733 flag = False 2742 2734 return 2743 2735 2744 2736 elif self.data.__class__.__name__ == "Data2D": 2745 2737 data_min = 0 … … 2747 2739 y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) 2748 2740 self.qmin_x = data_min 2749 self.qmax_x = math.sqrt(x * x + y *y)2741 self.qmax_x = math.sqrt(x*x + y*y) 2750 2742 #self.data.mask = numpy.ones(len(self.data.data),dtype=bool) 2751 2743 # check smearing … … 2757 2749 else: 2758 2750 flag = True 2759 2751 2760 2752 elif self.data == None: 2761 2753 self.qmin_x = _QMIN_DEFAULT … … 2763 2755 self.num_points = _NPTS_DEFAULT 2764 2756 self.state.npts = self.num_points 2765 2757 2766 2758 elif self.data.__class__.__name__ != "Data2D": 2767 2759 self.qmin_x = min(self.data.x) … … 2779 2771 else: 2780 2772 flag = False 2781 2773 2782 2774 if flag == False: 2783 2775 msg = "Cannot Plot :Must enter a number!!! " … … 2796 2788 self.state.qmin = self.qmin_x 2797 2789 self.state.qmax = self.qmax_x 2798 2790 2799 2791 #reset the q range values 2800 2792 self._reset_plotting_range(self.state) 2801 2793 self._draw_model() 2802 2794 2803 2795 def select_log(self, event): 2804 2796 """ … … 2809 2801 """ 2810 2802 Get the images of the plots corresponding this panel for report 2811 2803 2812 2804 : return graphs: list of figures 2813 2805 : Need Move to guiframe … … 2833 2825 # append to the list 2834 2826 graphs.append(item2.figure) 2835 canvases.append(item2.canvas) 2827 canvases.append(item2.canvas) 2836 2828 except: 2837 2829 # Not for control panels … … 2864 2856 name = self.formfactorbox.GetValue() 2865 2857 _PageAnchor = '#' + name.lower() 2866 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation,2858 _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, 2867 2859 _PageAnchor, name + " Help") 2868 2860 else: 2869 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation,2870 "","General Model Help")2861 _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 2862 "General Model Help") 2871 2863 2872 2864 … … 2883 2875 :param evt: on Description Button pressed event 2884 2876 """ 2885 2877 2886 2878 if self.model == None: 2887 2879 name = 'index.html' … … 2889 2881 name = self.formfactorbox.GetValue() 2890 2882 2891 msg = 'Model description:\n'2883 msg = 'Model description:\n' 2892 2884 info = "Info" 2893 2885 if self.model != None: 2894 2886 # frame.Destroy() 2895 if str(self.model.description).rstrip().lstrip() == '': 2896 msg += "Sorry, no information is available for this model." 2887 if str(self.model.description).rstrip().lstrip() == '': 2888 msg += "Sorry, no information is available for this model." 2889 else: 2890 msg += self.model.description + '\n' 2891 wx.MessageBox(msg, info) 2897 2892 else: 2898 msg += self.model.description + '\n'2899 wx.MessageBox(msg, info)2900 else:2901 2893 msg += "You must select a model to get information on this" 2902 2894 wx.MessageBox(msg, info) … … 2919 2911 2920 2912 _TreeLocation = "_images/M_angles_pic.bmp" 2921 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "",2913 _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 2922 2914 "Magnetic Angle Defintions") 2923 2915 2924 def _on_mag_help(self, event): 2916 def _on_mag_help(self, event): 2925 2917 """ 2926 2918 Bring up Magnetic Angle definition bmp image whenever the ? button … … 2939 2931 2940 2932 _TreeLocation = "user/perspectives/fitting/mag_help.html" 2941 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "",2933 _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 2942 2934 "Polarized Beam/Magnetc Help") 2943 2935 2944 def _on_mag_on(self, event): 2936 def _on_mag_on(self, event): 2945 2937 """ 2946 2938 Magnetic Parameters ON/OFF … … 2963 2955 #reset mag value to zero fo safety 2964 2956 self.model.setParam(key, 0.0) 2965 2966 self.Show(False) 2957 2958 self.Show(False) 2967 2959 self.set_model_param_sizer(self.model) 2968 2960 #self._set_sizer_dispersion() … … 2970 2962 self.SetupScrolling() 2971 2963 self.Show(True) 2972 2964 2973 2965 def on_pd_help_clicked(self, event): 2974 2966 """ … … 2980 2972 webbrowser does not pass anything past the # to the browser when it is 2981 2973 running "file:///...." 2982 2974 2983 2975 :param evt: Triggers on clicking ? in polydispersity box 2984 2976 """ … … 2986 2978 _TreeLocation = "user/perspectives/fitting/pd_help.html" 2987 2979 _PageAnchor = "" 2988 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation,2980 _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, 2989 2981 _PageAnchor, "Polydispersity Help") 2990 2982 2991 2983 def on_left_down(self, event): 2992 2984 """ … … 3003 2995 # make event free 3004 2996 event.Skip() 3005 2997 3006 2998 def get_copy(self): 3007 2999 """ … … 3012 3004 self._copy_info(flag) 3013 3005 return flag 3014 3006 3015 3007 def get_copy_params(self): 3016 3008 """ … … 3020 3012 # Do it if params exist 3021 3013 if self.parameters != []: 3022 3014 3023 3015 # go through the parameters 3024 3016 strings = self._get_copy_helper(self.parameters, 3025 3017 self.orientation_params) 3026 3018 content += strings 3027 3019 3028 3020 # go through the fittables 3029 3021 strings = self._get_copy_helper(self.fittable_param, … … 3035 3027 self.orientation_params_disp) 3036 3028 content += strings 3037 3029 3038 3030 # go through the str params 3039 3031 strings = self._get_copy_helper(self.str_parameters, … … 3068 3060 content += param[1] #parameter name 3069 3061 content += tab 3070 content += param[1] +"_err"3062 content += param[1]+"_err" 3071 3063 content += tab 3072 3064 … … 3076 3068 for param in self.parameters: 3077 3069 content += param[2].GetValue() #value 3078 content += 3070 content +=tab 3079 3071 content += param[4].GetValue() #error 3080 content += 3072 content +=tab 3081 3073 3082 3074 return content … … 3114 3106 3115 3107 for index, param in enumerate(self.parameters): 3116 content += param[1].replace('_', 3108 content += param[1].replace('_','\_') #parameter name 3117 3109 content += ' & ' 3118 content += param[1].replace('_', '\_') +"\_err"3119 if index < len(self.parameters) -1:3110 content += param[1].replace('_','\_')+"\_err" 3111 if index < len(self.parameters)-1: 3120 3112 content += ' & ' 3121 3113 content += '\\\\ \\hline' … … 3127 3119 content += ' & ' 3128 3120 content += param[4].GetValue() #parameter error 3129 if index < len(self.parameters) -1:3121 if index < len(self.parameters)-1: 3130 3122 content += ' & ' 3131 3123 content += '\\\\ \\hline' … … 3150 3142 return True 3151 3143 return None 3152 3144 3153 3145 def _get_copy_helper(self, param, orient_param): 3154 3146 """ 3155 3147 Helping get value and name of the params 3156 3148 3157 3149 : param param: parameters 3158 3150 : param orient_param = oritational params … … 3171 3163 except: 3172 3164 logging.error(sys.exc_info()[1]) 3173 3165 3174 3166 # 2D 3175 3167 if self.data.__class__.__name__ == "Data2D": … … 3193 3185 # add to the content 3194 3186 if disfunc != '': 3195 3187 3196 3188 disfunc = ',' + disfunc 3197 3189 # Need to support array func for copy/paste … … 3209 3201 3210 3202 return content 3211 3203 3212 3204 def get_clipboard(self): 3213 3205 """ … … 3229 3221 wx.TheClipboard.Close() 3230 3222 return text 3231 3223 3232 3224 def get_paste(self): 3233 3225 """ … … 3238 3230 self._copy_info(flag) 3239 3231 return flag 3240 3232 3241 3233 def get_paste_params(self, text=''): 3242 3234 """ … … 3267 3259 val = [float(a_val) for a_val in array_values[1:]] 3268 3260 weit = [float(a_weit) for a_weit in array_weights[1:]] 3269 3261 3270 3262 context[name].append(val) 3271 3263 context[name].append(weit) … … 3290 3282 self._get_paste_helper(self.fixed_param, 3291 3283 self.orientation_params_disp, context) 3292 3284 3293 3285 # go through the str params 3294 3286 self._get_paste_helper(self.str_parameters, 3295 3287 self.orientation_params, context) 3296 3288 3297 3289 return True 3298 3290 return None 3299 3291 3300 3292 def _get_paste_helper(self, param, orient_param, content): 3301 3293 """ 3302 3294 Helping set values of the params 3303 3295 3304 3296 : param param: parameters 3305 3297 : param orient_param: oritational params … … 3329 3321 fun_val = self.model.fun_list[content[name][1]] 3330 3322 self.model.setParam(name, fun_val) 3331 3323 3332 3324 value = content[name][1:] 3333 3325 self._paste_poly_help(item, value) … … 3375 3367 if is_true != None: 3376 3368 item[0].SetValue(is_true) 3377 3369 3378 3370 def _paste_poly_help(self, item, value): 3379 3371 """ 3380 3372 Helps get paste for poly function 3381 3373 3382 3374 :param item: Gui param items 3383 3375 :param value: the values for parameter ctrols … … 3419 3411 [self.state.values, 3420 3412 self.state.weights] 3421 3413 3422 3414 except: 3423 3415 logging.error(sys.exc_info()[1]) 3424 3416 print "Error in BasePage._paste_poly_help: %s" % \ 3425 3417 sys.exc_info()[1] 3426 3418 3427 3419 def _set_disp_array_cb(self, item): 3428 3420 """ … … 3438 3430 item[6].SetValue('') 3439 3431 item[6].Enable(False) 3440 3432 3441 3433 def update_pinhole_smear(self): 3442 3434 """ … … 3460 3452 if not os.path.isfile(categorization_file): 3461 3453 categorization_file = CategoryInstaller.get_default_file() 3462 cat_file = open(categorization_file, 'rb') 3454 cat_file = open(categorization_file, 'rb') 3463 3455 self.master_category_dict = json.load(cat_file) 3464 3456 self._regenerate_model_dict() … … 3472 3464 def _regenerate_model_dict(self): 3473 3465 """ 3474 regenerates self.by_model_dict which has each model name as the 3466 regenerates self.by_model_dict which has each model name as the 3475 3467 key and the list of categories belonging to that model 3476 3468 along with the enabled mapping … … 3481 3473 self.by_model_dict[model].append(category) 3482 3474 self.model_enabled_dict[model] = enabled 3483 3475 3484 3476 def _populate_listbox(self): 3485 3477 """ … … 3493 3485 if not uncat_str in cat_list: 3494 3486 cat_list.append(uncat_str) 3495 3487 3496 3488 for category in cat_list: 3497 3489 if category != '': … … 3501 3493 self.categorybox.SetSelection(0) 3502 3494 else: 3503 self.categorybox.SetSelection( \3495 self.categorybox.SetSelection( \ 3504 3496 self.categorybox.GetSelection()) 3505 3497 #self._on_change_cat(None) … … 3521 3513 3522 3514 else: 3523 for (model, 3524 key =lambda name: name[0]):3515 for (model,enabled) in sorted(self.master_category_dict[category], 3516 key = lambda name: name[0]): 3525 3517 if(enabled): 3526 3518 self.model_box.Append(model) … … 3530 3522 fill sizer containing model info 3531 3523 """ 3532 # This should only be called once per fit tab3533 #print "==== Entering _fill_model_sizer"3534 3524 ##Add model function Details button in fitpanel. 3535 3525 ##The following 3 lines are for Mac. Let JHC know before modifying... … … 3537 3527 self.formfactorbox = None 3538 3528 self.multifactorbox = None 3539 self.mbox_description = wx.StaticBox(self, wx.ID_ANY, str(title))3529 self.mbox_description = wx.StaticBox(self, -1, str(title)) 3540 3530 boxsizer1 = wx.StaticBoxSizer(self.mbox_description, wx.VERTICAL) 3541 3531 sizer_cat = wx.BoxSizer(wx.HORIZONTAL) 3542 3532 self.mbox_description.SetForegroundColour(wx.RED) 3543 wx_id = self._ids.next() 3544 self.model_func = wx.Button(self, wx_id, 'Help', size=(80, 23)) 3545 self.model_func.Bind(wx.EVT_BUTTON, self.on_function_help_clicked, 3546 id=wx_id) 3533 id = wx.NewId() 3534 self.model_func = wx.Button(self, id, 'Help', size=(80, 23)) 3535 self.model_func.Bind(wx.EVT_BUTTON, self.on_function_help_clicked, id=id) 3547 3536 self.model_func.SetToolTipString("Full Model Function Help") 3548 wx_id = self._ids.next() 3549 self.model_help = wx.Button(self, wx_id, 'Description', size=(80, 23)) 3550 self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked, 3551 id=wx_id) 3537 id = wx.NewId() 3538 self.model_help = wx.Button(self, id, 'Description', size=(80, 23)) 3539 self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked, id=id) 3552 3540 self.model_help.SetToolTipString("Short Model Function Description") 3553 wx_id = self._ids.next()3554 self.model_view = wx.Button(self, wx_id, "Show 2D", size=(80, 23))3555 self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id= wx_id)3541 id = wx.NewId() 3542 self.model_view = wx.Button(self, id, "Show 2D", size=(80, 23)) 3543 self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id) 3556 3544 hint = "toggle view of model from 1D to 2D or 2D to 1D" 3557 3545 self.model_view.SetToolTipString(hint) 3558 3559 cat_set_box = wx.StaticBox(self, wx.ID_ANY, 'Category')3546 3547 cat_set_box = wx.StaticBox(self, -1, 'Category') 3560 3548 sizer_cat_box = wx.StaticBoxSizer(cat_set_box, wx.HORIZONTAL) 3561 3549 sizer_cat_box.SetMinSize((200, 50)) 3562 self.categorybox = wx.ComboBox(self, wx.ID_ANY, 3563 style=wx.CB_READONLY) 3564 self.categorybox.SetToolTip(wx.ToolTip("Select a Category/Type")) 3550 self.categorybox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 3551 self.categorybox.SetToolTip( wx.ToolTip("Select a Category/Type") ) 3565 3552 self._populate_listbox() 3566 wx.EVT_COMBOBOX(self.categorybox, wx.ID_ANY, self._show_combox)3567 #self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes',3553 wx.EVT_COMBOBOX(self.categorybox, -1, self._show_combox) 3554 #self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', 3568 3555 # style=wx.RB_GROUP) 3569 #self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY,3556 #self.shape_indep_rbutton = wx.RadioButton(self, -1, 3570 3557 # "Shape-Independent") 3571 #self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY, 3572 # "Structure Factor ") 3573 #self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY, 3574 # "Uncategorized") 3575 3558 #self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") 3559 #self.plugin_rbutton = wx.RadioButton(self, -1, "Uncategorized") 3560 3576 3561 #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3577 3562 # id=self.shape_rbutton.GetId()) … … 3583 3568 # id=self.plugin_rbutton.GetId()) 3584 3569 #MAC needs SetValue 3585 3586 show_cat_button = wx.Button(self, wx.ID_ANY, "Modify")3570 3571 show_cat_button = wx.Button(self, -1, "Modify") 3587 3572 cat_tip = "Modify model categories \n" 3588 3573 cat_tip += "(also accessible from the menu bar)." 3589 show_cat_button.SetToolTip( wx.ToolTip(cat_tip))3574 show_cat_button.SetToolTip( wx.ToolTip(cat_tip) ) 3590 3575 show_cat_button.Bind(wx.EVT_BUTTON, self._on_modify_cat) 3591 3576 sizer_cat_box.Add(self.categorybox, 1, wx.RIGHT, 3) 3592 sizer_cat_box.Add((10, 3577 sizer_cat_box.Add((10,10)) 3593 3578 sizer_cat_box.Add(show_cat_button) 3594 3579 #self.shape_rbutton.SetValue(True) 3595 3580 3596 3581 sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) 3597 3582 #sizer_radiobutton.Add(self.shape_rbutton) 3598 3583 #sizer_radiobutton.Add(self.shape_indep_rbutton) 3599 sizer_radiobutton.Add((5, 3584 sizer_radiobutton.Add((5,5)) 3600 3585 sizer_radiobutton.Add(self.model_view, 1, wx.RIGHT, 5) 3601 3586 #sizer_radiobutton.Add(self.plugin_rbutton) … … 3609 3594 sizer_selection = wx.BoxSizer(wx.HORIZONTAL) 3610 3595 mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) 3611 3612 self.text1 = wx.StaticText(self, wx.ID_ANY, "")3613 self.text2 = wx.StaticText(self, wx.ID_ANY, "P(Q)*S(Q)")3614 self.mutifactor_text = wx.StaticText(self, wx.ID_ANY, "No. of Shells: ")3615 self.mutifactor_text1 = wx.StaticText(self, wx.ID_ANY, "")3616 self.show_sld_button = wx.Button(self, wx.ID_ANY, "Show SLD Profile")3596 3597 self.text1 = wx.StaticText(self, -1, "") 3598 self.text2 = wx.StaticText(self, -1, "P(Q)*S(Q)") 3599 self.mutifactor_text = wx.StaticText(self, -1, "No. of Shells: ") 3600 self.mutifactor_text1 = wx.StaticText(self, -1, "") 3601 self.show_sld_button = wx.Button(self, -1, "Show SLD Profile") 3617 3602 self.show_sld_button.Bind(wx.EVT_BUTTON, self._on_show_sld) 3618 3603 3619 self.formfactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY)3620 self.formfactorbox.SetToolTip( wx.ToolTip("Select a Model"))3604 self.formfactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 3605 self.formfactorbox.SetToolTip( wx.ToolTip("Select a Model") ) 3621 3606 if self.model != None: 3622 3607 self.formfactorbox.SetValue(self.model.name) 3623 self.structurebox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY)3624 self.multifactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY)3608 self.structurebox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 3609 self.multifactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 3625 3610 self.initialize_combox() 3626 wx.EVT_COMBOBOX(self.formfactorbox, wx.ID_ANY, self._on_select_model)3627 3628 wx.EVT_COMBOBOX(self.structurebox, wx.ID_ANY, self._on_select_model)3629 wx.EVT_COMBOBOX(self.multifactorbox, wx.ID_ANY, self._on_select_model)3611 wx.EVT_COMBOBOX(self.formfactorbox, -1, self._on_select_model) 3612 3613 wx.EVT_COMBOBOX(self.structurebox, -1, self._on_select_model) 3614 wx.EVT_COMBOBOX(self.multifactorbox, -1, self._on_select_model) 3630 3615 ## check model type to show sizer 3631 3616 if self.model != None: 3632 3617 print "_set_model_sizer_selection: disabled." 3633 3618 #self._set_model_sizer_selection(self.model) 3634 3619 3635 3620 sizer_selection.Add(self.text1) 3636 3621 sizer_selection.Add((10, 5)) … … 3640 3625 sizer_selection.Add((5, 5)) 3641 3626 sizer_selection.Add(self.structurebox) 3642 3627 3643 3628 mutifactor_selection.Add((13, 5)) 3644 3629 mutifactor_selection.Add(self.mutifactor_text) … … 3654 3639 boxsizer1.Add((10, 10)) 3655 3640 boxsizer1.Add(mutifactor_selection) 3656 3641 3657 3642 self._set_multfactor_combobox() 3658 3643 self.multifactorbox.SetSelection(1) … … 3660 3645 sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 3661 3646 sizer.Layout() 3662 3647 3663 3648 def on_smear_helper(self, update=False): 3664 3649 """ 3665 3650 Help for onSmear if implemented 3666 3651 3667 3652 :param update: force or not to update 3668 3653 """ … … 3673 3658 def onSmear(self, event): 3674 3659 """ 3675 Create a smear object if implemented 3660 Create a smear object if implemented 3676 3661 """ 3677 3662 def onPinholeSmear(self, event):
Note: See TracChangeset
for help on using the changeset viewer.