Changeset 7cd87c2 in sasview for src/sas/perspectives
- Timestamp:
- Mar 4, 2015 11:18:11 AM (10 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, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- af6b53c
- Parents:
- b6627d9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/fitting/basepage.py
rc1694f8 r7cd87c2 11 11 import string 12 12 import json 13 import logging 13 14 from collections import defaultdict 14 15 from wx.lib.scrolledpanel import ScrolledPanel … … 56 57 ## Title to appear on top of the window 57 58 window_caption = "Fit Page " 58 59 59 60 def __init__(self, parent, color='blue', **kwargs): 60 61 """ … … 65 66 #Set window's font size 66 67 self.SetWindowVariant(variant=FONT_VARIANT) 67 68 68 69 self.SetBackgroundColour(color) 69 70 ## parent of the page … … 127 128 self.Npts_fit = None 128 129 self.Npts_total = None 129 self.theory_qmin = None 130 self.theory_qmin = None 130 131 self.theory_qmax = None 131 132 self.theory_qmin_x = None … … 136 137 self.sld_axes = None 137 138 self.multi_factor = None 138 139 139 140 self.disp_cb_dict = {} 140 141 141 142 #self.state = PageState(parent=parent) 142 143 ## dictionary containing list of models 143 144 self.model_list_box = {} 144 145 145 146 ## Data member to store the dispersion object created 146 147 self._disp_obj_dict = {} … … 170 171 self.disp_list = [] 171 172 self.disp_name = "" 172 173 173 174 ## list of orientation parameters 174 175 self.orientation_params = [] … … 199 200 ## Create context menu for page 200 201 self.popUpMenu = wx.Menu() 201 202 202 203 id = wx.NewId() 203 204 self._keep = wx.MenuItem(self.popUpMenu, id, "Add bookmark", … … 209 210 wx.EVT_MENU(self, id, self.on_bookmark) 210 211 self.popUpMenu.AppendSeparator() 211 212 212 213 ## Default locations 213 214 self._default_save_location = os.getcwd() … … 215 216 #self.onSave(event=None) 216 217 self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 217 218 218 219 # bind key event 219 220 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) 220 221 221 222 ## create the basic structure of the panel with empty sizer 222 223 self.define_page_structure() 223 224 ## drawing Initial dispersion parameters sizer 224 225 self.set_dispers_sizer() 225 226 226 227 ## layout 227 228 self.set_layout() 228 229 229 230 def set_index_model(self, index): 230 231 """ … … 232 233 """ 233 234 self.index_model = index 234 235 235 236 def create_default_data(self): 236 237 """ … … 249 250 else: 250 251 self._create_default_1d_data() 251 252 252 253 if self.model != None: 253 254 if not self.data.is_data: … … 259 260 self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 260 261 self.state.slit_smearer = self.slit_smearer.GetValue() 261 262 262 263 def _create_default_1d_data(self): 263 264 """ … … 265 266 Only when the page is on theory mode. 266 267 :warning: This data is never plotted. 267 268 268 269 """ 269 270 x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, … … 275 276 self.data.id = str(self.uid) + " data" 276 277 self.data.group_id = str(self.uid) + " Model1D" 277 278 278 279 def _create_log_1d_data(self): 279 280 """ … … 281 282 Only when the page is on theory mode. 282 283 :warning: This data is never plotted. 283 284 284 285 """ 285 286 if self.qmin_x >= 1.e-10: 286 287 qmin = numpy.log10(self.qmin_x) 287 288 else: 288 qmin = -10. 289 289 qmin = -10. 290 290 291 if self.qmax_x <= 1.e10: 291 292 qmax = numpy.log10(self.qmax_x) 292 293 else: 293 qmax = 10. 294 294 qmax = 10. 295 295 296 x = numpy.logspace(start=qmin, stop=qmax, 296 297 num=self.npts_x, endpoint=True, base=10.0) … … 301 302 self.data.id = str(self.uid) + " data" 302 303 self.data.group_id = str(self.uid) + " Model1D" 303 304 304 305 def _create_default_2d_data(self): 305 306 """ … … 359 360 #xstep = x_size / len(x_bins - 1) 360 361 #ystep = y_size / len(y_bins - 1) 361 362 362 363 self.data.source = Source() 363 364 self.data.data = numpy.ones(len(mask)) … … 382 383 wx.PostEvent(self._manager.parent, PanelOnFocusEvent(panel=self)) 383 384 self.on_tap_focus() 384 385 385 386 def on_tap_focus(self): 386 387 """ … … 398 399 self._manager.menu1.FindItemById(self._manager.id_batchfit) 399 400 batch_menu.Enable(self.batch_on and flag) 400 401 401 402 class ModelTextCtrl(wx.TextCtrl): 402 403 """ … … 404 405 Binds the appropriate events for user interactions. 405 406 Default callback methods can be overwritten on initialization 406 407 407 408 :param kill_focus_callback: callback method for EVT_KILL_FOCUS event 408 409 :param set_focus_callback: callback method for EVT_SET_FOCUS event 409 410 :param mouse_up_callback: callback method for EVT_LEFT_UP event 410 411 :param text_enter_callback: callback method for EVT_TEXT_ENTER event 411 412 412 413 """ 413 414 ## Set to True when the mouse is clicked while whole string is selected … … 415 416 ## Call back for EVT_SET_FOCUS events 416 417 _on_set_focus_callback = None 417 418 def __init__(self, parent, id= -1,418 419 def __init__(self, parent, id= -1, 419 420 value=wx.EmptyString, 420 421 pos=wx.DefaultPosition, … … 427 428 mouse_up_callback=None, 428 429 text_enter_callback=None): 429 430 430 431 wx.TextCtrl.__init__(self, parent, id, value, pos, 431 432 size, style, validator, name) 432 433 433 434 # Bind appropriate events 434 435 self._on_set_focus_callback = parent.onSetFocus \ … … 442 443 self.Bind(wx.EVT_LEFT_UP, self._highlight_text \ 443 444 if mouse_up_callback is None else mouse_up_callback) 444 445 445 446 def _on_set_focus(self, event): 446 447 """ 447 448 Catch when the text control is set in focus to highlight the whole 448 449 text if necessary 449 450 450 451 :param event: mouse event 451 452 452 453 """ 453 454 event.Skip() 454 455 self.full_selection = True 455 456 return self._on_set_focus_callback(event) 456 457 457 458 def _highlight_text(self, event): 458 459 """ 459 460 Highlight text of a TextCtrl only of no text has be selected 460 461 461 462 :param event: mouse event 462 463 463 464 """ 464 465 # Make sure the mouse event is available to other listeners … … 474 475 if start == end: 475 476 control.SetSelection(-1, -1) 476 477 477 478 def _silent_kill_focus(self, event): 478 479 """ 479 480 Save the state of the page 480 481 """ 481 482 482 483 event.Skip() 483 484 #pass 484 485 485 486 def set_page_info(self, page_info): 486 487 """ … … 511 512 ## Data member to store the dispersion object created 512 513 self.populate_box(model_dict=self.model_list_box) 513 514 514 515 def onContextMenu(self, event): 515 516 """ … … 518 519 # Skipping the save state functionality for release 0.9.0 519 520 #return 520 521 521 522 pos = event.GetPosition() 522 523 pos = self.ScreenToClient(pos) 523 524 524 525 self.PopupMenu(self.popUpMenu, pos) 525 526 526 527 def onUndo(self, event): 527 528 """ … … 530 531 event = PreviousStateEvent(page=self) 531 532 wx.PostEvent(self.parent, event) 532 533 533 534 def onRedo(self, event): 534 535 """ … … 537 538 event = NextStateEvent(page=self) 538 539 wx.PostEvent(self.parent, event) 539 540 540 541 def define_page_structure(self): 541 542 """ … … 550 551 self.sizer5 = wx.BoxSizer(wx.VERTICAL) 551 552 self.sizer6 = wx.BoxSizer(wx.VERTICAL) 552 553 553 554 self.sizer0.SetMinSize((PANEL_WIDTH, -1)) 554 555 self.sizer1.SetMinSize((PANEL_WIDTH, -1)) … … 558 559 self.sizer5.SetMinSize((PANEL_WIDTH, -1)) 559 560 self.sizer6.SetMinSize((PANEL_WIDTH, -1)) 560 561 561 562 self.vbox.Add(self.sizer0) 562 563 self.vbox.Add(self.sizer1) … … 566 567 self.vbox.Add(self.sizer5) 567 568 self.vbox.Add(self.sizer6) 568 569 569 570 def set_layout(self): 570 571 """ … … 575 576 self.SetSizer(self.vbox) 576 577 self.Centre() 577 578 578 579 def set_owner(self, owner): 579 580 """ 580 581 set owner of fitpage 581 582 582 583 :param owner: the class responsible of plotting 583 584 584 585 """ 585 586 self.event_owner = owner 586 587 self.state.event_owner = owner 587 588 588 589 def get_state(self): 589 590 """ 590 591 """ 591 592 return self.state 592 593 593 594 def get_data(self): 594 595 """ … … 596 597 """ 597 598 return self.data 598 599 599 600 def get_data_list(self): 600 601 """ … … 602 603 """ 603 604 return self.data_list 604 605 605 606 def set_manager(self, manager): 606 607 """ 607 608 set panel manager 608 609 609 610 :param manager: instance of plugin fitting 610 611 611 612 """ 612 613 self._manager = manager 613 614 self.state.manager = manager 614 615 615 616 def populate_box(self, model_dict): 616 617 """ 617 618 Store list of model 618 619 619 620 :param model_dict: dictionary containing list of models 620 621 621 622 """ 622 623 self.model_list_box = model_dict 623 624 self.state.model_list_box = self.model_list_box 624 625 self.initialize_combox() 625 626 626 627 def set_model_dictionary(self, model_dict): 627 628 """ … … 635 636 """ 636 637 put default value in the combobox 637 """ 638 """ 638 639 ## fill combox box 639 640 if self.model_list_box is None: … … 666 667 self.structurebox.Disable() 667 668 self.text2.Disable() 668 669 669 670 if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: 670 671 self.structurebox.Show() … … 673 674 self.text2.Enable() 674 675 675 676 676 677 def set_dispers_sizer(self): 677 678 """ … … 698 699 self.on_pd_help_clicked, id=self.disp_help_bt.GetId()) 699 700 self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") 700 701 701 702 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 702 703 id=self.disable_disp.GetId()) … … 714 715 sizer_dispersion.Add((25, 20)) 715 716 sizer_dispersion.Add(self.disp_help_bt) 716 717 717 718 ## fill a sizer for dispersion 718 719 boxsizer1.Add(sizer_dispersion, 0, … … 727 728 self.sizer4.Layout() 728 729 self.Layout() 729 730 730 731 self.Refresh() 731 732 ## saving the state of enable dispersity button … … 733 734 self.state.disable_disp = self.disable_disp.GetValue() 734 735 self.SetupScrolling() 735 736 736 737 def onResetModel(self, event): 737 738 """ … … 751 752 previous_state = self.saved_states[name] 752 753 ## reset state of checkbox,textcrtl and regular parameters value 753 754 754 755 self.reset_page(previous_state) 755 756 self.state.m_name = self.m_name 756 757 self.Show(True) 757 758 758 759 def on_preview(self, event): 759 760 """ … … 764 765 # get the report dialog 765 766 self.state.report(images, canvases) 766 767 767 768 def on_save(self, event): 768 769 """ … … 782 783 path = dlg.GetPath() 783 784 self._default_save_location = os.path.dirname(path) 784 self._manager.parent._default_save_location = \785 self._manager.parent._default_save_location = \ 785 786 self._default_save_location 786 787 else: … … 793 794 self._manager.save_fit_state(filepath=fName, fitstate=new_state) 794 795 return new_state 795 796 796 797 def on_copy(self, event): 797 798 """ … … 810 811 wx.CallAfter(self.get_copy) 811 812 812 813 813 814 def on_paste(self, event): 814 815 """ … … 822 823 # messages depending on the flag 823 824 #self._copy_info(True) 824 825 825 826 def _copy_info(self, flag): 826 827 """ 827 828 Send event dpemding on flag 828 829 829 830 : Param flag: flag that distinguish event 830 831 """ … … 843 844 wx.PostEvent(self._manager.parent, 844 845 StatusEvent(status=msg, info=infor)) 845 846 846 847 def _get_time_stamp(self): 847 848 """ … … 853 854 current_date = str(month) + "/" + str(day) + "/" + str(year) 854 855 return current_time, current_date 855 856 856 857 def on_bookmark(self, event): 857 858 """ … … 872 873 name += "bookmarked at %s on %s" % (current_time, current_date) 873 874 self.saved_states[name] = new_state 874 875 875 876 ## Add item in the context menu 876 877 msg = "Model saved at %s on %s" % (current_time, current_date) … … 878 879 msg += " Saved! right click on this page to retrieve this model" 879 880 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 880 881 881 882 id = wx.NewId() 882 883 self.popUpMenu.Append(id, name, str(msg)) … … 886 887 hint=str(msg), 887 888 handler=self._back_to_bookmark)) 888 889 889 890 def _back_to_bookmark(self, event): 890 891 """ … … 894 895 self.onResetModel(event) 895 896 self._draw_model() 896 897 897 898 def onSetFocus(self, evt): 898 899 """ … … 901 902 """ 902 903 return 903 904 904 905 def read_file(self, path): 905 906 """ 906 907 Read two columns file 907 908 908 909 :param path: the path to the file to read 909 910 910 911 """ 911 912 try: 912 913 if path == None: 913 914 wx.PostEvent(self._manager.parent, 914 StatusEvent(status= 915 StatusEvent(status=\ 915 916 " Selected Distribution was not loaded: %s" % path)) 916 917 return None, None … … 930 931 except: 931 932 # Skip non-data lines 932 pass933 logging.error(sys.exc_value) 933 934 return numpy.array(angles), numpy.array(weights) 934 935 except: … … 940 941 """ 941 942 return self.state.clone() 942 943 943 944 def save_current_state(self): 944 945 """ … … 951 952 self.state.disp_list = copy.deepcopy(self.disp_list) 952 953 self.state.model = self.model.clone() 953 954 954 955 #model combobox: complex code because of mac's silent error 955 956 if self.structurebox != None: … … 970 971 self.state.categorycombobox = self.categorybox.\ 971 972 GetString(cb_select) 972 973 973 974 self.state.enable2D = copy.deepcopy(self.enable2D) 974 975 self.state.values = copy.deepcopy(self.values) … … 987 988 self.state.enable_disp = self.enable_disp.GetValue() 988 989 self.state.disable_disp = self.disable_disp.GetValue() 989 990 990 991 self.state.smearer = copy.deepcopy(self.current_smearer) 991 992 if hasattr(self, "enable_smearer"): … … 1002 1003 self.state.dxw = copy.deepcopy(self.dxw) 1003 1004 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 1004 1005 1005 1006 if len(self._disp_obj_dict) > 0: 1006 1007 for k, v in self._disp_obj_dict.iteritems(): … … 1011 1012 ## save plotting range 1012 1013 self._save_plotting_range() 1013 1014 1014 1015 self.state.orientation_params = [] 1015 1016 self.state.orientation_params_disp = [] … … 1026 1027 self._copy_parameters_state(self.orientation_params_disp, 1027 1028 self.state.orientation_params_disp) 1028 1029 1029 1030 self._copy_parameters_state(self.parameters, self.state.parameters) 1030 1031 self._copy_parameters_state(self.fittable_param, … … 1033 1034 #save chisqr 1034 1035 self.state.tcChi = self.tcChi.GetValue() 1035 1036 1036 1037 def save_current_state_fit(self): 1037 1038 """ … … 1045 1046 if hasattr(self, "engine_type"): 1046 1047 self.state.engine_type = copy.deepcopy(self.engine_type) 1047 1048 1048 1049 self.state.enable2D = copy.deepcopy(self.enable2D) 1049 1050 self.state.values = copy.deepcopy(self.values) … … 1051 1052 ## save data 1052 1053 self.state.data = copy.deepcopy(self.data) 1053 1054 1054 1055 if hasattr(self, "enable_disp"): 1055 1056 self.state.enable_disp = self.enable_disp.GetValue() 1056 1057 self.state.disable_disp = self.disable_disp.GetValue() 1057 1058 1058 1059 self.state.smearer = copy.deepcopy(self.current_smearer) 1059 1060 if hasattr(self, "enable_smearer"): … … 1062 1063 self.state.disable_smearer = \ 1063 1064 copy.deepcopy(self.disable_smearer.GetValue()) 1064 1065 1065 1066 self.state.pinhole_smearer = \ 1066 1067 copy.deepcopy(self.pinhole_smearer.GetValue()) … … 1085 1086 for k, v in self._disp_obj_dict.iteritems(): 1086 1087 self.state._disp_obj_dict[k] = v 1087 1088 1088 1089 self.state.values = copy.deepcopy(self.values) 1089 1090 self.state.weights = copy.deepcopy(self.weights) 1090 1091 1091 1092 ## save plotting range 1092 1093 self._save_plotting_range() 1093 1094 1094 1095 ## save checkbutton state and txtcrtl values 1095 1096 self._copy_parameters_state(self.orientation_params, … … 1101 1102 self.state.fittable_param) 1102 1103 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 1103 1104 1104 1105 def check_invalid_panel(self): 1105 1106 """ … … 1112 1113 wx.MessageBox(msg, 'Info') 1113 1114 return True 1114 1115 1115 1116 def set_model_state(self, state): 1116 1117 """ … … 1119 1120 self.disp_cb_dict = state.disp_cb_dict 1120 1121 self.disp_list = state.disp_list 1121 1122 1122 1123 ## set the state of the radio box 1123 1124 #self.shape_rbutton.SetValue(state.shape_rbutton) … … 1125 1126 #self.struct_rbutton.SetValue(state.struct_rbutton) 1126 1127 #self.plugin_rbutton.SetValue(state.plugin_rbutton) 1127 1128 1128 1129 ## fill model combobox 1129 1130 self._show_combox_helper() … … 1139 1140 category_pos = int(ind_cat) 1140 1141 break 1141 1142 1142 1143 self.categorybox.Select(category_pos) 1143 1144 try: … … 1151 1152 formfactor_pos = int(ind_form) 1152 1153 break 1153 1154 1154 1155 self.formfactorbox.Select(formfactor_pos) 1155 1156 1156 1157 try: 1157 1158 # to support older version … … 1164 1165 structfactor_pos = int(ind_struct) 1165 1166 break 1166 1167 1167 1168 self.structurebox.SetSelection(structfactor_pos) 1168 1169 1169 1170 if state.multi_factor != None: 1170 1171 self.multifactorbox.SetSelection(state.multi_factor) 1171 1172 1172 1173 ## reset state of checkbox,textcrtl and regular parameters value 1173 1174 self._reset_parameters_state(self.orientation_params_disp, … … 1181 1182 self.enable_disp.SetValue(state.enable_disp) 1182 1183 self.disable_disp.SetValue(state.disable_disp) 1183 1184 1184 1185 if hasattr(self, "disp_box") and self.disp_box != None: 1185 1186 self.disp_box.SetSelection(state.disp_box) … … 1189 1190 1190 1191 self._set_dipers_Param(event=None) 1191 1192 1192 1193 if name == "ArrayDispersion": 1193 1194 1194 1195 for item in self.disp_cb_dict.keys(): 1195 1196 1196 1197 if hasattr(self.disp_cb_dict[item], "SetValue"): 1197 1198 self.disp_cb_dict[item].SetValue(\ … … 1209 1210 else: 1210 1211 self._reset_dispersity() 1211 1212 1212 1213 self._disp_obj_dict[item] = disp_model 1213 1214 # Set the new model as the dispersion object 1214 1215 #for the selected parameter 1215 1216 self.model.set_dispersion(item, disp_model) 1216 1217 1217 1218 self.model._persistency_dict[item] = \ 1218 1219 [state.values, state.weights] 1219 1220 1220 1221 else: 1221 1222 keys = self.model.getParamList() … … 1235 1236 self.pinhole_smearer.SetValue(state.pinhole_smearer) 1236 1237 self.slit_smearer.SetValue(state.slit_smearer) 1237 1238 1238 1239 self.dI_noweight.SetValue(state.dI_noweight) 1239 1240 self.dI_didata.SetValue(state.dI_didata) 1240 1241 self.dI_sqrdata.SetValue(state.dI_sqrdata) 1241 1242 self.dI_idata.SetValue(state.dI_idata) 1242 1243 1243 1244 ## we have two more options for smearing 1244 1245 if self.pinhole_smearer.GetValue(): … … 1246 1247 elif self.slit_smearer.GetValue(): 1247 1248 self.onSlitSmear(event=None) 1248 1249 1249 1250 ## reset state of checkbox,textcrtl and dispersity parameters value 1250 1251 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1251 1252 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1252 1253 1253 1254 ## draw the model with previous parameters value 1254 1255 self._onparamEnter_helper() … … 1258 1259 self._lay_out() 1259 1260 self.Refresh() 1260 1261 1261 1262 def reset_page_helper(self, state): 1262 1263 """ 1263 1264 Use page_state and change the state of existing page 1264 1265 1265 1266 :precondition: the page is already drawn or created 1266 1267 1267 1268 :postcondition: the state of the underlying data change as well as the 1268 1269 state of the graphic interface … … 1290 1291 else: 1291 1292 self.set_data(data) 1292 1293 1293 1294 self.enable2D = state.enable2D 1294 1295 try: … … 1301 1302 self.disp_cb_dict = state.disp_cb_dict 1302 1303 self.disp_list = state.disp_list 1303 1304 1304 1305 ## set the state of the radio box 1305 1306 #self.shape_rbutton.SetValue(state.shape_rbutton) … … 1307 1308 #self.struct_rbutton.SetValue(state.struct_rbutton) 1308 1309 #self.plugin_rbutton.SetValue(state.plugin_rbutton) 1309 1310 1310 1311 ## fill model combobox 1311 1312 self._show_combox_helper() … … 1321 1322 category_pos = int(ind_cat) 1322 1323 break 1323 1324 1324 1325 self.categorybox.Select(category_pos) 1325 1326 self._show_combox(None) … … 1334 1335 formfactor_pos = int(ind_form) 1335 1336 break 1336 1337 1337 1338 self.formfactorbox.Select(formfactor_pos) 1338 1339 1339 1340 try: 1340 1341 # to support older version … … 1347 1348 structfactor_pos = int(ind_struct) 1348 1349 break 1349 1350 1350 1351 self.structurebox.SetSelection(structfactor_pos) 1351 1352 … … 1357 1358 #draw the pnael according to the new model parameter 1358 1359 self._on_select_model(event=None) 1359 1360 1360 1361 # take care of 2D button 1361 1362 if data == None and self.model_view.IsEnabled(): … … 1365 1366 self.model_view.SetLabel("1D Mode") 1366 1367 # else: 1367 1368 1368 1369 if self._manager != None and self.engine_type != None: 1369 1370 self._manager._on_change_engine(engine=self.engine_type) 1370 1371 ## set the select all check box to the a given state 1371 1372 self.cb1.SetValue(state.cb1) 1372 1373 1373 1374 ## reset state of checkbox,textcrtl and regular parameters value 1374 1375 self._reset_parameters_state(self.orientation_params_disp, … … 1409 1410 self.dI_sqrdata.SetValue(False) 1410 1411 self.dI_idata.SetValue(False) 1411 1412 1412 1413 ## we have two more options for smearing 1413 1414 if self.pinhole_smearer.GetValue(): … … 1425 1426 self.smear_slit_height.SetValue(str(self.dxl)) 1426 1427 if self.dxw != None: 1427 self.smear_slit_width.SetValue(str(self.dxw)) 1428 self.smear_slit_width.SetValue(str(self.dxw)) 1428 1429 else: 1429 self.smear_slit_width.SetValue('') 1430 self.smear_slit_width.SetValue('') 1430 1431 self.onSlitSmear(event=None) 1431 1432 1432 1433 ## reset state of checkbox,textcrtl and dispersity parameters value 1433 1434 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1434 1435 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1435 1436 1436 1437 ## draw the model with previous parameters value 1437 1438 self._onparamEnter_helper() … … 1440 1441 ## reset context menu items 1441 1442 self._reset_context_menu() 1442 1443 1443 1444 ## set the value of the current state to the state given as parameter 1444 1445 self.state = state.clone() 1445 1446 self.state.m_name = self.m_name 1446 1447 1447 1448 def _reset_page_disp_helper(self, state): 1448 1449 """ … … 1459 1460 self.values = copy.deepcopy(state.values) 1460 1461 self.weights = copy.deepcopy(state.weights) 1461 1462 1462 1463 for key, disp in state._disp_obj_dict.iteritems(): 1463 1464 # From saved file, disp_model can not be sent in model obj. … … 1479 1480 [state.values, state.weights] 1480 1481 except: 1481 pass1482 logging.error(sys.exc_value) 1482 1483 selection = self._find_polyfunc_selection(disp_model) 1483 1484 for list in self.fittable_param: … … 1496 1497 list[6].Disable() 1497 1498 except: 1498 pass1499 logging.error(sys.exc_value) 1499 1500 # For array, disable all fixed params 1500 1501 if selection == 1: … … 1505 1506 item[2].Disable() 1506 1507 except: 1507 pass1508 1508 logging.error(sys.exc_value) 1509 1509 1510 # Make sure the check box updated when all checked 1510 1511 if self.cb1.GetValue(): 1511 1512 self.select_all_param(None) 1512 1513 1513 1514 def _selectDlg(self): 1514 1515 """ 1515 open a dialog file to selected the customized dispersity 1516 open a dialog file to selected the customized dispersity 1516 1517 """ 1517 1518 if self.parent != None: … … 1538 1539 self.popUpMenu.Append(id, name, msg) 1539 1540 wx.EVT_MENU(self, id, self.onResetModel) 1540 1541 1541 1542 def _reset_plotting_range(self, state): 1542 1543 """ … … 1557 1558 self.state.formfactorcombobox = self.formfactorbox.GetLabel() 1558 1559 self.state.categorycombobox = self.categorybox.GetLabel() 1559 1560 1560 1561 ## post state to fit panel 1561 1562 event = PageInfoEvent(page=self) 1562 1563 wx.PostEvent(self.parent, event) 1563 1564 1564 1565 def _save_plotting_range(self): 1565 1566 """ … … 1569 1570 self.state.qmax = self.qmax_x 1570 1571 self.state.npts = self.npts_x 1571 1572 1572 1573 def _onparamEnter_helper(self): 1573 1574 """ … … 1592 1593 is_modified) 1593 1594 except: 1594 pass1595 logging.error(sys.exc_value) 1595 1596 1596 1597 # Here we should check whether the boundaries have been modified. … … 1606 1607 self.qmax_x = tempmax 1607 1608 is_modified = True 1608 1609 1609 1610 if is_2Ddata: 1610 1611 # set mask 1611 1612 is_modified = self._validate_Npts() 1612 1613 1613 1614 else: 1614 1615 self.fitrange = False 1615 1616 1616 1617 if not self.data.is_data: 1617 1618 is_modified = True … … 1633 1634 self.Refresh() 1634 1635 return is_modified 1635 1636 1636 1637 def _update_paramv_on_fit(self): 1637 1638 """ … … 1730 1731 msg += " model or Fitting range is not valid!!! " 1731 1732 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1732 1733 1733 1734 try: 1734 1735 self.save_current_state() 1735 1736 except: 1736 pass1737 1737 logging.error(sys.exc_value) 1738 1738 1739 return flag 1739 1740 1740 1741 def _is_modified(self, is_modified): 1741 1742 """ … … 1743 1744 """ 1744 1745 return is_modified 1745 1746 1746 1747 def _reset_parameters_state(self, listtorestore, statelist): 1747 1748 """ … … 1782 1783 item_page[5].Show(item_page_info[5][0]) 1783 1784 item_page[5].SetValue(item_page_info[5][1]) 1784 1785 1785 1786 if item_page[6] != None: 1786 1787 ## show of hide the text crtl for fitting error 1787 1788 item_page[6].Show(item_page_info[6][0]) 1788 1789 item_page[6].SetValue(item_page_info[6][1]) 1789 1790 1790 1791 def _reset_strparam_state(self, listtorestore, statelist): 1791 1792 """ … … 1796 1797 1797 1798 listtorestore = copy.deepcopy(statelist) 1798 1799 1799 1800 for j in range(len(listtorestore)): 1800 1801 item_page = listtorestore[j] 1801 1802 item_page_info = statelist[j] 1802 1803 ##change the state of the check box for simple parameters 1803 1804 1804 1805 if item_page[0] != None: 1805 1806 item_page[0].SetValue(format_number(item_page_info[0], True)) … … 1813 1814 item_page[2].SetValue(selection) 1814 1815 self.model.setParam(param_name, selection) 1815 1816 1816 1817 def _copy_parameters_state(self, listtocopy, statelist): 1817 1818 """ 1818 1819 copy the state of button 1819 1820 1820 1821 :param listtocopy: the list of check button to copy 1821 1822 :param statelist: list of state object to store the current state 1822 1823 1823 1824 """ 1824 1825 if len(listtocopy) == 0: 1825 1826 return 1826 1827 1827 1828 for item in listtocopy: 1828 1829 1829 1830 checkbox_state = None 1830 1831 if item[0] != None: … … 1842 1843 error_value = item[4].GetValue() 1843 1844 error_state = item[4].IsShown() 1844 1845 1845 1846 min_value = None 1846 1847 min_state = None … … 1848 1849 min_value = item[5].GetValue() 1849 1850 min_state = item[5].IsShown() 1850 1851 1851 1852 max_value = None 1852 1853 max_state = None … … 1857 1858 if item[7] != None: 1858 1859 unit = item[7].GetLabel() 1859 1860 1860 1861 statelist.append([checkbox_state, parameter_name, parameter_value, 1861 1862 static_text, [error_state, error_value], 1862 1863 [min_state, min_value], 1863 1864 [max_state, max_value], unit]) 1864 1865 1865 1866 1866 1867 def _draw_model(self, update_chisqr=True, source='model'): 1867 1868 """ … … 1869 1870 The method will use the data member from the model page 1870 1871 to build a call to the fitting perspective manager. 1871 1872 1872 1873 :param chisqr: update chisqr value [bool] 1873 1874 """ 1874 1875 wx.CallAfter(self._draw_model_after, update_chisqr, source) 1875 1876 1876 1877 def _draw_model_after(self, update_chisqr=True, source='model'): 1877 1878 """ … … 1879 1880 The method will use the data member from the model page 1880 1881 to build a call to the fitting perspective manager. 1881 1882 1882 1883 :param chisqr: update chisqr value [bool] 1883 1884 """ … … 1907 1908 source='model', 1908 1909 weight=weight) 1909 1910 1910 1911 def _on_show_sld(self, event=None): 1911 1912 """ … … 1922 1923 sld_data.name = 'SLD' 1923 1924 sld_data.axes = self.sld_axes 1924 self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id= -1)1925 self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id= -1) 1925 1926 self.panel.ShowModal() 1926 1927 1927 1928 def _set_multfactor_combobox(self, multiplicity=10): 1928 1929 """ … … 1934 1935 self.multifactorbox.Append(str(idx), int(idx)) 1935 1936 self._hide_multfactor_combobox() 1936 1937 1937 1938 def _show_multfactor_combobox(self): 1938 1939 """ … … 1944 1945 if not self.multifactorbox.IsShown(): 1945 1946 self.multifactorbox.Show(True) 1946 1947 1947 1948 def _hide_multfactor_combobox(self): 1948 1949 """ … … 1954 1955 if self.multifactorbox.IsShown(): 1955 1956 self.multifactorbox.Hide() 1956 1957 1957 1958 def formfactor_combo_init(self): 1958 1959 """ … … 1960 1961 """ 1961 1962 self._show_combox(None) 1962 1963 1963 1964 def _show_combox_helper(self): 1964 1965 """ … … 1993 1994 StatusEvent(status=msg, info="error")) 1994 1995 self._populate_box(self.formfactorbox, m_list) 1995 1996 def _on_modify_cat(self, event=None): 1997 self._manager.parent.on_category_panel(event) 1998 1996 1997 def _on_modify_cat(self, event=None): 1998 self._manager.parent.on_category_panel(event) 1999 1999 2000 def _show_combox(self, event=None): 2000 2001 """ … … 2010 2011 self.Layout() 2011 2012 self.Refresh() 2012 2013 2013 2014 def _populate_box(self, combobox, list): 2014 2015 """ 2015 2016 fill combox box with dict item 2016 2017 2017 2018 :param list: contains item to fill the combox 2018 2019 item must model class … … 2026 2027 name = model.name 2027 2028 mlist.append((name, models)) 2028 2029 2029 2030 # Sort the models 2030 2031 mlist_sorted = sorted(mlist) … … 2032 2033 combobox.Append(item[0], item[1]) 2033 2034 return 0 2034 2035 2035 2036 def _onQrangeEnter(self, event): 2036 2037 """ 2037 2038 Check validity of value enter in the Q range field 2038 2039 2039 2040 """ 2040 2041 tcrtl = event.GetEventObject() … … 2088 2089 self.create_default_data() 2089 2090 self._draw_model() 2090 2091 2091 2092 def _theory_qrange_enter(self, event): 2092 2093 """ 2093 2094 Check validity of value enter in the Q range field 2094 2095 """ 2095 2096 2096 2097 tcrtl = event.GetEventObject() 2097 2098 #Clear msg if previously shown. … … 2144 2145 self.create_default_data() 2145 2146 self._draw_model() 2146 2147 2147 2148 def _on_select_model_helper(self): 2148 2149 """ … … 2170 2171 self.structurebox.Enable() 2171 2172 self.text2.Enable() 2172 2173 2173 2174 if form_factor != None: 2174 2175 # set multifactor for Mutifunctional models … … 2187 2188 # default value 2188 2189 m_id = 1 2189 2190 2190 2191 self.multi_factor = self.multifactorbox.GetClientData(m_id) 2191 2192 if self.multi_factor == None: … … 2215 2216 self.show_sld_button.Hide() 2216 2217 self.multi_factor = None 2217 2218 2218 2219 s_id = self.structurebox.GetCurrentSelection() 2219 2220 struct_factor = self.structurebox.GetClientData(s_id) 2220 2221 2221 2222 if struct_factor != None: 2222 2223 from sas.models.MultiplicationModel import MultiplicationModel … … 2233 2234 # check if model has magnetic parameters 2234 2235 if len(self.model.magnetic_params) > 0: 2235 self._has_magnetic = True 2236 self._has_magnetic = True 2236 2237 else: 2237 self._has_magnetic = False 2238 self._has_magnetic = False 2238 2239 ## post state to fit panel 2239 2240 self.state.parameters = [] … … 2245 2246 self.on_set_focus(None) 2246 2247 self.Layout() 2247 2248 2248 2249 def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 2249 2250 """ 2250 2251 Verify that the Q range controls have valid values 2251 2252 and that Qmin < Qmax. 2252 2253 2253 2254 :param qmin_ctrl: text control for Qmin 2254 2255 :param qmax_ctrl: text control for Qmax 2255 2256 2256 2257 :return: True is the Q range is value, False otherwise 2257 2258 2258 2259 """ 2259 2260 qmin_validity = check_float(qmin_ctrl) … … 2279 2280 return False 2280 2281 return True 2281 2282 2282 2283 def _validate_Npts(self): 2283 2284 """ … … 2314 2315 self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 2315 2316 self.fitrange = True 2316 2317 2317 2318 return flag 2318 2319 … … 2349 2350 self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 2350 2351 self.fitrange = True 2351 2352 2352 2353 return flag 2353 2354 2354 2355 def _check_value_enter(self, list, modified): 2355 2356 """ … … 2373 2374 #try: 2374 2375 name = str(item[1]) 2375 2376 2376 2377 if string.find(name, ".npts") == -1 and \ 2377 2378 string.find(name, ".nsigmas") == -1: … … 2379 2380 param_min = None 2380 2381 param_max = None 2381 2382 2382 2383 ## check minimun value 2383 2384 if item[5] != None and item[5] != "": … … 2388 2389 if numpy.isfinite(param_min): 2389 2390 item[2].SetValue(format_number(param_min)) 2390 2391 2391 2392 item[5].SetBackgroundColour(wx.WHITE) 2392 2393 item[2].SetBackgroundColour(wx.WHITE) 2393 2394 2394 2395 except: 2395 2396 msg = "Wrong fit parameter range entered" … … 2406 2407 if numpy.isfinite(param_max): 2407 2408 item[2].SetValue(format_number(param_max)) 2408 2409 2409 2410 item[6].SetBackgroundColour(wx.WHITE) 2410 2411 item[2].SetBackgroundColour(wx.WHITE) … … 2415 2416 raise ValueError, msg 2416 2417 is_modified = True 2417 2418 2418 2419 if param_min != None and param_max != None: 2419 2420 if not self._validate_qrange(item[5], item[6]): … … 2422 2423 wx.PostEvent(self._manager.parent, 2423 2424 StatusEvent(status=msg)) 2424 2425 2425 2426 if name in self.model.details.keys(): 2426 2427 self.model.details[name][1:3] = param_min, param_max … … 2443 2444 msg = "Wrong Fit parameter value entered " 2444 2445 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2445 2446 2446 2447 return is_modified 2447 2448 2448 2449 def _set_dipers_Param(self, event): 2449 2450 """ … … 2464 2465 2465 2466 self._reset_dispersity() 2466 2467 2467 2468 if self.model == None: 2468 2469 self.model_disp.Hide() … … 2472 2473 if self.enable_disp.GetValue(): 2473 2474 ## layout for model containing no dispersity parameters 2474 2475 2475 2476 self.disp_list = self.model.getDispParamList() 2476 2477 2477 2478 if len(self.disp_list) == 0 and len(self.disp_cb_dict) == 0: 2478 2479 self._layout_sizer_noDipers() … … 2482 2483 else: 2483 2484 self.sizer4_4.Clear(True) 2484 2485 2485 2486 ## post state to fit panel 2486 2487 self.save_current_state() … … 2494 2495 self.Layout() 2495 2496 self.Refresh() 2496 2497 2497 2498 def _layout_sizer_noDipers(self): 2498 2499 """ … … 2504 2505 self.fixed_param = [] 2505 2506 self.orientation_params_disp = [] 2506 2507 2507 2508 self.sizer4_4.Clear(True) 2508 2509 text = "No polydispersity available for this model" … … 2512 2513 self.sizer4_4.Layout() 2513 2514 self.sizer4.Layout() 2514 2515 2515 2516 def _reset_dispersity(self): 2516 2517 """ … … 2525 2526 if item in self.param_toFit: 2526 2527 self.param_toFit.remove(item) 2527 2528 2528 2529 self.fittable_param = [] 2529 2530 self.fixed_param = [] … … 2531 2532 self.values = {} 2532 2533 self.weights = {} 2533 2534 2534 2535 from sas.models.dispersion_models import GaussianDispersion 2535 2536 if len(self.disp_cb_dict) == 0: … … 2543 2544 # Go back to Gaussian model (with 0 pts) 2544 2545 disp_model = GaussianDispersion() 2545 2546 2546 2547 self._disp_obj_dict[p] = disp_model 2547 2548 # Set the new model as the dispersion object … … 2550 2551 self.model.set_dispersion(p, disp_model) 2551 2552 except: 2552 2553 pass 2553 logging.error(sys.exc_value) 2554 2554 2555 2555 ## save state into … … 2557 2557 self.Layout() 2558 2558 self.Refresh() 2559 2559 2560 2560 def _on_select_Disp(self, event): 2561 2561 """ … … 2570 2570 event = PageInfoEvent(page=self) 2571 2571 wx.PostEvent(self.parent, event) 2572 2572 2573 2573 self.sizer4_4.Layout() 2574 2574 self.sizer4.Layout() 2575 2575 self.SetupScrolling() 2576 2576 2577 2577 def _on_disp_func(self, event=None): 2578 2578 """ 2579 2579 Select a distribution function for the polydispersion 2580 2580 2581 2581 :Param event: ComboBox event 2582 2582 """ … … 2594 2594 disp_name = disp_box.GetValue() 2595 2595 dispersity = disp_box.GetClientData(selection) 2596 2596 2597 2597 #disp_model = GaussianDispersion() 2598 2598 disp_model = dispersity() … … 2612 2612 self.model.set_dispersion(param_name, disp_model) 2613 2613 self.state._disp_obj_dict[name1] = disp_model 2614 2614 2615 2615 value1 = str(format_number(self.model.getParam(name1), True)) 2616 2616 value2 = str(format_number(self.model.getParam(name2))) … … 2640 2640 for item in self.fixed_param: 2641 2641 if item[1] == name2: 2642 item[2].SetValue(value2) 2642 item[2].SetValue(value2) 2643 2643 # Disable Npts for array 2644 2644 if disp_name.lower() == "array": … … 2653 2653 else: 2654 2654 item[2].Enable() 2655 2655 2656 2656 # Make sure the check box updated when all checked 2657 2657 if self.cb1.GetValue(): … … 2674 2674 wx.PostEvent(self._manager.parent, 2675 2675 StatusEvent(status=msg, info="error")) 2676 2676 2677 2677 def _set_array_disp(self, name=None, disp=None): 2678 2678 """ 2679 2679 Set array dispersion 2680 2680 2681 2681 :param name: name of the parameter for the dispersion to be set 2682 2682 :param disp: the polydisperion object … … 2695 2695 self._default_save_location = os.path.dirname(path) 2696 2696 if self._manager != None: 2697 self._manager.parent._default_save_location = \2697 self._manager.parent._default_save_location = \ 2698 2698 self._default_save_location 2699 2699 2700 2700 basename = os.path.basename(path) 2701 2701 values, weights = self.read_file(path) 2702 2702 2703 2703 # If any of the two arrays is empty, notify the user that we won't 2704 2704 # proceed … … 2713 2713 values=values, weights=weights) 2714 2714 return basename 2715 2715 2716 2716 def _set_array_disp_model(self, name=None, disp=None, 2717 2717 values=[], weights=[]): 2718 2718 """ 2719 2719 Set array dispersion model 2720 2720 2721 2721 :param name: name of the parameter for the dispersion to be set 2722 2722 :param disp: the polydisperion object … … 2747 2747 self.state.model._persistency_dict[name.split('.')[0]] = \ 2748 2748 [values, weights] 2749 2749 2750 2750 def _del_array_values(self, name=None): 2751 2751 """ 2752 2752 Reset array dispersion 2753 2753 2754 2754 :param name: name of the parameter for the dispersion to be set 2755 2755 """ … … 2764 2764 del self.state.model._persistency_dict[name.split('.')[0]] 2765 2765 except: 2766 pass2767 2766 logging.error(sys.exc_value) 2767 2768 2768 def _lay_out(self): 2769 2769 """ 2770 2770 returns self.Layout 2771 2771 2772 2772 :Note: Mac seems to like this better when self. 2773 2773 Layout is called after fitting. … … 2776 2776 self.Layout() 2777 2777 return 2778 2778 2779 2779 def _sleep4sec(self): 2780 2780 """ … … 2785 2785 if ON_MAC == True: 2786 2786 time.sleep(1) 2787 2787 2788 2788 def _find_polyfunc_selection(self, disp_func=None): 2789 2789 """ 2790 2790 FInd Comboox selection from disp_func 2791 2791 2792 2792 :param disp_function: dispersion distr. function 2793 2793 """ … … 2803 2803 except: 2804 2804 return 3 2805 2805 2806 2806 def on_reset_clicked(self, event): 2807 2807 """ … … 2815 2815 flag = False 2816 2816 return 2817 2817 2818 2818 elif self.data.__class__.__name__ == "Data2D": 2819 2819 data_min = 0 … … 2821 2821 y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) 2822 2822 self.qmin_x = data_min 2823 self.qmax_x = math.sqrt(x *x + y*y)2823 self.qmax_x = math.sqrt(x * x + y * y) 2824 2824 #self.data.mask = numpy.ones(len(self.data.data),dtype=bool) 2825 2825 # check smearing … … 2831 2831 else: 2832 2832 flag = True 2833 2833 2834 2834 elif self.data == None: 2835 2835 self.qmin_x = _QMIN_DEFAULT … … 2837 2837 self.num_points = _NPTS_DEFAULT 2838 2838 self.state.npts = self.num_points 2839 2839 2840 2840 elif self.data.__class__.__name__ != "Data2D": 2841 2841 self.qmin_x = min(self.data.x) … … 2853 2853 else: 2854 2854 flag = False 2855 2855 2856 2856 if flag == False: 2857 2857 msg = "Cannot Plot :Must enter a number!!! " … … 2870 2870 self.state.qmin = self.qmin_x 2871 2871 self.state.qmax = self.qmax_x 2872 2872 2873 2873 #reset the q range values 2874 2874 self._reset_plotting_range(self.state) 2875 2875 self._draw_model() 2876 2876 2877 2877 def select_log(self, event): 2878 2878 """ … … 2883 2883 """ 2884 2884 Get the images of the plots corresponding this panel for report 2885 2885 2886 2886 : return graphs: list of figures 2887 2887 : Need Move to guiframe … … 2907 2907 # append to the list 2908 2908 graphs.append(item2.figure) 2909 canvases.append(item2.canvas) 2909 canvases.append(item2.canvas) 2910 2910 except: 2911 2911 # Not for control panels 2912 pass2912 logging.error(sys.exc_value) 2913 2913 # Make sure the resduals plot goes to the last 2914 2914 if res_item != None: … … 2921 2921 """ 2922 2922 Function called when 'Help' button is pressed next to model 2923 of interest. This calls DocumentationWindow from 2923 of interest. This calls DocumentationWindow from 2924 2924 documentation_window.py. It will load the top level of the model 2925 2925 help documenation sphinx generated html if no model is presented. … … 2930 2930 accessible because webbrowser module does not pass anything after 2931 2931 the # to the browser. 2932 2932 2933 2933 :param evt: on Help Button pressed event 2934 2934 """ … … 2939 2939 name = self.formfactorbox.GetValue() 2940 2940 2941 if self.model != None: 2942 _docspath ='user/models/model_functions.html#' + name2941 if self.model != None: 2942 _docspath = 'user/models/model_functions.html#' + name 2943 2943 _doc_viewer = DocumentationWindow(self, -1, _docspath, name + "Help") 2944 2944 else: … … 2956 2956 behaved model is encountered which has no description then it will 2957 2957 give the message that none is available. 2958 2958 2959 2959 :param evt: on Description Button pressed event 2960 2960 """ … … 2978 2978 wx.MessageBox(msg, info) 2979 2979 2980 def _on_mag_help(self, event): 2981 """ 2982 Bring up Magnetic Angle definition bmp image whenever the ? button 2983 is clicked. Calls DocumentationWindow with the path of the location 2984 within the documentation tree (after /doc/ ....". When using old 2980 def _on_mag_help(self, event): 2981 """ 2982 Bring up Magnetic Angle definition bmp image whenever the ? button 2983 is clicked. Calls DocumentationWindow with the path of the location 2984 within the documentation tree (after /doc/ ....". When using old 2985 2985 versions of Wx (i.e. before 2.9 and therefore not part of release 2986 2986 versions distributed via installer) it brings up an image viewer 2987 box which allows the user to click through the rest of the images in 2987 box which allows the user to click through the rest of the images in 2988 2988 the directory. Not ideal but probably better than alternative which 2989 would bring up the entire discussion of how magnetic models work? 2989 would bring up the entire discussion of how magnetic models work? 2990 2990 Specially since it is not likely to be accessed. The normal release 2991 2991 versions bring up the normal image box. 2992 2992 2993 2993 :param evt: Triggers on clicking ? in Magnetic Angles? box 2994 2994 """ 2995 2995 2996 2996 _TreeLocation = "_images/M_angles_pic.bmp" 2997 2997 _doc_viewer = DocumentationWindow(self, -1, \ 2998 _TreeLocation, "Magnetic Angle Defintions")2999 3000 def _on_mag_on(self, event): 2998 _TreeLocation, "Magnetic Angle Defintions") 2999 3000 def _on_mag_on(self, event): 3001 3001 """ 3002 3002 Magnetic Parameters ON/OFF … … 3019 3019 #reset mag value to zero fo safety 3020 3020 self.model.setParam(key, 0.0) 3021 3022 self.Show(False) 3021 3022 self.Show(False) 3023 3023 self.set_model_param_sizer(self.model) 3024 3024 #self._set_sizer_dispersion() … … 3026 3026 self.SetupScrolling() 3027 3027 self.Show(True) 3028 3028 3029 3029 def on_pd_help_clicked(self, event): 3030 3030 """ 3031 Bring up Polydispersity Documentation whenever the ? button is clicked. 3031 Bring up Polydispersity Documentation whenever the ? button is clicked. 3032 3032 Calls DocumentationWindow with the path of the location within the 3033 documentation tree (after /doc/ ....". Note that when using old 3034 versions of Wx (before 2.9) and thus not the release version of 3035 istallers, the help comes up at the top level of the file as 3033 documentation tree (after /doc/ ....". Note that when using old 3034 versions of Wx (before 2.9) and thus not the release version of 3035 istallers, the help comes up at the top level of the file as 3036 3036 webbrowser does not pass anything past the # to the browser when it is 3037 3037 running "file:///...." 3038 3038 3039 3039 :param evt: Triggers on clicking ? in polydispersity box 3040 3040 """ 3041 3041 3042 3042 _TreeLocation = "user/perspectives/fitting/fitting_help.html" 3043 3043 _TreeLocation += "#polydispersity-distributions" 3044 3044 _doc_viewer = DocumentationWindow(self, -1, \ 3045 _TreeLocation, "Polydispersity Help")3046 3045 _TreeLocation, "Polydispersity Help") 3046 3047 3047 def on_left_down(self, event): 3048 3048 """ … … 3059 3059 # make event free 3060 3060 event.Skip() 3061 3061 3062 3062 def get_copy(self): 3063 3063 """ … … 3068 3068 self._copy_info(flag) 3069 3069 return flag 3070 3070 3071 3071 def get_copy_params(self): 3072 3072 """ … … 3076 3076 # Do it if params exist 3077 3077 if self.parameters != []: 3078 3078 3079 3079 # go through the parameters 3080 3080 strings = self._get_copy_helper(self.parameters, 3081 3081 self.orientation_params) 3082 3082 content += strings 3083 3083 3084 3084 # go through the fittables 3085 3085 strings = self._get_copy_helper(self.fittable_param, … … 3091 3091 self.orientation_params_disp) 3092 3092 content += strings 3093 3093 3094 3094 # go through the str params 3095 3095 strings = self._get_copy_helper(self.str_parameters, … … 3124 3124 content += param[1] #parameter name 3125 3125 content += tab 3126 content += param[1] +"_err"3126 content += param[1] + "_err" 3127 3127 content += tab 3128 3128 … … 3132 3132 for param in self.parameters: 3133 3133 content += param[2].GetValue() #value 3134 content += tab3134 content += tab 3135 3135 content += param[4].GetValue() #error 3136 content += tab3136 content += tab 3137 3137 3138 3138 return content … … 3170 3170 3171 3171 for index, param in enumerate(self.parameters): 3172 content += param[1].replace('_', '\_') #parameter name3172 content += param[1].replace('_', '\_') #parameter name 3173 3173 content += ' & ' 3174 content += param[1].replace('_', '\_')+"\_err"3175 if index < len(self.parameters) -1:3174 content += param[1].replace('_', '\_') + "\_err" 3175 if index < len(self.parameters) - 1: 3176 3176 content += ' & ' 3177 3177 content += '\\\\ \\hline' … … 3183 3183 content += ' & ' 3184 3184 content += param[4].GetValue() #parameter error 3185 if index < len(self.parameters) -1:3185 if index < len(self.parameters) - 1: 3186 3186 content += ' & ' 3187 3187 content += '\\\\ \\hline' … … 3206 3206 return True 3207 3207 return None 3208 3208 3209 3209 def _get_copy_helper(self, param, orient_param): 3210 3210 """ 3211 3211 Helping get value and name of the params 3212 3212 3213 3213 : param param: parameters 3214 3214 : param orient_param = oritational params … … 3226 3226 disfunc = str(item[7].GetValue()) 3227 3227 except: 3228 pass3229 3228 logging.error(sys.exc_value) 3229 3230 3230 # 2D 3231 3231 if self.data.__class__.__name__ == "Data2D": … … 3249 3249 # add to the content 3250 3250 if disfunc != '': 3251 3251 3252 3252 disfunc = ',' + disfunc 3253 3253 # Need to support array func for copy/paste … … 3261 3261 disfunc += ' ' + str(weight) 3262 3262 except: 3263 pass3263 logging.error(sys.exc_value) 3264 3264 content += name + ',' + str(check) + ',' + value + disfunc + ':' 3265 3265 3266 3266 return content 3267 3267 3268 3268 def get_clipboard(self): 3269 3269 """ … … 3285 3285 wx.TheClipboard.Close() 3286 3286 return text 3287 3287 3288 3288 def get_paste(self): 3289 3289 """ … … 3294 3294 self._copy_info(flag) 3295 3295 return flag 3296 3296 3297 3297 def get_paste_params(self, text=''): 3298 3298 """ … … 3323 3323 val = [float(a_val) for a_val in array_values[1:]] 3324 3324 weit = [float(a_weit) for a_weit in array_weights[1:]] 3325 3325 3326 3326 context[name].append(val) 3327 3327 context[name].append(weit) … … 3346 3346 self._get_paste_helper(self.fixed_param, 3347 3347 self.orientation_params_disp, context) 3348 3348 3349 3349 # go through the str params 3350 3350 self._get_paste_helper(self.str_parameters, 3351 3351 self.orientation_params, context) 3352 3352 3353 3353 return True 3354 3354 return None 3355 3355 3356 3356 def _get_paste_helper(self, param, orient_param, content): 3357 3357 """ 3358 3358 Helping set values of the params 3359 3359 3360 3360 : param param: parameters 3361 3361 : param orient_param: oritational params … … 3385 3385 fun_val = self.model.fun_list[content[name][1]] 3386 3386 self.model.setParam(name, fun_val) 3387 3387 3388 3388 value = content[name][1:] 3389 3389 self._paste_poly_help(item, value) … … 3431 3431 if is_true != None: 3432 3432 item[0].SetValue(is_true) 3433 3433 3434 3434 def _paste_poly_help(self, item, value): 3435 3435 """ 3436 3436 Helps get paste for poly function 3437 3437 3438 3438 :param item: Gui param items 3439 3439 :param value: the values for parameter ctrols … … 3462 3462 is_array = True 3463 3463 except: 3464 pass3464 logging.error(sys.exc_value) 3465 3465 if not is_array: 3466 3466 self._disp_obj_dict[name] = disp_model … … 3475 3475 [self.state.values, 3476 3476 self.state.weights] 3477 3477 3478 3478 except: 3479 logging.error(sys.exc_value) 3479 3480 print "Error in BasePage._paste_poly_help: %s" % sys.exc_value 3480 3481 3481 3482 def _set_disp_array_cb(self, item): 3482 3483 """ … … 3492 3493 item[6].SetValue('') 3493 3494 item[6].Enable(False) 3494 3495 3495 3496 def update_pinhole_smear(self): 3496 3497 """ … … 3518 3519 if not os.path.isfile(categorization_file): 3519 3520 categorization_file = CategoryInstaller.get_default_file() 3520 cat_file = open(categorization_file, 'rb') 3521 cat_file = open(categorization_file, 'rb') 3521 3522 self.master_category_dict = json.load(cat_file) 3522 3523 self._regenerate_model_dict() … … 3531 3532 def _regenerate_model_dict(self): 3532 3533 """ 3533 regenerates self.by_model_dict which has each model name as the 3534 regenerates self.by_model_dict which has each model name as the 3534 3535 key and the list of categories belonging to that model 3535 3536 along with the enabled mapping … … 3541 3542 self.by_model_dict[model].append(category) 3542 3543 self.model_enabled_dict[model] = enabled 3543 3544 3544 3545 def _populate_listbox(self): 3545 3546 """ … … 3553 3554 if not uncat_str in cat_list: 3554 3555 cat_list.append(uncat_str) 3555 3556 3556 3557 for category in cat_list: 3557 3558 if category != '': … … 3561 3562 self.categorybox.SetSelection(0) 3562 3563 else: 3563 self.categorybox.SetSelection( 3564 self.categorybox.SetSelection(\ 3564 3565 self.categorybox.GetSelection()) 3565 3566 … … 3583 3584 3584 3585 else: 3585 for (model, enabled) in sorted(self.master_category_dict[category],3586 key =lambda name: name[0]):3586 for (model, enabled) in sorted(self.master_category_dict[category], 3587 key=lambda name: name[0]): 3587 3588 if(enabled): 3588 3589 self.model_box.Append(model) … … 3617 3618 hint = "toggle view of model from 1D to 2D or 2D to 1D" 3618 3619 self.model_view.SetToolTipString(hint) 3619 3620 3620 3621 cat_set_box = wx.StaticBox(self, -1, 'Category') 3621 3622 sizer_cat_box = wx.StaticBoxSizer(cat_set_box, wx.HORIZONTAL) 3622 3623 sizer_cat_box.SetMinSize((200, 50)) 3623 3624 self.categorybox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 3624 self.categorybox.SetToolTip( wx.ToolTip("Select a Category/Type"))3625 self.categorybox.SetToolTip(wx.ToolTip("Select a Category/Type")) 3625 3626 self._populate_listbox() 3626 3627 wx.EVT_COMBOBOX(self.categorybox, -1, self._show_combox) … … 3631 3632 #self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") 3632 3633 #self.plugin_rbutton = wx.RadioButton(self, -1, "Uncategorized") 3633 3634 3634 3635 #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3635 3636 # id=self.shape_rbutton.GetId()) … … 3641 3642 # id=self.plugin_rbutton.GetId()) 3642 3643 #MAC needs SetValue 3643 3644 3644 3645 show_cat_button = wx.Button(self, -1, "Modify") 3645 3646 cat_tip = "Modify model categories \n" 3646 3647 cat_tip += "(also accessible from the menu bar)." 3647 show_cat_button.SetToolTip( wx.ToolTip(cat_tip))3648 show_cat_button.SetToolTip(wx.ToolTip(cat_tip)) 3648 3649 show_cat_button.Bind(wx.EVT_BUTTON, self._on_modify_cat) 3649 3650 sizer_cat_box.Add(self.categorybox, 1, wx.RIGHT, 3) 3650 sizer_cat_box.Add((10, 10))3651 sizer_cat_box.Add((10, 10)) 3651 3652 sizer_cat_box.Add(show_cat_button) 3652 3653 #self.shape_rbutton.SetValue(True) 3653 3654 3654 3655 sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) 3655 3656 3656 3657 3657 3658 #sizer_radiobutton.Add(self.shape_rbutton) 3658 3659 #sizer_radiobutton.Add(self.shape_indep_rbutton) 3659 sizer_radiobutton.Add((5, 5))3660 sizer_radiobutton.Add((5, 5)) 3660 3661 sizer_radiobutton.Add(self.model_view, 1, wx.RIGHT, 5) 3661 3662 #sizer_radiobutton.Add(self.plugin_rbutton) 3662 3663 #sizer_radiobutton.Add(self.struct_rbutton) 3663 3664 # sizer_radiobutton.Add((5,5)) 3664 sizer_radiobutton.Add(self.model_help, 1, wx.RIGHT |wx.LEFT, 5)3665 sizer_radiobutton.Add(self.model_help, 1, wx.RIGHT | wx.LEFT, 5) 3665 3666 # sizer_radiobutton.Add((5,5)) 3666 3667 sizer_radiobutton.Add(self.model_func, 1, wx.RIGHT, 5) … … 3669 3670 sizer_selection = wx.BoxSizer(wx.HORIZONTAL) 3670 3671 mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) 3671 3672 3672 3673 self.text1 = wx.StaticText(self, -1, "") 3673 3674 self.text2 = wx.StaticText(self, -1, "P(Q)*S(Q)") … … 3678 3679 3679 3680 self.formfactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 3680 self.formfactorbox.SetToolTip( wx.ToolTip("Select a Model"))3681 self.formfactorbox.SetToolTip(wx.ToolTip("Select a Model")) 3681 3682 if self.model != None: 3682 3683 self.formfactorbox.SetValue(self.model.name) … … 3692 3693 print "_set_model_sizer_selection: disabled." 3693 3694 #self._set_model_sizer_selection(self.model) 3694 3695 3695 3696 sizer_selection.Add(self.text1) 3696 3697 sizer_selection.Add((10, 5)) … … 3700 3701 sizer_selection.Add((5, 5)) 3701 3702 sizer_selection.Add(self.structurebox) 3702 3703 3703 3704 mutifactor_selection.Add((13, 5)) 3704 3705 mutifactor_selection.Add(self.mutifactor_text) … … 3714 3715 boxsizer1.Add((10, 10)) 3715 3716 boxsizer1.Add(mutifactor_selection) 3716 3717 3717 3718 self._set_multfactor_combobox() 3718 3719 self.multifactorbox.SetSelection(1) … … 3720 3721 sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 3721 3722 sizer.Layout() 3722 3723 3723 3724 def on_smear_helper(self, update=False): 3724 3725 """ 3725 3726 Help for onSmear if implemented 3726 3727 3727 3728 :param update: force or not to update 3728 3729 """ … … 3733 3734 def onSmear(self, event): 3734 3735 """ 3735 Create a smear object if implemented 3736 Create a smear object if implemented 3736 3737 """ 3737 3738 def onPinholeSmear(self, event):
Note: See TracChangeset
for help on using the changeset viewer.