Changeset c8e1996 in sasview
- Timestamp:
- Oct 20, 2016 1:54:06 PM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 880e845, cf1910f
- Parents:
- 8b645cc
- Location:
- src/sas/sasgui
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/data_panel.py
r998ca90 rc8e1996 1 1 ################################################################################ 2 # This software was developed by the University of Tennessee as part of the3 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE)4 # project funded by the US National Science Foundation.2 # This software was developed by the University of Tennessee as part of the 3 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 # project funded by the US National Science Foundation. 5 5 # 6 # See the license text in license.txt6 # See the license text in license.txt 7 7 # 8 # copyright 2010, University of Tennessee8 # copyright 2010, University of Tennessee 9 9 ################################################################################ 10 10 """ … … 14 14 from wx.build import build_options 15 15 16 # Check version17 toks = str(wx.__version__).split('.')18 if int(toks[1]) < 9:19 if int(toks[2]) < 12:20 wx_version = 81121 else:22 wx_version = 81223 else:24 wx_version = 90025 16 import sys 26 17 from wx.lib.scrolledpanel import ScrolledPanel 27 import 18 import wx.lib.agw.customtreectrl as CT 28 19 from sas.sasgui.guiframe.dataFitting import Data1D 29 20 from sas.sasgui.guiframe.dataFitting import Data2D … … 36 27 from sas.sasgui.guiframe.events import NewBatchEvent 37 28 from sas.sascalc.dataloader.loader import Loader 38 # from sas.sasgui.guiframe.local_perspectives.plotting.masking \29 # from sas.sasgui.guiframe.local_perspectives.plotting.masking \ 39 30 # import FloatPanel as QucikPlotDialog 40 from sas.sasgui.guiframe.local_perspectives.plotting.SimplePlot import PlotFrame\41 31 from sas.sasgui.guiframe.local_perspectives.plotting.SimplePlot \ 32 import PlotFrame as QucikPlotDialog 42 33 import sas.sasgui.guiframe.config as config 34 35 # Check version 36 toks = str(wx.__version__).split('.') 37 if int(toks[1]) < 9: 38 if int(toks[2]) < 12: 39 wx_version = 811 40 else: 41 wx_version = 812 42 else: 43 wx_version = 900 43 44 44 45 extension_list = [] … … 49 50 APPLICATION_WLIST = config.APPLICATION_WLIST 50 51 51 # Control panel width52 # Control panel width 52 53 if sys.platform.count("win32") > 0: 53 54 PANEL_WIDTH = 235 … … 65 66 IS_MAC = True 66 67 67 STYLE_FLAG = wx.RAISED_BORDER |CT.TR_HAS_BUTTONS| CT.TR_HIDE_ROOT|\68 wx.WANTS_CHARS |CT.TR_HAS_VARIABLE_ROW_HEIGHT68 STYLE_FLAG = wx.RAISED_BORDER | CT.TR_HAS_BUTTONS | CT.TR_HIDE_ROOT |\ 69 wx.WANTS_CHARS | CT.TR_HAS_VARIABLE_ROW_HEIGHT 69 70 70 71 … … 74 75 """ 75 76 def __init__(self, parent, *args, **kwds): 76 # agwstyle is introduced in wx.2.8.11 but is not working for mac77 # agwstyle is introduced in wx.2.8.11 but is not working for mac 77 78 if IS_MAC and wx_version < 812: 78 79 try: … … 114 115 return 0 115 116 117 116 118 class DataPanel(ScrolledPanel, PanelBase): 117 119 """ … … 119 121 interact with data. 120 122 """ 121 # #Internal name for the AUI manager123 # Internal name for the AUI manager 122 124 window_name = "Data Panel" 123 # #Title to appear on top of the window125 # Title to appear on top of the window 124 126 window_caption = "Data Explorer" 125 # type of window127 # type of window 126 128 window_type = "Data Panel" 127 # #Flag to tell the GUI manager that this panel is not129 # Flag to tell the GUI manager that this panel is not 128 130 # tied to any perspective 129 #ALWAYS_ON = True 131 # ALWAYS_ON = True 132 130 133 def __init__(self, parent, 131 134 list=None, … … 133 136 id=-1, 134 137 list_of_perspective=None, manager=None, *args, **kwds): 135 # kwds['size'] = size136 # kwds['style'] = STYLE_FLAG138 # kwds['size'] = size 139 # kwds['style'] = STYLE_FLAG 137 140 ScrolledPanel.__init__(self, parent=parent, id=id, *args, **kwds) 138 141 PanelBase.__init__(self, parent) 139 142 self.SetupScrolling() 140 # Set window's font size143 # Set window's font size 141 144 self.SetWindowVariant(variant=FONT_VARIANT) 142 145 self.loader = Loader() 143 # Default location146 # Default location 144 147 self._default_save_location = None 145 148 self.all_data1d = True … … 159 162 self.tree_ctrl_theory = None 160 163 self.perspective_cbox = None 161 # #Create context menu for page164 # Create context menu for page 162 165 self.data_menu = None 163 166 self.popUpMenu = None … … 165 168 self.editmask_id = None 166 169 # Default attr 167 self.vbox 170 self.vbox = None 168 171 self.sizer1 = None 169 172 self.sizer2 = None … … 210 213 """ 211 214 w, h = self.parent.GetSize() 212 self.vbox 215 self.vbox = wx.BoxSizer(wx.VERTICAL) 213 216 self.sizer1 = wx.BoxSizer(wx.VERTICAL) 214 217 self.sizer1.SetMinSize(wx.Size(w/13, h*2/5)) … … 219 222 self.sizer5 = wx.BoxSizer(wx.VERTICAL) 220 223 221 self.vbox.Add(self.sizer5, 0, wx.EXPAND |wx.ALL, 1)222 self.vbox.Add(self.sizer1, 1, wx.EXPAND |wx.ALL, 0)223 self.vbox.Add(self.sizer2, 0, wx.EXPAND |wx.ALL, 1)224 self.vbox.Add(self.sizer3, 0, wx.EXPAND |wx.ALL, 10)225 # self.vbox.Add(self.sizer4, 0, wx.EXPAND|wx.ALL,5)224 self.vbox.Add(self.sizer5, 0, wx.EXPAND | wx.ALL, 1) 225 self.vbox.Add(self.sizer1, 1, wx.EXPAND | wx.ALL, 0) 226 self.vbox.Add(self.sizer2, 0, wx.EXPAND | wx.ALL, 1) 227 self.vbox.Add(self.sizer3, 0, wx.EXPAND | wx.ALL, 10) 228 # self.vbox.Add(self.sizer4, 0, wx.EXPAND|wx.ALL,5) 226 229 227 230 self.SetSizer(self.vbox) … … 235 238 self.selection_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 236 239 list_of_options = ['Select all Data', 237 240 'Unselect all Data', 238 241 'Select all Data 1D', 239 242 'Unselect all Data 1D', 240 243 'Select all Data 2D', 241 'Unselect all Data 2D' 244 'Unselect all Data 2D'] 242 245 for option in list_of_options: 243 246 self.selection_cbox.Append(str(option)) … … 245 248 wx.EVT_COMBOBOX(self.selection_cbox, -1, self._on_selection_type) 246 249 self.sizer5.AddMany([(select_txt, 0, wx.ALL, 5), 247 (self.selection_cbox, 0, wx.ALL, 5)])250 (self.selection_cbox, 0, wx.ALL, 5)]) 248 251 self.enable_selection() 249 250 252 251 253 def _on_selection_type(self, event): … … 257 259 self.tree_ctrl.CheckItem(data_ctrl, check_value) 258 260 if data_ctrl.HasChildren(): 259 if check_value == Trueand not control.IsExpanded():261 if check_value and not control.IsExpanded(): 260 262 # Only select children if control is expanded 261 263 # Always deselect children, regardless (see ticket #259) … … 299 301 Layout widgets related to buttons 300 302 """ 301 # Load Data Button303 # Load Data Button 302 304 self.bt_add = wx.Button(self, wx.NewId(), "Load Data", 303 305 size=(BUTTON_WIDTH, -1)) … … 305 307 wx.EVT_BUTTON(self, self.bt_add.GetId(), self._load_data) 306 308 307 # Delete Data Button309 # Delete Data Button 308 310 self.bt_remove = wx.Button(self, wx.NewId(), "Delete Data", 309 size=(BUTTON_WIDTH, -1))311 size=(BUTTON_WIDTH, -1)) 310 312 self.bt_remove.SetToolTipString("Delete data from the application") 311 313 wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove) 312 314 313 # Send data to perspective button315 # Send data to perspective button 314 316 self.bt_import = wx.Button(self, wx.NewId(), "Send To", 315 317 size=(BUTTON_WIDTH, -1)) 316 318 self.bt_import.SetToolTipString("Send Data set to active perspective") 317 319 wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import) 318 320 319 # Choose perspective to be send data to combo box321 # Choose perspective to be send data to combo box 320 322 self.perspective_cbox = wx.ComboBox(self, -1, 321 style=wx.CB_READONLY)323 style=wx.CB_READONLY) 322 324 if not IS_MAC: 323 325 self.perspective_cbox.SetMinSize((BUTTON_WIDTH*1.6, -1)) … … 325 327 self._on_perspective_selection) 326 328 327 # Append data to current Graph Button329 # Append data to current Graph Button 328 330 self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To", 329 331 size=(BUTTON_WIDTH, -1)) 330 self.bt_append_plot.SetToolTipString( \331 332 self.bt_append_plot.SetToolTipString( 333 "Plot the selected data in the active panel") 332 334 wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot) 333 335 334 # Create a new graph and send data to that new graph button336 # Create a new graph and send data to that new graph button 335 337 self.bt_plot = wx.Button(self, wx.NewId(), "New Plot", 336 338 size=(BUTTON_WIDTH, -1)) … … 338 340 wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot) 339 341 340 # Freeze current theory button - becomes a data set and stays on graph342 # Freeze current theory button - becomes a data set and stays on graph 341 343 self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze Theory", 342 344 size=(BUTTON_WIDTH, -1)) … … 347 349 wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze) 348 350 349 # select plot to send to combo box (blank if no data)351 # select plot to send to combo box (blank if no data) 350 352 if sys.platform == 'darwin': 351 353 self.cb_plotpanel = wx.ComboBox(self, -1, … … 353 355 else: 354 356 self.cb_plotpanel = wx.ComboBox(self, -1, 355 style=wx.CB_READONLY |wx.CB_SORT)357 style=wx.CB_READONLY | wx.CB_SORT) 356 358 wx.EVT_COMBOBOX(self.cb_plotpanel, -1, self._on_plot_selection) 357 359 self.cb_plotpanel.Disable() 358 360 359 # Help button361 # Help button 360 362 self.bt_help = wx.Button(self, wx.NewId(), "HELP", 361 363 size=(BUTTON_WIDTH, -1)) 362 364 self.bt_help.SetToolTipString("Help for the Data Explorer.") 363 wx.EVT_BUTTON(self, self.bt_help.GetId(), self.on_help)365 wx.EVT_BUTTON(self, self.bt_help.GetId(), self.on_help) 364 366 365 367 self.sizer3.AddMany([(self.bt_add), … … 373 375 (self.bt_append_plot), 374 376 (self.cb_plotpanel, 375 wx.EXPAND |wx.ADJUST_MINSIZE, 5),377 wx.EXPAND | wx.ADJUST_MINSIZE, 5), 376 378 ((5, 5)), 377 379 ((5, 5)), 378 (self.bt_import, 0, wx.EXPAND |wx.RIGHT, 5),380 (self.bt_import, 0, wx.EXPAND | wx.RIGHT, 5), 379 381 (self.perspective_cbox, 380 wx.EXPAND |wx.ADJUST_MINSIZE, 5),382 wx.EXPAND | wx.ADJUST_MINSIZE, 5), 381 383 ((10, 10)), 382 384 (self.sizer4), … … 401 403 self.rb_batch_mode = wx.RadioButton(self, -1, 'Batch Mode') 402 404 self.Bind(wx.EVT_RADIOBUTTON, self.on_single_mode, 403 405 id=self.rb_single_mode.GetId()) 404 406 self.Bind(wx.EVT_RADIOBUTTON, self.on_batch_mode, 405 407 id=self.rb_batch_mode.GetId()) 406 408 407 409 self.rb_single_mode.SetValue(not self.parent.batch_on) … … 433 435 """ 434 436 data = None 435 # selection = event.GetSelection()437 # selection = event.GetSelection() 436 438 id, _, _ = self.FindFocus().GetSelection().GetData() 437 439 data_list, theory_list = \ 438 440 self.parent.get_data_manager().get_by_id(id_list=[id]) 439 441 if data_list: 440 442 data = data_list.values()[0] 441 if data ==None:443 if data is None: 442 444 data = theory_list.values()[0][0] 443 445 return data … … 461 463 data = self._get_data_selection(event) 462 464 from sas.sasgui.guiframe.local_perspectives.plotting.masking \ 463 import FloatPanel as Float3dDialog465 import FloatPanel as Float3dDialog 464 466 465 467 panel = Float3dDialog(base=self, data=data, … … 476 478 else: 477 479 dimension = 1 478 # panel = QucikPlotDialog(base=self, data=data,480 # panel = QucikPlotDialog(base=self, data=data, 479 481 # dimension=dimension, id=wx.NewId()) 480 482 frame = QucikPlotDialog(self, -1, "Plot " + data.name, 'log_{10}') 481 483 self.parent.put_icon(frame) 482 484 frame.add_plot(data) 483 # frame.SetTitle(title)485 # frame.SetTitle(title) 484 486 frame.Show(True) 485 487 frame.SetFocus() 486 # panel.ShowModal()488 # panel.ShowModal() 487 489 488 490 def on_data_info(self, event): … … 501 503 """ 502 504 data = self._get_data_selection(event) 503 # path = None505 # path = None 504 506 default_name = data.name 505 507 if default_name.count('.') > 0: 506 508 default_name = default_name.split('.')[0] 507 509 default_name += "_out" 508 if self.parent !=None:510 if self.parent is not None: 509 511 if issubclass(data.__class__, Data1D): 510 512 self.parent.save_data1d(data, default_name) … … 523 525 self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item) 524 526 self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_MENU, self.on_right_click_data) 525 # #Create context menu for page527 # Create context menu for page 526 528 self.data_menu = wx.Menu() 527 529 id = wx.NewId() … … 558 560 tree_ctrl_theory_label.SetForegroundColour('blue') 559 561 self.tree_ctrl_theory = DataTreeCtrl(parent=self, 560 562 style=wx.SUNKEN_BORDER) 561 563 self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, 562 564 self.on_check_item) 563 565 self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_MENU, 564 566 self.on_right_click_theory) 565 567 self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10) 566 self.sizer1.Add(self.tree_ctrl, 1, wx.EXPAND |wx.ALL, 10)568 self.sizer1.Add(self.tree_ctrl, 1, wx.EXPAND | wx.ALL, 10) 567 569 self.sizer1.Add(tree_ctrl_theory_label, 0, wx.LEFT, 10) 568 self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND |wx.ALL, 10)570 self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND | wx.ALL, 10) 569 571 570 572 def on_right_click_theory(self, event): … … 588 590 Allow Editing Data 589 591 """ 590 # selection = event.GetSelection()592 # selection = event.GetSelection() 591 593 is_data = True 592 594 try: 593 595 id, data_class_name, _ = self.tree_ctrl.GetSelection().GetData() 594 596 data_list, _ = \ 595 597 self.parent.get_data_manager().get_by_id(id_list=[id]) 596 598 if not data_list: 597 599 is_data = False … … 610 612 """ 611 613 # Skipping the save state functionality for release 0.9.0 612 # return614 # return 613 615 pos = event.GetPosition() 614 616 pos = self.ScreenToClient(pos) 615 617 self.PopupMenu(self.popUpMenu, pos) 616 617 618 618 619 def on_check_item(self, event): … … 636 637 if self.parent is None or \ 637 638 not hasattr(self.parent, "get_current_perspective") or \ 638 len(self.list_of_perspective) == 0:639 len(self.list_of_perspective) == 0: 639 640 return 640 if self.parent is not None and self.perspective_cbox 641 if self.parent is not None and self.perspective_cbox is not None: 641 642 for plug in self.list_of_perspective: 642 643 if plug.get_perspective(): … … 666 667 s_path = str(path) 667 668 if state_id not in self.list_cb_data: 668 # new state669 # new state 669 670 data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root, 670 0, data_name, ct_type=1, 671 0, data_name, 672 ct_type=1, 671 673 data=(data_id, data_class, state_id)) 672 674 data_c.Check(True) 673 675 d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info') 674 676 d_t_c = self.tree_ctrl.AppendItem(d_i_c, 675 'Title: %s' % data_title) 677 'Title: %s' % 678 data_title) 676 679 r_n_c = self.tree_ctrl.AppendItem(d_i_c, 677 'Run: %s' % data_run)680 'Run: %s' % data_run) 678 681 i_c_c = self.tree_ctrl.AppendItem(d_i_c, 679 'Type: %s' % data_class) 682 'Type: %s' % 683 data_class) 680 684 p_c_c = self.tree_ctrl.AppendItem(d_i_c, 681 "Path: '%s'" % s_path)685 "Path: '%s'" % s_path) 682 686 d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process') 683 687 684 688 for process in process_list: 685 process_str = str(process).replace('\n', ' ')686 if len(process_str) >20:687 process_str = process_str[:20] +' [...]'689 process_str = str(process).replace('\n', ' ') 690 if len(process_str) > 20: 691 process_str = process_str[:20] + ' [...]' 688 692 self.tree_ctrl.AppendItem(d_p_c, process_str) 689 693 theory_child = self.tree_ctrl.AppendItem(data_c, … … 698 702 theory_child] 699 703 else: 700 data_ctrl_list = 701 # This state is already display replace it contains704 data_ctrl_list = self.list_cb_data[state_id] 705 # This state is already display replace it contains 702 706 data_c, d_i_c, d_t_c, r_n_c, i_c_c, p_c_c, d_p_c, _ \ 703 707 = data_ctrl_list … … 713 717 if not process.is_empty(): 714 718 _ = self.tree_ctrl.AppendItem(d_p_c, 715 719 process.single_line_desc()) 716 720 wx.CallAfter(self.append_theory, state_id, theory_list) 717 721 # Sort by data name … … 757 761 theory_list=theory_list) 758 762 759 760 763 def append_theory_helper(self, tree, root, state_id, theory_list): 761 764 """ … … 763 766 """ 764 767 if state_id in self.list_cb_theory.keys(): 765 # update current list of theory for this data768 # update current list of theory for this data 766 769 theory_list_ctrl = self.list_cb_theory[state_id] 767 770 … … 777 780 theory_class = theory_data.__class__.__name__ 778 781 theory_id = theory_data.id 779 # if theory_state is not None:782 # if theory_state is not None: 780 783 # name = theory_state.model.name 781 784 temp = (theory_id, theory_class, state_id) 782 785 if theory_id not in theory_list_ctrl: 783 # add new theory786 # add new theory 784 787 t_child = tree.AppendItem(root, 785 788 name, ct_type=1, data=temp) … … 795 798 t_p_c] 796 799 else: 797 # replace theory800 # replace theory 798 801 t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id] 799 802 tree.SetItemText(t_child, name) … … 805 808 806 809 else: 807 # data didn't have a theory associated it before810 # data didn't have a theory associated it before 808 811 theory_list_ctrl = {} 809 812 for theory_id, item in theory_list.iteritems(): … … 813 816 theory_class = theory_data.__class__.__name__ 814 817 theory_id = theory_data.id 815 # if theory_state is not None:818 # if theory_state is not None: 816 819 # name = theory_state.model.name 817 820 temp = (theory_id, theory_class, state_id) … … 828 831 829 832 theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c] 830 # self.list_cb_theory[data_id] = theory_list_ctrl833 # self.list_cb_theory[data_id] = theory_list_ctrl 831 834 self.list_cb_theory[state_id] = theory_list_ctrl 832 833 834 835 835 836 def set_data_helper(self): … … 889 890 wx.PostEvent(self.parent, NewLoadDataEvent()) 890 891 891 892 def on_remove(self, event, msg=""): 892 def on_remove(self, event, prompt=True): 893 893 """ 894 894 Get a list of item checked and remove them from the treectrl 895 895 Ask the parent to remove reference to this item 896 896 """ 897 if msg == "":897 if prompt: 898 898 msg = "This operation will delete the data sets checked " 899 899 msg += "and all the dependents." 900 msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK|wx.CANCEL)901 if msg_box.ShowModal() != wx.ID_OK:902 return True900 msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK|wx.CANCEL) 901 if msg_box.ShowModal() != wx.ID_OK: 902 return 903 903 904 904 data_to_remove, theory_to_remove, _ = self.set_data_helper() 905 905 data_key = [] 906 906 theory_key = [] 907 # remove data from treectrl907 # remove data from treectrl 908 908 for d_key, item in self.list_cb_data.iteritems(): 909 909 data_c, _, _, _, _, _, _, _ = item … … 916 916 # Remove theory from treectrl 917 917 for _, theory_dict in self.list_cb_theory.iteritems(): 918 for 918 for key, value in theory_dict.iteritems(): 919 919 item, _, _ = value 920 920 if item.IsChecked(): … … 925 925 theory_key.append(key) 926 926 927 # Remove data and related theory references927 # Remove data and related theory references 928 928 for key in data_key: 929 929 del self.list_cb_data[key] 930 930 if key in theory_key: 931 931 del self.list_cb_theory[key] 932 # remove theory references independently of data932 # remove theory references independently of data 933 933 for key in theory_key: 934 934 for _, theory_dict in self.list_cb_theory.iteritems(): 935 935 if key in theory_dict: 936 for 936 for key, value in theory_dict.iteritems(): 937 937 item, _, _ = value 938 938 if item.IsChecked(): … … 943 943 del theory_dict[key] 944 944 945 946 945 self.parent.remove_data(data_id=data_to_remove, 947 946 theory_id=theory_to_remove) … … 954 953 Get all select data and set them to the current active perspetive 955 954 """ 956 if event !=None:955 if event is not None: 957 956 event.Skip() 958 957 data_id, theory_id, state_id = self.set_data_helper() … … 986 985 On close 987 986 """ 988 if event !=None:987 if event is not None: 989 988 event.Skip() 990 989 # send parent to update menu with no show nor hide action … … 1016 1015 from the combobox of the current panel 1017 1016 """ 1018 # name = event.name1017 # name = event.name 1019 1018 caption = event.caption 1020 1019 if self.cb_plotpanel is not None: … … 1034 1033 if name_plot_panel not in self.cb_plotpanel.GetItems(): 1035 1034 self.cb_plotpanel.Append(name_plot_panel, value) 1036 if name !=None and name == name_plot_panel:1035 if name is not None and name == name_plot_panel: 1037 1036 self.cb_plotpanel.SetStringSelection(name_plot_panel) 1038 1037 break … … 1060 1059 On source combobox selection 1061 1060 """ 1062 if event !=None:1061 if event is not None: 1063 1062 combo = event.GetEventObject() 1064 1063 event.Skip() … … 1107 1106 running "file:///...." 1108 1107 1109 :param ev t: Triggers on clicking the help button1108 :param event: Triggers on clicking the help button 1110 1109 """ 1111 1110 … … 1156 1155 """ 1157 1156 n_t = 0 1158 if self.tree_ctrl !=None:1157 if self.tree_ctrl is not None: 1159 1158 n_t = self.tree_ctrl.GetCount() 1160 1159 if n_t > 0 and len(self.list_of_perspective) > 0: … … 1175 1174 n_t = 0 1176 1175 n_t_t = 0 1177 if self.tree_ctrl !=None:1176 if self.tree_ctrl is not None: 1178 1177 n_t = self.tree_ctrl.GetCount() 1179 if self.tree_ctrl_theory !=None:1178 if self.tree_ctrl_theory is not None: 1180 1179 n_t_t = self.tree_ctrl_theory.GetCount() 1181 1180 if n_t + n_t_t <= 0: … … 1191 1190 n_t = 0 1192 1191 n_t_t = 0 1193 if self.tree_ctrl !=None:1192 if self.tree_ctrl is not None: 1194 1193 n_t = self.tree_ctrl.GetCount() 1195 if self.tree_ctrl_theory !=None:1194 if self.tree_ctrl_theory is not None: 1196 1195 n_t_t = self.tree_ctrl_theory.GetCount() 1197 1196 if n_t + n_t_t <= 0: … … 1215 1214 n_t_t = 0 1216 1215 n_l = 0 1217 if self.tree_ctrl_theory !=None:1216 if self.tree_ctrl_theory is not None: 1218 1217 n_t_t = self.tree_ctrl_theory.GetCount() 1219 1218 n_l = len(self.list_cb_theory) … … 1229 1228 n_t = 0 1230 1229 n_t_t = 0 1231 if self.tree_ctrl !=None:1230 if self.tree_ctrl is not None: 1232 1231 n_t = self.tree_ctrl.GetCount() 1233 if self.tree_ctrl_theory !=None:1232 if self.tree_ctrl_theory is not None: 1234 1233 n_t_t = self.tree_ctrl_theory.GetCount() 1235 if n_t + n_t_t > 0 and self.selection_cbox !=None:1234 if n_t + n_t_t > 0 and self.selection_cbox is not None: 1236 1235 self.selection_cbox.Enable() 1237 1236 else: … … 1255 1254 #self.bt_remove.Hide() 1256 1255 self.bt_add.Hide() 1257 1258 1256 1259 1257 … … 1288 1286 if not data_list or len(data_list) <= 1: 1289 1287 return 1290 # add text1288 # add text 1291 1289 1292 1290 text = "Deleting these file reset some panels.\n" … … 1296 1294 iy = 0 1297 1295 ix = 0 1298 # data_count = 01296 # data_count = 0 1299 1297 for (data_name, in_use, sub_menu) in range(len(data_list)): 1300 if in_use == True:1298 if in_use: 1301 1299 ctrl_name = wx.StaticBox(self, -1, str(data_name)) 1302 1300 ctrl_in_use = wx.StaticBox(self, -1, " is used by ") 1303 1301 plug_name = str(sub_menu) + "\n" 1304 # ctrl_sub_menu = wx.StaticBox(self, -1, plug_name)1302 # ctrl_sub_menu = wx.StaticBox(self, -1, plug_name) 1305 1303 self.sizer.Add(ctrl_name, (iy, ix), 1306 1304 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) … … 1313 1311 iy += 1 1314 1312 self._panel.SetSizer(self.sizer) 1315 # add sizer1313 # add sizer 1316 1314 self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 1317 1315 button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") … … 1376 1374 1377 1375 1378 1379 1376 from sas.sasgui.guiframe.dataFitting import Theory1D 1380 1377 from sas.sasgui.guiframe.data_state import DataState 1378 1381 1379 1382 1380 class State(): … … 1392 1390 return self.msg 1393 1391 1392 1394 1393 def set_data_state(data=None, path=None, theory=None, state=None): 1395 1394 """ … … 1406 1405 app = wx.App() 1407 1406 try: 1408 # list_of_perspective = [('perspective2', False), ('perspective1', True)]1407 # list_of_perspective = [('perspective2', False), ('perspective1', True)] 1409 1408 data_list1 = {} 1410 1409 # state 1 … … 1421 1420 state1 = State() 1422 1421 data_list1['1'] = set_data_state(data1, path1, theory1, state1) 1423 # state 21422 # state 2 1424 1423 data1 = Data2D() 1425 1424 data1.name = "data2" … … 1429 1428 theory1.name = "CoreShell 07/24/25" 1430 1429 path1 = "path2" 1431 # state31430 # state3 1432 1431 state1 = State() 1433 1432 data_list1['2'] = set_data_state(data1, path1, theory1, state1) … … 1446 1445 process1.data = "07/22/2010" 1447 1446 data_list1['4'] = set_data_state(data1, path1, theory1, state1) 1448 # state 41447 # state 4 1449 1448 temp_data_list = {} 1450 1449 data1.name = "data5 erasing data2" 1451 1450 temp_data_list['4'] = set_data_state(data1, path1, theory1, state1) 1452 # state 51451 # state 5 1453 1452 data1 = Data2D() 1454 1453 data1.name = "data3" … … 1483 1482 window.load_data_list(list=temp_data_list) 1484 1483 except: 1485 # raise1484 # raise 1486 1485 print "error", sys.exc_value 1487 1486 -
src/sas/sasgui/guiframe/gui_manager.py
ra4c2445 rc8e1996 3 3 """ 4 4 ################################################################################ 5 # This software was developed by the University of Tennessee as part of the6 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE)7 # project funded by the US National Science Foundation.5 # This software was developed by the University of Tennessee as part of the 6 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 7 # project funded by the US National Science Foundation. 8 8 # 9 # See the license text in license.txtz9 # See the license text in license.txtz 10 10 # 11 # copyright 2008, University of Tennessee11 # copyright 2008, University of Tennessee 12 12 ################################################################################ 13 13 … … 21 21 import warnings 22 22 import re 23 warnings.simplefilter("ignore")24 23 import logging 25 24 import httplib … … 49 48 from matplotlib import _pylab_helpers 50 49 50 warnings.simplefilter("ignore") 51 51 52 52 53 def get_app_dir(): … … 82 83 return app_path 83 84 85 84 86 def get_user_directory(): 85 87 """ … … 90 92 os.makedirs(userdir) 91 93 return userdir 94 92 95 93 96 def _find_local_config(file, path): … … 113 116 114 117 # GUI always starts from the App folder 115 # os.chdir(PATH_APP)118 # os.chdir(PATH_APP) 116 119 # Read in the local config, which can either be with the main 117 120 # application or in the installation directory … … 128 131 logging.info("found local_config in %s" % PATH_APP) 129 132 130 from sas.sasgui.guiframe.customdir 133 from sas.sasgui.guiframe.customdir import SetupCustom 131 134 c_conf_dir = SetupCustom().setup_dir(PATH_APP) 132 135 custom_config = _find_local_config('custom_config', c_conf_dir) … … 141 144 logging.info("using custom_config from %s" % c_conf_dir) 142 145 143 # read some constants from config146 # read some constants from config 144 147 APPLICATION_STATE_EXTENSION = config.APPLICATION_STATE_EXTENSION 145 148 APPLICATION_NAME = config.__appname__ … … 169 172 # custom open_path 170 173 open_folder = custom_config.DEFAULT_OPEN_FOLDER 171 if open_folder !=None and os.path.isdir(open_folder):174 if open_folder is not None and os.path.isdir(open_folder): 172 175 DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 173 176 else: … … 222 225 CHILD_FRAME = wx.Frame 223 226 227 224 228 class ViewerFrame(PARENT_FRAME): 225 229 """ … … 235 239 Initialize the Frame object 236 240 """ 237 PARENT_FRAME.__init__(self, parent=parent, title=title, pos=pos, size=size) 241 PARENT_FRAME.__init__(self, parent=parent, title=title, 242 pos=pos, size=size) 238 243 # title 239 244 self.title = title … … 256 261 self.path = PATH_APP 257 262 self.application_name = APPLICATION_NAME 258 # #Application manager263 # Application manager 259 264 self._input_file = None 260 265 self.app_manager = None 261 266 self._mgr = None 262 # add current perpsective267 # add current perpsective 263 268 self._current_perspective = None 264 269 self._plotting_plugin = None 265 270 self._data_plugin = None 266 # Menu bar and item271 # Menu bar and item 267 272 self._menubar = None 268 273 self._file_menu = None … … 278 283 self._toolbar_menu = None 279 284 self._save_appl_menu = None 280 # tool bar285 # tool bar 281 286 self._toolbar = None 282 287 # Status bar … … 286 291 # plot duck cleanup option 287 292 self.cleanup_plots = CLEANUP_PLOT 288 # #Find plug-ins293 # Find plug-ins 289 294 # Modify this so that we can specify the directory to look into 290 295 self.plugins = [] 291 # add local plugin296 # add local plugin 292 297 self.plugins += self._get_local_plugins() 293 298 self.plugins += self._find_plugins() 294 # #List of panels299 # List of panels 295 300 self.panels = {} 296 301 # List of plot panels … … 304 309 self.defaultPanel = None 305 310 self.welcome_panel_class = None 306 # panel on focus311 # panel on focus 307 312 self.panel_on_focus = None 308 # control_panel on focus313 # control_panel on focus 309 314 self.cpanel_on_focus = None 310 315 311 316 self.loader = Loader() 312 # data manager317 # data manager 313 318 self.batch_on = False 314 319 from sas.sasgui.guiframe.data_manager import DataManager 315 320 self._data_manager = DataManager() 316 self._data_panel = None #DataPanel(parent=self)321 self._data_panel = None # DataPanel(parent=self) 317 322 if self.panel_on_focus is not None: 318 self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption) 323 self._data_panel.set_panel_on_focus( 324 self.panel_on_focus.window_caption) 319 325 # list of plot panels in schedule to full redraw 320 326 self.schedule = False 321 # self.callback = True327 # self.callback = True 322 328 self._idle_count = 0 323 329 self.schedule_full_draw_list = [] … … 333 339 # Register to status events 334 340 self.Bind(EVT_STATUS, self._on_status_event) 335 # Register add extra data on the same panel event on load341 # Register add extra data on the same panel event on load 336 342 self.Bind(EVT_PANEL_ON_FOCUS, self.set_panel_on_focus) 337 343 self.Bind(EVT_APPEND_BOOKMARK, self.append_bookmark) … … 373 379 # Adjust toolbar height 374 380 toolbar = self.GetToolBar() 375 if toolbar !=None:381 if toolbar is not None: 376 382 _, tb_h = toolbar.GetSizeTuple() 377 383 height -= tb_h … … 386 392 fitpanel = item.fit_panel 387 393 388 if fitpanel !=None:394 if fitpanel is not None: 389 395 for i in range(0, fitpanel.GetPageCount()): 390 396 fitpanel.GetPage(i)._populate_listbox() … … 413 419 """ 414 420 Display value of data into the application grid 415 :param data: dictionary of string and list of items 421 :param data_inputs: dictionary of string and list of items 422 :param details: descriptive string 423 :param file_name: file name 424 :param data_outputs: Data outputs 416 425 """ 417 426 self.batch_frame.set_data(data_inputs=data_inputs, … … 427 436 """ 428 437 path = None 429 if self._default_save_location ==None:438 if self._default_save_location is None: 430 439 self._default_save_location = os.getcwd() 431 440 wildcard = "(*.csv; *.txt)|*.csv; *.txt" … … 469 478 line.strip() 470 479 count = 0 471 if separator ==None:480 if separator is None: 472 481 line.replace('\t', ' ') 473 # found the first line containing the label482 # found the first line containing the label 474 483 col_name_toks = line.split() 475 484 for item in col_name_toks: … … 480 489 elif line.find(separator) != -1: 481 490 if line.count(separator) >= 2: 482 # found the first line containing the label491 # found the first line containing the label 483 492 col_name_toks = line.split(separator) 484 493 for item in col_name_toks: … … 534 543 separator = "," 535 544 fd.write(str(details)) 536 for col_name 545 for col_name in data.keys(): 537 546 fd.write(str(col_name)) 538 547 fd.write(separator) … … 597 606 Set up custom configuration if exists 598 607 """ 599 if custom_config ==None:608 if custom_config is None: 600 609 return 601 610 … … 617 626 Set default starting perspective 618 627 """ 619 if custom_config ==None:628 if custom_config is None: 620 629 return 621 630 for plugin in self.plugins: … … 626 635 frame = plugin.get_frame() 627 636 frame.Show(True) 628 # break637 # break 629 638 else: 630 639 frame = plugin.get_frame() … … 683 692 try: 684 693 flag = self.panel_on_focus.get_save_flag() 685 if self._save_appl_menu !=None:694 if self._save_appl_menu is not None: 686 695 self._save_appl_menu.Enable(flag) 687 696 … … 694 703 self.panel_on_focus is not None: 695 704 self.set_panel_on_focus_helper() 696 # update toolbar705 # update toolbar 697 706 self._update_toolbar_helper() 698 # update edit menu707 # update edit menu 699 708 self.enable_edit_menu() 700 709 except wx._core.PyDeadObjectError: … … 711 720 Send focusing on ID to data explorer 712 721 """ 713 if self._data_panel !=None:722 if self._data_panel is not None: 714 723 self._data_panel.set_panel_on_focus(name) 715 724 … … 720 729 caption = self.panel_on_focus.window_caption 721 730 self.send_focus_to_datapanel(caption) 722 # update combo731 # update combo 723 732 if self.panel_on_focus in self.plot_panels.values(): 724 733 combo = self._data_panel.cb_plotpanel … … 739 748 """ 740 749 cpanel = panel 741 if self._toolbar !=None and cpanel._bookmark_flag:742 for item in 750 if self._toolbar is not None and cpanel._bookmark_flag: 751 for item in self._toolbar.get_bookmark_items(): 743 752 self._toolbar.remove_bookmark_item(item) 744 753 self._toolbar.add_bookmark_default() … … 841 850 field = self.sb.get_msg_position() 842 851 wx.Frame.PushStatusText(self, field=field, 843 string="FIXME - PushStatusText called without text") 852 string= 853 "FIXME - PushStatusText called without text") 844 854 845 855 def add_perspective(self, plugin): … … 866 876 """ 867 877 plugins = [] 868 # import guiframe local plugins869 # check if the style contain guiframe.dataloader878 # import guiframe local plugins 879 # check if the style contain guiframe.dataloader 870 880 style1 = self.__gui_style & GUIFRAME.DATALOADER_ON 871 881 style2 = self.__gui_style & GUIFRAME.PLOTTING_ON 872 882 if style1 == GUIFRAME.DATALOADER_ON: 873 883 try: 874 from sas.sasgui.guiframe.local_perspectives.data_loader import data_loader 884 from sas.sasgui.guiframe.local_perspectives.data_loader \ 885 import data_loader 875 886 self._data_plugin = data_loader.Plugin() 876 887 plugins.append(self._data_plugin) … … 881 892 if style2 == GUIFRAME.PLOTTING_ON: 882 893 try: 883 from sas.sasgui.guiframe.local_perspectives.plotting import plotting 894 from sas.sasgui.guiframe.local_perspectives.plotting \ 895 import plotting 884 896 self._plotting_plugin = plotting.Plugin() 885 897 plugins.append(self._plotting_plugin) … … 907 919 else: 908 920 file_list = [] 909 # #the default panel is the panel is the last plugin added921 # the default panel is the panel is the last plugin added 910 922 for item in file_list: 911 923 toks = os.path.splitext(os.path.basename(item)) … … 914 926 if toks[1] == '.py' or toks[1] == '': 915 927 name = toks[0] 916 # check the validity of the module name parsed917 # before trying to import it928 # check the validity of the module name parsed 929 # before trying to import it 918 930 if name is None or name.strip() == '': 919 931 continue … … 941 953 logging.error(msg) 942 954 finally: 943 if not file ==None:955 if file is not None: 944 956 file.close() 945 957 except: … … 956 968 """ 957 969 self._window_width, self._window_height = self.get_client_size() 958 # #Default size970 # Default size 959 971 if DATAPANEL_WIDTH < 0: 960 972 panel_width = int(self._window_width * 0.25) … … 962 974 panel_width = DATAPANEL_WIDTH 963 975 panel_height = int(self._window_height) 964 if self._data_panel is not None 976 if self._data_panel is not None and (p == self._data_panel): 965 977 return panel_width, panel_height 966 978 if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: … … 994 1006 if self.welcome_panel_class is not None: 995 1007 welcome_panel = MDIFrame(self, None, 'None', (100, 200)) 996 self.defaultPanel = self.welcome_panel_class(welcome_panel, -1, style=wx.RAISED_BORDER) 1008 self.defaultPanel = self.welcome_panel_class(welcome_panel, -1, 1009 style=wx.RAISED_BORDER) 997 1010 welcome_panel.set_panel(self.defaultPanel) 998 1011 self.defaultPanel.set_frame(welcome_panel) … … 1010 1023 frame.SetPosition((0, mac_pos_y + size_t_bar)) 1011 1024 frame.Show(True) 1012 # add data panel1025 # add data panel 1013 1026 win = MDIFrame(self, None, 'None', (100, 200)) 1014 1027 data_panel = DataPanel(parent=win, id=-1) … … 1018 1031 d_panel_width, h = self._get_panels_size(self._data_panel) 1019 1032 win.SetSize((d_panel_width, h)) 1020 is_visible = self.__gui_style & GUIFRAME.MANAGER_ON == GUIFRAME.MANAGER_ON 1033 is_visible = self.__gui_style & \ 1034 GUIFRAME.MANAGER_ON == GUIFRAME.MANAGER_ON 1021 1035 if IS_WIN: 1022 1036 win.SetPosition((0, 0)) … … 1064 1078 Update the data. 1065 1079 """ 1066 prev_id, data_state = self._data_manager.update_data( \1080 prev_id, data_state = self._data_manager.update_data( 1067 1081 prev_data=prev_data, new_data=new_data) 1068 1082 … … 1115 1129 self._current_perspective.delete_data(data) 1116 1130 1117 1118 1131 def get_context_menu(self, plotpanel=None): 1119 1132 """ … … 1139 1152 menu_list = [] 1140 1153 item = self._current_perspective 1141 if item !=None:1154 if item is not None: 1142 1155 menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 1143 1156 return menu_list … … 1158 1171 self.cpanel_on_focus.SetFocus() 1159 1172 1160 1161 1173 def popup_panel(self, p): 1162 1174 """ … … 1170 1182 ID = wx.NewId() 1171 1183 self.panels[str(ID)] = p 1172 # #Check and set the size1184 # Check and set the size 1173 1185 if PLOPANEL_WIDTH < 0: 1174 1186 p_panel_width = int(self._window_width * 0.45) … … 1209 1221 # Register for showing/hiding the panel 1210 1222 wx.EVT_MENU(self, ID, self.on_view) 1211 if p not in self.plot_panels.values() and p.group_id !=None:1223 if p not in self.plot_panels.values() and p.group_id is not None: 1212 1224 self.plot_panels[ID] = p 1213 1225 if len(self.plot_panels) == 1: … … 1215 1227 self.set_panel_on_focus(None) 1216 1228 if self._data_panel is not None and \ 1217 self._plotting_plugin is not None:1229 self._plotting_plugin is not None: 1218 1230 ind = self._data_panel.cb_plotpanel.FindString('None') 1219 1231 if ind != wx.NOT_FOUND: … … 1258 1270 panel_name = 'No Panel on Focus' 1259 1271 c_panel = self.cpanel_on_focus 1260 if self._toolbar is 1272 if self._toolbar is None: 1261 1273 return 1262 1274 if c_panel is not None: … … 1303 1315 """ 1304 1316 if self._menubar is None or self._current_perspective is None \ 1305 or self._menubar.GetMenuCount() == 0:1317 or self._menubar.GetMenuCount() == 0: 1306 1318 return 1307 # replace or add a new menu for the current plugin1319 # replace or add a new menu for the current plugin 1308 1320 pos = self._menubar.FindMenu(str(self._applications_menu_name)) 1309 1321 if pos == -1 and self._applications_menu_pos > 0: … … 1325 1337 for (menu, name) in menu_list: 1326 1338 if self._applications_menu_pos == -1: 1327 # Find the Analysis position and insert just after it if possible1339 # Find the Analysis position and insert just after it 1328 1340 analysis_pos = self._menubar.FindMenu("Analysis") 1329 1341 if analysis_pos == -1: … … 1334 1346 self._applications_menu_pos = analysis_pos + 1 1335 1347 else: 1336 self._menubar.Insert(self._applications_menu_pos, menu, name) 1348 self._menubar.Insert(self._applications_menu_pos, 1349 menu, name) 1337 1350 self._applications_menu_name = name 1338 1351 … … 1362 1375 if config._do_acknowledge: 1363 1376 wx_id = wx.NewId() 1364 self._help_menu.Append(wx_id, '&Acknowledge', 'Acknowledging SasView') 1377 self._help_menu.Append(wx_id, '&Acknowledge', 1378 'Acknowledging SasView') 1365 1379 wx.EVT_MENU(self, wx_id, self._onAcknowledge) 1366 1380 … … 1379 1393 wx_id = wx.NewId() 1380 1394 self._help_menu.Append(wx_id, '&Check for update', 1381 'Check for the latest version of %s' % config.__appname__) 1395 'Check for the latest version of %s' % 1396 config.__appname__) 1382 1397 wx.EVT_MENU(self, wx_id, self._check_update) 1383 1398 self._menubar.Append(self._help_menu, '&Help') … … 1400 1415 wx_id = wx.NewId() 1401 1416 self._data_panel_menu = self._view_menu.Append(wx_id, 1402 '&Show Data Explorer', '') 1417 '&Show Data Explorer', 1418 '') 1403 1419 wx.EVT_MENU(self, wx_id, self.show_data_panel) 1404 1420 if style == GUIFRAME.MANAGER_ON: … … 1411 1427 style1 = self.__gui_style & GUIFRAME.TOOLBAR_ON 1412 1428 if style1 == GUIFRAME.TOOLBAR_ON: 1413 self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', '') 1429 self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', 1430 '') 1414 1431 else: 1415 self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', '') 1432 self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', 1433 '') 1416 1434 wx.EVT_MENU(self, wx_id, self._on_toggle_toolbar) 1417 1435 1418 if custom_config !=None:1436 if custom_config is not None: 1419 1437 self._view_menu.AppendSeparator() 1420 1438 wx_id = wx.NewId() … … 1427 1445 wx_id = wx.NewId() 1428 1446 self._view_menu.AppendSeparator() 1429 self._view_menu.Append(wx_id, 'Category Manager', 'Edit model categories') 1447 self._view_menu.Append(wx_id, 'Category Manager', 1448 'Edit model categories') 1430 1449 wx.EVT_MENU(self, wx_id, self._on_category_manager) 1431 1450 … … 1440 1459 self.batch_frame.Show(True) 1441 1460 1442 def 1461 def on_category_panel(self, event): 1443 1462 """ 1444 1463 On cat panel … … 1459 1478 """ 1460 1479 from sas.sasgui.guiframe.startup_configuration \ 1461 import StartupConfiguration as ConfDialog1480 import StartupConfiguration as ConfDialog 1462 1481 1463 1482 dialog = ConfDialog(parent=self, gui=self.__gui_style) … … 1466 1485 dialog.write_custom_config() 1467 1486 # post event for info 1468 wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", info='info')) 1487 wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", 1488 info='info')) 1469 1489 dialog.Destroy() 1470 1490 … … 1485 1505 id = wx.NewId() 1486 1506 if plug.use_data(): 1487 self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, \ 1488 "Switch to analysis: %s" % plug.sub_menu) 1507 self._applications_menu.InsertCheckItem(pos, id, 1508 plug.sub_menu, 1509 "Switch to analysis: %s" % plug.sub_menu) 1489 1510 plug_data_count = True 1490 1511 pos += 1 1491 1512 else: 1492 1513 plug_no_data_count = True 1493 self._applications_menu.AppendCheckItem(id, plug.sub_menu, \ 1514 self._applications_menu.AppendCheckItem(id, 1515 plug.sub_menu, 1494 1516 "Switch to analysis: %s" % plug.sub_menu) 1495 1517 wx.EVT_MENU(self, id, plug.on_perspective) … … 1497 1519 if not plug_data_count or not plug_no_data_count: 1498 1520 self._applications_menu.RemoveItem(separator) 1499 # Windows introduces a "Window" menu item during the layout process1500 # somehow. We want it to be next to the last item with Help as1501 # last. However Analysis gets stuck after Window in normal ordering1502 # so force it to be next after the Tools menu item. Should we add1503 # another menu item will need to check if this is still where we1504 # want Analysis. This is NOT an issue on the Mac which does not1505 # have the extra Window menu item.1521 # Windows introduces a "Window" menu item during the layout process 1522 # somehow. We want it to be next to the last item with Help as 1523 # last. However Analysis gets stuck after Window in normal ordering 1524 # so force it to be next after the Tools menu item. Should we add 1525 # another menu item will need to check if this is still where we 1526 # want Analysis. This is NOT an issue on the Mac which does not 1527 # have the extra Window menu item. 1506 1528 # March 2016 Code Camp -- PDB 1507 1529 Tools_pos = self._menubar.FindMenu("Tools") 1508 self._menubar.Insert(Tools_pos+1, self._applications_menu,1530 self._menubar.Insert(Tools_pos+1, self._applications_menu, 1509 1531 '&Analysis') 1510 1532 self._check_applications_menu() … … 1527 1549 wx_id = wx.NewId() 1528 1550 hint_load_file = "read all analysis states saved previously" 1529 self._save_appl_menu = self._file_menu.Append(wx_id, '&Open Project', hint_load_file) 1551 self._save_appl_menu = self._file_menu.Append(wx_id, 1552 '&Open Project', 1553 hint_load_file) 1530 1554 wx.EVT_MENU(self, wx_id, self._on_open_state_project) 1531 1555 … … 1536 1560 wx_id = wx.NewId() 1537 1561 self._save_appl_menu = self._file_menu.Append(wx_id, 1538 '&Open Analysis', hint_load_file) 1562 '&Open Analysis', 1563 hint_load_file) 1539 1564 wx.EVT_MENU(self, wx_id, self._on_open_state_application) 1540 1565 if OPEN_SAVE_MENU: … … 1546 1571 if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 1547 1572 wx_id = wx.NewId() 1548 self._save_appl_menu = self._file_menu.Append(wx_id, \ 1549 '&Save Analysis', 'Save state of the current active analysis panel') 1573 txt = '&Save Analysis' 1574 txt2 = 'Save state of the current active analysis panel' 1575 self._save_appl_menu = self._file_menu.Append(wx_id, txt, txt2) 1550 1576 wx.EVT_MENU(self, wx_id, self._on_save_application) 1551 1577 if not sys.platform == 'darwin': … … 1589 1615 1590 1616 self._edit_menu_copyas = wx.Menu() 1591 #Sub menu for Copy As... 1592 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 'Copy current tab to Excel', 1617 # Sub menu for Copy As... 1618 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 1619 'Copy current tab to Excel', 1593 1620 'Copy parameter values in tabular format') 1594 1621 wx.EVT_MENU(self, GUIFRAME_ID.COPYEX_ID, self.on_copy_panel) 1595 1622 1596 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 'Copy current tab to LaTeX', 1623 self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 1624 'Copy current tab to LaTeX', 1597 1625 'Copy parameter values in tabular format') 1598 1626 wx.EVT_MENU(self, GUIFRAME_ID.COPYLAT_ID, self.on_copy_panel) 1599 1600 1627 1601 1628 self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...', … … 1620 1647 Return the gui style 1621 1648 """ 1622 return 1649 return self.__gui_style 1623 1650 1624 1651 def _add_menu_data(self): … … 1675 1702 return 1676 1703 frame = self.panels['default'].get_frame() 1677 if frame ==None:1704 if frame is None: 1678 1705 return 1679 1706 # Show default panel … … 1708 1735 self.schedule_full_draw_list.remove(panel) 1709 1736 1710 # delete uid number not str(uid)1737 # delete uid number not str(uid) 1711 1738 if ID in self.plot_panels.keys(): 1712 1739 del self.plot_panels[ID] … … 1734 1761 return 1735 1762 1736 # reading a state file1763 # reading a state file 1737 1764 for plug in self.plugins: 1738 1765 reader, ext = plug.get_extensions() 1739 1766 if reader is not None: 1740 # read the state of the single plugin1767 # read the state of the single plugin 1741 1768 if extension == ext: 1742 1769 reader.read(path) … … 1749 1776 msg += "\n(%s)" % sys.exc_value 1750 1777 wx.PostEvent(self, StatusEvent(status=msg, 1751 info="error", type="stop")) 1778 info="error", 1779 type="stop")) 1752 1780 return 1753 1781 … … 1788 1816 basename = os.path.basename(path) 1789 1817 if APPLICATION_STATE_EXTENSION is not None \ 1790 and basename.endswith(APPLICATION_STATE_EXTENSION):1818 and basename.endswith(APPLICATION_STATE_EXTENSION): 1791 1819 if is_project: 1792 1820 for ID in self.plot_panels.keys(): … … 1858 1886 """ 1859 1887 path = None 1860 if self._default_save_location ==None:1888 if self._default_save_location is None: 1861 1889 self._default_save_location = os.getcwd() 1862 1890 wx.PostEvent(self, StatusEvent(status="Loading Analysis file...")) … … 1892 1920 break 1893 1921 # Found the extension 1894 if ind !=None:1922 if ind is not None: 1895 1923 plug_wlist.remove(ind) 1896 1924 plug_wlist.insert(0, ind) … … 1910 1938 """ 1911 1939 path = None 1912 if self._default_save_location ==None:1940 if self._default_save_location is None: 1913 1941 self._default_save_location = os.getcwd() 1914 1942 msg = "This operation will set remove all data, plots and analyses from" 1915 1943 msg += " SasView before loading the project. Do you wish to continue?" 1916 self._data_panel.selection_cbox.SetValue('Select all Data') 1917 self._data_panel._on_selection_type(None) 1918 for _, theory_dict in self._data_panel.list_cb_theory.iteritems(): 1919 for key, value in theory_dict.iteritems(): 1920 item, _, _ = value 1921 item.Check(True) 1922 if not self._data_panel.on_remove(None, msg): 1944 msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK | wx.CANCEL) 1945 if msg_box.ShowModal() == wx.ID_OK: 1946 self._data_panel.selection_cbox.SetValue('Select all Data') 1947 self._data_panel._on_selection_type(None) 1948 for _, theory_dict in self._data_panel.list_cb_theory.iteritems(): 1949 for key, value in theory_dict.iteritems(): 1950 item, _, _ = value 1951 item.Check(True) 1952 self._data_panel.on_remove(None, False) 1953 1923 1954 wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 1924 dlg = wx.FileDialog(self, 1925 "Choose a file", 1926 self._default_save_location, "", 1927 APPLICATION_WLIST) 1955 dlg = wx.FileDialog(self, "Choose a file", 1956 self._default_save_location, "", 1957 APPLICATION_WLIST) 1928 1958 if dlg.ShowModal() == wx.ID_OK: 1929 1959 path = dlg.GetPath() … … 1969 1999 save the state of the SasView as *.svs 1970 2000 """ 1971 if self._current_perspective is 2001 if self._current_perspective is None: 1972 2002 return 1973 2003 wx.PostEvent(self, StatusEvent(status="Saving Project file...")) … … 1997 2027 extens = APPLICATION_STATE_EXTENSION 1998 2028 fName = os.path.splitext(path)[0] + extens 1999 if doc !=None:2029 if doc is not None: 2000 2030 fd = open(fName, 'w') 2001 2031 fd.write(doc.toprettyxml()) … … 2029 2059 if data is not None: 2030 2060 new_doc = reader.write_toXML(data, state) 2031 if doc !=None and hasattr(doc, "firstChild"):2061 if doc is not None and hasattr(doc, "firstChild"): 2032 2062 child = new_doc.firstChild.firstChild 2033 2063 doc.firstChild.appendChild(child) … … 2040 2070 if data is not None: 2041 2071 new_doc = reader.write_toXML(data, state) 2042 if doc !=None and hasattr(doc, "firstChild"):2072 if doc is not None and hasattr(doc, "firstChild"): 2043 2073 child = new_doc.firstChild.firstChild 2044 2074 doc.firstChild.appendChild(child) … … 2095 2125 except: 2096 2126 logging.info("Failed to connect to www.sasview.org") 2097 self._process_version(version_info, standalone=event ==None)2127 self._process_version(version_info, standalone=event is None) 2098 2128 2099 2129 def _process_version(self, version_info, standalone=True): … … 2184 2214 try: 2185 2215 # Try an alternate method 2186 logging.error("Could not open the tutorial pdf, trying xhtml2pdf") 2216 logging.error( 2217 "Could not open the tutorial pdf, trying xhtml2pdf") 2187 2218 from xhtml2pdf import pisa 2188 2219 pisa.startViewer(path) 2189 2220 except: 2190 logging.error("Could not open the tutorial pdf with xhtml2pdf") 2221 logging.error( 2222 "Could not open the tutorial pdf with xhtml2pdf") 2191 2223 msg = "This feature requires 'PDF Viewer'\n" 2192 2224 wx.MessageBox(msg, 'Error') … … 2198 2230 try: 2199 2231 # Try an alternate method 2200 logging.error("Could not open the tutorial pdf, trying xhtml2pdf") 2232 logging.error( 2233 "Could not open the tutorial pdf, trying xhtml2pdf") 2201 2234 from xhtml2pdf import pisa 2202 2235 pisa.startViewer(path) 2203 2236 except: 2204 logging.error("Could not open the tutorial pdf with xhtml2pdf") 2205 msg = "This feature requires the 'Preview' application\n" 2237 logging.error( 2238 "Could not open the tutorial pdf with xhtml2pdf") 2239 msg = "This feature requires the Preview application\n" 2206 2240 wx.MessageBox(msg, 'Error') 2207 2241 … … 2218 2252 from documentation_window import DocumentationWindow 2219 2253 _TreeLocation = "user/user.html" 2220 DocumentationWindow(self, -1, _TreeLocation, "", "SasView Documentation") 2254 DocumentationWindow(self, -1, _TreeLocation, "", 2255 "SasView Documentation") 2221 2256 2222 2257 def set_manager(self, manager): … … 2252 2287 if self.panels[item].ALWAYS_ON: 2253 2288 continue 2254 if self.panels[item] ==None:2289 if self.panels[item] is None: 2255 2290 continue 2256 2291 if self.panels[item].window_name in panels: … … 2261 2296 # always show the data panel if enable 2262 2297 style = self.__gui_style & GUIFRAME.MANAGER_ON 2263 if (style == GUIFRAME.MANAGER_ON) and self.panels[item] == self._data_panel: 2298 if (style == GUIFRAME.MANAGER_ON) \ 2299 and self.panels[item] == self._data_panel: 2264 2300 if 'data_panel' in self.panels.keys(): 2265 2301 frame = self.panels['data_panel'].get_frame() 2266 if frame ==None:2302 if frame is None: 2267 2303 continue 2268 2304 flag = frame.IsShown() … … 2270 2306 else: 2271 2307 frame = self.panels[item].get_frame() 2272 if frame ==None:2308 if frame is None: 2273 2309 continue 2274 2310 … … 2280 2316 show the data panel 2281 2317 """ 2282 if self._data_panel_menu ==None:2318 if self._data_panel_menu is None: 2283 2319 return 2284 2320 label = self._data_panel_menu.GetText() … … 2310 2346 :param data_list: dictionary of data's ID and value Data 2311 2347 """ 2312 # Store data into manager2348 # Store data into manager 2313 2349 self.add_data_helper(data_list) 2314 2350 # set data in the data panel … … 2316 2352 data_state = self._data_manager.get_data_state(data_list.keys()) 2317 2353 self._data_panel.load_data_list(data_state) 2318 # if the data panel is shown wait for the user to press a button2319 # to send data to the current perspective. if the panel is not2320 # show automatically send the data to the current perspective2354 # if the data panel is shown wait for the user to press a button 2355 # to send data to the current perspective. if the panel is not 2356 # show automatically send the data to the current perspective 2321 2357 style = self.__gui_style & GUIFRAME.MANAGER_ON 2322 2358 if style == GUIFRAME.MANAGER_ON: 2323 # wait for button press from the data panel to set_data2359 # wait for button press from the data panel to set_data 2324 2360 if self._data_panel is not None: 2325 2361 self._data_panel.frame.Show(True) 2326 2362 else: 2327 # automatically send that to the current perspective2363 # automatically send that to the current perspective 2328 2364 self.set_data(data_id=data_list.keys()) 2329 2365 … … 2386 2422 info='warning')) 2387 2423 else: 2388 # if not append then new plot2424 # if not append then new plot 2389 2425 from sas.sasgui.guiframe.dataFitting import Data2D 2390 2426 if issubclass(Data2D, new_plot.__class__): 2391 # for 2 D always plot in a separated new plot2427 # for 2 D always plot in a separated new plot 2392 2428 new_plot.group_id = wx.NewId() 2393 2429 else: … … 2420 2456 group_id=group_id, 2421 2457 action='remove')) 2422 # remove res plot: Todo: improve2458 # remove res plot: Todo: improve 2423 2459 wx.CallAfter(self._remove_res_plot, new_plot.id) 2424 2460 self._data_manager.delete_data(data_id=data_id, … … 2462 2498 mypath = os.path.basename(path) 2463 2499 2464 # Instantiate a loader2500 # Instantiate a loader 2465 2501 loader = Loader() 2466 2502 ext_format = ".txt" … … 2482 2518 dlg.Destroy() 2483 2519 2484 2485 2520 def _onsaveTXT(self, data, path): 2486 2521 """ … … 2489 2524 .. todo:: Refactor and remove this method. See 'TODO' in _onSave. 2490 2525 """ 2491 if not path ==None:2526 if path is not None: 2492 2527 out = open(path, 'w') 2493 2528 has_errors = True 2494 if data.dy ==None or data.dy == []:2529 if data.dy is None or data.dy == []: 2495 2530 has_errors = False 2496 2531 # Sanity check … … 2502 2537 has_errors = False 2503 2538 if has_errors: 2504 if data.dx !=None and data.dx != []:2539 if data.dx is not None and data.dx != []: 2505 2540 out.write("<X> <Y> <dY> <dX>\n") 2506 2541 else: … … 2511 2546 for i in range(len(data.x)): 2512 2547 if has_errors: 2513 if data.dx !=None and data.dx != []:2514 if data.dx[i] !=None:2548 if data.dx is not None and data.dx != []: 2549 if data.dx[i] is not None: 2515 2550 out.write("%g %g %g %g\n" % (data.x[i], 2516 2551 data.y[i], … … 2543 2578 info="error")) 2544 2579 raise ValueError, msg 2545 # #text = str(data)2580 # text = str(data) 2546 2581 text = data.__str__() 2547 2582 text += 'Data Min Max:\n' 2548 2583 text += 'X_min = %s: X_max = %s\n' % (xmin, max(data.x)) 2549 2584 text += 'Y_min = %s: Y_max = %s\n' % (ymin, max(data.y)) 2550 if data.dy !=None:2585 if data.dy is not None: 2551 2586 text += 'dY_min = %s: dY_max = %s\n' % (min(data.dy), max(data.dy)) 2552 2587 text += '\nData Points:\n' 2553 2588 x_st = "X" 2554 2589 for index in range(len(data.x)): 2555 if data.dy !=None and len(data.dy) > index:2590 if data.dy is not None and len(data.dy) > index: 2556 2591 dy_val = data.dy[index] 2557 2592 else: 2558 2593 dy_val = 0.0 2559 if data.dx !=None and len(data.dx) > index:2594 if data.dx is not None and len(data.dx) > index: 2560 2595 dx_val = data.dx[index] 2561 2596 else: 2562 2597 dx_val = 0.0 2563 if data.dxl !=None and len(data.dxl) > index:2598 if data.dxl is not None and len(data.dxl) > index: 2564 2599 if index == 0: 2565 2600 x_st = "Xl" 2566 2601 dx_val = data.dxl[index] 2567 elif data.dxw !=None and len(data.dxw) > index:2602 elif data.dxw is not None and len(data.dxw) > index: 2568 2603 if index == 0: 2569 2604 x_st = "Xw" … … 2605 2640 mypath = os.path.basename(path) 2606 2641 2607 # Instantiate a loader2642 # Instantiate a loader 2608 2643 loader = Loader() 2609 2644 … … 2642 2677 y_val = data.qy_data[index] 2643 2678 i_val = data.data[index] 2644 if data.err_data !=None:2679 if data.err_data is not None: 2645 2680 di_val = data.err_data[index] 2646 if data.dqx_data !=None:2681 if data.dqx_data is not None: 2647 2682 dx_val = data.dqx_data[index] 2648 if data.dqy_data !=None:2683 if data.dqy_data is not None: 2649 2684 dy_val = data.dqy_data[index] 2650 2685 … … 2681 2716 for name in self._current_perspective.get_perspective(): 2682 2717 frame = panel.get_frame() 2683 if frame !=None:2718 if frame is not None: 2684 2719 if name == panel.window_name: 2685 2720 panel.on_set_focus(event=None) … … 2691 2726 self._data_panel.set_active_perspective(name) 2692 2727 self._check_applications_menu() 2693 # Set the SasView title2728 # Set the SasView title 2694 2729 self._set_title_name(name) 2695 2730 … … 2723 2758 """ 2724 2759 2725 if self.panel_on_focus not in self._plotting_plugin.plot_panels.values(): 2760 if self.panel_on_focus \ 2761 not in self._plotting_plugin.plot_panels.values(): 2726 2762 return 2763 check = "Theory1D" 2727 2764 is_theory = len(self.panel_on_focus.plots) <= 1 and \ 2728 self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D"2765 self.panel_on_focus.plots.values()[0].__class__.__name__ == check 2729 2766 2730 2767 is_data2d = hasattr(new_plot, 'data') … … 2734 2771 has_meta_data = hasattr(new_plot, 'meta_data') 2735 2772 2736 # disable_add_data if the data is being recovered from a saved state file.2773 # disable_add_data if the data is being recovered from a saved state 2737 2774 is_state_data = False 2738 2775 if has_meta_data: 2739 2776 if 'invstate' in new_plot.meta_data: 2740 2777 is_state_data = True 2741 if 2778 if 'prstate' in new_plot.meta_data: 2742 2779 is_state_data = True 2743 if 2780 if 'fitstate' in new_plot.meta_data: 2744 2781 is_state_data = True 2745 2782 2746 return is_data1d and not is_data2d and not is_theory and not is_state_data 2783 return is_data1d and not is_data2d and not is_theory \ 2784 and not is_state_data 2747 2785 2748 2786 def check_multimode(self, perspective=None): … … 2750 2788 Check the perspective have batch mode capablitity 2751 2789 """ 2752 if perspective == None or self._data_panel ==None:2790 if perspective is None or self._data_panel is None: 2753 2791 return 2754 2792 flag = perspective.get_batch_capable() … … 2777 2815 self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag) 2778 2816 2779 # Copy menu2817 # Copy menu 2780 2818 flag = self.cpanel_on_focus.get_copy_flag() 2781 2819 self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYEX_ID, flag) … … 2908 2946 if data_panel.cb_plotpanel is not None: 2909 2947 # Check if any panel has the same caption 2910 has_newstring = data_panel.cb_plotpanel.FindString \2911 (str(new_caption))2948 has_newstring = data_panel.cb_plotpanel.FindString( 2949 str(new_caption)) 2912 2950 caption = new_caption 2913 2951 if has_newstring != wx.NOT_FOUND: … … 3026 3064 drag 3027 3065 """ 3028 # Not implemeted3066 # Not implemeted 3029 3067 3030 3068 def enable_reset(self): … … 3039 3077 """ 3040 3078 size_y = 0 3041 if self.GetToolBar() !=None and self.GetToolBar().IsShown():3079 if self.GetToolBar() is not None and self.GetToolBar().IsShown(): 3042 3080 if not IS_LINUX: 3043 3081 _, size_y = self.GetToolBar().GetSizeTuple() … … 3054 3092 # append this panel in the schedule list if not in yet 3055 3093 if func == 'append': 3056 if not panelin self.schedule_full_draw_list:3094 if panel not in self.schedule_full_draw_list: 3057 3095 self.schedule_full_draw_list.append(panel) 3058 3096 # remove this panel from schedule list … … 3074 3112 3075 3113 count = len(self.schedule_full_draw_list) 3076 # if not self.schedule:3114 # if not self.schedule: 3077 3115 if count < 1: 3078 3116 self.set_schedule(False) … … 3089 3127 if ind == count: 3090 3128 return 3091 #Simple redraw only for a panel shown 3129 # Simple redraw only for a panel shown 3130 3092 3131 def f_draw(panel): 3093 3132 """ … … 3102 3141 # draw if possible 3103 3142 panel.set_resizing(False) 3104 # panel.Show(True)3143 # panel.Show(True) 3105 3144 panel.draw_plot() 3106 3145 # Check if the panel is not shown … … 3137 3176 Set focus on a plot panel 3138 3177 """ 3139 if panel ==None:3178 if panel is None: 3140 3179 return 3141 # self.set_plot_unfocus()3180 # self.set_plot_unfocus() 3142 3181 panel.on_set_focus(None) 3143 3182 # set focusing panel … … 3172 3211 try: 3173 3212 # check if it is time to redraw 3174 if self.GetCapture() ==None:3213 if self.GetCapture() is None: 3175 3214 # Draw plot, changes resizing too 3176 3215 self.full_draw() … … 3180 3219 # restart idle 3181 3220 self._redraw_idle(*args, **kwargs) 3182 3183 3221 3184 3222 def _redraw_idle(self, *args, **kwargs): … … 3195 3233 the GUI manager 3196 3234 """ 3197 # #Internal nickname for the window, used by the AUI manager3235 # Internal nickname for the window, used by the AUI manager 3198 3236 window_name = "default" 3199 # #Name to appear on the window title bar3237 # Name to appear on the window title bar 3200 3238 window_caption = "Welcome panel" 3201 # #Flag to tell the AUI manager to put this panel in the center pane3239 # Flag to tell the AUI manager to put this panel in the center pane 3202 3240 CENTER_PANE = True 3241 3203 3242 def __init__(self, parent, *args, **kwds): 3204 3243 wx.Panel.__init__(self, parent, *args, **kwds) 3205 3244 PanelBase.__init__(self, parent) 3206 3207 3245 3208 3246 … … 3236 3274 try: 3237 3275 if os.path.isfile(SPLASH_SCREEN_PATH): 3238 self.s_screen = self.display_splash_screen(parent=self.frame, 3239 path=SPLASH_SCREEN_PATH) 3276 self.s_screen = \ 3277 self.display_splash_screen(parent=self.frame, 3278 path=SPLASH_SCREEN_PATH) 3240 3279 else: 3241 3280 self.frame.Show() … … 3300 3339 os.remove(file_path) 3301 3340 except: 3302 logging.error("gui_manager.clean_plugin_models:\n %s" \3341 logging.error("gui_manager.clean_plugin_models:\n %s" 3303 3342 % sys.exc_value) 3304 3343 … … 3314 3353 Build the GUI 3315 3354 """ 3316 # try to load file at the start3355 # try to load file at the start 3317 3356 self.open_file() 3318 3357 self.frame.build_gui() … … 3390 3429 # Return the suggested position and size for the application frame. 3391 3430 return (posX, posY), (customWidth, customHeight), is_maximized 3392 3393 3431 3394 3432 def display_splash_screen(self, parent, … … 3427 3465 return s_screen 3428 3466 3429 3430 3467 def on_close_splash_screen(self, event): 3431 3468 """ … … 3447 3484 """ 3448 3485 # Initialize the Frame object 3449 CHILD_FRAME.__init__(self, parent=parent, id=wx.ID_ANY, title=title, size=size) 3486 CHILD_FRAME.__init__(self, parent=parent, id=wx.ID_ANY, 3487 title=title, size=size) 3450 3488 self.parent = parent 3451 3489 self.name = "Untitled" 3452 3490 self.batch_on = self.parent.batch_on 3453 3491 self.panel = panel 3454 if panel !=None:3492 if panel is not None: 3455 3493 self.set_panel(panel) 3456 3494 self.Show(False) -
src/sas/sasgui/perspectives/fitting/basepage.py
r313c5c9 rc8e1996 19 19 20 20 from sas.sasgui.guiframe.panel_base import PanelBase 21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList, check_int 21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList, \ 22 check_int 22 23 from sas.sasgui.guiframe.events import PanelOnFocusEvent 23 24 from sas.sasgui.guiframe.events import StatusEvent … … 42 43 _QMAX_DEFAULT = 0.5 43 44 _NPTS_DEFAULT = 50 44 # Control panel width45 # Control panel width 45 46 if sys.platform.count("win32") > 0: 46 47 PANEL_WIDTH = 450 … … 57 58 This class provide general structure of fitpanel page 58 59 """ 59 # #Internal name for the AUI manager60 # Internal name for the AUI manager 60 61 window_name = "Fit Page" 61 # #Title to appear on top of the window62 # Title to appear on top of the window 62 63 window_caption = "Fit Page " 63 64 … … 75 76 PanelBase.__init__(self, parent) 76 77 self.SetupScrolling() 77 # Set window's font size78 # Set window's font size 78 79 self.SetWindowVariant(variant=FONT_VARIANT) 79 80 self.SetBackgroundColour(color) 80 81 81 82 self._ids = iter(self._id_pool) 82 # #parent of the page83 # parent of the page 83 84 self.parent = parent 84 # #manager is the fitting plugin85 # #owner of the page (fitting plugin)85 # manager is the fitting plugin 86 # owner of the page (fitting plugin) 86 87 self.event_owner = None 87 # #current model88 # current model 88 89 self.model = None 89 90 self.m_name = None 90 91 self.index_model = None 91 92 self.panel = None 92 # #data93 # data 93 94 self.data = None 94 # list of available data95 # list of available data 95 96 self.data_list = [] 96 97 self.mask = None 97 98 self.uid = wx.NewId() 98 99 self.graph_id = None 99 # Q range for data set100 # Q range for data set 100 101 self.qmin_data_set = numpy.inf 101 102 self.qmax_data_set = None 102 103 self.npts_data_set = 0 103 # #Q range104 # Q range 104 105 self.qmin = None 105 106 self.qmax = None … … 107 108 self.qmin_x = _QMIN_DEFAULT 108 109 self.npts_x = _NPTS_DEFAULT 109 # #total number of point: float110 # total number of point: float 110 111 self.npts = None 111 112 self.num_points = None 112 # #smear default113 # smear default 113 114 self.current_smearer = None 114 # #2D smear accuracy default115 # 2D smear accuracy default 115 116 self.smear2d_accuracy = 'Low' 116 # #slit smear:117 # slit smear: 117 118 self.dxl = None 118 119 self.dxw = None 119 # #pinhole smear120 # pinhole smear 120 121 self.dx_min = None 121 122 self.dx_max = None 122 # #semar attrbs123 # smear attrbs 123 124 self.enable_smearer = None 124 125 self.disable_smearer = None 125 126 self.pinhole_smearer = None 126 127 self.slit_smearer = None 127 # #weigthattrbs128 # weight attrbs 128 129 self.dI_noweight = None 129 130 self.dI_didata = None 130 131 self.dI_sqrdata = None 131 132 self.dI_idata = None 132 # #other attrbs133 # other attrbs 133 134 self.dq_l = None 134 135 self.dq_r = None … … 149 150 self.disp_cb_dict = {} 150 151 151 # self.state = PageState(parent=parent)152 # #dictionary containing list of models152 # self.state = PageState(parent=parent) 153 # dictionary containing list of models 153 154 self.model_list_box = {} 154 155 155 # #Data member to store the dispersion object created156 # Data member to store the dispersion object created 156 157 self._disp_obj_dict = {} 157 # #selected parameters to apply dispersion158 # selected parameters to apply dispersion 158 159 self.disp_cb_dict = {} 159 # #smearer object160 # smearer object 160 161 self.enable2D = False 161 162 self._has_magnetic = False … … 165 166 self.structurebox = None 166 167 self.categorybox = None 167 # #list of model parameters. each item must have same length168 # #each item related to a given parameters169 # #[cb state, name, value, "+/-", error of fit, min, max , units]168 # list of model parameters. each item must have same length 169 # each item related to a given parameters 170 # [cb state, name, value, "+/-", error of fit, min, max , units] 170 171 self.parameters = [] 171 172 # non-fittable parameter whose value is astring 172 173 self.str_parameters = [] 173 # #list of parameters to fit , must be like self.parameters174 # list of parameters to fit , must be like self.parameters 174 175 self.param_toFit = [] 175 # #list of looking like parameters but with non fittable parameters info176 # list of looking like parameters but with non fittable parameters info 176 177 self.fixed_param = [] 177 # #list of looking like parameters but with fittable parameters info178 # list of looking like parameters but with fittable parameters info 178 179 self.fittable_param = [] 179 # #list of dispersion parameters180 # list of dispersion parameters 180 181 self.disp_list = [] 181 182 self.disp_name = "" 182 183 183 # #list of orientation parameters184 # list of orientation parameters 184 185 self.orientation_params = [] 185 186 self.orientation_params_disp = [] … … 188 189 # and this - commenting out on 4/8/2014 by PDB. Remove once clear 189 190 # it is pointless. 190 # if self.model !=None:191 # if self.model is not None: 191 192 # self.disp_list = self.model.getDispParamList() 192 193 self.temp_multi_functional = False 193 # #enable model 2D draw194 # enable model 2D draw 194 195 self.enable2D = False 195 # #check that the fit range is correct to plot the model again196 # check that the fit range is correct to plot the model again 196 197 self.fitrange = True 197 # #Create memento to save the current state198 # Create memento to save the current state 198 199 self.state = PageState(parent=self.parent, 199 200 model=self.model, data=self.data) 200 # #flag to determine if state has change201 # flag to determine if state has change 201 202 self.state_change = False 202 # #save customized array203 # save customized array 203 204 self.values = {} # type: Dict[str, List[float, ...]] 204 205 self.weights = {} # type: Dict[str, List[float, ...]] 205 # #retrieve saved state206 # retrieve saved state 206 207 self.number_saved_state = 0 207 # #dictionary of saved state208 # dictionary of saved state 208 209 self.saved_states = {} 209 # #Create context menu for page210 # Create context menu for page 210 211 self.popUpMenu = wx.Menu() 211 212 … … 220 221 self.popUpMenu.AppendSeparator() 221 222 222 # #Default locations223 # Default locations 223 224 self._default_save_location = os.getcwd() 224 # #save initial state on context menu225 # self.onSave(event=None)225 # save initial state on context menu 226 # self.onSave(event=None) 226 227 self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 227 228 … … 229 230 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) 230 231 231 # #create the basic structure of the panel with empty sizer232 # create the basic structure of the panel with empty sizer 232 233 self.define_page_structure() 233 # #drawing Initial dispersion parameters sizer234 # drawing Initial dispersion parameters sizer 234 235 self.set_dispers_sizer() 235 236 236 # #layout237 # layout 237 238 self.set_layout() 238 239 … … 260 261 self._create_default_1d_data() 261 262 262 if self.model !=None:263 if self.model is not None: 263 264 if not self.data.is_data: 264 self._manager.page_finder[self.uid].set_fit_data( data=\265 265 self._manager.page_finder[self.uid].set_fit_data( 266 data=[self.data]) 266 267 self.on_smear_helper(update=True) 267 268 self.state.enable_smearer = self.enable_smearer.GetValue() … … 325 326 self.data.id = str(self.uid) + " data" 326 327 self.data.group_id = str(self.uid) + " Model2D" 327 # #Default values328 # Default values 328 329 self.data.detector.append(Detector()) 329 330 index = len(self.data.detector) - 1 … … 342 343 x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 343 344 y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 344 # #use data info instead345 # use data info instead 345 346 new_x = numpy.tile(x, (len(y), 1)) 346 347 new_y = numpy.tile(y, (len(x), 1)) … … 383 384 Update menu1 on cliking the page tap 384 385 """ 385 if self._manager.menu1 !=None:386 chain_menu = self._manager.menu1.FindItemById( \386 if self._manager.menu1 is not None: 387 chain_menu = self._manager.menu1.FindItemById( 387 388 self._manager.id_reset_flag) 388 389 chain_menu.Enable(self.batch_on) 389 390 sim_menu = self._manager.menu1.FindItemById(self._manager.id_simfit) 390 391 flag = self.data.is_data\ 391 and (self.model !=None)392 and (self.model is not None) 392 393 sim_menu.Enable(not self.batch_on and flag) 393 394 batch_menu = \ … … 530 531 fill sizer containing dispersity info 531 532 """ 532 # print "==== entering set_dispers_sizer ==="533 # print "==== entering set_dispers_sizer ===" 533 534 self.sizer4.Clear(True) 534 535 name = "Polydispersity and Orientational Distribution" … … 536 537 box_description.SetForegroundColour(wx.BLUE) 537 538 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 538 # ----------------------------------------------------539 # ---------------------------------------------------- 539 540 self.disable_disp = wx.RadioButton(self, wx.ID_ANY, 'Off', (10, 10), 540 541 style=wx.RB_GROUP) … … 556 557 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 557 558 id=self.enable_disp.GetId()) 558 # MAC needs SetValue559 # MAC needs SetValue 559 560 self.disable_disp.SetValue(True) 560 561 sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) … … 568 569 sizer_dispersion.Add(self.disp_help_bt) 569 570 570 # #fill a sizer for dispersion571 # fill a sizer for dispersion 571 572 boxsizer1.Add(sizer_dispersion, 0, 572 573 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, … … 575 576 576 577 boxsizer1.Add(self.sizer4_4) 577 # -----------------------------------------------------578 # ----------------------------------------------------- 578 579 self.sizer4.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 579 580 self.sizer4_4.Layout() … … 582 583 583 584 self.Refresh() 584 # #saving the state of enable dispersity button585 # saving the state of enable dispersity button 585 586 self.state.enable_disp = self.enable_disp.GetValue() 586 587 self.state.disable_disp = self.disable_disp.GetValue() … … 592 593 """ 593 594 menu = event.GetEventObject() 594 # #post help message for the selected model595 # post help message for the selected model 595 596 msg = menu.GetHelpString(event.GetId()) 596 597 msg += " reloaded" … … 599 600 name = menu.GetLabel(event.GetId()) 600 601 self._on_select_model_helper() 601 if self.model !=None:602 if self.model is not None: 602 603 self.m_name = self.model.name 603 604 if name in self.saved_states.keys(): 604 605 previous_state = self.saved_states[name] 605 # #reset state of checkbox,textcrtl and regular parameters value606 # reset state of checkbox,textcrtl and regular parameters value 606 607 607 608 self.reset_page(previous_state) … … 626 627 # Ask the user the location of the file to write to. 627 628 path = None 628 if self.parent !=None:629 if self.parent is not None: 629 630 self._default_save_location = \ 630 631 self._manager.parent._default_save_location … … 636 637 self._default_save_location = os.path.dirname(path) 637 638 self._manager.parent._default_save_location = \ 638 639 self._default_save_location 639 640 else: 640 641 return None … … 643 644 # Make sure the ext included in the file name 644 645 fName = os.path.splitext(path)[0] + extens 645 # the manager write the state into file646 # the manager write the state into file 646 647 self._manager.save_fit_state(filepath=fName, fitstate=new_state) 647 648 return new_state … … 651 652 Copy Parameter values to the clipboad 652 653 """ 653 if event !=None:654 if event is not None: 654 655 event.Skip() 655 656 # It seems MAC needs wxCallAfter … … 667 668 Paste Parameter values to the panel if possible 668 669 """ 669 # if event !=None:670 # if event is not None: 670 671 # event.Skip() 671 672 # It seems MAC needs wxCallAfter for the setvalues … … 673 674 wx.CallAfter(self.get_paste) 674 675 # messages depending on the flag 675 # self._copy_info(True)676 # self._copy_info(True) 676 677 677 678 def _copy_info(self, flag): … … 682 683 """ 683 684 # messages depending on the flag 684 if flag ==None:685 if flag is None: 685 686 msg = " Parameter values are copied to the clipboard..." 686 687 infor = 'warning' … … 710 711 save history of the data and model 711 712 """ 712 if self.model ==None:713 if self.model is None: 713 714 msg = "Can not bookmark; Please select Data and Model first..." 714 715 wx.MessageBox(msg, 'Info') … … 716 717 self.save_current_state() 717 718 new_state = self.state.clone() 718 # #Add model state on context menu719 # Add model state on context menu 719 720 self.number_saved_state += 1 720 721 current_time, current_date = self._get_time_stamp() 721 # name= self.model.name+"[%g]"%self.number_saved_state722 # name= self.model.name+"[%g]"%self.number_saved_state 722 723 name = "Fitting: %g]" % self.number_saved_state 723 724 name += self.model.__class__.__name__ … … 725 726 self.saved_states[name] = new_state 726 727 727 # #Add item in the context menu728 # Add item in the context menu 728 729 msg = "Model saved at %s on %s" % (current_time, current_date) 729 # #post help message for the selected model730 # post help message for the selected model 730 731 msg += " Saved! right click on this page to retrieve this model" 731 732 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 761 762 """ 762 763 try: 763 if path ==None:764 if path is None: 764 765 status = " Selected Distribution was not loaded: %s" % path 765 766 wx.PostEvent(self._manager.parent, … … 796 797 Store current state 797 798 """ 798 # #save model option799 if self.model !=None:799 # save model option 800 if self.model is not None: 800 801 self.disp_list = self.model.getDispParamList() 801 802 self.state.disp_list = copy.deepcopy(self.disp_list) 802 803 self.state.model = self.model.clone() 803 804 804 # model combobox: complex code because of mac's silent error805 if self.structurebox !=None:805 # model combobox: complex code because of mac's silent error 806 if self.structurebox is not None: 806 807 if self.structurebox.IsShown(): 807 808 self.state.structurecombobox = 'None' 808 809 s_select = self.structurebox.GetSelection() 809 810 if s_select > 0: 810 self.state.structurecombobox = self.structurebox.\811 GetString(s_select)812 if self.formfactorbox !=None:811 self.state.structurecombobox = \ 812 self.structurebox.GetString(s_select) 813 if self.formfactorbox is not None: 813 814 f_select = self.formfactorbox.GetSelection() 814 815 if f_select > 0: 815 self.state.formfactorcombobox = self.formfactorbox.\816 GetString(f_select)817 if self.categorybox !=None:816 self.state.formfactorcombobox = \ 817 self.formfactorbox.GetString(f_select) 818 if self.categorybox is not None: 818 819 cb_select = self.categorybox.GetSelection() 819 820 if cb_select > 0: 820 self.state.categorycombobox = self.categorybox.\821 GetString(cb_select)821 self.state.categorycombobox = \ 822 self.categorybox.GetString(cb_select) 822 823 823 824 self.state.enable2D = copy.deepcopy(self.enable2D) 824 825 self.state.values = copy.deepcopy(self.values) 825 826 self.state.weights = copy.deepcopy(self.weights) 826 # #save data827 # save data 827 828 self.state.data = copy.deepcopy(self.data) 828 829 self.state.qmax_x = self.qmax_x … … 859 860 self.state.values = copy.deepcopy(self.values) 860 861 self.state.weights = copy.deepcopy(self.weights) 861 # #save plotting range862 # save plotting range 862 863 self._save_plotting_range() 863 864 … … 869 870 self.state.str_parameters = [] 870 871 871 # #save checkbutton state and txtcrtl values872 # save checkbutton state and txtcrtl values 872 873 self._copy_parameters_state(self.str_parameters, 873 874 self.state.str_parameters) … … 881 882 self.state.fittable_param) 882 883 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 883 # save chisqr884 # save chisqr 884 885 self.state.tcChi = self.tcChi.GetValue() 885 886 … … 888 889 Store current state for fit_page 889 890 """ 890 # #save model option891 if self.model !=None:891 # save model option 892 if self.model is not None: 892 893 self.disp_list = self.model.getDispParamList() 893 894 self.state.disp_list = copy.deepcopy(self.disp_list) … … 897 898 self.state.values = copy.deepcopy(self.values) 898 899 self.state.weights = copy.deepcopy(self.weights) 899 # #save data900 # save data 900 901 self.state.data = copy.deepcopy(self.data) 901 902 … … 918 919 self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) 919 920 self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) 920 if hasattr(self, "disp_box") and self.disp_box !=None:921 if hasattr(self, "disp_box") and self.disp_box is not None: 921 922 self.state.disp_box = self.disp_box.GetCurrentSelection() 922 923 923 924 if len(self.disp_cb_dict) > 0: 924 925 for k, v in self.disp_cb_dict.iteritems(): 925 if v ==None:926 if v is None: 926 927 self.state.disp_cb_dict[k] = v 927 928 else: … … 937 938 self.state.weights = copy.deepcopy(self.weights) 938 939 939 # #save plotting range940 # save plotting range 940 941 self._save_plotting_range() 941 942 942 # #save checkbutton state and txtcrtl values943 # save checkbutton state and txtcrtl values 943 944 self._copy_parameters_state(self.orientation_params, 944 945 self.state.orientation_params) … … 959 960 msg = "Please load Data and select Model to start..." 960 961 wx.MessageBox(msg, 'Info') 961 return 962 return True 962 963 963 964 def set_model_state(self, state): … … 968 969 self.disp_list = state.disp_list 969 970 970 # #fill model combobox971 # fill model combobox 971 972 self._show_combox_helper() 972 # select the current model973 # select the current model 973 974 try: 974 975 # to support older version … … 1009 1010 self.structurebox.SetSelection(structfactor_pos) 1010 1011 1011 if state.multi_factor !=None:1012 if state.multi_factor is not None: 1012 1013 self.multifactorbox.SetSelection(state.multi_factor) 1013 1014 1014 # #reset state of checkbox,textcrtl and regular parameters value1015 # reset state of checkbox,textcrtl and regular parameters value 1015 1016 self._reset_parameters_state(self.orientation_params_disp, 1016 1017 state.orientation_params_disp) … … 1020 1021 state.str_parameters) 1021 1022 self._reset_parameters_state(self.parameters, state.parameters) 1022 # #display dispersion info layer1023 # display dispersion info layer 1023 1024 self.enable_disp.SetValue(state.enable_disp) 1024 1025 self.disable_disp.SetValue(state.disable_disp) 1025 1026 1026 if hasattr(self, "disp_box") and self.disp_box !=None:1027 if hasattr(self, "disp_box") and self.disp_box is not None: 1027 1028 self.disp_box.SetSelection(state.disp_box) 1028 1029 n = self.disp_box.GetCurrentSelection() … … 1036 1037 1037 1038 if hasattr(self.disp_cb_dict[item], "SetValue"): 1038 self.disp_cb_dict[item].SetValue( \1039 self.disp_cb_dict[item].SetValue( 1039 1040 state.disp_cb_dict[item]) 1040 1041 # Create the dispersion objects 1041 1042 disp_model = POLYDISPERSITY_MODELS['array']() 1042 1043 if hasattr(state, "values") and \ 1043 self.disp_cb_dict[item].GetValue() ==True:1044 self.disp_cb_dict[item].GetValue() is True: 1044 1045 if len(state.values) > 0: 1045 1046 self.values = state.values … … 1052 1053 self._disp_obj_dict[item] = disp_model 1053 1054 # Set the new model as the dispersion object 1054 # for the selected parameter1055 # for the selected parameter 1055 1056 self.model.set_dispersion(item, disp_model) 1056 1057 … … 1062 1063 for item in keys: 1063 1064 if item in self.disp_list and \ 1064 not itemin self.model.details:1065 item not in self.model.details: 1065 1066 self.model.details[item] = ["", None, None] 1066 1067 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1067 1068 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1068 # #smearing info restore1069 # smearing info restore 1069 1070 if hasattr(self, "enable_smearer"): 1070 # #set smearing value whether or not the data1071 # contain the smearing info1071 # set smearing value whether or not the data 1072 # contain the smearing info 1072 1073 self.enable_smearer.SetValue(state.enable_smearer) 1073 1074 self.disable_smearer.SetValue(state.disable_smearer) … … 1081 1082 self.dI_idata.SetValue(state.dI_idata) 1082 1083 1083 # #we have two more options for smearing1084 # we have two more options for smearing 1084 1085 if self.pinhole_smearer.GetValue(): 1085 1086 self.onPinholeSmear(event=None) … … 1087 1088 self.onSlitSmear(event=None) 1088 1089 1089 # #reset state of checkbox,textcrtl and dispersity parameters value1090 # reset state of checkbox,textcrtl and dispersity parameters value 1090 1091 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1091 1092 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1092 1093 1093 # #draw the model with previous parameters value1094 # draw the model with previous parameters value 1094 1095 self._onparamEnter_helper() 1095 1096 self.select_param(event=None) 1096 # Save state_fit1097 # Save state_fit 1097 1098 self.save_current_state_fit() 1098 1099 self._lay_out() … … 1108 1109 if state.formfactorcombobox in list_item: 1109 1110 return self.categorybox.Items.index(key) 1111 return 0 1110 1112 1111 1113 def reset_page_helper(self, state): … … 1118 1120 state of the graphic interface 1119 1121 """ 1120 if state ==None:1122 if state is None: 1121 1123 return 1122 1124 # set data, etc. from the state … … 1124 1126 data = state.data 1125 1127 1126 if data ==None:1128 if data is None: 1127 1129 data_min = state.qmin 1128 1130 data_max = state.qmax … … 1148 1150 self.disp_list = state.disp_list 1149 1151 1150 # #fill model combobox1152 # fill model combobox 1151 1153 self._show_combox_helper() 1152 # select the current model1154 # select the current model 1153 1155 try: 1154 1156 # to support older version 1155 1157 category_pos = int(state.categorycombobox) 1156 1158 except: 1157 state.formfactorcombobox = unicode(state.formfactorcombobox.lower()) 1159 state.formfactorcombobox = state.formfactorcombobox.lower() 1160 state.formfactorcombobox = \ 1161 state.formfactorcombobox.replace('model', '') 1162 state.formfactorcombobox = unicode(state.formfactorcombobox) 1158 1163 state.categorycombobox = unicode(state.categorycombobox) 1159 category_pos = 01160 1164 if state.categorycombobox in self.categorybox.Items: 1161 1165 category_pos = self.categorybox.Items.index( … … 1180 1184 self.formfactorbox.Select(formfactor_pos) 1181 1185 1186 structfactor_pos = 0 1182 1187 try: 1183 1188 # to support older version … … 1185 1190 except: 1186 1191 if state.structurecombobox is not None: 1187 structfactor_pos = 01188 1192 state.structurecombobox = unicode(state.structurecombobox) 1189 1193 for ind_struct in range(self.structurebox.GetCount()): 1190 1194 if self.structurebox.GetString(ind_struct) == \ 1191 1195 (state.structurecombobox): 1192 1196 structfactor_pos = int(ind_struct) 1193 1197 break … … 1195 1199 self.structurebox.SetSelection(structfactor_pos) 1196 1200 1197 if state.multi_factor !=None:1201 if state.multi_factor is not None: 1198 1202 self.multifactorbox.SetSelection(state.multi_factor) 1199 1203 1200 # draw the panel according to the new model parameter1204 # draw the panel according to the new model parameter 1201 1205 self._on_select_model(event=None) 1202 1206 1203 1207 # take care of 2D button 1204 if data ==None and self.model_view.IsEnabled():1208 if data is None and self.model_view.IsEnabled(): 1205 1209 if self.enable2D: 1206 1210 self.model_view.SetLabel("2D Mode") … … 1208 1212 self.model_view.SetLabel("1D Mode") 1209 1213 1210 # #reset state of checkbox,textcrtl and regular parameters value1214 # reset state of checkbox,textcrtl and regular parameters value 1211 1215 self._reset_parameters_state(self.orientation_params_disp, 1212 1216 state.orientation_params_disp) … … 1216 1220 state.str_parameters) 1217 1221 self._reset_parameters_state(self.parameters, state.parameters) 1218 # #display dispersion info layer1222 # display dispersion info layer 1219 1223 self.enable_disp.SetValue(state.enable_disp) 1220 1224 self.disable_disp.SetValue(state.disable_disp) … … 1224 1228 self._set_dipers_Param(event=None) 1225 1229 self._reset_page_disp_helper(state) 1226 # #plotting range restore1230 # plotting range restore 1227 1231 self._reset_plotting_range(state) 1228 # #smearing info restore1232 # smearing info restore 1229 1233 if hasattr(self, "enable_smearer"): 1230 # #set smearing value whether or not the data1231 # contain the smearing info1234 # set smearing value whether or not the data 1235 # contain the smearing info 1232 1236 self.enable_smearer.SetValue(state.enable_smearer) 1233 1237 self.disable_smearer.SetValue(state.disable_smearer) … … 1247 1251 self.dI_idata.SetValue(False) 1248 1252 1249 # #we have two more options for smearing1253 # we have two more options for smearing 1250 1254 if self.pinhole_smearer.GetValue(): 1251 1255 self.dx_min = state.dx_min 1252 1256 self.dx_max = state.dx_max 1253 if self.dx_min !=None:1257 if self.dx_min is not None: 1254 1258 self.smear_pinhole_min.SetValue(str(self.dx_min)) 1255 if self.dx_max !=None:1259 if self.dx_max is not None: 1256 1260 self.smear_pinhole_max.SetValue(str(self.dx_max)) 1257 1261 self.onPinholeSmear(event=None) … … 1259 1263 self.dxl = state.dxl 1260 1264 self.dxw = state.dxw 1261 if self.dxl !=None:1265 if self.dxl is not None: 1262 1266 self.smear_slit_height.SetValue(str(self.dxl)) 1263 if self.dxw !=None:1267 if self.dxw is not None: 1264 1268 self.smear_slit_width.SetValue(str(self.dxw)) 1265 1269 else: … … 1267 1271 self.onSlitSmear(event=None) 1268 1272 1269 # #reset state of checkbox,textcrtl and dispersity parameters value1273 # reset state of checkbox,textcrtl and dispersity parameters value 1270 1274 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1271 1275 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1272 1276 1273 # #draw the model with previous parameters value1277 # draw the model with previous parameters value 1274 1278 self._onparamEnter_helper() 1275 # reset the value of chisqr when not consistent with the value computed1279 # reset the value of chisqr when not consistent with the value computed 1276 1280 self.tcChi.SetValue(str(self.state.tcChi)) 1277 # #reset context menu items1281 # reset context menu items 1278 1282 self._reset_context_menu() 1279 1283 1280 # #set the value of the current state to the state given as parameter1284 # set the value of the current state to the state given as parameter 1281 1285 self.state = state.clone() 1282 1286 self.state.m_name = self.m_name … … 1289 1293 for item in keys: 1290 1294 if item in self.disp_list and \ 1291 not itemin self.model.details:1295 item not in self.model.details: 1292 1296 self.model.details[item] = ["", None, None] 1293 # for k,v in self.state.disp_cb_dict.iteritems():1297 # for k,v in self.state.disp_cb_dict.iteritems(): 1294 1298 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1295 1299 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) … … 1298 1302 1299 1303 for key, disp_type in state._disp_obj_dict.iteritems(): 1300 # disp_model = disp1304 # disp_model = disp 1301 1305 disp_model = POLYDISPERSITY_MODELS[disp_type]() 1302 1306 self._disp_obj_dict[key] = disp_model … … 1307 1311 self.model.set_dispersion(param_name, disp_model) 1308 1312 self.model._persistency_dict[key] = \ 1309 1313 [state.values, state.weights] 1310 1314 except Exception: 1311 1315 logging.error(traceback.format_exc()) 1312 1316 selection = self._find_polyfunc_selection(disp_model) 1313 1317 for list in self.fittable_param: 1314 if list[1] == key and list[7] !=None:1318 if list[1] == key and list[7] is not None: 1315 1319 list[7].SetSelection(selection) 1316 1320 # For the array disp_model, set the values and weights … … 1341 1345 open a dialog file to selected the customized dispersity 1342 1346 """ 1343 if self.parent !=None:1347 if self.parent is not None: 1344 1348 self._default_save_location = \ 1345 1349 self._manager.parent.get_save_location() … … 1360 1364 for name, _ in self.state.saved_states.iteritems(): 1361 1365 self.number_saved_state += 1 1362 # #Add item in the context menu1366 # Add item in the context menu 1363 1367 wx_id = ids.next() 1364 1368 msg = 'Save model and state %g' % self.number_saved_state … … 1377 1381 save radiobutton containing the type model that can be selected 1378 1382 """ 1379 # self.state.shape_rbutton = self.shape_rbutton.GetValue()1380 # self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue()1381 # self.state.struct_rbutton = self.struct_rbutton.GetValue()1382 # self.state.plugin_rbutton = self.plugin_rbutton.GetValue()1383 # self.state.shape_rbutton = self.shape_rbutton.GetValue() 1384 # self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() 1385 # self.state.struct_rbutton = self.struct_rbutton.GetValue() 1386 # self.state.plugin_rbutton = self.plugin_rbutton.GetValue() 1383 1387 self.state.structurecombobox = self.structurebox.GetLabel() 1384 1388 self.state.formfactorcombobox = self.formfactorbox.GetLabel() 1385 1389 self.state.categorycombobox = self.categorybox.GetLabel() 1386 1390 1387 # #post state to fit panel1391 # post state to fit panel 1388 1392 event = PageInfoEvent(page=self) 1389 1393 wx.PostEvent(self.parent, event) … … 1397 1401 self.state.npts = self.npts_x 1398 1402 1399 def _onparamEnter_helper(self, is_modified =False):1403 def _onparamEnter_helper(self, is_modified=False): 1400 1404 """ 1401 1405 check if values entered by the user are changed and valid to replot … … 1403 1407 """ 1404 1408 # Flag to register when a parameter has changed. 1405 # is_modified = False1409 # is_modified = False 1406 1410 self.fitrange = True 1407 1411 is_2Ddata = False 1408 # self._undo.Enable(True)1412 # self._undo.Enable(True) 1409 1413 # check if 2d data 1410 1414 if self.data.__class__.__name__ == "Data2D": 1411 1415 is_2Ddata = True 1412 if self.model !=None:1413 # Either we get a is_modified = True passed in because1414 # _update_paramv_on_fit() has been called already or1416 if self.model is not None: 1417 # Either we get a is_modified = True passed in because 1418 # _update_paramv_on_fit() has been called already or 1415 1419 # we need to check here ourselves. 1416 1420 if not is_modified: … … 1439 1443 self.fitrange = False 1440 1444 1441 # #if any value is modify draw model with new value1445 # if any value is modify draw model with new value 1442 1446 if not self.fitrange: 1443 # self.btFit.Disable()1447 # self.btFit.Disable() 1444 1448 if is_2Ddata: 1445 1449 self.btEditMask.Disable() … … 1455 1459 self.Refresh() 1456 1460 1457 # logging.info("is_modified flag set to %g",is_modified)1461 # logging.info("is_modified flag set to %g",is_modified) 1458 1462 return is_modified 1459 1463 … … 1462 1466 make sure that update param values just before the fitting 1463 1467 """ 1464 # flag for qmin qmax check values1468 # flag for qmin qmax check values 1465 1469 flag = True 1466 1470 self.fitrange = True 1467 1471 is_modified = False 1468 1472 1469 # wx.PostEvent(self._manager.parent, StatusEvent(status=" \1470 # updating ... ",type="update"))1471 1472 # #So make sure that update param values on_Fit.1473 # self._undo.Enable(True)1474 if self.model !=None:1473 # wx.PostEvent(self._manager.parent, StatusEvent(status=" \ 1474 # updating ... ",type="update")) 1475 1476 # So make sure that update param values on_Fit. 1477 # self._undo.Enable(True) 1478 if self.model is not None: 1475 1479 if self.Npts_total.GetValue() != self.Npts_fit.GetValue(): 1476 1480 if not self.data.is_data: 1477 self._manager.page_finder[self.uid].set_fit_data( data=\1478 1479 # #Check the values1481 self._manager.page_finder[self.uid].set_fit_data( 1482 data=[self.data]) 1483 # Check the values 1480 1484 is_modified = (self._check_value_enter(self.fittable_param) 1481 1482 1485 or self._check_value_enter(self.fixed_param) 1486 or self._check_value_enter(self.parameters)) 1483 1487 1484 1488 # If qmin and qmax have been modified, update qmin and qmax and … … 1521 1525 enable_smearer=enable_smearer, 1522 1526 draw=False) 1523 if self.data !=None:1524 index_data = ((self.qmin_x <= self.data.x) & \1527 if self.data is not None: 1528 index_data = ((self.qmin_x <= self.data.x) & 1525 1529 (self.data.x <= self.qmax_x)) 1526 val = str(len(self.data.x[index_data ==True]))1530 val = str(len(self.data.x[index_data is True])) 1527 1531 self.Npts_fit.SetValue(val) 1528 1532 else: … … 1544 1548 flag = False 1545 1549 1546 # For invalid q range, disable the mask editor and fit button, vs.1550 # For invalid q range, disable the mask editor and fit button, vs. 1547 1551 if not self.fitrange: 1548 1552 if self._is_2D(): 1549 1553 self.btEditMask.Disable() 1550 1554 else: 1551 if self._is_2D() and 1555 if self._is_2D() and self.data.is_data and not self.batch_on: 1552 1556 self.btEditMask.Enable(True) 1553 1557 … … 1562 1566 logging.error(traceback.format_exc()) 1563 1567 1564 return flag, is_modified1568 return flag, is_modified 1565 1569 1566 1570 def _reset_parameters_state(self, listtorestore, statelist): … … 1576 1580 item_page = listtorestore[j] 1577 1581 item_page_info = statelist[j] 1578 # #change the state of the check box for simple parameters1579 if item_page[0] !=None:1582 # change the state of the check box for simple parameters 1583 if item_page[0] is not None: 1580 1584 item_page[0].SetValue(item_page_info[0]) 1581 if item_page[2] !=None:1585 if item_page[2] is not None: 1582 1586 item_page[2].SetValue(item_page_info[2]) 1583 1587 if item_page[2].__class__.__name__ == "ComboBox": … … 1585 1589 fun_val = self.model.fun_list[item_page_info[2]] 1586 1590 self.model.setParam(item_page_info[1], fun_val) 1587 if item_page[3] !=None:1588 # #show or hide text +/-1591 if item_page[3] is not None: 1592 # show or hide text +/- 1589 1593 if item_page_info[2]: 1590 1594 item_page[3].Show(True) 1591 1595 else: 1592 1596 item_page[3].Hide() 1593 if item_page[4] !=None:1594 # #show of hide the text crtl for fitting error1597 if item_page[4] is not None: 1598 # show of hide the text crtl for fitting error 1595 1599 if item_page_info[4][0]: 1596 1600 item_page[4].Show(True) … … 1598 1602 else: 1599 1603 item_page[3].Hide() 1600 if item_page[5] !=None:1601 # #show of hide the text crtl for fitting error1604 if item_page[5] is not None: 1605 # show of hide the text crtl for fitting error 1602 1606 item_page[5].Show(item_page_info[5][0]) 1603 1607 item_page[5].SetValue(item_page_info[5][1]) 1604 1608 1605 if item_page[6] !=None:1606 # #show of hide the text crtl for fitting error1609 if item_page[6] is not None: 1610 # show of hide the text crtl for fitting error 1607 1611 item_page[6].Show(item_page_info[6][0]) 1608 1612 item_page[6].SetValue(item_page_info[6][1]) … … 1620 1624 item_page = listtorestore[j] 1621 1625 item_page_info = statelist[j] 1622 # #change the state of the check box for simple parameters1623 1624 if item_page[0] !=None:1626 # change the state of the check box for simple parameters 1627 1628 if item_page[0] is not None: 1625 1629 item_page[0].SetValue(format_number(item_page_info[0], True)) 1626 1630 1627 if item_page[2] !=None:1631 if item_page[2] is not None: 1628 1632 param_name = item_page_info[1] 1629 1633 value = item_page_info[2] … … 1648 1652 1649 1653 checkbox_state = None 1650 if item[0] !=None:1654 if item[0] is not None: 1651 1655 checkbox_state = item[0].GetValue() 1652 1656 parameter_name = item[1] 1653 1657 parameter_value = None 1654 if item[2] !=None:1658 if item[2] is not None: 1655 1659 parameter_value = item[2].GetValue() 1656 1660 static_text = None 1657 if item[3] !=None:1661 if item[3] is not None: 1658 1662 static_text = item[3].IsShown() 1659 1663 error_value = None 1660 1664 error_state = None 1661 if item[4] !=None:1665 if item[4] is not None: 1662 1666 error_value = item[4].GetValue() 1663 1667 error_state = item[4].IsShown() … … 1665 1669 min_value = None 1666 1670 min_state = None 1667 if item[5] !=None:1671 if item[5] is not None: 1668 1672 min_value = item[5].GetValue() 1669 1673 min_state = item[5].IsShown() … … 1671 1675 max_value = None 1672 1676 max_state = None 1673 if item[6] !=None:1677 if item[6] is not None: 1674 1678 max_value = item[6].GetValue() 1675 1679 max_state = item[6].IsShown() 1676 1680 unit = None 1677 if item[7] !=None:1681 if item[7] is not None: 1678 1682 unit = item[7].GetLabel() 1679 1683 … … 1683 1687 [max_state, max_value], unit]) 1684 1688 1685 1686 1689 def _draw_model(self, update_chisqr=True, source='model'): 1687 1690 """ … … 1702 1705 :param chisqr: update chisqr value [bool] 1703 1706 """ 1704 # if self.check_invalid_panel():1707 # if self.check_invalid_panel(): 1705 1708 # return 1706 if self.model !=None:1709 if self.model is not None: 1707 1710 temp_smear = None 1708 1711 if hasattr(self, "enable_smearer"): … … 1716 1719 is_2d = self._is_2D() 1717 1720 self._manager.draw_model(self.model, 1718 data=self.data,1719 smearer=temp_smear,1720 qmin=float(self.qmin_x),1721 qmax=float(self.qmax_x),1722 page_id=self.uid,1723 toggle_mode_on=toggle_mode_on,1724 state=self.state,1725 enable2D=is_2d,1726 update_chisqr=update_chisqr,1727 source='model',1728 weight=weight)1721 data=self.data, 1722 smearer=temp_smear, 1723 qmin=float(self.qmin_x), 1724 qmax=float(self.qmax_x), 1725 page_id=self.uid, 1726 toggle_mode_on=toggle_mode_on, 1727 state=self.state, 1728 enable2D=is_2d, 1729 update_chisqr=update_chisqr, 1730 source='model', 1731 weight=weight) 1729 1732 1730 1733 def _on_show_sld(self, event=None): … … 1736 1739 1737 1740 from sas.sasgui.plottools import Data1D as pf_data1d 1738 # from sas.sasgui.perspectives.theory.profile_dialog import SLDPanel1741 # from sas.sasgui.perspectives.theory.profile_dialog import SLDPanel 1739 1742 from sas.sasgui.guiframe.local_perspectives.plotting.profile_dialog \ 1740 import SLDPanel1743 import SLDPanel 1741 1744 sld_data = pf_data1d(x, y) 1742 1745 sld_data.name = 'SLD' … … 1791 1794 self.structurebox.Disable() 1792 1795 self.formfactorbox.Clear() 1793 if mod_cat ==None:1796 if mod_cat is None: 1794 1797 return 1795 1798 m_list = [] … … 1853 1856 """ 1854 1857 tcrtl = event.GetEventObject() 1855 # Clear msg if previously shown.1858 # Clear msg if previously shown. 1856 1859 msg = "" 1857 1860 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1872 1875 tcrtl.SetBackgroundColour("pink") 1873 1876 msg = "Model Error: wrong value entered: %s" % \ 1874 1877 sys.exc_info()[1] 1875 1878 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1876 1879 return … … 1880 1883 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1881 1884 return 1882 # Check if # of points for theory model are valid(>0).1883 if self.npts !=None:1885 # Check if # of points for theory model are valid(>0). 1886 if self.npts is not None: 1884 1887 if check_float(self.npts): 1885 1888 temp_npts = float(self.npts.GetValue()) … … 1897 1900 wx.PostEvent(self.parent, event) 1898 1901 self.state_change = False 1899 # Draw the model for a different range1902 # Draw the model for a different range 1900 1903 if not self.data.is_data: 1901 1904 self.create_default_data() … … 1908 1911 1909 1912 tcrtl = event.GetEventObject() 1910 # Clear msg if previously shown.1913 # Clear msg if previously shown. 1911 1914 msg = "" 1912 1915 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1929 1932 tcrtl.SetBackgroundColour("pink") 1930 1933 msg = "Model Error: wrong value entered: %s" % \ 1931 1934 sys.exc_info()[1] 1932 1935 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1933 1936 return … … 1937 1940 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1938 1941 return 1939 # Check if # of points for theory model are valid(>0).1942 # Check if # of points for theory model are valid(>0). 1940 1943 if self.Npts_total.IsEditable(): 1941 1944 if check_float(self.Npts_total): … … 1955 1958 wx.PostEvent(self.parent, event) 1956 1959 self.state_change = False 1957 # Draw the model for a different range1960 # Draw the model for a different range 1958 1961 self.create_default_data() 1959 1962 self._draw_model() … … 1963 1966 call back for model selection 1964 1967 """ 1965 # #reset dictionary containing reference to dispersion1968 # reset dictionary containing reference to dispersion 1966 1969 self._disp_obj_dict = {} 1967 1970 self.disp_cb_dict = {} 1968 1971 self.temp_multi_functional = False 1969 1972 f_id = self.formfactorbox.GetCurrentSelection() 1970 # For MAC1973 # For MAC 1971 1974 form_factor = None 1972 1975 if f_id >= 0: … … 1975 1978 if form_factor is None or \ 1976 1979 not hasattr(form_factor, 'is_form_factor') or \ 1977 not form_factor.is_form_factor:1980 not form_factor.is_form_factor: 1978 1981 self.structurebox.Hide() 1979 1982 self.text2.Hide() … … 1987 1990 self.text2.Enable() 1988 1991 1989 if form_factor !=None:1992 if form_factor is not None: 1990 1993 # set multifactor for Mutifunctional models 1991 1994 if form_factor.is_multiplicity_model: … … 1995 1998 self._set_multfactor_combobox(multiplicity) 1996 1999 self._show_multfactor_combobox() 1997 # ToDo:this info should be called directly from the model2000 # ToDo: this info should be called directly from the model 1998 2001 text = form_factor.multiplicity_info[1] # 'No. of Shells: ' 1999 2002 … … 2004 2007 2005 2008 self.multi_factor = self.multifactorbox.GetClientData(m_id) 2006 if self.multi_factor ==None:2009 if self.multi_factor is None: 2007 2010 self.multi_factor = 0 2008 2011 self.multifactorbox.SetSelection(m_id) … … 2010 2013 text = '' 2011 2014 if form_factor.multiplicity_info[0] == \ 2012 2015 len(form_factor.multiplicity_info[2]): 2013 2016 text = form_factor.multiplicity_info[2][self.multi_factor] 2014 2017 self.mutifactor_text1.SetLabel(text) … … 2031 2034 struct_factor = self.structurebox.GetClientData(s_id) 2032 2035 2033 if struct_factor !=None:2036 if struct_factor is not None: 2034 2037 from sasmodels.sasview_model import MultiplicationModel 2035 2038 self.model = MultiplicationModel(form_factor(self.multi_factor), … … 2038 2041 if len(form_factor.non_fittable) > 0: 2039 2042 self.temp_multi_functional = True 2040 elif form_factor !=None:2043 elif form_factor is not None: 2041 2044 if self.multi_factor is not None: 2042 2045 self.model = form_factor(self.multi_factor) … … 2053 2056 else: 2054 2057 self._has_magnetic = False 2055 # #post state to fit panel2058 # post state to fit panel 2056 2059 self.state.parameters = [] 2057 2060 self.state.model = self.model … … 2063 2066 self.Layout() 2064 2067 2065 2066 2068 def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 2067 2069 """ … … 2083 2085 qmax = float(qmax_ctrl.GetValue()) 2084 2086 if qmin < qmax: 2085 # Make sure to set both colours white.2087 # Make sure to set both colours white. 2086 2088 qmin_ctrl.SetBackgroundColour(wx.WHITE) 2087 2089 qmin_ctrl.Refresh() … … 2103 2105 If valid, setvalues Npts_fit otherwise post msg. 2104 2106 """ 2105 # default flag2107 # default flag 2106 2108 flag = True 2107 2109 # Theory 2108 if self.data ==None and self.enable2D:2110 if self.data is None and self.enable2D: 2109 2111 return flag 2110 2112 for data in self.data_list: … … 2112 2114 radius = numpy.sqrt(data.qx_data * data.qx_data + 2113 2115 data.qy_data * data.qy_data) 2114 # get unmasked index2116 # get unmasked index 2115 2117 index_data = (float(self.qmin.GetValue()) <= radius) & \ 2116 2118 (radius <= float(self.qmax.GetValue())) 2117 2119 index_data = (index_data) & (data.mask) 2118 2120 index_data = (index_data) & (numpy.isfinite(data.data)) … … 2130 2132 flag = False 2131 2133 else: 2132 self.Npts_fit.SetValue(str(len(index_data[index_data ==True])))2134 self.Npts_fit.SetValue(str(len(index_data[index_data is True]))) 2133 2135 self.fitrange = True 2134 2136 … … 2140 2142 If valid, setvalues Npts_fit otherwise post msg. 2141 2143 """ 2142 # default flag2144 # default flag 2143 2145 flag = True 2144 2146 # Theory 2145 if self.data ==None:2147 if self.data is None: 2146 2148 return flag 2147 2149 for data in self.data_list: 2148 2150 # q value from qx and qy 2149 2151 radius = data.x 2150 # get unmasked index2152 # get unmasked index 2151 2153 index_data = (float(self.qmin.GetValue()) <= radius) & \ 2152 2154 (radius <= float(self.qmax.GetValue())) 2153 2155 index_data = (index_data) & (numpy.isfinite(data.y)) 2154 2156 … … 2165 2167 flag = False 2166 2168 else: 2167 self.Npts_fit.SetValue(str(len(index_data[index_data ==True])))2169 self.Npts_fit.SetValue(str(len(index_data[index_data is True]))) 2168 2170 self.fitrange = True 2169 2171 … … 2185 2187 is_modified = False 2186 2188 for item in list: 2187 # skip angle parameters for 1D2189 # skip angle parameters for 1D 2188 2190 if not self.enable2D and item in self.orientation_params: 2189 2191 continue … … 2230 2232 max_ctrl.SetBackgroundColour("pink") 2231 2233 max_ctrl.Refresh() 2232 #msg = "Invalid fit range for %s: min must be smaller than max"%name 2233 #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2234 # msg = "Invalid fit range for %s: min must be smaller 2235 # than max"%name 2236 # wx.PostEvent(self._manager.parent, 2237 # StatusEvent(status=msg)) 2234 2238 continue 2235 2239 … … 2249 2253 # The configuration has changed but it won't change the 2250 2254 # computed curve so no need to set is_modified to True 2251 # is_modified = True2255 # is_modified = True 2252 2256 self.model.details[name][1:3] = low, high 2253 2257 … … 2267 2271 Redraw the model with the default dispersity (Gaussian) 2268 2272 """ 2269 # #On selction if no model exists.2270 if self.model ==None:2273 # On selction if no model exists. 2274 if self.model is None: 2271 2275 self.disable_disp.SetValue(True) 2272 2276 msg = "Please select a Model first..." … … 2278 2282 self._reset_dispersity() 2279 2283 2280 if self.model ==None:2284 if self.model is None: 2281 2285 self.model_disp.Hide() 2282 2286 self.sizer4_4.Clear(True) … … 2284 2288 2285 2289 if self.enable_disp.GetValue(): 2286 # #layout for model containing no dispersity parameters2290 # layout for model containing no dispersity parameters 2287 2291 2288 2292 self.disp_list = self.model.getDispParamList() … … 2291 2295 self._layout_sizer_noDipers() 2292 2296 else: 2293 # #set gaussian sizer2297 # set gaussian sizer 2294 2298 self._on_select_Disp(event=None) 2295 2299 else: 2296 2300 self.sizer4_4.Clear(True) 2297 2301 2298 # #post state to fit panel2302 # post state to fit panel 2299 2303 self.save_current_state() 2300 if event !=None:2304 if event is not None: 2301 2305 event = PageInfoEvent(page=self) 2302 2306 wx.PostEvent(self.parent, event) 2303 # draw the model with the current dispersity2304 2305 # Wojtek P, Oct 8, 2016: Calling draw_model seems to be unessecary.2306 # By comenting it we save an extra Iq calculation2307 # self._draw_model()2308 2309 # #Need to use FitInside again here to replace the next four lines.2310 # #Otherwised polydispersity off does not resize the scrollwindow.2311 # #PDB Nov 28, 20152307 # draw the model with the current dispersity 2308 2309 # Wojtek P, Oct 8, 2016: Calling draw_model seems to be unessecary. 2310 # By comenting it we save an extra Iq calculation 2311 # self._draw_model() 2312 2313 # Need to use FitInside again here to replace the next four lines. 2314 # Otherwised polydispersity off does not resize the scrollwindow. 2315 # PDB Nov 28, 2015 2312 2316 self.FitInside() 2313 2317 # self.sizer4_4.Layout() … … 2353 2357 self.weights = {} 2354 2358 2355 # from sas.models.dispersion_models import GaussianDispersion2359 # from sas.models.dispersion_models import GaussianDispersion 2356 2360 from sasmodels.weights import GaussianDispersion 2357 2361 if len(self.disp_cb_dict) == 0: … … 2374 2378 logging.error(traceback.format_exc()) 2375 2379 2376 # #save state into2380 # save state into 2377 2381 self.save_current_state() 2378 2382 self.Layout() … … 2386 2390 self._set_sizer_dispersion() 2387 2391 2388 # #Redraw the model2392 # Redraw the model 2389 2393 self._draw_model() 2390 # self._undo.Enable(True)2394 # self._undo.Enable(True) 2391 2395 event = PageInfoEvent(page=self) 2392 2396 wx.PostEvent(self.parent, event) … … 2403 2407 """ 2404 2408 # get ready for new event 2405 if event !=None:2409 if event is not None: 2406 2410 event.Skip() 2407 2411 # Get event object … … 2416 2420 dispersity = disp_box.GetClientData(selection) 2417 2421 2418 # disp_model = GaussianDispersion()2422 # disp_model = GaussianDispersion() 2419 2423 disp_model = dispersity() 2420 2424 # Get param names to reset the values of the param … … 2429 2433 else: 2430 2434 self._del_array_values(name1) 2431 # self._reset_array_disp(param_name)2435 # self._reset_array_disp(param_name) 2432 2436 self._disp_obj_dict[name1] = disp_model 2433 2437 self.model.set_dispersion(param_name, disp_model) … … 2513 2517 if path is None: 2514 2518 self.disp_cb_dict[name].SetValue(False) 2515 # self.noDisper_rbox.SetValue(True)2519 # self.noDisper_rbox.SetValue(True) 2516 2520 return 2517 2521 self._default_save_location = os.path.dirname(path) 2518 if self._manager !=None:2522 if self._manager is not None: 2519 2523 self._manager.parent._default_save_location = \ 2520 2524 self._default_save_location … … 2533 2537 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2534 2538 self._set_array_disp_model(name=name, disp=disp, 2535 2539 values=values, weights=weights) 2536 2540 return basename 2537 2541 … … 2552 2556 # Store the object to make it persist outside the 2553 2557 # scope of this method 2554 # TODO: refactor model to clean this up?2558 # TODO: refactor model to clean this up? 2555 2559 self.state.values = {} 2556 2560 self.state.weights = {} … … 2559 2563 2560 2564 # Set the new model as the dispersion object for the 2561 # selected parameter2562 # self.model.set_dispersion(p, disp_model)2565 # selected parameter 2566 # self.model.set_dispersion(p, disp_model) 2563 2567 # Store a reference to the weights in the model object 2564 # so that2568 # so that 2565 2569 # it's not lost when we use the model within another thread. 2566 2570 self.state.model = self.model.clone() 2567 2571 self.model._persistency_dict[name.split('.')[0]] = \ 2568 2572 [values, weights] 2569 2573 self.state.model._persistency_dict[name.split('.')[0]] = \ 2570 2574 [values, weights] 2571 2575 2572 2576 def _del_array_values(self, name=None): … … 2606 2610 Layout after self._draw_model 2607 2611 """ 2608 if ON_MAC ==True:2612 if ON_MAC is True: 2609 2613 time.sleep(1) 2610 2614 … … 2628 2632 """ 2629 2633 flag = True 2630 # #For 3 different cases: Data2D, Data1D, and theory2631 if self.model ==None:2634 # For 3 different cases: Data2D, Data1D, and theory 2635 if self.model is None: 2632 2636 msg = "Please select a model first..." 2633 2637 wx.MessageBox(msg, 'Info') … … 2641 2645 self.qmin_x = data_min 2642 2646 self.qmax_x = math.sqrt(x * x + y * y) 2643 # self.data.mask = numpy.ones(len(self.data.data),dtype=bool)2647 # self.data.mask = numpy.ones(len(self.data.data),dtype=bool) 2644 2648 # check smearing 2645 2649 if not self.disable_smearer.GetValue(): 2646 # #set smearing value whether or2650 # set smearing value whether or 2647 2651 # not the data contain the smearing info 2648 2652 if self.pinhole_smearer.GetValue(): … … 2651 2655 flag = True 2652 2656 2653 elif self.data ==None:2657 elif self.data is None: 2654 2658 self.qmin_x = _QMIN_DEFAULT 2655 2659 self.qmax_x = _QMAX_DEFAULT … … 2662 2666 # check smearing 2663 2667 if not self.disable_smearer.GetValue(): 2664 # #set smearing value whether or2668 # set smearing value whether or 2665 2669 # not the data contain the smearing info 2666 2670 if self.slit_smearer.GetValue(): … … 2673 2677 flag = False 2674 2678 2675 if flag ==False:2679 if flag is False: 2676 2680 msg = "Cannot Plot :Must enter a number!!! " 2677 2681 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 2690 2694 self.state.qmax = self.qmax_x 2691 2695 2692 # reset the q range values2696 # reset the q range values 2693 2697 self._reset_plotting_range(self.state) 2694 2698 self._draw_model() … … 2731 2735 logging.error(traceback.format_exc()) 2732 2736 # Make sure the resduals plot goes to the last 2733 if res_item !=None:2737 if res_item is not None: 2734 2738 graphs.append(res_item[0]) 2735 2739 canvases.append(res_item[1]) … … 2750 2754 the # to the browser. 2751 2755 2752 :param ev t: on Help Button pressed event2753 """ 2754 2755 if self.model !=None:2756 :param event: on Help Button pressed event 2757 """ 2758 2759 if self.model is not None: 2756 2760 name = self.formfactorbox.GetValue() 2757 _TreeLocation = 'user/models/' + name.lower()+'.html'2761 _TreeLocation = 'user/models/' + name.lower()+'.html' 2758 2762 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 2759 2763 "", name + " Help") … … 2762 2766 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 2763 2767 "", "General Model Help") 2764 2765 2768 2766 2769 def on_model_help_clicked(self, event): … … 2774 2777 give the message that none is available. 2775 2778 2776 :param ev t: on Description Button pressed event2777 """ 2778 2779 if self.model ==None:2779 :param event: on Description Button pressed event 2780 """ 2781 2782 if self.model is None: 2780 2783 name = 'index.html' 2781 2784 else: … … 2784 2787 msg = 'Model description:\n' 2785 2788 info = "Info" 2786 if self.model !=None:2787 #frame.Destroy()2789 if self.model is not None: 2790 # frame.Destroy() 2788 2791 if str(self.model.description).rstrip().lstrip() == '': 2789 2792 msg += "Sorry, no information is available for this model." … … 2854 2857 for key in self.model.magnetic_params: 2855 2858 if key.count('M0') > 0: 2856 # reset mag value to zero fo safety2859 # reset mag value to zero fo safety 2857 2860 self.model.setParam(key, 0.0) 2858 2861 2859 2862 self.Show(False) 2860 2863 self.set_model_param_sizer(self.model) 2861 # self._set_sizer_dispersion()2864 # self._set_sizer_dispersion() 2862 2865 self.state.magnetic_on = self.magnetic_on 2863 2866 self.SetupScrolling() … … 2874 2877 running "file:///...." 2875 2878 2876 :param ev t: Triggers on clicking ? in polydispersity box2879 :param event: Triggers on clicking ? in polydispersity box 2877 2880 """ 2878 2881 … … 2912 2915 content = 'sasview_parameter_values:' 2913 2916 # Do it if params exist 2914 if self.parameters != []:2917 if self.parameters: 2915 2918 2916 2919 # go through the parameters … … 2956 2959 2957 2960 # Do it if params exist 2958 if self.parameters != []:2961 if self.parameters: 2959 2962 2960 2963 for param in self.parameters: 2961 content += param[1] #parameter name2964 content += param[1] # parameter name 2962 2965 content += tab 2963 2966 content += param[1] + "_err" … … 2966 2969 content += crlf 2967 2970 2968 # row of values and errors...2971 # row of values and errors... 2969 2972 for param in self.parameters: 2970 content += param[2].GetValue() #value2973 content += param[2].GetValue() # value 2971 2974 content += tab 2972 content += param[4].GetValue() #error2975 content += param[4].GetValue() # error 2973 2976 content += tab 2974 2977 … … 2976 2979 else: 2977 2980 return False 2978 2979 2981 2980 2982 def get_copy_latex(self): … … 2998 3000 2999 3001 # Do it if params exist 3000 if self.parameters != []:3002 if self.parameters: 3001 3003 3002 3004 content += '{|' … … 3007 3009 3008 3010 for index, param in enumerate(self.parameters): 3009 content += param[1].replace('_', '\_') #parameter name3011 content += param[1].replace('_', '\_') # parameter name 3010 3012 content += ' & ' 3011 3013 content += param[1].replace('_', '\_') + "\_err" … … 3015 3017 content += crlf 3016 3018 3017 # row of values and errors...3019 # row of values and errors... 3018 3020 for index, param in enumerate(self.parameters): 3019 content += param[2].GetValue() #parameter value3021 content += param[2].GetValue() # parameter value 3020 3022 content += ' & ' 3021 content += param[4].GetValue() #parameter error3023 content += param[4].GetValue() # parameter error 3022 3024 if index < len(self.parameters) - 1: 3023 3025 content += ' & ' … … 3030 3032 else: 3031 3033 return False 3032 3033 3034 3034 3035 def set_clipboard(self, content=None): … … 3077 3078 # 1D 3078 3079 else: 3079 # #for 1D all parameters except orientation3080 # for 1D all parameters except orientation 3080 3081 if not item[1] in orient_param: 3081 3082 try: … … 3109 3110 except Exception: 3110 3111 logging.error(traceback.format_exc()) 3111 content += name + ',' + str(check) + ',' +\ 3112 value + disfunc + ',' + bound_lo + ',' +\ 3113 bound_hi + ':' 3112 content += name + ',' + str(check) + ',' + value + disfunc + ',' + \ 3113 bound_lo + ',' + bound_hi + ':' 3114 3114 3115 3115 return content … … 3189 3189 3190 3190 # Do it if params exist 3191 if self.parameters != []:3191 if self.parameters: 3192 3192 # go through the parameters 3193 3193 self._get_paste_helper(self.parameters, … … 3237 3237 pd = int(pd) 3238 3238 except Exception: 3239 # continue3239 # continue 3240 3240 if not pd and pd != '': 3241 3241 continue … … 3265 3265 else: 3266 3266 is_true = None 3267 if is_true !=None:3267 if is_true is not None: 3268 3268 item[0].SetValue(is_true) 3269 3269 # 1D 3270 3270 else: 3271 # #for 1D all parameters except orientation3271 # for 1D all parameters except orientation 3272 3272 if not item[1] in orient_param: 3273 3273 name = item[1] … … 3278 3278 pd = value[0] 3279 3279 if name.count('.') > 0: 3280 # If this is parameter.width, then pd may be a floating 3281 # point value or it may be an array distribution. 3282 # Nothing to do for parameter.npts or parameter.nsigmas. 3280 # If this is parameter.width, then pd may be a 3281 # floating point value or it may be an array 3282 # distribution. Nothing to do for parameter.npts or 3283 # parameter.nsigmas. 3283 3284 try: 3284 3285 pd = float(pd) … … 3286 3287 pd = int(pd) 3287 3288 except: 3288 # continue3289 # continue 3289 3290 if not pd and pd != '': 3290 3291 continue … … 3314 3315 else: 3315 3316 is_true = None 3316 if is_true !=None:3317 if is_true is not None: 3317 3318 item[0].SetValue(is_true) 3318 3319 … … 3381 3382 logging.error(traceback.format_exc()) 3382 3383 print "Error in BasePage._paste_poly_help: %s" % \ 3383 3384 sys.exc_info()[1] 3384 3385 3385 3386 def _set_disp_cb(self, isarray, item): … … 3447 3448 self.categorybox.Clear() 3448 3449 cat_list = sorted(self.master_category_dict.keys()) 3449 if not uncat_strin cat_list:3450 if uncat_str not in cat_list: 3450 3451 cat_list.append(uncat_str) 3451 3452 … … 3457 3458 self.categorybox.SetSelection(0) 3458 3459 else: 3459 self.categorybox.SetSelection( \3460 self.categorybox.SetSelection( 3460 3461 self.categorybox.GetSelection()) 3461 # self._on_change_cat(None)3462 # self._on_change_cat(None) 3462 3463 3463 3464 def _on_change_cat(self, event): … … 3467 3468 self.model_name = None 3468 3469 category = self.categorybox.GetStringSelection() 3469 if category ==None:3470 if category is None: 3470 3471 return 3471 3472 self.model_box.Clear() … … 3478 3479 else: 3479 3480 for (model, enabled) in sorted(self.master_category_dict[category], 3480 key=lambda name: name[0]):3481 key=lambda name: name[0]): 3481 3482 if(enabled): 3482 3483 self.model_box.Append(model) … … 3487 3488 """ 3488 3489 # This should only be called once per fit tab 3489 # print "==== Entering _fill_model_sizer"3490 # #Add model function Details button in fitpanel.3491 # #The following 3 lines are for Mac. Let JHC know before modifying...3490 # print "==== Entering _fill_model_sizer" 3491 # Add model function Details button in fitpanel. 3492 # The following 3 lines are for Mac. Let JHC know before modifying... 3492 3493 title = "Model" 3493 3494 self.formfactorbox = None … … 3521 3522 self._populate_listbox() 3522 3523 wx.EVT_COMBOBOX(self.categorybox, wx.ID_ANY, self._show_combox) 3523 # self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes',3524 # self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes', 3524 3525 # style=wx.RB_GROUP) 3525 # self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY,3526 # self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY, 3526 3527 # "Shape-Independent") 3527 # self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY,3528 # self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY, 3528 3529 # "Structure Factor ") 3529 # self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY,3530 # self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY, 3530 3531 # "Uncategorized") 3531 3532 3532 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3533 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3533 3534 # id=self.shape_rbutton.GetId()) 3534 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3535 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3535 3536 # id=self.shape_indep_rbutton.GetId()) 3536 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3537 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3537 3538 # id=self.struct_rbutton.GetId()) 3538 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3539 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3539 3540 # id=self.plugin_rbutton.GetId()) 3540 # MAC needs SetValue3541 # MAC needs SetValue 3541 3542 3542 3543 show_cat_button = wx.Button(self, wx.ID_ANY, "Modify") 3543 3544 cat_tip = "Modify model categories \n" 3544 3545 cat_tip += "(also accessible from the menu bar)." 3545 show_cat_button.SetToolTip( wx.ToolTip(cat_tip))3546 show_cat_button.SetToolTip(wx.ToolTip(cat_tip)) 3546 3547 show_cat_button.Bind(wx.EVT_BUTTON, self._on_modify_cat) 3547 3548 sizer_cat_box.Add(self.categorybox, 1, wx.RIGHT, 3) 3548 sizer_cat_box.Add((10, 10))3549 sizer_cat_box.Add((10, 10)) 3549 3550 sizer_cat_box.Add(show_cat_button) 3550 # self.shape_rbutton.SetValue(True)3551 # self.shape_rbutton.SetValue(True) 3551 3552 3552 3553 sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) 3553 # sizer_radiobutton.Add(self.shape_rbutton)3554 # sizer_radiobutton.Add(self.shape_indep_rbutton)3555 sizer_radiobutton.Add((5, 5))3554 # sizer_radiobutton.Add(self.shape_rbutton) 3555 # sizer_radiobutton.Add(self.shape_indep_rbutton) 3556 sizer_radiobutton.Add((5, 5)) 3556 3557 sizer_radiobutton.Add(self.model_view, 1, wx.RIGHT, 5) 3557 # sizer_radiobutton.Add(self.plugin_rbutton)3558 # sizer_radiobutton.Add(self.struct_rbutton)3559 #sizer_radiobutton.Add((5,5))3558 # sizer_radiobutton.Add(self.plugin_rbutton) 3559 # sizer_radiobutton.Add(self.struct_rbutton) 3560 # sizer_radiobutton.Add((5,5)) 3560 3561 sizer_radiobutton.Add(self.model_help, 1, wx.RIGHT | wx.LEFT, 5) 3561 #sizer_radiobutton.Add((5,5))3562 # sizer_radiobutton.Add((5,5)) 3562 3563 sizer_radiobutton.Add(self.model_func, 1, wx.RIGHT, 5) 3563 3564 sizer_cat.Add(sizer_cat_box, 1, wx.LEFT, 2.5) … … 3575 3576 self.formfactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 3576 3577 self.formfactorbox.SetToolTip(wx.ToolTip("Select a Model")) 3577 if self.model !=None:3578 if self.model is not None: 3578 3579 self.formfactorbox.SetValue(self.model.name) 3579 3580 self.structurebox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) … … 3584 3585 wx.EVT_COMBOBOX(self.structurebox, wx.ID_ANY, self._on_select_model) 3585 3586 wx.EVT_COMBOBOX(self.multifactorbox, wx.ID_ANY, self._on_select_model) 3586 # #check model type to show sizer3587 if self.model !=None:3587 # check model type to show sizer 3588 if self.model is not None: 3588 3589 print "_set_model_sizer_selection: disabled." 3589 # self._set_model_sizer_selection(self.model)3590 # self._set_model_sizer_selection(self.model) 3590 3591 3591 3592 sizer_selection.Add(self.text1) … … 3682 3683 """ 3683 3684 3685 3684 3686 class ModelTextCtrl(wx.TextCtrl): 3685 3687 """ … … 3694 3696 3695 3697 """ 3696 # #Set to True when the mouse is clicked while whole string is selected3698 # Set to True when the mouse is clicked while whole string is selected 3697 3699 full_selection = False 3698 # #Call back for EVT_SET_FOCUS events3700 # Call back for EVT_SET_FOCUS events 3699 3701 _on_set_focus_callback = None 3700 3702 … … 3718 3720 if set_focus_callback is None else set_focus_callback 3719 3721 self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) 3720 self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus \3721 3722 self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \3723 3722 self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus 3723 if kill_focus_callback is None else kill_focus_callback) 3724 self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter 3725 if text_enter_callback is None else text_enter_callback) 3724 3726 if not ON_MAC: 3725 self.Bind(wx.EVT_LEFT_UP, self._highlight_text \3726 3727 self.Bind(wx.EVT_LEFT_UP, self._highlight_text 3728 if mouse_up_callback is None else mouse_up_callback) 3727 3729 3728 3730 def _on_set_focus(self, event): … … 3764 3766 3765 3767 event.Skip() 3766 # pass3768 # pass -
src/sas/sasgui/perspectives/fitting/fitpage.py
r3bec50a rc8e1996 14 14 from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS 15 15 16 from sas.sasgui.guiframe.events import StatusEvent 17 from sas.sasgui.guiframe.events import NewPlotEvent 18 from sas.sasgui.guiframe.events import PlotQrangeEvent 16 from sas.sasgui.guiframe.events import StatusEvent, NewPlotEvent, \ 17 PlotQrangeEvent 19 18 from sas.sasgui.guiframe.dataFitting import check_data_validity 20 from sas.sasgui.guiframe.utils import format_number 21 from sas.sasgui.guiframe.utils import check_float 19 from sas.sasgui.guiframe.utils import format_number, check_float 22 20 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 21 22 from sas.sasgui.perspectives.fitting.basepage import BasicPage as BasicPage 23 from sas.sasgui.perspectives.fitting.basepage import PageInfoEvent as \ 24 PageInfoEvent 25 from sas.sascalc.data_util.qsmearing import smear_selection 26 from .basepage import ModelTextCtrl 23 27 24 28 (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() … … 28 32 SMEAR_SIZE_H = 0.00 29 33 30 from sas.sasgui.perspectives.fitting.basepage import BasicPage as BasicPage31 from sas.sasgui.perspectives.fitting.basepage import PageInfoEvent as PageInfoEvent32 from sas.sascalc.data_util.qsmearing import smear_selection33 from .basepage import ModelTextCtrl34 35 34 36 35 class FitPage(BasicPage): … … 49 48 BasicPage.__init__(self, parent, color=color) 50 49 51 # #draw sizer50 # draw sizer 52 51 self._fill_data_sizer() 53 52 self.is_2D = None … … 72 71 self.enable_fit_button() 73 72 self.fill_data_combobox(data_list=self.data_list) 74 # create a default data for an empty panel73 # create a default data for an empty panel 75 74 self.create_default_data() 76 75 self._manager.frame.Bind(wx.EVT_SET_FOCUS, self.on_set_focus) … … 105 104 self.data_box_description.SetForegroundColour(dname_color) 106 105 boxsizer1 = wx.StaticBoxSizer(self.data_box_description, wx.VERTICAL) 107 # ----------------------------------------------------------106 # ---------------------------------------------------------- 108 107 sizer_data = wx.BoxSizer(wx.HORIZONTAL) 109 108 self.dataSource = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) … … 134 133 self.enable_datasource() 135 134 if len(data_list) > 0: 136 # find the maximum range covering all data135 # find the maximum range covering all data 137 136 qmin, qmax, npts = self.compute_data_set_range(data_list) 138 137 self.qmin_data_set = qmin … … 185 184 186 185 :return: True or False 187 188 186 """ 189 187 if self.data.__class__.__name__ == "Data2D" or \ … … 199 197 buttons, xi^2, number of points etc. 200 198 """ 201 is_2 Ddata = False199 is_2d_data = False 202 200 203 201 # Check if data is 2D 204 202 if self.data.__class__.__name__ == "Data2D" or \ 205 203 self.enable2D: 206 is_2 Ddata = True204 is_2d_data = True 207 205 208 206 title = "Fitting" 209 # smear messages & titles207 # smear messages & titles 210 208 smear_message_none = "No smearing is selected..." 211 209 smear_message_dqdata = "The dQ data is being used for smearing..." … … 225 223 self._get_smear_info() 226 224 227 # Sizers225 # Sizers 228 226 box_description_range = wx.StaticBox(self, wx.ID_ANY, str(title)) 229 227 box_description_range.SetForegroundColour(wx.BLUE) … … 244 242 sizer_weighting = wx.BoxSizer(wx.HORIZONTAL) 245 243 weighting_box.SetMinSize((_DATA_BOX_WIDTH, 40)) 246 # Filling the sizer containing weighting info.244 # Filling the sizer containing weighting info. 247 245 self.dI_noweight = wx.RadioButton(self, wx.ID_ANY, 248 246 'No Weighting', style=wx.RB_GROUP) … … 286 284 self._on_select_accuracy) 287 285 288 # Fit button286 # Fit button 289 287 self.btFit = wx.Button(self, self._ids.next(), 'Fit') 290 288 self.default_bt_colour = self.btFit.GetDefaultAttributes() … … 292 290 self.btFit.SetToolTipString("Start fitting.") 293 291 294 # General Help button292 # General Help button 295 293 self.btFitHelp = wx.Button(self, wx.ID_ANY, 'Help') 296 294 self.btFitHelp.SetToolTipString("General fitting help.") 297 295 self.btFitHelp.Bind(wx.EVT_BUTTON, self._onFitHelp) 298 296 299 # Resolution Smearing Help button (for now use same technique as300 # used for dI help to get tiniest possible button that works301 # both on MAC and PC. Should completely rewrite the fitting sizer302 # in future. This is minimum to get out release 3.1297 # Resolution Smearing Help button (for now use same technique as 298 # used for dI help to get tiniest possible button that works 299 # both on MAC and PC. Should completely rewrite the fitting sizer 300 # in future. This is minimum to get out release 3.1 303 301 # comment June 14, 2015 --- PDB 304 302 if sys.platform.count("win32") > 0: 305 size_q = (20, 15) # on PC303 size_q = (20, 15) # on PC 306 304 else: 307 size_q = (30, 20) # on MAC305 size_q = (30, 20) # on MAC 308 306 self.btSmearHelp = wx.Button(self, wx.ID_ANY, '?', 309 307 style=wx.BU_EXACTFIT, size=size_q) … … 311 309 self.btSmearHelp.Bind(wx.EVT_BUTTON, self._onSmearHelp) 312 310 313 # textcntrl for custom resolution311 # textcntrl for custom resolution 314 312 self.smear_pinhole_max = ModelTextCtrl(self, wx.ID_ANY, 315 313 size=(_BOX_WIDTH - 25, 20), … … 329 327 text_enter_callback=self.onSlitSmear) 330 328 331 # #smear329 # smear 332 330 self.smear_data_left = BGTextCtrl(self, wx.ID_ANY, 333 331 size=(_BOX_WIDTH - 25, 20), style=0) … … 337 335 self.smear_data_right.SetValue(str(self.dq_r)) 338 336 339 # set default values for smear337 # set default values for smear 340 338 self.smear_pinhole_max.SetValue(str(self.dx_max)) 341 339 self.smear_pinhole_min.SetValue(str(self.dx_min)) … … 343 341 self.smear_slit_width.SetValue(str(self.dxw)) 344 342 345 # Filling the sizer containing instruments smearing info.343 # Filling the sizer containing instruments smearing info. 346 344 self.disable_smearer = wx.RadioButton(self, wx.ID_ANY, 347 345 'None', style=wx.RB_GROUP) 348 346 self.enable_smearer = wx.RadioButton(self, wx.ID_ANY, 'Use dQ Data') 349 # self.enable_smearer.SetToolTipString(350 # "Click to use the loaded dQ data for smearing.")347 # self.enable_smearer.SetToolTipString( 348 # "Click to use the loaded dQ data for smearing.") 351 349 self.pinhole_smearer = wx.RadioButton(self, wx.ID_ANY, 352 350 'Custom Pinhole Smear') 353 # self.pinhole_smearer.SetToolTipString354 # ("Click to input custom resolution for pinhole smearing.")351 # self.pinhole_smearer.SetToolTipString 352 # ("Click to input custom resolution for pinhole smearing.") 355 353 self.slit_smearer = wx.RadioButton(self, wx.ID_ANY, 'Custom Slit Smear') 356 # self.slit_smearer.SetToolTipString357 # ("Click to input custom resolution for slit smearing.")354 # self.slit_smearer.SetToolTipString 355 # ("Click to input custom resolution for slit smearing.") 358 356 self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, 359 357 id=self.disable_smearer.GetId()) … … 378 376 self.Npts_fit = BGTextCtrl(self, wx.ID_ANY, "-", size=(75, 20), style=0) 379 377 self.Npts_fit.SetToolTipString( 380 378 " Npts : number of points selected for fitting") 381 379 self.Npts_total = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 382 style=wx.TE_PROCESS_ENTER,383 text_enter_callback=self._onQrangeEnter)380 style=wx.TE_PROCESS_ENTER, 381 text_enter_callback=self._onQrangeEnter) 384 382 self.Npts_total.SetValue(format_number(self.npts_x)) 385 self.Npts_total.SetToolTipString( \386 383 self.Npts_total.SetToolTipString( 384 " Total Npts : total number of data points") 387 385 388 386 # Update and Draw button … … 429 427 self.smear_description_2d_y = wx.StaticText(self, wx.ID_ANY, 430 428 smear_message_2d_y_title, style=wx.ALIGN_LEFT) 431 self.smear_description_2d_y.SetToolTipString( \429 self.smear_description_2d_y.SetToolTipString( 432 430 " dQs(perpendicular) in q_phi direction.") 433 431 self.smear_description_pin_min = wx.StaticText(self, wx.ID_ANY, … … 440 438 smear_message_slit_width_title, style=wx.ALIGN_LEFT) 441 439 442 # arrange sizers440 # arrange sizers 443 441 self.sizer_set_smearer.Add(sizer_smearer) 444 442 self.sizer_set_smearer.Add((10, 10)) 445 443 self.sizer_set_smearer.Add(self.smear_description_none, 446 444 0, wx.CENTER, 10) 447 445 self.sizer_set_smearer.Add(self.smear_description_dqdata, 448 446 0, wx.CENTER, 10) 449 447 self.sizer_set_smearer.Add(self.smear_description_2d, 450 448 0, wx.CENTER, 10) 451 449 self.sizer_new_smear.Add(self.smear_description_type, 452 450 0, wx.CENTER, 10) 453 451 self.sizer_new_smear.Add(self.smear_description_accuracy_type, 454 452 0, wx.CENTER, 10) 455 453 self.sizer_new_smear.Add(self.smear_accuracy) 456 454 self.sizer_new_smear.Add(self.smear_description_smear_type, 457 455 0, wx.CENTER, 10) 458 456 self.sizer_new_smear.Add((15, -1)) 459 self.sizer_new_smear.Add(self.smear_description_2d_x, 460 0, wx.CENTER, 10) 457 self.sizer_new_smear.Add(self.smear_description_2d_x, 0, wx.CENTER, 10) 461 458 self.sizer_new_smear.Add(self.smear_description_pin_min, 462 459 0, wx.CENTER, 10) 463 460 self.sizer_new_smear.Add(self.smear_description_slit_height, 464 0, wx.CENTER, 10) 465 466 self.sizer_new_smear.Add(self.smear_pinhole_min, 467 0, wx.CENTER, 10) 468 self.sizer_new_smear.Add(self.smear_slit_height, 469 0, wx.CENTER, 10) 470 self.sizer_new_smear.Add(self.smear_data_left, 471 0, wx.CENTER, 10) 461 0, wx.CENTER, 10) 462 463 self.sizer_new_smear.Add(self.smear_pinhole_min, 0, wx.CENTER, 10) 464 self.sizer_new_smear.Add(self.smear_slit_height, 0, wx.CENTER, 10) 465 self.sizer_new_smear.Add(self.smear_data_left, 0, wx.CENTER, 10) 472 466 self.sizer_new_smear.Add((20, -1)) 473 467 self.sizer_new_smear.Add(self.smear_description_2d_y, 474 468 0, wx.CENTER, 10) 475 469 self.sizer_new_smear.Add(self.smear_description_pin_max, 476 470 0, wx.CENTER, 10) 477 471 self.sizer_new_smear.Add(self.smear_description_slit_width, 478 472 0, wx.CENTER, 10) 479 473 480 474 self.sizer_new_smear.Add(self.smear_pinhole_max, 0, wx.CENTER, 10) … … 501 495 502 496 # Show only the relevant smear messages, etc 503 if self.current_smearer ==None:504 if not is_2 Ddata:497 if self.current_smearer is None: 498 if not is_2d_data: 505 499 self.smear_description_none.Show(True) 506 500 self.enable_smearer.Disable() … … 508 502 self.smear_description_none.Show(True) 509 503 self.slit_smearer.Disable() 510 if self.data ==None:504 if self.data is None: 511 505 self.slit_smearer.Disable() 512 506 self.pinhole_smearer.Disable() … … 515 509 self._show_smear_sizer() 516 510 boxsizer_range.Add(self.sizer_set_masking) 517 # 2D data? default518 is_2 Ddata = False519 520 # check if it is 2D data511 # 2D data? default 512 is_2d_data = False 513 514 # check if it is 2D data 521 515 if self.data.__class__.__name__ == "Data2D" or self.enable2D: 522 is_2 Ddata = True516 is_2d_data = True 523 517 524 518 self.sizer5.Clear(True) … … 568 562 sizer.Add(wx.StaticText(self, wx.ID_ANY, ' Max[1/A]')) 569 563 sizer.Add(self.EditMask_title) 570 sizer.Add((-1, 5))564 sizer.Add((-1, 5)) 571 565 572 566 sizer.Add(self.reset_qrange) … … 574 568 sizer.Add(self.qmax) 575 569 sizer.Add(self.btEditMask) 576 sizer.Add((-1, 5))577 578 sizer.AddMany(5*[(-1, 5)])570 sizer.Add((-1, 5)) 571 572 sizer.AddMany(5*[(-1, 5)]) 579 573 580 574 sizer.Add(box_description_1, 0, 0) … … 582 576 sizer.Add(self.points_sizer, 0, 0) 583 577 sizer.Add(self.draw_button, 0, 0) 584 sizer.Add((-1, 5))578 sizer.Add((-1, 5)) 585 579 586 580 sizer.Add(self.tcChi, 0, 0) … … 592 586 boxsizer_range.Add(sizer_chi2) 593 587 boxsizer_range.Add(sizer) 594 if is_2 Ddata:588 if is_2d_data: 595 589 self.btEditMask.Enable() 596 590 self.EditMask_title.Enable() … … 598 592 self.btEditMask.Disable() 599 593 self.EditMask_title.Disable() 600 # #save state594 # save state 601 595 self.save_current_state() 602 596 self.sizer5.Add(boxsizer_range, 0, wx.EXPAND | wx.ALL, 10) 603 597 self.sizer5.Layout() 604 598 605 606 599 def _set_sizer_dispersion(self): 607 600 """ … … 613 606 614 607 self.sizer4_4.Clear(True) 615 if self.model ==None:616 # #no model is selected608 if self.model is None: 609 # no model is selected 617 610 return 618 611 if not self.enable_disp.GetValue(): 619 # #the user didn't select dispersity display612 # the user didn't select dispersity display 620 613 return 621 614 622 615 self._reset_dispersity() 623 616 624 # #fill a sizer with the combobox to select dispersion type617 # fill a sizer with the combobox to select dispersion type 625 618 model_disp = wx.StaticText(self, wx.ID_ANY, 'Function') 626 619 CHECK_STATE = False … … 645 638 err_text = '' 646 639 self.text_disp_1 = wx.StaticText(self, wx.ID_ANY, err_text) 647 self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), \640 self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), 648 641 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 649 642 650 643 ix += 1 651 644 self.text_disp_min = wx.StaticText(self, wx.ID_ANY, 'Min') 652 self.sizer4_4.Add(self.text_disp_min, (iy, ix), (1, 1), \645 self.sizer4_4.Add(self.text_disp_min, (iy, ix), (1, 1), 653 646 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 654 647 … … 683 676 if item in self.model.magnetic_params: 684 677 continue 685 if not itemin self.model.orientation_params:686 if not itemin self.disp_cb_dict:678 if item not in self.model.orientation_params: 679 if item not in self.disp_cb_dict: 687 680 self.disp_cb_dict[item] = None 688 681 name0 = "Distribution of " + item … … 690 683 name2 = item + ".npts" 691 684 name3 = item + ".nsigmas" 692 if n ot name1in self.model.details:685 if name1 not in self.model.details: 693 686 self.model.details[name1] = ["", None, None] 694 687 … … 716 709 ctl1.SetValue(str(format_number(value, True))) 717 710 self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 718 # #text to show error sign711 # text to show error sign 719 712 ix = 2 720 713 text2 = wx.StaticText(self, wx.ID_ANY, '+/-') … … 776 769 Tct2.SetValue(str(format_number(value))) 777 770 self.sizer4_4.Add(Tct2, (iy, ix), (1, 1), 778 771 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 779 772 self.fixed_param.append([None, name3, Tct2, 780 773 None, None, None, … … 802 795 if item in self.model.magnetic_params: 803 796 continue 804 if 805 if not itemin self.disp_cb_dict:797 if item in self.model.orientation_params: 798 if item not in self.disp_cb_dict: 806 799 self.disp_cb_dict[item] = None 807 800 name0 = "Distribution of " + item … … 810 803 name3 = item + ".nsigmas" 811 804 812 if n ot name1in self.model.details:805 if name1 not in self.model.details: 813 806 self.model.details[name1] = ["", None, None] 814 807 … … 855 848 856 849 self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 857 # #text to show error sign850 # text to show error sign 858 851 ix = 2 859 852 text2 = wx.StaticText(self, wx.ID_ANY, '+/-') … … 968 961 969 962 self.state.model = self.model.clone() 970 # #save state into963 # save state into 971 964 self._copy_parameters_state(self.parameters, self.state.parameters) 972 965 self._copy_parameters_state(self.orientation_params_disp, … … 978 971 wx.PostEvent(self.parent, 979 972 StatusEvent(status=" Selected Distribution: Gaussian")) 980 # Fill the list of fittable parameters973 # Fill the list of fittable parameters 981 974 self.get_all_checked_params() 982 975 self.Layout() … … 986 979 Update and Draw the model 987 980 """ 988 if self.model ==None:981 if self.model is None: 989 982 msg = "Please select a Model first..." 990 983 wx.MessageBox(msg, 'Info') … … 996 989 self.create_default_data() 997 990 """ 998 flag, is_modified = self._update_paramv_on_fit()999 1000 wx.CallAfter(self._onparamEnter_helper, is_modified)991 flag, is_modified = self._update_paramv_on_fit() 992 993 wx.CallAfter(self._onparamEnter_helper, is_modified) 1001 994 if not flag: 1002 995 msg = "The parameters are invalid" … … 1008 1001 Allow to fit 1009 1002 """ 1010 if event !=None:1003 if event is not None: 1011 1004 event.Skip() 1012 1005 if self.fit_started: … … 1048 1041 return 1049 1042 1050 self.select_param( event=None)1043 self.select_param() 1051 1044 1052 1045 # Remove or do not allow fitting on the Q=0 point, especially … … 1059 1052 qmax=self.qmax_x) 1060 1053 1061 # single fit1062 # self._manager.onFit(uid=self.uid)1054 # single fit 1055 # self._manager.onFit(uid=self.uid) 1063 1056 self.fit_started = self._manager.onFit(uid=self.uid) 1064 1057 wx.CallAfter(self.set_fitbutton) … … 1073 1066 versions of Wx (before 2.9) and thus not the release version of 1074 1067 installers, the help comes up at the top level of the file as 1075 web browser does not pass anything past the # to the browser when it is1068 web browser does not pass anything past the # to the browser when it is 1076 1069 running "file:///...." 1077 1070 1078 :param evt: Triggers on clicking the help button1079 """1071 :param evt: Triggers on clicking the help button 1072 """ 1080 1073 1081 1074 _TreeLocation = "user/sasgui/perspectives/fitting/fitting_help.html" … … 1092 1085 versions of Wx (before 2.9) and thus not the release version of 1093 1086 installers, the help comes up at the top level of the file as 1094 web browser does not pass anything past the # to the browser when it is1087 web browser does not pass anything past the # to the browser when it is 1095 1088 running "file:///...." 1096 1089 1097 :param evt: Triggers on clicking the help button1098 """1090 :param evt: Triggers on clicking the help button 1091 """ 1099 1092 1100 1093 _TreeLocation = "user/sasgui/perspectives/fitting/sm_help.html" … … 1108 1101 """ 1109 1102 # Skip this feature if we are not on Windows 1110 # NOTE: the is_mac data member actually means "is no Windows".1103 # NOTE: the is_mac data member actually means "is no Windows". 1111 1104 if self.is_mac: 1112 1105 return … … 1118 1111 label = "Fit" 1119 1112 color = "black" 1120 # self.btFit.Enable(False)1113 # self.btFit.Enable(False) 1121 1114 self.btFit.SetLabel(label) 1122 1115 self.btFit.SetForegroundColour(color) … … 1149 1142 Stop fit 1150 1143 """ 1151 if event !=None:1144 if event is not None: 1152 1145 event.Skip() 1153 1146 self._manager.stop_fit(self.uid) … … 1169 1162 copy_flag = False 1170 1163 is_poly_enabled = None 1171 if event !=None:1172 if (event.GetEventObject() == self.formfactorbox \1164 if event is not None: 1165 if (event.GetEventObject() == self.formfactorbox 1173 1166 and self.structurebox.GetLabel() != 'None')\ 1174 1167 or event.GetEventObject() == self.structurebox\ … … 1183 1176 self._keep.Enable(False) 1184 1177 self._set_save_flag(False) 1185 # TODO: why do we have to variables for one flag??1186 1178 self.enable_disp.SetValue(False) 1187 1179 self.disable_disp.SetValue(True) … … 1213 1205 self._keep.Enable(not self.batch_on) 1214 1206 self._set_save_flag(True) 1207 self._set_smear(self.data) 1215 1208 1216 1209 # more disables for 2D … … 1226 1219 except: 1227 1220 raise 1228 # #error occured on chisqr computation1229 # pass1230 # #event to post model to fit to fitting plugins1221 # error occured on chisqr computation 1222 # pass 1223 # event to post model to fit to fitting plugins 1231 1224 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 1232 1225 1233 ## set smearing value whether or not 1234 # the data contain the smearing info 1226 # set smearing value whether or not data contain the smearing info 1235 1227 evt = ModelEventbox(model=self.model, 1236 1228 smearer=temp_smear, … … 1242 1234 1243 1235 self._manager._on_model_panel(evt=evt) 1244 self.mbox_description.SetLabel("Model [ %s ]" % str(self.model.name)) 1236 self.mbox_description.SetLabel("Model [ %s ]" % 1237 str(self.model.name)) 1245 1238 self.mbox_description.SetForegroundColour(wx.BLUE) 1246 1239 self.state.model = self.model.clone() 1247 1240 self.state.model.name = self.model.name 1248 1241 1249 if event !=None:1250 # #post state to fit panel1242 if event is not None: 1243 # post state to fit panel 1251 1244 new_event = PageInfoEvent(page=self) 1252 1245 wx.PostEvent(self.parent, new_event) 1253 # update list of plugins if new plugin is available1246 # update list of plugins if new plugin is available 1254 1247 custom_model = 'Customized Models' 1255 1248 mod_cat = self.categorybox.GetStringSelection() … … 1264 1257 self.formfactorbox.SetValue(current_val) 1265 1258 # when select a model only from guictr/button 1266 if is_poly_enabled !=None:1259 if is_poly_enabled is not None: 1267 1260 self.enable_disp.SetValue(is_poly_enabled) 1268 1261 self.disable_disp.SetValue(not is_poly_enabled) … … 1292 1285 when enter value on panel redraw model according to changed 1293 1286 """ 1294 if self.model ==None:1287 if self.model is None: 1295 1288 msg = "Please select a Model first..." 1296 1289 wx.MessageBox(msg, 'Info') 1297 1290 return 1298 1291 1299 # default flag1292 # default flag 1300 1293 flag = False 1301 1294 self.fitrange = True 1302 # get event object1295 # get event object 1303 1296 tcrtl = event.GetEventObject() 1304 # Clear msg if previously shown.1297 # Clear msg if previously shown. 1305 1298 msg = "" 1306 1299 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1313 1306 if not self.disable_smearer.GetValue(): 1314 1307 temp_smearer = self.current_smearer 1315 # # set smearing value whether or not1316 # the data contain thesmearing info1308 # set smearing value whether or not data contain the 1309 # smearing info 1317 1310 if self.slit_smearer.GetValue(): 1318 1311 flag1 = self.update_slit_smear() … … 1331 1324 enable_smearer=enable_smearer) 1332 1325 if flag: 1333 # self.compute_chisqr(smearer= temp_smearer)1334 1335 # #new state posted1326 # self.compute_chisqr(smearer= temp_smearer) 1327 1328 # new state posted 1336 1329 if self.state_change: 1337 # self._undo.Enable(True)1330 # self._undo.Enable(True) 1338 1331 event = PageInfoEvent(page=self) 1339 1332 wx.PostEvent(self.parent, event) … … 1345 1338 else: 1346 1339 self.save_current_state() 1347 msg = "Cannot Plot :Must enter a number!!! "1340 msg = "Cannot Plot: Must enter a number!!! " 1348 1341 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1349 1342 … … 1356 1349 """ 1357 1350 tcrtl = event.GetEventObject() 1358 # Clear msg if previously shown.1351 # Clear msg if previously shown. 1359 1352 msg = "" 1360 1353 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1374 1367 tcrtl.SetBackgroundColour(wx.WHITE) 1375 1368 1376 # self._undo.Enable(True)1369 # self._undo.Enable(True) 1377 1370 self.save_current_state() 1378 1371 event = PageInfoEvent(page=self) … … 1384 1377 ON Qrange focus 1385 1378 """ 1386 if event !=None:1379 if event is not None: 1387 1380 event.Skip() 1388 # tcrtl = event.GetEventObject()1381 # tcrtl = event.GetEventObject() 1389 1382 self._validate_qrange(self.qmin, self.qmax) 1390 1383 … … 1393 1386 On Qrange textctrl click, make the qrange lines in the plot 1394 1387 """ 1395 if event !=None:1388 if event is not None: 1396 1389 event.Skip() 1397 1390 if self.data.__class__.__name__ == "Data2D": … … 1411 1404 #On q range value updated. DO not combine with qrange_click(). 1412 1405 """ 1413 if event !=None:1406 if event is not None: 1414 1407 event.Skip() 1415 1408 if self.data.__class__.__name__ == "Data2D": … … 1439 1432 length = len(self.data.x) 1440 1433 indx = (numpy.abs(self.data.x - x_data)).argmin() 1441 # return array.flat[idx]1434 # return array.flat[idx] 1442 1435 if key == wx.WXK_PAGEUP or key == wx.WXK_NUMPAD_PAGEUP: 1443 1436 indx += 1 … … 1458 1451 """ 1459 1452 tcrtl = event.GetEventObject() 1460 # Clear msg if previously shown.1453 # Clear msg if previously shown. 1461 1454 msg = "" 1462 1455 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1488 1481 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1489 1482 return 1490 # Check if # of points for theory model are valid(>0).1483 # Check if # of points for theory model are valid(>0). 1491 1484 # check for 2d 1492 1485 if self.data.__class__.__name__ == "Data2D" or \ … … 1495 1488 radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + 1496 1489 self.data.qy_data * self.data.qy_data) 1497 index_data = ((self.qmin_x <= radius) & \ 1498 (radius <= self.qmax_x)) 1490 index_data = ((self.qmin_x <= radius) & (radius <= self.qmax_x)) 1499 1491 index_data = (index_data) & (self.data.mask) 1500 1492 index_data = (index_data) & (numpy.isfinite(self.data.data)) … … 1506 1498 return 1507 1499 else: 1508 # self.data.mask = index_data1509 # self.Npts_fit.SetValue(str(len(self.data.mask)))1500 # self.data.mask = index_data 1501 # self.Npts_fit.SetValue(str(len(self.data.mask))) 1510 1502 self.show_npts2fit() 1511 1503 else: 1512 index_data = ((self.qmin_x <= self.data.x) & \1504 index_data = ((self.qmin_x <= self.data.x) & 1513 1505 (self.data.x <= self.qmax_x)) 1514 1506 self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) … … 1543 1535 for item in self.parameters: 1544 1536 if item[0].IsShown(): 1545 # Skip the angle parameters if 1D data1537 # Skip the angle parameters if 1D data 1546 1538 if self.data.__class__.__name__ != "Data2D" and \ 1547 1539 not self.enable2D: … … 1550 1542 if item in self.param_toFit: 1551 1543 continue 1552 # #hide statictext +/-1544 # hide statictext +/- 1553 1545 if len(item) < 4: 1554 1546 continue 1555 if item[3] !=None and item[3].IsShown():1547 if item[3] is not None and item[3].IsShown(): 1556 1548 item[3].Hide() 1557 # #hide textcrtl for error after fit1558 if item[4] !=None and item[4].IsShown():1549 # hide textcrtl for error after fit 1550 if item[4] is not None and item[4].IsShown(): 1559 1551 item[4].Hide() 1560 1552 … … 1562 1554 for item in self.fittable_param: 1563 1555 if item[0].IsShown(): 1564 # Skip the angle parameters if 1D data1556 # Skip the angle parameters if 1D data 1565 1557 if self.data.__class__.__name__ != "Data2D" and \ 1566 1558 not self.enable2D: … … 1571 1563 if len(item) < 4: 1572 1564 continue 1573 # #hide statictext +/-1574 if item[3] !=None and item[3].IsShown():1565 # hide statictext +/- 1566 if item[3] is not None and item[3].IsShown(): 1575 1567 item[3].Hide() 1576 # #hide textcrtl for error after fit1577 if item[4] !=None and item[4].IsShown():1568 # hide textcrtl for error after fit 1569 if item[4] is not None and item[4].IsShown(): 1578 1570 item[4].Hide() 1579 1571 return … … 1584 1576 """ 1585 1577 # get the default values 1586 if self.dxl ==None:1578 if self.dxl is None: 1587 1579 self.dxl = 0.0 1588 if self.dxw ==None:1580 if self.dxw is None: 1589 1581 self.dxw = "" 1590 if self.dx_min ==None:1582 if self.dx_min is None: 1591 1583 self.dx_min = SMEAR_SIZE_L 1592 if self.dx_max ==None:1584 if self.dx_max is None: 1593 1585 self.dx_max = SMEAR_SIZE_H 1594 1586 … … 1611 1603 elif self.data.__class__.__name__ == "Data2D" or \ 1612 1604 self.enable2D: 1613 if data.dqx_data == None or data.dqy_data ==None:1605 if data.dqx_data is None or data.dqy_data is None: 1614 1606 return 1615 elif self.current_smearer !=None \1607 elif self.current_smearer is not None \ 1616 1608 and data.dqx_data.any() != 0 \ 1617 1609 and data.dqx_data.any() != 0: … … 1623 1615 return 1624 1616 # check if it is pinhole smear and get min max if it is. 1625 if data.dx != None and all(data.dx != 0):1617 if data.dx is not None and not numpy.any(data.dx): 1626 1618 self.smear_type = "Pinhole" 1627 1619 self.dq_l = data.dx[0] … … 1629 1621 1630 1622 # check if it is slit smear and get min max if it is. 1631 elif data.dxl != None or data.dxw !=None:1623 elif data.dxl is not None or data.dxw is not None: 1632 1624 self.smear_type = "Slit" 1633 if data.dxl != None and all(data.dxl !=0):1625 if data.dxl is not None and not numpy.all(data.dxl, 0): 1634 1626 self.dq_l = data.dxl[0] 1635 if data.dxw != None and all(data.dxw !=0):1627 if data.dxw is not None and not numpy.all(data.dxw, 0): 1636 1628 self.dq_r = data.dxw[0] 1637 # return self.smear_type,self.dq_l,self.dq_r1629 # return self.smear_type,self.dq_l,self.dq_r 1638 1630 1639 1631 def _show_smear_sizer(self): … … 1659 1651 1660 1652 self.smear_description_dqdata.Show(True) 1661 if self.smear_type !=None:1653 if self.smear_type is not None: 1662 1654 self.smear_description_smear_type.Show(True) 1663 1655 if self.smear_type == 'Slit': … … 1750 1742 Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low 1751 1743 """ 1752 # event.Skip()1744 # event.Skip() 1753 1745 # Check if the accuracy is same as before 1754 # self.smear2d_accuracy = event.GetEventObject().GetValue()1746 # self.smear2d_accuracy = event.GetEventObject().GetValue() 1755 1747 self.smear2d_accuracy = self.smear_accuracy.GetValue() 1756 1748 if self.pinhole_smearer.GetValue(): … … 1758 1750 else: 1759 1751 self.onSmear(event=None) 1760 if self.current_smearer !=None:1752 if self.current_smearer is not None: 1761 1753 self.current_smearer.set_accuracy(accuracy=\ 1762 1754 self.smear2d_accuracy) … … 1790 1782 Build a panel to allow to edit Mask 1791 1783 """ 1792 from sas.sasgui.guiframe.local_perspectives.plotting.masking \1793 importMaskPanel as MaskDialog1784 from sas.sasgui.guiframe.local_perspectives.plotting.masking import \ 1785 MaskPanel as MaskDialog 1794 1786 1795 1787 self.panel = MaskDialog(base=self, data=self.data, id=wx.NewId()) … … 1802 1794 is_valid_qrange = self._update_paramv_on_fit() 1803 1795 1804 if is_valid_qrange and self.model !=None:1796 if is_valid_qrange and self.model is not None: 1805 1797 self.panel.MakeModal(False) 1806 1798 event.Skip() … … 1808 1800 self._draw_model() 1809 1801 self.show_npts2fit() 1810 elif self.model ==None:1802 elif self.model is None: 1811 1803 self.panel.MakeModal(False) 1812 1804 event.Skip() … … 1875 1867 npts = len(data.x) 1876 1868 except: 1877 msg = "Unable to find min/max/length of \n data named %s" % 1869 msg = "Unable to find min/max/length of \n data named %s" %\ 1878 1870 data.filename 1879 1871 wx.PostEvent(self._manager.parent, StatusEvent(status=msg, … … 1892 1884 info="error")) 1893 1885 raise ValueError, msg 1894 # #Maximum value of data1886 # Maximum value of data 1895 1887 qmax = math.sqrt(x * x + y * y) 1896 1888 npts = len(data.data) … … 1904 1896 flag = False 1905 1897 is_data = False 1898 npts = 0 1906 1899 try: 1907 1900 old_id = self.data.id … … 1915 1908 flag = True 1916 1909 if data is not None: 1917 id = data.id1918 1910 if is_data: 1919 1911 self.graph_id = self.data.group_id … … 1930 1922 self._set_save_flag(False) 1931 1923 else: 1932 if self.model !=None:1924 if self.model is not None: 1933 1925 self._set_bookmark_flag(not self.batch_on) 1934 1926 self._keep.Enable(not self.batch_on) … … 1937 1929 self._set_preview_flag(True) 1938 1930 1939 self._set_smear(data)1940 1931 # more disables for 2D 1941 1932 if self.data.__class__.__name__ == "Data2D" or \ … … 1944 1935 self.pinhole_smearer.Enable(True) 1945 1936 self.default_mask = copy.deepcopy(self.data.mask) 1946 if self.data.err_data ==None or\1947 (self.data.err_data == 1).all() or\1948 (self.data.err_data == 0).all():1937 if self.data.err_data is None or\ 1938 numpy.all(err == 1 for err in self.data.err_data) or \ 1939 not numpy.any(self.data.err_data): 1949 1940 self.dI_didata.Enable(False) 1950 1941 self.dI_noweight.SetValue(True) … … 1957 1948 self.slit_smearer.Enable(True) 1958 1949 self.pinhole_smearer.Enable(True) 1959 if self.data.dy == None or\ 1960 (self.data.dy == 1).all() or\ 1961 (self.data.dy == 0).all(): 1950 1951 if self.data.dy is None or\ 1952 numpy.all(self.data.dy == 1) or\ 1953 not numpy.any(self.data.dy): 1962 1954 self.dI_didata.Enable(False) 1963 1955 self.dI_noweight.SetValue(True) … … 1967 1959 self.dI_didata.SetValue(True) 1968 1960 self.weightbt_string = self.dI_didata.GetLabelText() 1969 # Enable weighting radio uttons1961 # Enable weighting radio buttons 1970 1962 self.dI_noweight.Enable(True) 1971 1963 self.dI_sqrdata.Enable(True) … … 1976 1968 data_name = self.data.name 1977 1969 _, _, npts = self.compute_data_range(self.data) 1978 # set maximum range for x in linear scale1970 # set maximum range for x in linear scale 1979 1971 if not hasattr(self.data, "data"): # Display only for 1D data fit 1980 1972 self.btEditMask.Disable() … … 1985 1977 1986 1978 self.Npts_total.SetValue(str(npts)) 1987 # default:number of data points selected to fit1979 # default:number of data points selected to fit 1988 1980 self.Npts_fit.SetValue(str(npts)) 1989 1981 self.Npts_total.SetEditable(False) 1990 self.Npts_total.SetBackgroundColour( \1982 self.Npts_total.SetBackgroundColour( 1991 1983 self.GetParent().GetBackgroundColour()) 1992 1984 … … 1998 1990 # send graph_id to page_finder 1999 1991 self._manager.set_graph_id(uid=self.uid, graph_id=self.graph_id) 2000 # focus the page1992 # focus the page 2001 1993 if check_data_validity(data): 2002 1994 self.data_box_description.SetForegroundColour(wx.BLUE) … … 2010 2002 self.on_set_focus(None) 2011 2003 self.Refresh() 2012 # update model plot with new data information2004 # update model plot with new data information 2013 2005 if flag: 2014 #set model view button2015 self.onSmear(None)2016 2017 2006 if self.data.__class__.__name__ == "Data2D": 2018 2007 self.enable2D = True … … 2022 2011 self.model_view.SetLabel("1D Mode") 2023 2012 self.model_view.Disable() 2024 # replace data plot on combo box selection2025 # by removing the previous selected data2013 # replace data plot on combo box selection 2014 # by removing the previous selected data 2026 2015 try: 2027 2016 wx.PostEvent(self._manager.parent, … … 2030 2019 except: 2031 2020 pass 2032 # plot the current selected data2021 # plot the current selected data 2033 2022 wx.PostEvent(self._manager.parent, 2034 2023 NewPlotEvent(action="check", plot=self.data, … … 2050 2039 self.reset_page_helper(state) 2051 2040 2052 self.select_param( event=None)2053 # Save state_fit2041 self.select_param() 2042 # Save state_fit 2054 2043 self.save_current_state_fit() 2055 2044 except: … … 2090 2079 else: 2091 2080 for qx in self.data.x: 2092 if q x >= qmin and qx <= qmax:2081 if qmax >= qx >= qmin: 2093 2082 npts2fit += 1 2094 2083 return npts2fit … … 2119 2108 # make sure stop button to fit button all the time 2120 2109 self._on_fit_complete() 2121 if out ==None or not numpy.isfinite(chisqr):2110 if out is None or not numpy.isfinite(chisqr): 2122 2111 raise ValueError, "Fit error occured..." 2123 2112 … … 2126 2115 dispersity = '' 2127 2116 2128 # Hide textctrl boxes of errors.2117 # Hide textctrl boxes of errors. 2129 2118 self._clear_Err_on_Fit() 2130 2119 2131 # Check if chi2 is finite2132 if chisqr !=None and numpy.isfinite(chisqr):2133 # format chi22120 # Check if chi2 is finite 2121 if chisqr is not None and numpy.isfinite(chisqr): 2122 # format chi2 2134 2123 chi2 = format_number(chisqr, True) 2135 2124 self.tcChi.SetValue(chi2) … … 2138 2127 self.tcChi.SetValue("-") 2139 2128 2140 # Hide error title2129 # Hide error title 2141 2130 if self.text2_3.IsShown() and not self.is_mac: 2142 2131 self.text2_3.Hide() … … 2145 2134 if self.enable_disp.GetValue(): 2146 2135 if hasattr(self, "text_disp_1"): 2147 if self.text_disp_1 !=None and not self.is_mac:2136 if self.text_disp_1 is not None and not self.is_mac: 2148 2137 self.text_disp_1.Hide() 2149 2138 except: … … 2152 2141 2153 2142 i = 0 2154 # Set the panel when fit result are list2143 # Set the panel when fit result are list 2155 2144 2156 2145 for item in self.param_toFit: 2157 if len(item) > 5 and item !=None:2146 if len(item) > 5 and item is not None: 2158 2147 2159 2148 if item[0].IsShown(): 2160 # #reset error value to initial state2149 # reset error value to initial state 2161 2150 if not self.is_mac: 2162 2151 item[3].Hide() … … 2165 2154 if item[1] == p_name[ind]: 2166 2155 break 2167 if len(out) > 0 and out[ind] !=None:2156 if len(out) > 0 and out[ind] is not None: 2168 2157 val_out = format_number(out[ind], True) 2169 2158 item[2].SetValue(val_out) 2170 2159 2171 if(cov !=None and len(cov) == len(out)):2160 if(cov is not None and len(cov) == len(out)): 2172 2161 try: 2173 if dispersity !=None:2162 if dispersity is not None: 2174 2163 if self.enable_disp.GetValue(): 2175 2164 if hasattr(self, "text_disp_1"): 2176 if self.text_disp_1 !=None:2165 if self.text_disp_1 is not None: 2177 2166 if not self.text_disp_1.IsShown()\ 2178 and not self.is_mac:2167 and not self.is_mac: 2179 2168 self.text_disp_1.Show(True) 2180 2169 except: 2181 2170 pass 2182 2171 2183 if cov[ind] !=None:2172 if cov[ind] is not None: 2184 2173 if numpy.isfinite(float(cov[ind])): 2185 2174 val_err = format_number(cov[ind], True) 2186 2175 item[4].SetForegroundColour(wx.BLACK) 2187 2176 else: 2188 2177 val_err = 'NaN' … … 2196 2185 else: 2197 2186 raise ValueError, "onsetValues: Invalid parameters..." 2198 # Show error title when any errors displayed2187 # Show error title when any errors displayed 2199 2188 if has_error: 2200 2189 if not self.text2_3.IsShown(): 2201 2190 self.text2_3.Show(True) 2202 # #save current state2191 # save current state 2203 2192 self.save_current_state() 2204 2193 … … 2207 2196 self.Refresh() 2208 2197 self._mac_sleep(0.1) 2209 # plot model ( when drawing, do not update chisqr value again)2198 # plot model ( when drawing, do not update chisqr value again) 2210 2199 self._draw_model(update_chisqr=False, source='fit') 2211 2200 … … 2223 2212 # compute weight for the current data 2224 2213 flag_weight = self.get_weight_flag() 2225 if is_2D ==None:2214 if is_2D is None: 2226 2215 is_2D = self._is_2D() 2227 2216 self._manager.set_fit_weight(uid=self.uid, … … 2242 2231 self._update_paramv_on_fit() 2243 2232 2244 if event !=None:2233 if event is not None: 2245 2234 tcrtl = event.GetEventObject() 2246 2235 # event case of radio button 2247 if tcrtl.GetValue() == True:2236 if tcrtl.GetValue(): 2248 2237 self.dx_min = 0.0 2249 2238 self.dx_max = 0.0 … … 2263 2252 2264 2253 self.sizer_set_smearer.Layout() 2265 # #we need FitInside here not just self.Layout to ensure all the sizers2266 # #end up with the necessasary space to in the scroll panel. In2267 # #particular the compute and fit buttons end up on top of each other2268 # # PDB Nov 28 2015.2254 # we need FitInside here not just self.Layout to ensure all the sizers 2255 # end up with the necessasary space to in the scroll panel. In 2256 # particular the compute and fit buttons end up on top of each other 2257 # PDB Nov 28 2015. 2269 2258 self.FitInside() 2270 2259 2271 if event !=None:2260 if event is not None: 2272 2261 event.Skip() 2273 # self._undo.Enable(True)2262 # self._undo.Enable(True) 2274 2263 self.save_current_state() 2275 2264 event = PageInfoEvent(page=self) … … 2346 2335 get_pin_max.SetBackgroundColour("pink") 2347 2336 msg = "Model Error:This value can not be negative!!!" 2348 elif self.dx_min != None and self.dx_max !=None:2337 elif self.dx_min is not None and self.dx_max is not None: 2349 2338 if self._is_2D(): 2350 2339 data.dqx_data[data.dqx_data == 0] = self.dx_min … … 2357 2346 self.dx_max + step / 1.1, 2358 2347 step) 2359 elif self.dx_min !=None:2348 elif self.dx_min is not None: 2360 2349 if self._is_2D(): 2361 2350 data.dqx_data[data.dqx_data == 0] = self.dx_min 2362 2351 else: 2363 2352 data.dx[data.dx == 0] = self.dx_min 2364 elif self.dx_max !=None:2353 elif self.dx_max is not None: 2365 2354 if self._is_2D(): 2366 2355 data.dqy_data[data.dqy_data == 0] = self.dx_max … … 2370 2359 # 2D need to set accuracy 2371 2360 if self._is_2D(): 2372 self.current_smearer.set_accuracy( accuracy=\2373 2374 2375 if msg !=None:2361 self.current_smearer.set_accuracy( 2362 accuracy=self.smear2d_accuracy) 2363 2364 if msg is not None: 2376 2365 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2377 2366 else: 2378 2367 get_pin_min.SetBackgroundColour("white") 2379 2368 get_pin_max.SetBackgroundColour("white") 2380 # #set smearing value whether or not the data contain the smearing info2369 # set smearing value whether or not the data contain the smearing info 2381 2370 2382 2371 enable_smearer = not self.disable_smearer.GetValue() … … 2404 2393 wx.CallAfter(self.save_current_state) 2405 2394 2406 if msg !=None:2395 if msg is not None: 2407 2396 return False 2408 2397 else: … … 2420 2409 msg = None 2421 2410 # for event given 2422 if event !=None:2411 if event is not None: 2423 2412 tcrtl = event.GetEventObject() 2424 2413 # event case of radio button … … 2441 2430 self._show_smear_sizer() 2442 2431 self.sizer_set_smearer.Layout() 2443 # #we need FitInside here not just self.Layout to ensure all the sizers2444 # #end up with the necessasary space to in the scroll panel. In2445 # #particular the compute and fit buttons end up on top of each other2446 # # PDB Nov 28 2015.2432 # we need FitInside here not just self.Layout to ensure all the sizers 2433 # end up with the necessasary space to in the scroll panel. In 2434 # particular the compute and fit buttons end up on top of each other 2435 # PDB Nov 28 2015. 2447 2436 self.FitInside() 2448 2437 2449 if event !=None:2438 if event is not None: 2450 2439 event.Skip() 2451 2440 self.save_current_state() 2452 2441 event = PageInfoEvent(page=self) 2453 2442 wx.PostEvent(self.parent, event) 2454 if msg !=None:2443 if msg is not None: 2455 2444 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2456 2445 … … 2541 2530 2542 2531 self.current_smearer = smear_selection(data, self.model) 2543 # #set smearing value whether or not the data contain the smearing info2532 # set smearing value whether or not the data contain the smearing info 2544 2533 enable_smearer = not self.disable_smearer.GetValue() 2545 2534 self._manager.set_smearer(smearer=self.current_smearer, … … 2564 2553 if self._is_changed_slit(): 2565 2554 msg = self._set_slit_smear() 2566 # self._undo.Enable(True)2555 # self._undo.Enable(True) 2567 2556 self.save_current_state() 2568 2557 2569 if msg !=None:2558 if msg is not None: 2570 2559 return False 2571 2560 else: … … 2577 2566 are computed when fitting 2578 2567 """ 2579 if event !=None:2568 if event is not None: 2580 2569 event.Skip() 2581 2570 if self.data is None: … … 2590 2579 2591 2580 self.sizer_set_smearer.Layout() 2592 # #we need FitInside here not just self.Layout to ensure all the sizers2593 # #end up with the necessasary space to in the scroll panel. In2594 # #particular the compute and fit buttons end up on top of each other2595 # # PDB Nov 28 2015.2581 # we need FitInside here not just self.Layout to ensure all the sizers 2582 # end up with the necessasary space to in the scroll panel. In 2583 # particular the compute and fit buttons end up on top of each other 2584 # PDB Nov 28 2015. 2596 2585 self.FitInside() 2597 2586 self._set_weight() 2598 2587 2599 # #set smearing value whether or not the data contain the smearing info2588 # set smearing value whether or not the data contain the smearing info 2600 2589 enable_smearer = not self.disable_smearer.GetValue() 2601 2590 wx.CallAfter(self._manager.set_smearer, uid=self.uid, … … 2618 2607 """ 2619 2608 self._get_smear_info() 2620 # renew smear sizer2609 # renew smear sizer 2621 2610 if self.smear_type is not None: 2622 2611 self.smear_description_smear_type.SetValue(str(self.smear_type)) … … 2658 2647 """ 2659 2648 try: 2660 if event ==None:2649 if event is None: 2661 2650 output = "-" 2662 2651 elif not numpy.isfinite(event.output): … … 2693 2682 self._manager.set_param2fit(self.uid, param2fit) 2694 2683 2695 def select_param(self, event ):2684 def select_param(self, event=None): 2696 2685 """ 2697 2686 Select TextCtrl checked for fitting purpose and stores them … … 2700 2689 self.param_toFit = [] 2701 2690 for item in self.parameters: 2702 # Skip t ifhe angle parameters if 1D data2691 # Skip t ifhe angle parameters if 1D data 2703 2692 if self.data.__class__.__name__ != "Data2D" and\ 2704 2693 not self.enable2D: 2705 2694 if item in self.orientation_params: 2706 2695 continue 2707 # Select parameters to fit for list of primary parameters2696 # Select parameters to fit for list of primary parameters 2708 2697 if item[0].GetValue() and item[0].IsShown(): 2709 2698 if not (item in self.param_toFit): … … 2714 2703 self.param_toFit.remove(item) 2715 2704 2716 # Select parameters to fit for list of fittable parameters2705 # Select parameters to fit for list of fittable parameters 2717 2706 # with dispersion 2718 2707 for item in self.fittable_param: 2719 # Skip t ifhe angle parameters if 1D data2708 # Skip t ifhe angle parameters if 1D data 2720 2709 if self.data.__class__.__name__ != "Data2D" and\ 2721 2710 not self.enable2D: … … 2726 2715 self.param_toFit.append(item) 2727 2716 else: 2728 # remove parameters from the fitting list2717 # remove parameters from the fitting list 2729 2718 if item in self.param_toFit: 2730 2719 self.param_toFit.remove(item) 2731 2720 2732 # Calculate num. of angle parameters2721 # Calculate num. of angle parameters 2733 2722 if self.data.__class__.__name__ == "Data2D" or \ 2734 2723 self.enable2D: … … 2736 2725 else: 2737 2726 len_orient_para = len(self.orientation_params) # assume even len 2738 # Total num. of angle parameters2727 # Total num. of angle parameters 2739 2728 if len(self.fittable_param) > 0: 2740 2729 len_orient_para *= 2 2741 2730 2742 2731 self.save_current_state_fit() 2743 if event !=None:2744 # #post state to fit panel2732 if event is not None: 2733 # post state to fit panel 2745 2734 event = PageInfoEvent(page=self) 2746 2735 wx.PostEvent(self.parent, event) … … 2768 2757 self.orientation_params_disp = [] 2769 2758 2770 if model ==None:2759 if model is None: 2771 2760 self.sizer3.Layout() 2772 2761 self.SetupScrolling() … … 2776 2765 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 2777 2766 sizer = wx.GridBagSizer(5, 5) 2778 # #save the current model2767 # save the current model 2779 2768 self.model = model 2780 2769 2781 2770 keys = self.model.getParamList() 2782 2771 2783 # list of dispersion parameters2772 # list of dispersion parameters 2784 2773 self.disp_list = self.model.getDispParamList() 2785 2774 … … 2814 2803 return -1 2815 2804 # both have a number 2816 if num_a != None and num_b !=None:2805 if num_a is not None and num_b is not None: 2817 2806 if num_a > num_b: 2818 2807 return -1 … … 2827 2816 return 1 2828 2817 # one of them has a number 2829 elif num_a !=None:2818 elif num_a is not None: 2830 2819 return 1 2831 elif num_b !=None:2820 elif num_b is not None: 2832 2821 return -1 2833 2822 # no numbers … … 2835 2824 return cmp(a.lower(), b.lower()) 2836 2825 2837 # keys obtained now from ordered dict, so commenting alphabetical ordering2838 # keys.sort(custom_compare)2826 # keys obtained now from ordered dict, so commenting alphabetical 2827 # ordering keys.sort(custom_compare) 2839 2828 2840 2829 iy = 0 … … 2844 2833 ix += 1 2845 2834 self.text2_2 = wx.StaticText(self, wx.ID_ANY, 'Value') 2846 sizer.Add(self.text2_2, (iy, ix), (1, 1), \2835 sizer.Add(self.text2_2, (iy, ix), (1, 1), 2847 2836 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2848 2837 ix += 2 2849 2838 self.text2_3 = wx.StaticText(self, wx.ID_ANY, 'Error') 2850 sizer.Add(self.text2_3, (iy, ix), (1, 1), \2851 2839 sizer.Add(self.text2_3, (iy, ix), (1, 1), 2840 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2852 2841 if not self.is_mac: 2853 2842 self.text2_3.Hide() 2854 2843 ix += 1 2855 2844 self.text2_min = wx.StaticText(self, wx.ID_ANY, 'Min') 2856 sizer.Add(self.text2_min, (iy, ix), (1, 1), \2857 2858 # self.text2_min.Hide()2845 sizer.Add(self.text2_min, (iy, ix), (1, 1), 2846 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2847 # self.text2_min.Hide() 2859 2848 ix += 1 2860 2849 self.text2_max = wx.StaticText(self, wx.ID_ANY, 'Max') 2861 sizer.Add(self.text2_max, (iy, ix), (1, 1), \2862 2863 # self.text2_max.Hide()2850 sizer.Add(self.text2_max, (iy, ix), (1, 1), 2851 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2852 # self.text2_max.Hide() 2864 2853 ix += 1 2865 2854 self.text2_4 = wx.StaticText(self, wx.ID_ANY, '[Units]') 2866 sizer.Add(self.text2_4, (iy, ix), (1, 1), \2867 2855 sizer.Add(self.text2_4, (iy, ix), (1, 1), 2856 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2868 2857 self.text2_4.Hide() 2869 2858 … … 2871 2860 for item in keys: 2872 2861 2873 if not itemin self.disp_list and not item in \2862 if item not in self.disp_list and not item in \ 2874 2863 self.model.orientation_params: 2875 2864 2876 # #prepare a spot to store errors2877 if not itemin self.model.details:2865 # prepare a spot to store errors 2866 if item not in self.model.details: 2878 2867 self.model.details[item] = ["", None, None] 2879 2868 2880 2869 iy += 1 2881 2870 ix = 0 2882 if (self.model.__class__ in \2883 self.model_list_box["Multi-Functions"] or \2871 if (self.model.__class__ in 2872 self.model_list_box["Multi-Functions"] or 2884 2873 self.temp_multi_functional)\ 2885 2874 and (item in self.model.non_fittable): 2886 2875 non_fittable_name = wx.StaticText(self, wx.ID_ANY, item) 2887 sizer.Add(non_fittable_name, (iy, ix), (1, 1), \2876 sizer.Add(non_fittable_name, (iy, ix), (1, 1), 2888 2877 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 21) 2889 # #add parameter value2878 # add parameter value 2890 2879 ix += 1 2891 2880 value = self.model.getParam(item) 2892 2881 if len(self.model.fun_list) > 0: 2893 # num = item.split('_')[1][5:7]2882 # num = item.split('_')[1][5:7] 2894 2883 fun_box = wx.ComboBox(self, wx.ID_ANY, size=(100, -1), 2895 2884 style=wx.CB_READONLY, name='%s' % item) 2896 2885 self._set_fun_box_list(fun_box) 2897 2886 fun_box.SetSelection(0) 2898 # self.fun_box.SetToolTipString("A function2887 # self.fun_box.SetToolTipString("A function 2899 2888 # describing the interface") 2900 2889 wx.EVT_COMBOBOX(fun_box, wx.ID_ANY, self._on_fun_box) … … 2903 2892 size=(_BOX_WIDTH, 20), 2904 2893 style=wx.TE_PROCESS_ENTER, name='%s' % item) 2905 fun_box.SetToolTipString( \2894 fun_box.SetToolTipString( 2906 2895 "Hit 'Enter' after typing to update the plot.") 2907 2896 fun_box.SetValue(format_number(value, True)) … … 2911 2900 None, None]) 2912 2901 else: 2913 # #add parameters name with checkbox for selecting to fit2902 # add parameters name with checkbox for selecting to fit 2914 2903 cb = wx.CheckBox(self, wx.ID_ANY, item) 2915 2904 cb.SetValue(CHECK_STATE) 2916 2905 cb.SetToolTipString(" Check mark to fit.") 2917 # cb.SetValue(True)2906 # cb.SetValue(True) 2918 2907 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 2919 2908 … … 2921 2910 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 2922 2911 2923 # #add parameter value2912 # add parameter value 2924 2913 ix += 1 2925 2914 value = self.model.getParam(item) 2926 2915 ctl1 = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 2927 2916 style=wx.TE_PROCESS_ENTER) 2928 ctl1.SetToolTipString( \2917 ctl1.SetToolTipString( 2929 2918 "Hit 'Enter' after typing to update the plot.") 2930 2919 ctl1.SetValue(format_number(value, True)) 2931 2920 sizer.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 2932 # #text to show error sign2921 # text to show error sign 2933 2922 ix += 1 2934 2923 text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 2935 sizer.Add(text2, (iy, ix), (1, 1), \2924 sizer.Add(text2, (iy, ix), (1, 1), 2936 2925 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2937 2926 if not self.is_mac: … … 2994 2983 iy += 1 2995 2984 ix = 0 2996 # Add tile for orientational angle2985 # Add tile for orientational angle 2997 2986 for item in keys: 2998 2987 if item in self.model.orientation_params: … … 3001 2990 mag_on_button.SetToolTipString("Turn Pol Beam/Mag scatt on/off") 3002 2991 mag_on_button.Bind(wx.EVT_BUTTON, self._on_mag_on) 3003 mag_angle_help_button = wx.Button(self, wx.ID_ANY, "Magnetic angles?") 2992 mag_angle_help_button = wx.Button(self, wx.ID_ANY, 2993 "Magnetic angles?") 3004 2994 mag_angle_help_button.SetToolTipString("see angle definitions") 3005 2995 mag_help_button = wx.Button(self, wx.ID_ANY, "Mag HELP") 3006 2996 mag_help_button.SetToolTipString("Help on pol beam/mag fitting") 3007 2997 mag_help_button.Bind(wx.EVT_BUTTON, self._on_mag_help) 3008 mag_angle_help_button.Bind(wx.EVT_BUTTON, \2998 mag_angle_help_button.Bind(wx.EVT_BUTTON, 3009 2999 self._on_mag_angle_help) 3010 3000 sizer.Add(orient_angle, (iy, ix), (1, 1), … … 3019 3009 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 3020 3010 3021 # handle the magnetic buttons3022 # clean this up so that assume mag is off then turn3023 # all buttons on IF mag has mag and has 2D3011 # handle the magnetic buttons 3012 # clean this up so that assume mag is off then turn 3013 # all buttons on IF mag has mag and has 2D 3024 3014 if not self._has_magnetic: 3025 3015 mag_on_button.Show(False) … … 3047 3037 break 3048 3038 3049 # For Gaussian only3039 # For Gaussian only 3050 3040 if type.lower() != "array": 3051 3041 for item in self.model.orientation_params: … … 3053 3043 if item in self.model.magnetic_params: 3054 3044 continue 3055 if not itemin self.disp_list:3056 # #prepare a spot to store min max3057 if not itemin self.model.details:3045 if item not in self.disp_list: 3046 # prepare a spot to store min max 3047 if item not in self.model.details: 3058 3048 self.model.details[item] = ["", None, None] 3059 3049 3060 3050 iy += 1 3061 3051 ix = 0 3062 # #add parameters name with checkbox for selecting to fit3052 # add parameters name with checkbox for selecting to fit 3063 3053 cb = wx.CheckBox(self, wx.ID_ANY, item) 3064 3054 cb.SetValue(CHECK_STATE) … … 3073 3063 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 3074 3064 3075 # #add parameter value3065 # add parameter value 3076 3066 ix += 1 3077 3067 value = self.model.getParam(item) 3078 3068 ctl1 = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 3079 3069 style=wx.TE_PROCESS_ENTER) 3080 ctl1.SetToolTipString( \3070 ctl1.SetToolTipString( 3081 3071 "Hit 'Enter' after typing to update the plot.") 3082 3072 ctl1.SetValue(format_number(value, True)) … … 3087 3077 ctl1.Hide() 3088 3078 sizer.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 3089 # #text to show error sign3079 # text to show error sign 3090 3080 ix += 1 3091 3081 text2 = wx.StaticText(self, -1, '+/-') 3092 sizer.Add(text2, (iy, ix), (1, 1), \3082 sizer.Add(text2, (iy, ix), (1, 1), 3093 3083 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 3094 3084 … … 3155 3145 iy += 1 3156 3146 box_description.SetForegroundColour(wx.BLUE) 3157 # Display units text on panel3147 # Display units text on panel 3158 3148 for item in keys: 3159 3149 if item in self.model.details: 3160 3150 self.text2_4.Show() 3161 # Fill the list of fittable parameters3151 # Fill the list of fittable parameters 3162 3152 self.get_all_checked_params() 3163 3153 self.save_current_state_fit() … … 3171 3161 Get key stroke event 3172 3162 """ 3173 if self.data ==None:3163 if self.data is None: 3174 3164 return 3175 3165 # Figuring out key combo: Cmd for copy, Alt for paste -
src/sas/sasgui/perspectives/fitting/fitpanel.py
re6de6b8 rc8e1996 187 187 """ 188 188 189 # get number of pages190 nop = self.GetPageCount()191 189 # use while-loop, for-loop will not do the job well. 192 while ( nop> 0):190 while (self.GetPageCount() > 0): 193 191 # delete the first page until no page exists 194 192 page = self.GetPage(0) … … 197 195 self._close_helper(selected_page=page) 198 196 self.DeletePage(0) 199 nop = self.GetPageCount()200 197 # Clear list of names 201 198 self.fit_page_name = {} … … 240 237 # close all panels only when svs file opened 241 238 self.close_all() 242 self._manager.mypanels = []243 239 self.sim_page = None 244 240 self.batch_page = None … … 248 244 close page and remove all references to the closed page 249 245 """ 250 nbr_page = self.GetPageCount()251 246 selected_page = self.GetPage(self.GetSelection()) 252 if nbr_page== 1:247 if self.GetPageCount() == 1: 253 248 if selected_page.get_data() is not None: 254 249 if event is not None: … … 293 288 copy a dictionary of model into its own dictionary 294 289 295 :param m_dict: dictionnary made of model name as key and model class290 :param dict: dictionnary made of model name as key and model class 296 291 as value 297 292 """ … … 320 315 if caption == "Const & Simul Fit": 321 316 self.sim_page = SimultaneousFitPage(self, page_finder=page_finder, 322 id= 317 id=wx.ID_ANY, batch_on=False) 323 318 self.sim_page.window_caption = caption 324 319 self.sim_page.window_name = caption … … 397 392 raise ValueError, "Fitpanel delete_data expect list of id" 398 393 else: 399 n = self.GetPageCount()400 394 for page in self.opened_pages.values(): 401 395 pos = self.GetPageIndex(page) … … 441 435 if data_1d_list and data_2d_list: 442 436 # need to warning the user that this batch is a special case 443 from sas.sasgui.perspectives.fitting.fitting_widgets import BatchDataDialog 437 from sas.sasgui.perspectives.fitting.fitting_widgets import \ 438 BatchDataDialog 444 439 dlg = BatchDataDialog(self) 445 440 if dlg.ShowModal() == wx.ID_OK: … … 461 456 page = self.add_empty_page() 462 457 if data_1d_list and not data_2d_list: 463 # only on type of data458 # only on type of data 464 459 page.fill_data_combobox(data_1d_list) 465 460 elif not data_1d_list and data_2d_list: … … 477 472 Add a fitting page on the notebook contained by fitpanel 478 473 479 :param data : data to fit474 :param data_list: data to fit 480 475 481 476 :return panel : page just added for further used. -
src/sas/sasgui/perspectives/fitting/pagestate.py
r467202f rc8e1996 46 46 ["npts", "npts", "float"], 47 47 ["categorycombobox", "categorycombobox", "string"], 48 ["formfactorcombobox", "formfactorcombobox", "string"], 49 ["structurecombobox", "structurecombobox", "string"], 48 ["formfactorcombobox", "formfactorcombobox", 49 "string"], 50 ["structurecombobox", "structurecombobox", 51 "string"], 50 52 ["multi_factor", "multi_factor", "float"], 51 53 ["magnetic_on", "magnetic_on", "bool"], … … 65 67 ["smearer", "smearer", "float"], 66 68 ["smear_type", "smear_type", "string"], 67 ["dq_l", "dq_l", " string"],68 ["dq_r", "dq_r", " string"],69 ["dq_l", "dq_l", "float"], 70 ["dq_r", "dq_r", "float"], 69 71 ["dx_max", "dx_max", "float"], 70 72 ["dx_min", "dx_min", "float"], … … 80 82 ["str_parameters", "str_parameters"], 81 83 ["orientation_parameters", "orientation_params"], 82 ["dispersity_parameters", "orientation_params_disp"], 84 ["dispersity_parameters", 85 "orientation_params_disp"], 83 86 ["fixed_param", "fixed_param"], 84 87 ["fittable_param", "fittable_param"]] … … 120 123 try: 121 124 return node.get(item[0]).strip() == "True" 122 except :125 except Exception: 123 126 return None 124 127 else: 125 128 try: 126 129 return float(node.get(item[0])) 127 except :130 except Exception: 128 131 return None 129 132 … … 188 191 # page name 189 192 self.page_name = "" 190 # Contains link between model, allits parameters, and panel organization193 # Contains link between model, its parameters, and panel organization 191 194 self.parameters = [] 192 195 # String parameter list that can not be fitted … … 305 308 obj.fittable_param = copy.deepcopy(self.fittable_param) 306 309 obj.orientation_params = copy.deepcopy(self.orientation_params) 307 obj.orientation_params_disp = copy.deepcopy(self.orientation_params_disp) 310 obj.orientation_params_disp = \ 311 copy.deepcopy(self.orientation_params_disp) 308 312 obj.enable_disp = copy.deepcopy(self.enable_disp) 309 313 obj.disable_disp = copy.deepcopy(self.disable_disp) … … 397 401 rep += "data : %s\n" % str(self.data) 398 402 rep += "Plotting Range: min: %s, max: %s, steps: %s\n" % \ 399 (str(self.qmin), str(self.qmax), str(self.npts))403 (str(self.qmin), str(self.qmax), str(self.npts)) 400 404 rep += "Dispersion selection : %s\n" % str(self.disp_box) 401 405 rep += "Smearing enable : %s\n" % str(self.enable_smearer) … … 413 417 414 418 rep += "2D enable : %s\n" % str(self.enable2D) 415 rep += "All parameters checkbox selected: %s\n" % s tr(self.cb1)419 rep += "All parameters checkbox selected: %s\n" % self.cb1 416 420 rep += "Value of Chisqr : %s\n" % str(self.tcChi) 417 rep += "Smear object : %s\n" % s tr(self.smearer)418 rep += "Smear type : %s\n" % s tr(self.smear_type)421 rep += "Smear object : %s\n" % self.smearer 422 rep += "Smear type : %s\n" % self.smear_type 419 423 rep += "dq_l : %s\n" % self.dq_l 420 424 rep += "dq_r : %s\n" % self.dq_r … … 478 482 value = content[1] 479 483 except Exception: 480 msg = "Report string expected 'name: value' but got %r" %line484 msg = "Report string expected 'name: value' but got %r" % line 481 485 logging.error(msg) 482 486 if name.count("State created"): … … 493 497 if name == "value": 494 498 param_string += value + ',' 499 fixed_parameter = False 495 500 if name == "selected": 496 501 if value == u' False': 497 502 fixed_parameter = True 498 else:499 fixed_parameter = False500 503 if name == "error value": 501 504 if fixed_parameter: … … 617 620 dialog.Show() 618 621 619 def _to XML_helper(self, thelist, element, newdoc):622 def _to_xml_helper(self, thelist, element, newdoc): 620 623 """ 621 624 Helper method to create xml file for saving state … … 635 638 element.appendChild(sub_element) 636 639 637 def to XML(self, file="fitting_state.fitv", doc=None,638 entry_node=None, batch_fit_state=None):640 def to_xml(self, file="fitting_state.fitv", doc=None, 641 entry_node=None, batch_fit_state=None): 639 642 """ 640 643 Writes the state of the fit panel to file, as XML. … … 648 651 :param entry_node: XML node within the XML document at which we 649 652 will append the data [optional] 653 :param batch_fit_state: simultaneous fit state 650 654 """ 651 655 from xml.dom.minidom import getDOMImplementation … … 746 750 for item in LIST_OF_STATE_PARAMETERS: 747 751 element = newdoc.createElement(item[0]) 748 self._to XML_helper(thelist=getattr(self, item[1]),749 element=element, newdoc=newdoc)752 self._to_xml_helper(thelist=getattr(self, item[1]), 753 element=element, newdoc=newdoc) 750 754 inputs.appendChild(element) 751 755 … … 765 769 for constraint in batch_fit_state.constraints_list: 766 770 if constraint.model_cbox.GetValue() != "": 767 # model_cbox, param_cbox, egal_txt, constraint, btRemove, sizer 771 # model_cbox, param_cbox, egal_txt, constraint, 772 # btRemove, sizer 768 773 doc_cons = newdoc.createElement('constraint') 769 774 doc_cons.setAttribute('model_cbox', … … 808 813 return newdoc 809 814 810 def _from XML_helper(self, node, list):815 def _from_xml_helper(self, node, list): 811 816 """ 812 817 Helper function to write state to xml … … 858 863 [maximum_displayed, maximum_value], unit]) 859 864 860 def from XML(self, file=None, node=None):865 def from_xml(self, file=None, node=None): 861 866 """ 862 867 Load fitting state from a file … … 887 892 logging.error(msg) 888 893 889 # Parse fitting attributes890 entry = get_content('ns:Attributes', node)891 for item in LIST_OF_DATA_ATTRIBUTES:892 node = get_content('ns:%s' % item[0], entry)893 setattr(self, item[0], parse_entry_helper(node, item))894 895 894 if entry is not None: 895 # Parse fitting attributes 896 entry = get_content('ns:Attributes', node) 897 for item in LIST_OF_DATA_ATTRIBUTES: 898 node = get_content('ns:%s' % item[0], entry) 899 setattr(self, item[0], parse_entry_helper(node, item)) 900 896 901 for item in LIST_OF_STATE_ATTRIBUTES: 897 902 node = get_content('ns:%s' % item[0], entry) … … 900 905 for item in LIST_OF_STATE_PARAMETERS: 901 906 node = get_content("ns:%s" % item[0], entry) 902 self._fromXML_helper(node=node, list=getattr(self, item[1])) 907 self._from_xml_helper(node=node, 908 list=getattr(self, item[1])) 903 909 904 910 # Recover _disp_obj_dict from xml file … … 950 956 """ 951 957 images = [] 952 # some imports953 import wx954 958 955 959 # Reset memory … … 958 962 959 963 # For no figures in the list, prepare empty plot 960 if figs ==None or len(figs) == 0:964 if figs is None or len(figs) == 0: 961 965 figs = [None] 962 966 … … 965 969 self.imgRAM = wx.MemoryFSHandler() 966 970 for fig in figs: 967 if fig s !=None:971 if fig is not None: 968 972 ind = figs.index(fig) 969 973 canvas = canvases[ind] 970 974 971 # store the image in wx.FileSystem Object975 # store the image in wx.FileSystem Object 972 976 wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 973 977 … … 975 979 ind = figs.index(fig) 976 980 977 # AddFile, image can be retrieved with 'memory:filename'981 # AddFile, image can be retrieved with 'memory:filename' 978 982 self.imgRAM.AddFile('img_fit%s.png' % ind, 979 983 canvas.bitmap, wx.BITMAP_TYPE_PNG) 980 984 981 # append figs985 # append figs 982 986 images.append(fig) 983 987 … … 989 993 Class to load a .fitv fitting file 990 994 """ 991 # #File type995 # File type 992 996 type_name = "Fitting" 993 997 994 # #Wildcards998 # Wildcards 995 999 type = ["Fitting files (*.fitv)|*.fitv" 996 1000 "SASView file (*.svs)|*.svs"] 997 # #List of allowed extensions1001 # List of allowed extensions 998 1002 ext = ['.fitv', '.FITV', '.svs', 'SVS'] 999 1003 … … 1009 1013 1010 1014 """ 1011 # #Call back method to be executed after a file is read1015 # Call back method to be executed after a file is read 1012 1016 self.call_back = call_back 1013 # #CanSAS format flag1017 # CanSAS format flag 1014 1018 self.cansas = cansas 1015 1019 self.state = None … … 1027 1031 1028 1032 """ 1029 if self.cansas == True:1033 if self.cansas: 1030 1034 return self._read_cansas(path) 1031 1035 … … 1061 1065 for item in datainfo.run: 1062 1066 runname = {} 1063 if datainfo.run_name.has_key(item)and \1067 if item in datainfo.run_name and \ 1064 1068 len(str(datainfo.run_name[item])) > 1: 1065 1069 runname = {'name': datainfo.run_name[item]} … … 1076 1080 root_node = doc.createElement(item[0]) 1077 1081 new_node.appendChild(root_node) 1078 temp_list = None1079 1082 temp_list = getattr(datainfo, item[1]) 1080 1083 … … 1113 1116 datainfo.sample.position.z, 1114 1117 {"unit": datainfo.sample.position_unit}) 1115 if written == True:1118 if written: 1116 1119 sample.appendChild(pos) 1117 1120 … … 1121 1124 written = written | write_node(doc, ori, "pitch", 1122 1125 datainfo.sample.orientation.y, 1123 {"unit": datainfo.sample.orientation_unit}) 1126 {"unit": 1127 datainfo.sample.orientation_unit}) 1124 1128 written = written | write_node(doc, ori, "yaw", 1125 1129 datainfo.sample.orientation.z, 1126 {"unit": datainfo.sample.orientation_unit}) 1127 if written == True: 1130 {"unit": 1131 datainfo.sample.orientation_unit}) 1132 if written: 1128 1133 sample.appendChild(ori) 1129 1134 … … 1153 1158 datainfo.source.beam_size.z, 1154 1159 {"unit": datainfo.source.beam_size_unit}) 1155 if written == True:1160 if written: 1156 1161 source.appendChild(size) 1157 1162 … … 1198 1203 written = written | write_node(doc, size, "z", apert.size.z, 1199 1204 {"unit": apert.size_unit}) 1200 if written == True:1205 if written: 1201 1206 ap.appendChild(size) 1202 1207 … … 1210 1215 item.slit_length, 1211 1216 {"unit": item.slit_length_unit}) 1212 if written == True:1217 if written: 1213 1218 instr.appendChild(det) 1214 1219 … … 1220 1225 written = written | write_node(doc, off, "z", item.offset.z, 1221 1226 {"unit": item.offset_unit}) 1222 if written == True:1227 if written: 1223 1228 det.appendChild(off) 1224 1229 … … 1232 1237 item.beam_center.z, 1233 1238 {"unit": item.beam_center_unit}) 1234 if written == True:1239 if written: 1235 1240 det.appendChild(center) 1236 1241 … … 1242 1247 written = written | write_node(doc, pix, "z", item.pixel_size.z, 1243 1248 {"unit": item.pixel_size_unit}) 1244 if written == True:1249 if written: 1245 1250 det.appendChild(pix) 1246 1251 … … 1253 1258 written = written | write_node(doc, ori, "yaw", item.orientation.z, 1254 1259 {"unit": item.orientation_unit}) 1255 if written == True:1260 if written: 1256 1261 det.appendChild(ori) 1257 1262 … … 1290 1295 # Create an empty state 1291 1296 state = PageState() 1292 state.from XML(node=nodes[0])1297 state.from_xml(node=nodes[0]) 1293 1298 1294 1299 except: … … 1314 1319 simfitstate_0 = simfitstate[0] 1315 1320 all = simfitstate_0.xpath('ns:select_all', 1316 namespaces={'ns': CANSAS_NS})1321 namespaces={'ns': CANSAS_NS}) 1317 1322 atts = all[0].attrib 1318 1323 checked = atts.get('checked') 1319 1324 sim_fit_state.select_all = bool(checked) 1320 1325 model_list = simfitstate_0.xpath('ns:model_list', 1321 namespaces={'ns': CANSAS_NS})1326 namespaces={'ns': CANSAS_NS}) 1322 1327 model_list_items = model_list[0].xpath('ns:model_list_item', 1323 namespaces={'ns': CANSAS_NS}) 1328 namespaces={'ns': 1329 CANSAS_NS}) 1324 1330 for model in model_list_items: 1325 1331 attrs = model.attrib … … 1368 1374 return return_value, _ 1369 1375 1370 # Parse 2D1376 # Parse 2D 1371 1377 data_info = Data2D() 1372 1378 … … 1590 1596 for entry in nodes: 1591 1597 for item in LIST_OF_DATA_2D_ATTR: 1592 # get node1598 # get node 1593 1599 node = get_content('ns:%s' % item[0], entry) 1594 1600 setattr(data_info, item[1], parse_entry_helper(node, item)) … … 1633 1639 entry_list = root.xpath('ns:SASentry', 1634 1640 namespaces={'ns': CANSAS_NS}) 1635 name_map = {}1636 1641 for entry in entry_list: 1637 1642 try: … … 1679 1684 state.data.is_data = state.is_data 1680 1685 if output[ind].run_name is not None\ 1681 and len(output[ind].run_name) != 0:1686 and len(output[ind].run_name) != 0: 1682 1687 if isinstance(output[ind].run_name, dict): 1683 1688 name = output[ind].run_name.keys()[0] … … 1715 1720 # Write the XML document 1716 1721 else: 1717 doc = fitstate.to XML(file=filename)1722 doc = fitstate.to_xml(file=filename) 1718 1723 1719 1724 # Save the document no matter the type … … 1749 1754 1750 1755 if state is not None: 1751 doc = state.to XML(doc=doc, file=data.filename, entry_node=sasentry,1752 batch_fit_state=self.batchfit_params)1756 doc = state.to_xml(doc=doc, file=data.filename, entry_node=sasentry, 1757 batch_fit_state=self.batchfit_params) 1753 1758 1754 1759 return doc
Note: See TracChangeset
for help on using the changeset viewer.