Changeset c8e1996 in sasview for src/sas/sasgui/perspectives


Ignore:
Timestamp:
Oct 20, 2016 3:54:06 PM (8 years ago)
Author:
krzywon
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
Message:

Fixes #738: No errors are thrown on loading projects with fits, plus linting.

Location:
src/sas/sasgui/perspectives/fitting
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/basepage.py

    r313c5c9 rc8e1996  
    1919 
    2020from sas.sasgui.guiframe.panel_base import PanelBase 
    21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList, check_int 
     21from sas.sasgui.guiframe.utils import format_number, check_float, IdList, \ 
     22    check_int 
    2223from sas.sasgui.guiframe.events import PanelOnFocusEvent 
    2324from sas.sasgui.guiframe.events import StatusEvent 
     
    4243_QMAX_DEFAULT = 0.5 
    4344_NPTS_DEFAULT = 50 
    44 #Control panel width 
     45# Control panel width 
    4546if sys.platform.count("win32") > 0: 
    4647    PANEL_WIDTH = 450 
     
    5758    This class provide general structure of  fitpanel page 
    5859    """ 
    59     ## Internal name for the AUI manager 
     60    # Internal name for the AUI manager 
    6061    window_name = "Fit Page" 
    61     ## Title to appear on top of the window 
     62    # Title to appear on top of the window 
    6263    window_caption = "Fit Page " 
    6364 
     
    7576        PanelBase.__init__(self, parent) 
    7677        self.SetupScrolling() 
    77         #Set window's font size 
     78        # Set window's font size 
    7879        self.SetWindowVariant(variant=FONT_VARIANT) 
    7980        self.SetBackgroundColour(color) 
    8081 
    8182        self._ids = iter(self._id_pool) 
    82         ## parent of the page 
     83        # parent of the page 
    8384        self.parent = parent 
    84         ## manager is the fitting plugin 
    85         ## owner of the page (fitting plugin) 
     85        # manager is the fitting plugin 
     86        # owner of the page (fitting plugin) 
    8687        self.event_owner = None 
    87         ## current model 
     88        # current model 
    8889        self.model = None 
    8990        self.m_name = None 
    9091        self.index_model = None 
    9192        self.panel = None 
    92         ## data 
     93        # data 
    9394        self.data = None 
    94         #list of available data 
     95        # list of available data 
    9596        self.data_list = [] 
    9697        self.mask = None 
    9798        self.uid = wx.NewId() 
    9899        self.graph_id = None 
    99         #Q range for data set 
     100        # Q range for data set 
    100101        self.qmin_data_set = numpy.inf 
    101102        self.qmax_data_set = None 
    102103        self.npts_data_set = 0 
    103         ## Q range 
     104        # Q range 
    104105        self.qmin = None 
    105106        self.qmax = None 
     
    107108        self.qmin_x = _QMIN_DEFAULT 
    108109        self.npts_x = _NPTS_DEFAULT 
    109         ## total number of point: float 
     110        # total number of point: float 
    110111        self.npts = None 
    111112        self.num_points = None 
    112         ## smear default 
     113        # smear default 
    113114        self.current_smearer = None 
    114         ## 2D smear accuracy default 
     115        # 2D smear accuracy default 
    115116        self.smear2d_accuracy = 'Low' 
    116         ## slit smear: 
     117        # slit smear: 
    117118        self.dxl = None 
    118119        self.dxw = None 
    119         ## pinhole smear 
     120        # pinhole smear 
    120121        self.dx_min = None 
    121122        self.dx_max = None 
    122         ##semar attrbs 
     123        # smear attrbs 
    123124        self.enable_smearer = None 
    124125        self.disable_smearer = None 
    125126        self.pinhole_smearer = None 
    126127        self.slit_smearer = None 
    127         ##weigth attrbs 
     128        # weight attrbs 
    128129        self.dI_noweight = None 
    129130        self.dI_didata = None 
    130131        self.dI_sqrdata = None 
    131132        self.dI_idata = None 
    132         ##other attrbs 
     133        # other attrbs 
    133134        self.dq_l = None 
    134135        self.dq_r = None 
     
    149150        self.disp_cb_dict = {} 
    150151 
    151         #self.state = PageState(parent=parent) 
    152         ## dictionary containing list of models 
     152        # self.state = PageState(parent=parent) 
     153        # dictionary containing list of models 
    153154        self.model_list_box = {} 
    154155 
    155         ## Data member to store the dispersion object created 
     156        # Data member to store the dispersion object created 
    156157        self._disp_obj_dict = {} 
    157         ## selected parameters to apply dispersion 
     158        # selected parameters to apply dispersion 
    158159        self.disp_cb_dict = {} 
    159         ## smearer object 
     160        # smearer object 
    160161        self.enable2D = False 
    161162        self._has_magnetic = False 
     
    165166        self.structurebox = None 
    166167        self.categorybox = None 
    167         ##list of model parameters. each item must have same length 
    168         ## each item related to a given parameters 
    169         ##[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] 
    170171        self.parameters = [] 
    171172        # non-fittable parameter whose value is astring 
    172173        self.str_parameters = [] 
    173         ## list of parameters to fit , must be like self.parameters 
     174        # list of parameters to fit , must be like self.parameters 
    174175        self.param_toFit = [] 
    175         ## list of looking like parameters but with non fittable parameters info 
     176        # list of looking like parameters but with non fittable parameters info 
    176177        self.fixed_param = [] 
    177         ## list of looking like parameters but with  fittable parameters info 
     178        # list of looking like parameters but with  fittable parameters info 
    178179        self.fittable_param = [] 
    179         ##list of dispersion parameters 
     180        # list of dispersion parameters 
    180181        self.disp_list = [] 
    181182        self.disp_name = "" 
    182183 
    183         ## list of orientation parameters 
     184        # list of orientation parameters 
    184185        self.orientation_params = [] 
    185186        self.orientation_params_disp = [] 
     
    188189#       and this - commenting out on 4/8/2014 by PDB.  Remove once clear 
    189190#       it is pointless. 
    190 #        if self.model != None: 
     191#        if self.model is not None: 
    191192#            self.disp_list = self.model.getDispParamList() 
    192193        self.temp_multi_functional = False 
    193         ##enable model 2D draw 
     194        # enable model 2D draw 
    194195        self.enable2D = False 
    195         ## check that the fit range is correct to plot the model again 
     196        # check that the fit range is correct to plot the model again 
    196197        self.fitrange = True 
    197         ## Create memento to save the current state 
     198        # Create memento to save the current state 
    198199        self.state = PageState(parent=self.parent, 
    199200                               model=self.model, data=self.data) 
    200         ## flag to determine if state has change 
     201        # flag to determine if state has change 
    201202        self.state_change = False 
    202         ## save customized array 
     203        # save customized array 
    203204        self.values = {}   # type: Dict[str, List[float, ...]] 
    204205        self.weights = {}   # type: Dict[str, List[float, ...]] 
    205         ## retrieve saved state 
     206        # retrieve saved state 
    206207        self.number_saved_state = 0 
    207         ## dictionary of saved state 
     208        # dictionary of saved state 
    208209        self.saved_states = {} 
    209         ## Create context menu for page 
     210        # Create context menu for page 
    210211        self.popUpMenu = wx.Menu() 
    211212 
     
    220221        self.popUpMenu.AppendSeparator() 
    221222 
    222         ## Default locations 
     223        # Default locations 
    223224        self._default_save_location = os.getcwd() 
    224         ## save initial state on context menu 
    225         #self.onSave(event=None) 
     225        # save initial state on context menu 
     226        # self.onSave(event=None) 
    226227        self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 
    227228 
     
    229230        self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) 
    230231 
    231         ## create the basic structure of the panel with empty sizer 
     232        # create the basic structure of the panel with empty sizer 
    232233        self.define_page_structure() 
    233         ## drawing Initial dispersion parameters sizer 
     234        # drawing Initial dispersion parameters sizer 
    234235        self.set_dispers_sizer() 
    235236 
    236         ## layout 
     237        # layout 
    237238        self.set_layout() 
    238239 
     
    260261                    self._create_default_1d_data() 
    261262 
    262             if self.model != None: 
     263            if self.model is not None: 
    263264                if not self.data.is_data: 
    264                     self._manager.page_finder[self.uid].set_fit_data(data=\ 
    265                                                                 [self.data]) 
     265                    self._manager.page_finder[self.uid].set_fit_data( 
     266                        data=[self.data]) 
    266267            self.on_smear_helper(update=True) 
    267268            self.state.enable_smearer = self.enable_smearer.GetValue() 
     
    325326        self.data.id = str(self.uid) + " data" 
    326327        self.data.group_id = str(self.uid) + " Model2D" 
    327         ## Default values 
     328        # Default values 
    328329        self.data.detector.append(Detector()) 
    329330        index = len(self.data.detector) - 1 
     
    342343        x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 
    343344        y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 
    344         ## use data info instead 
     345        # use data info instead 
    345346        new_x = numpy.tile(x, (len(y), 1)) 
    346347        new_y = numpy.tile(y, (len(x), 1)) 
     
    383384        Update menu1 on cliking the page tap 
    384385        """ 
    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( 
    387388                                                   self._manager.id_reset_flag) 
    388389            chain_menu.Enable(self.batch_on) 
    389390            sim_menu = self._manager.menu1.FindItemById(self._manager.id_simfit) 
    390391            flag = self.data.is_data\ 
    391                             and (self.model != None) 
     392                            and (self.model is not None) 
    392393            sim_menu.Enable(not self.batch_on and flag) 
    393394            batch_menu = \ 
     
    530531        fill sizer containing dispersity info 
    531532        """ 
    532         #print "==== entering set_dispers_sizer ===" 
     533        # print "==== entering set_dispers_sizer ===" 
    533534        self.sizer4.Clear(True) 
    534535        name = "Polydispersity and Orientational Distribution" 
     
    536537        box_description.SetForegroundColour(wx.BLUE) 
    537538        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    538         #---------------------------------------------------- 
     539        # ---------------------------------------------------- 
    539540        self.disable_disp = wx.RadioButton(self, wx.ID_ANY, 'Off', (10, 10), 
    540541                                           style=wx.RB_GROUP) 
     
    556557        self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 
    557558                  id=self.enable_disp.GetId()) 
    558         #MAC needs SetValue 
     559        # MAC needs SetValue 
    559560        self.disable_disp.SetValue(True) 
    560561        sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) 
     
    568569        sizer_dispersion.Add(self.disp_help_bt) 
    569570 
    570         ## fill a sizer for dispersion 
     571        # fill a sizer for dispersion 
    571572        boxsizer1.Add(sizer_dispersion, 0, 
    572573                      wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 
     
    575576 
    576577        boxsizer1.Add(self.sizer4_4) 
    577         #----------------------------------------------------- 
     578        # ----------------------------------------------------- 
    578579        self.sizer4.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    579580        self.sizer4_4.Layout() 
     
    582583 
    583584        self.Refresh() 
    584         ## saving the state of enable dispersity button 
     585        # saving the state of enable dispersity button 
    585586        self.state.enable_disp = self.enable_disp.GetValue() 
    586587        self.state.disable_disp = self.disable_disp.GetValue() 
     
    592593        """ 
    593594        menu = event.GetEventObject() 
    594         ## post help message for the selected model 
     595        # post help message for the selected model 
    595596        msg = menu.GetHelpString(event.GetId()) 
    596597        msg += " reloaded" 
     
    599600        name = menu.GetLabel(event.GetId()) 
    600601        self._on_select_model_helper() 
    601         if self.model != None: 
     602        if self.model is not None: 
    602603            self.m_name = self.model.name 
    603604        if name in self.saved_states.keys(): 
    604605            previous_state = self.saved_states[name] 
    605             ## reset state of checkbox,textcrtl  and  regular parameters value 
     606            # reset state of checkbox,textcrtl  and  regular parameters value 
    606607 
    607608            self.reset_page(previous_state) 
     
    626627        # Ask the user the location of the file to write to. 
    627628        path = None 
    628         if self.parent != None: 
     629        if self.parent is not None: 
    629630            self._default_save_location = \ 
    630631                        self._manager.parent._default_save_location 
     
    636637            self._default_save_location = os.path.dirname(path) 
    637638            self._manager.parent._default_save_location = \ 
    638                                 self._default_save_location 
     639                self._default_save_location 
    639640        else: 
    640641            return None 
     
    643644        # Make sure the ext included in the file name 
    644645        fName = os.path.splitext(path)[0] + extens 
    645         #the manager write the state into file 
     646        # the manager write the state into file 
    646647        self._manager.save_fit_state(filepath=fName, fitstate=new_state) 
    647648        return new_state 
     
    651652        Copy Parameter values to the clipboad 
    652653        """ 
    653         if event != None: 
     654        if event is not None: 
    654655            event.Skip() 
    655656        # It seems MAC needs wxCallAfter 
     
    667668        Paste Parameter values to the panel if possible 
    668669        """ 
    669         #if event != None: 
     670        # if event is not None: 
    670671        #    event.Skip() 
    671672        # It seems MAC needs wxCallAfter for the setvalues 
     
    673674        wx.CallAfter(self.get_paste) 
    674675        # messages depending on the flag 
    675         #self._copy_info(True) 
     676        # self._copy_info(True) 
    676677 
    677678    def _copy_info(self, flag): 
     
    682683        """ 
    683684        # messages depending on the flag 
    684         if flag == None: 
     685        if flag is None: 
    685686            msg = " Parameter values are copied to the clipboard..." 
    686687            infor = 'warning' 
     
    710711        save history of the data and model 
    711712        """ 
    712         if self.model == None: 
     713        if self.model is None: 
    713714            msg = "Can not bookmark; Please select Data and Model first..." 
    714715            wx.MessageBox(msg, 'Info') 
     
    716717        self.save_current_state() 
    717718        new_state = self.state.clone() 
    718         ##Add model state on context menu 
     719        # Add model state on context menu 
    719720        self.number_saved_state += 1 
    720721        current_time, current_date = self._get_time_stamp() 
    721         #name= self.model.name+"[%g]"%self.number_saved_state 
     722        # name= self.model.name+"[%g]"%self.number_saved_state 
    722723        name = "Fitting: %g]" % self.number_saved_state 
    723724        name += self.model.__class__.__name__ 
     
    725726        self.saved_states[name] = new_state 
    726727 
    727         ## Add item in the context menu 
     728        # Add item in the context menu 
    728729        msg = "Model saved at %s on %s" % (current_time, current_date) 
    729         ## post help message for the selected model 
     730        # post help message for the selected model 
    730731        msg += " Saved! right click on this page to retrieve this model" 
    731732        wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
     
    761762        """ 
    762763        try: 
    763             if path == None: 
     764            if path is None: 
    764765                status = " Selected Distribution was not loaded: %s" % path 
    765766                wx.PostEvent(self._manager.parent, 
     
    796797        Store current state 
    797798        """ 
    798         ## save model option 
    799         if self.model != None: 
     799        # save model option 
     800        if self.model is not None: 
    800801            self.disp_list = self.model.getDispParamList() 
    801802            self.state.disp_list = copy.deepcopy(self.disp_list) 
    802803            self.state.model = self.model.clone() 
    803804 
    804             #model combobox: complex code because of mac's silent error 
    805             if self.structurebox != None: 
     805            # model combobox: complex code because of mac's silent error 
     806            if self.structurebox is not None: 
    806807                if self.structurebox.IsShown(): 
    807808                    self.state.structurecombobox = 'None' 
    808809                    s_select = self.structurebox.GetSelection() 
    809810                    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: 
    813814                f_select = self.formfactorbox.GetSelection() 
    814815                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: 
    818819            cb_select = self.categorybox.GetSelection() 
    819820            if cb_select > 0: 
    820                 self.state.categorycombobox = self.categorybox.\ 
    821                 GetString(cb_select) 
     821                self.state.categorycombobox = \ 
     822                    self.categorybox.GetString(cb_select) 
    822823 
    823824        self.state.enable2D = copy.deepcopy(self.enable2D) 
    824825        self.state.values = copy.deepcopy(self.values) 
    825826        self.state.weights = copy.deepcopy(self.weights) 
    826         ## save data 
     827        # save data 
    827828        self.state.data = copy.deepcopy(self.data) 
    828829        self.state.qmax_x = self.qmax_x 
     
    859860            self.state.values = copy.deepcopy(self.values) 
    860861            self.state.weights = copy.deepcopy(self.weights) 
    861         ## save plotting range 
     862        # save plotting range 
    862863        self._save_plotting_range() 
    863864 
     
    869870        self.state.str_parameters = [] 
    870871 
    871         ## save checkbutton state and txtcrtl values 
     872        # save checkbutton state and txtcrtl values 
    872873        self._copy_parameters_state(self.str_parameters, 
    873874                                    self.state.str_parameters) 
     
    881882                                    self.state.fittable_param) 
    882883        self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 
    883         #save chisqr 
     884        # save chisqr 
    884885        self.state.tcChi = self.tcChi.GetValue() 
    885886 
     
    888889        Store current state for fit_page 
    889890        """ 
    890         ## save model option 
    891         if self.model != None: 
     891        # save model option 
     892        if self.model is not None: 
    892893            self.disp_list = self.model.getDispParamList() 
    893894            self.state.disp_list = copy.deepcopy(self.disp_list) 
     
    897898        self.state.values = copy.deepcopy(self.values) 
    898899        self.state.weights = copy.deepcopy(self.weights) 
    899         ## save data 
     900        # save data 
    900901        self.state.data = copy.deepcopy(self.data) 
    901902 
     
    918919        self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) 
    919920        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: 
    921922            self.state.disp_box = self.disp_box.GetCurrentSelection() 
    922923 
    923924            if len(self.disp_cb_dict) > 0: 
    924925                for k, v in self.disp_cb_dict.iteritems(): 
    925                     if v == None: 
     926                    if v is None: 
    926927                        self.state.disp_cb_dict[k] = v 
    927928                    else: 
     
    937938            self.state.weights = copy.deepcopy(self.weights) 
    938939 
    939         ## save plotting range 
     940        # save plotting range 
    940941        self._save_plotting_range() 
    941942 
    942         ## save checkbutton state and txtcrtl values 
     943        # save checkbutton state and txtcrtl values 
    943944        self._copy_parameters_state(self.orientation_params, 
    944945                                    self.state.orientation_params) 
     
    959960            msg = "Please load Data and select Model to start..." 
    960961            wx.MessageBox(msg, 'Info') 
    961             return  True 
     962            return True 
    962963 
    963964    def set_model_state(self, state): 
     
    968969        self.disp_list = state.disp_list 
    969970 
    970         ## fill model combobox 
     971        # fill model combobox 
    971972        self._show_combox_helper() 
    972         #select the current model 
     973        # select the current model 
    973974        try: 
    974975            # to support older version 
     
    10091010        self.structurebox.SetSelection(structfactor_pos) 
    10101011 
    1011         if state.multi_factor != None: 
     1012        if state.multi_factor is not None: 
    10121013            self.multifactorbox.SetSelection(state.multi_factor) 
    10131014 
    1014         ## reset state of checkbox,textcrtl  and  regular parameters value 
     1015        # reset state of checkbox,textcrtl  and  regular parameters value 
    10151016        self._reset_parameters_state(self.orientation_params_disp, 
    10161017                                     state.orientation_params_disp) 
     
    10201021                                     state.str_parameters) 
    10211022        self._reset_parameters_state(self.parameters, state.parameters) 
    1022         ## display dispersion info layer 
     1023        # display dispersion info layer 
    10231024        self.enable_disp.SetValue(state.enable_disp) 
    10241025        self.disable_disp.SetValue(state.disable_disp) 
    10251026 
    1026         if hasattr(self, "disp_box") and self.disp_box != None: 
     1027        if hasattr(self, "disp_box") and self.disp_box is not None: 
    10271028            self.disp_box.SetSelection(state.disp_box) 
    10281029            n = self.disp_box.GetCurrentSelection() 
     
    10361037 
    10371038                    if hasattr(self.disp_cb_dict[item], "SetValue"): 
    1038                         self.disp_cb_dict[item].SetValue(\ 
     1039                        self.disp_cb_dict[item].SetValue( 
    10391040                                                    state.disp_cb_dict[item]) 
    10401041                        # Create the dispersion objects 
    10411042                        disp_model = POLYDISPERSITY_MODELS['array']() 
    10421043                        if hasattr(state, "values") and \ 
    1043                                  self.disp_cb_dict[item].GetValue() == True: 
     1044                                 self.disp_cb_dict[item].GetValue() is True: 
    10441045                            if len(state.values) > 0: 
    10451046                                self.values = state.values 
     
    10521053                        self._disp_obj_dict[item] = disp_model 
    10531054                        # Set the new model as the dispersion object 
    1054                         #for the selected parameter 
     1055                        # for the selected parameter 
    10551056                        self.model.set_dispersion(item, disp_model) 
    10561057 
     
    10621063                for item in keys: 
    10631064                    if item in self.disp_list and \ 
    1064                         not item in self.model.details: 
     1065                            item not in self.model.details: 
    10651066                        self.model.details[item] = ["", None, None] 
    10661067                self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 
    10671068                self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 
    1068         ## smearing info  restore 
     1069        # smearing info  restore 
    10691070        if hasattr(self, "enable_smearer"): 
    1070             ## set smearing value whether or not the data 
    1071             #contain the smearing info 
     1071            # set smearing value whether or not the data 
     1072            # contain the smearing info 
    10721073            self.enable_smearer.SetValue(state.enable_smearer) 
    10731074            self.disable_smearer.SetValue(state.disable_smearer) 
     
    10811082        self.dI_idata.SetValue(state.dI_idata) 
    10821083 
    1083         ## we have two more options for smearing 
     1084        # we have two more options for smearing 
    10841085        if self.pinhole_smearer.GetValue(): 
    10851086            self.onPinholeSmear(event=None) 
     
    10871088            self.onSlitSmear(event=None) 
    10881089 
    1089         ## reset state of checkbox,textcrtl  and dispersity parameters value 
     1090        # reset state of checkbox,textcrtl  and dispersity parameters value 
    10901091        self._reset_parameters_state(self.fittable_param, state.fittable_param) 
    10911092        self._reset_parameters_state(self.fixed_param, state.fixed_param) 
    10921093 
    1093         ## draw the model with previous parameters value 
     1094        # draw the model with previous parameters value 
    10941095        self._onparamEnter_helper() 
    10951096        self.select_param(event=None) 
    1096         #Save state_fit 
     1097        # Save state_fit 
    10971098        self.save_current_state_fit() 
    10981099        self._lay_out() 
     
    11081109                if state.formfactorcombobox in list_item: 
    11091110                    return self.categorybox.Items.index(key) 
     1111        return 0 
    11101112 
    11111113    def reset_page_helper(self, state): 
     
    11181120            state of the graphic interface 
    11191121        """ 
    1120         if state == None: 
     1122        if state is None: 
    11211123            return 
    11221124        # set data, etc. from the state 
     
    11241126        data = state.data 
    11251127 
    1126         if data == None: 
     1128        if data is None: 
    11271129            data_min = state.qmin 
    11281130            data_max = state.qmax 
     
    11481150        self.disp_list = state.disp_list 
    11491151 
    1150         ## fill model combobox 
     1152        # fill model combobox 
    11511153        self._show_combox_helper() 
    1152         #select the current model 
     1154        # select the current model 
    11531155        try: 
    11541156            # to support older version 
    11551157            category_pos = int(state.categorycombobox) 
    11561158        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) 
    11581163            state.categorycombobox = unicode(state.categorycombobox) 
    1159             category_pos = 0 
    11601164            if state.categorycombobox in self.categorybox.Items: 
    11611165                category_pos = self.categorybox.Items.index( 
     
    11801184        self.formfactorbox.Select(formfactor_pos) 
    11811185 
     1186        structfactor_pos = 0 
    11821187        try: 
    11831188            # to support older version 
     
    11851190        except: 
    11861191            if state.structurecombobox is not None: 
    1187                 structfactor_pos = 0 
    11881192                state.structurecombobox = unicode(state.structurecombobox) 
    11891193                for ind_struct in range(self.structurebox.GetCount()): 
    11901194                    if self.structurebox.GetString(ind_struct) == \ 
    1191                                                         (state.structurecombobox): 
     1195                                                    (state.structurecombobox): 
    11921196                        structfactor_pos = int(ind_struct) 
    11931197                        break 
     
    11951199        self.structurebox.SetSelection(structfactor_pos) 
    11961200 
    1197         if state.multi_factor != None: 
     1201        if state.multi_factor is not None: 
    11981202            self.multifactorbox.SetSelection(state.multi_factor) 
    11991203 
    1200         #draw the panel according to the new model parameter 
     1204        # draw the panel according to the new model parameter 
    12011205        self._on_select_model(event=None) 
    12021206 
    12031207        # take care of 2D button 
    1204         if data == None and self.model_view.IsEnabled(): 
     1208        if data is None and self.model_view.IsEnabled(): 
    12051209            if self.enable2D: 
    12061210                self.model_view.SetLabel("2D Mode") 
     
    12081212                self.model_view.SetLabel("1D Mode") 
    12091213 
    1210         ## reset state of checkbox,textcrtl  and  regular parameters value 
     1214        # reset state of checkbox,textcrtl  and  regular parameters value 
    12111215        self._reset_parameters_state(self.orientation_params_disp, 
    12121216                                     state.orientation_params_disp) 
     
    12161220                                     state.str_parameters) 
    12171221        self._reset_parameters_state(self.parameters, state.parameters) 
    1218         ## display dispersion info layer 
     1222        # display dispersion info layer 
    12191223        self.enable_disp.SetValue(state.enable_disp) 
    12201224        self.disable_disp.SetValue(state.disable_disp) 
     
    12241228            self._set_dipers_Param(event=None) 
    12251229            self._reset_page_disp_helper(state) 
    1226         ##plotting range restore 
     1230        # plotting range restore 
    12271231        self._reset_plotting_range(state) 
    1228         ## smearing info  restore 
     1232        # smearing info  restore 
    12291233        if hasattr(self, "enable_smearer"): 
    1230             ## set smearing value whether or not the data 
    1231             #contain the smearing info 
     1234            # set smearing value whether or not the data 
     1235            # contain the smearing info 
    12321236            self.enable_smearer.SetValue(state.enable_smearer) 
    12331237            self.disable_smearer.SetValue(state.disable_smearer) 
     
    12471251            self.dI_idata.SetValue(False) 
    12481252 
    1249         ## we have two more options for smearing 
     1253        # we have two more options for smearing 
    12501254        if self.pinhole_smearer.GetValue(): 
    12511255            self.dx_min = state.dx_min 
    12521256            self.dx_max = state.dx_max 
    1253             if self.dx_min != None: 
     1257            if self.dx_min is not None: 
    12541258                self.smear_pinhole_min.SetValue(str(self.dx_min)) 
    1255             if self.dx_max != None: 
     1259            if self.dx_max is not None: 
    12561260                self.smear_pinhole_max.SetValue(str(self.dx_max)) 
    12571261            self.onPinholeSmear(event=None) 
     
    12591263            self.dxl = state.dxl 
    12601264            self.dxw = state.dxw 
    1261             if self.dxl != None: 
     1265            if self.dxl is not None: 
    12621266                self.smear_slit_height.SetValue(str(self.dxl)) 
    1263             if self.dxw != None: 
     1267            if self.dxw is not None: 
    12641268                self.smear_slit_width.SetValue(str(self.dxw)) 
    12651269            else: 
     
    12671271            self.onSlitSmear(event=None) 
    12681272 
    1269         ## reset state of checkbox,textcrtl  and dispersity parameters value 
     1273        # reset state of checkbox,textcrtl  and dispersity parameters value 
    12701274        self._reset_parameters_state(self.fittable_param, state.fittable_param) 
    12711275        self._reset_parameters_state(self.fixed_param, state.fixed_param) 
    12721276 
    1273         ## draw the model with previous parameters value 
     1277        # draw the model with previous parameters value 
    12741278        self._onparamEnter_helper() 
    1275         #reset the value of chisqr when not consistent with the value computed 
     1279        # reset the value of chisqr when not consistent with the value computed 
    12761280        self.tcChi.SetValue(str(self.state.tcChi)) 
    1277         ## reset context menu items 
     1281        # reset context menu items 
    12781282        self._reset_context_menu() 
    12791283 
    1280         ## set the value of the current state to the state given as parameter 
     1284        # set the value of the current state to the state given as parameter 
    12811285        self.state = state.clone() 
    12821286        self.state.m_name = self.m_name 
     
    12891293        for item in keys: 
    12901294            if item in self.disp_list and \ 
    1291                 not item in self.model.details: 
     1295                            item not in self.model.details: 
    12921296                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(): 
    12941298        self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 
    12951299        self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 
     
    12981302 
    12991303        for key, disp_type in state._disp_obj_dict.iteritems(): 
    1300             #disp_model = disp 
     1304            # disp_model = disp 
    13011305            disp_model = POLYDISPERSITY_MODELS[disp_type]() 
    13021306            self._disp_obj_dict[key] = disp_model 
     
    13071311                self.model.set_dispersion(param_name, disp_model) 
    13081312                self.model._persistency_dict[key] = \ 
    1309                                  [state.values, state.weights] 
     1313                    [state.values, state.weights] 
    13101314            except Exception: 
    13111315                logging.error(traceback.format_exc()) 
    13121316            selection = self._find_polyfunc_selection(disp_model) 
    13131317            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: 
    13151319                    list[7].SetSelection(selection) 
    13161320                    # For the array disp_model, set the values and weights 
     
    13411345        open a dialog file to selected the customized dispersity 
    13421346        """ 
    1343         if self.parent != None: 
     1347        if self.parent is not None: 
    13441348            self._default_save_location = \ 
    13451349                        self._manager.parent.get_save_location() 
     
    13601364        for name, _ in self.state.saved_states.iteritems(): 
    13611365            self.number_saved_state += 1 
    1362             ## Add item in the context menu 
     1366            # Add item in the context menu 
    13631367            wx_id = ids.next() 
    13641368            msg = 'Save model and state %g' % self.number_saved_state 
     
    13771381        save radiobutton containing the type model that can be selected 
    13781382        """ 
    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() 
    13831387        self.state.structurecombobox = self.structurebox.GetLabel() 
    13841388        self.state.formfactorcombobox = self.formfactorbox.GetLabel() 
    13851389        self.state.categorycombobox = self.categorybox.GetLabel() 
    13861390 
    1387         ## post state to fit panel 
     1391        # post state to fit panel 
    13881392        event = PageInfoEvent(page=self) 
    13891393        wx.PostEvent(self.parent, event) 
     
    13971401        self.state.npts = self.npts_x 
    13981402 
    1399     def _onparamEnter_helper(self,is_modified = False): 
     1403    def _onparamEnter_helper(self, is_modified=False): 
    14001404        """ 
    14011405        check if values entered by the user are changed and valid to replot 
     
    14031407        """ 
    14041408        # Flag to register when a parameter has changed. 
    1405         #is_modified = False 
     1409        # is_modified = False 
    14061410        self.fitrange = True 
    14071411        is_2Ddata = False 
    1408         #self._undo.Enable(True) 
     1412        # self._undo.Enable(True) 
    14091413        # check if 2d data 
    14101414        if self.data.__class__.__name__ == "Data2D": 
    14111415            is_2Ddata = True 
    1412         if self.model != None: 
    1413             #Either we get a is_modified = True passed in because 
    1414             #_update_paramv_on_fit() has been called already or 
     1416        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 
    14151419            # we need to check here ourselves. 
    14161420            if not is_modified: 
     
    14391443                self.fitrange = False 
    14401444 
    1441             ## if any value is modify draw model with new value 
     1445            # if any value is modify draw model with new value 
    14421446            if not self.fitrange: 
    1443                 #self.btFit.Disable() 
     1447                # self.btFit.Disable() 
    14441448                if is_2Ddata: 
    14451449                    self.btEditMask.Disable() 
     
    14551459                self.Refresh() 
    14561460 
    1457         #logging.info("is_modified flag set to %g",is_modified) 
     1461        # logging.info("is_modified flag set to %g",is_modified) 
    14581462        return is_modified 
    14591463 
     
    14621466        make sure that update param values just before the fitting 
    14631467        """ 
    1464         #flag for qmin qmax check values 
     1468        # flag for qmin qmax check values 
    14651469        flag = True 
    14661470        self.fitrange = True 
    14671471        is_modified = False 
    14681472 
    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: 
    14751479            if self.Npts_total.GetValue() != self.Npts_fit.GetValue(): 
    14761480                if not self.data.is_data: 
    1477                     self._manager.page_finder[self.uid].set_fit_data(data=\ 
    1478                                                                 [self.data]) 
    1479             ##Check the values 
     1481                    self._manager.page_finder[self.uid].set_fit_data( 
     1482                        data=[self.data]) 
     1483            # Check the values 
    14801484            is_modified = (self._check_value_enter(self.fittable_param) 
    1481                             or self._check_value_enter(self.fixed_param) 
    1482                             or self._check_value_enter(self.parameters)) 
     1485                           or self._check_value_enter(self.fixed_param) 
     1486                           or self._check_value_enter(self.parameters)) 
    14831487 
    14841488            # If qmin and qmax have been modified, update qmin and qmax and 
     
    15211525                                              enable_smearer=enable_smearer, 
    15221526                                              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) & 
    15251529                                      (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])) 
    15271531                        self.Npts_fit.SetValue(val) 
    15281532                    else: 
     
    15441548            flag = False 
    15451549 
    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. 
    15471551        if not self.fitrange: 
    15481552            if self._is_2D(): 
    15491553                self.btEditMask.Disable() 
    15501554        else: 
    1551             if self._is_2D() and  self.data.is_data and not self.batch_on: 
     1555            if self._is_2D() and self.data.is_data and not self.batch_on: 
    15521556                self.btEditMask.Enable(True) 
    15531557 
     
    15621566            logging.error(traceback.format_exc()) 
    15631567 
    1564         return flag,is_modified 
     1568        return flag, is_modified 
    15651569 
    15661570    def _reset_parameters_state(self, listtorestore, statelist): 
     
    15761580            item_page = listtorestore[j] 
    15771581            item_page_info = statelist[j] 
    1578             ##change the state of the check box for simple parameters 
    1579             if item_page[0] != None: 
     1582            # change the state of the check box for simple parameters 
     1583            if item_page[0] is not None: 
    15801584                item_page[0].SetValue(item_page_info[0]) 
    1581             if item_page[2] != None: 
     1585            if item_page[2] is not None: 
    15821586                item_page[2].SetValue(item_page_info[2]) 
    15831587                if item_page[2].__class__.__name__ == "ComboBox": 
     
    15851589                        fun_val = self.model.fun_list[item_page_info[2]] 
    15861590                        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 +/- 
    15891593                if item_page_info[2]: 
    15901594                    item_page[3].Show(True) 
    15911595                else: 
    15921596                    item_page[3].Hide() 
    1593             if item_page[4] != None: 
    1594                 ## show of hide the text crtl for fitting error 
     1597            if item_page[4] is not None: 
     1598                # show of hide the text crtl for fitting error 
    15951599                if item_page_info[4][0]: 
    15961600                    item_page[4].Show(True) 
     
    15981602                else: 
    15991603                    item_page[3].Hide() 
    1600             if item_page[5] != None: 
    1601                 ## show of hide the text crtl for fitting error 
     1604            if item_page[5] is not None: 
     1605                # show of hide the text crtl for fitting error 
    16021606                item_page[5].Show(item_page_info[5][0]) 
    16031607                item_page[5].SetValue(item_page_info[5][1]) 
    16041608 
    1605             if item_page[6] != None: 
    1606                 ## show of hide the text crtl for fitting error 
     1609            if item_page[6] is not None: 
     1610                # show of hide the text crtl for fitting error 
    16071611                item_page[6].Show(item_page_info[6][0]) 
    16081612                item_page[6].SetValue(item_page_info[6][1]) 
     
    16201624            item_page = listtorestore[j] 
    16211625            item_page_info = statelist[j] 
    1622             ##change the state of the check box for simple parameters 
    1623  
    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: 
    16251629                item_page[0].SetValue(format_number(item_page_info[0], True)) 
    16261630 
    1627             if item_page[2] != None: 
     1631            if item_page[2] is not None: 
    16281632                param_name = item_page_info[1] 
    16291633                value = item_page_info[2] 
     
    16481652 
    16491653            checkbox_state = None 
    1650             if item[0] != None: 
     1654            if item[0] is not None: 
    16511655                checkbox_state = item[0].GetValue() 
    16521656            parameter_name = item[1] 
    16531657            parameter_value = None 
    1654             if item[2] != None: 
     1658            if item[2] is not None: 
    16551659                parameter_value = item[2].GetValue() 
    16561660            static_text = None 
    1657             if item[3] != None: 
     1661            if item[3] is not None: 
    16581662                static_text = item[3].IsShown() 
    16591663            error_value = None 
    16601664            error_state = None 
    1661             if item[4] != None: 
     1665            if item[4] is not None: 
    16621666                error_value = item[4].GetValue() 
    16631667                error_state = item[4].IsShown() 
     
    16651669            min_value = None 
    16661670            min_state = None 
    1667             if item[5] != None: 
     1671            if item[5] is not None: 
    16681672                min_value = item[5].GetValue() 
    16691673                min_state = item[5].IsShown() 
     
    16711675            max_value = None 
    16721676            max_state = None 
    1673             if item[6] != None: 
     1677            if item[6] is not None: 
    16741678                max_value = item[6].GetValue() 
    16751679                max_state = item[6].IsShown() 
    16761680            unit = None 
    1677             if item[7] != None: 
     1681            if item[7] is not None: 
    16781682                unit = item[7].GetLabel() 
    16791683 
     
    16831687                              [max_state, max_value], unit]) 
    16841688 
    1685  
    16861689    def _draw_model(self, update_chisqr=True, source='model'): 
    16871690        """ 
     
    17021705        :param chisqr: update chisqr value [bool] 
    17031706        """ 
    1704         #if self.check_invalid_panel(): 
     1707        # if self.check_invalid_panel(): 
    17051708        #    return 
    1706         if self.model != None: 
     1709        if self.model is not None: 
    17071710            temp_smear = None 
    17081711            if hasattr(self, "enable_smearer"): 
     
    17161719            is_2d = self._is_2D() 
    17171720            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) 
    17291732 
    17301733    def _on_show_sld(self, event=None): 
     
    17361739 
    17371740        from sas.sasgui.plottools import Data1D as pf_data1d 
    1738         #from sas.sasgui.perspectives.theory.profile_dialog import SLDPanel 
     1741        # from sas.sasgui.perspectives.theory.profile_dialog import SLDPanel 
    17391742        from sas.sasgui.guiframe.local_perspectives.plotting.profile_dialog \ 
    1740         import SLDPanel 
     1743            import SLDPanel 
    17411744        sld_data = pf_data1d(x, y) 
    17421745        sld_data.name = 'SLD' 
     
    17911794        self.structurebox.Disable() 
    17921795        self.formfactorbox.Clear() 
    1793         if mod_cat == None: 
     1796        if mod_cat is None: 
    17941797            return 
    17951798        m_list = [] 
     
    18531856        """ 
    18541857        tcrtl = event.GetEventObject() 
    1855         #Clear msg if previously shown. 
     1858        # Clear msg if previously shown. 
    18561859        msg = "" 
    18571860        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     
    18721875                    tcrtl.SetBackgroundColour("pink") 
    18731876                    msg = "Model Error: wrong value entered: %s" % \ 
    1874                                     sys.exc_info()[1] 
     1877                          sys.exc_info()[1] 
    18751878                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    18761879                    return 
     
    18801883                wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    18811884                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: 
    18841887                if check_float(self.npts): 
    18851888                    temp_npts = float(self.npts.GetValue()) 
     
    18971900        wx.PostEvent(self.parent, event) 
    18981901        self.state_change = False 
    1899         #Draw the model for a different range 
     1902        # Draw the model for a different range 
    19001903        if not self.data.is_data: 
    19011904            self.create_default_data() 
     
    19081911 
    19091912        tcrtl = event.GetEventObject() 
    1910         #Clear msg if previously shown. 
     1913        # Clear msg if previously shown. 
    19111914        msg = "" 
    19121915        wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
     
    19291932                    tcrtl.SetBackgroundColour("pink") 
    19301933                    msg = "Model Error: wrong value entered: %s" % \ 
    1931                                         sys.exc_info()[1] 
     1934                          sys.exc_info()[1] 
    19321935                    wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    19331936                    return 
     
    19371940                wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    19381941                return 
    1939             #Check if # of points for theory model are valid(>0). 
     1942            # Check if # of points for theory model are valid(>0). 
    19401943            if self.Npts_total.IsEditable(): 
    19411944                if check_float(self.Npts_total): 
     
    19551958        wx.PostEvent(self.parent, event) 
    19561959        self.state_change = False 
    1957         #Draw the model for a different range 
     1960        # Draw the model for a different range 
    19581961        self.create_default_data() 
    19591962        self._draw_model() 
     
    19631966        call back for model selection 
    19641967        """ 
    1965         ## reset dictionary containing reference to dispersion 
     1968        # reset dictionary containing reference to dispersion 
    19661969        self._disp_obj_dict = {} 
    19671970        self.disp_cb_dict = {} 
    19681971        self.temp_multi_functional = False 
    19691972        f_id = self.formfactorbox.GetCurrentSelection() 
    1970         #For MAC 
     1973        # For MAC 
    19711974        form_factor = None 
    19721975        if f_id >= 0: 
     
    19751978        if form_factor is None or \ 
    19761979            not hasattr(form_factor, 'is_form_factor') or \ 
    1977             not form_factor.is_form_factor: 
     1980                not form_factor.is_form_factor: 
    19781981            self.structurebox.Hide() 
    19791982            self.text2.Hide() 
     
    19871990            self.text2.Enable() 
    19881991 
    1989         if form_factor != None: 
     1992        if form_factor is not None: 
    19901993            # set multifactor for Mutifunctional models 
    19911994            if form_factor.is_multiplicity_model: 
     
    19951998                self._set_multfactor_combobox(multiplicity) 
    19961999                self._show_multfactor_combobox() 
    1997                 #ToDo: this info should be called directly from the model 
     2000                # ToDo: this info should be called directly from the model 
    19982001                text = form_factor.multiplicity_info[1]  # 'No. of Shells: ' 
    19992002 
     
    20042007 
    20052008                self.multi_factor = self.multifactorbox.GetClientData(m_id) 
    2006                 if self.multi_factor == None: 
     2009                if self.multi_factor is None: 
    20072010                    self.multi_factor = 0 
    20082011                self.multifactorbox.SetSelection(m_id) 
     
    20102013                text = '' 
    20112014                if form_factor.multiplicity_info[0] == \ 
    2012                                         len(form_factor.multiplicity_info[2]): 
     2015                        len(form_factor.multiplicity_info[2]): 
    20132016                    text = form_factor.multiplicity_info[2][self.multi_factor] 
    20142017                self.mutifactor_text1.SetLabel(text) 
     
    20312034        struct_factor = self.structurebox.GetClientData(s_id) 
    20322035 
    2033         if  struct_factor != None: 
     2036        if struct_factor is not None: 
    20342037            from sasmodels.sasview_model import MultiplicationModel 
    20352038            self.model = MultiplicationModel(form_factor(self.multi_factor), 
     
    20382041            if len(form_factor.non_fittable) > 0: 
    20392042                self.temp_multi_functional = True 
    2040         elif form_factor != None: 
     2043        elif form_factor is not None: 
    20412044            if self.multi_factor is not None: 
    20422045                self.model = form_factor(self.multi_factor) 
     
    20532056        else: 
    20542057            self._has_magnetic = False 
    2055         ## post state to fit panel 
     2058        # post state to fit panel 
    20562059        self.state.parameters = [] 
    20572060        self.state.model = self.model 
     
    20632066        self.Layout() 
    20642067 
    2065  
    20662068    def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 
    20672069        """ 
     
    20832085            qmax = float(qmax_ctrl.GetValue()) 
    20842086            if qmin < qmax: 
    2085                 #Make sure to set both colours white. 
     2087                # Make sure to set both colours white. 
    20862088                qmin_ctrl.SetBackgroundColour(wx.WHITE) 
    20872089                qmin_ctrl.Refresh() 
     
    21032105        If valid, setvalues Npts_fit otherwise post msg. 
    21042106        """ 
    2105         #default flag 
     2107        # default flag 
    21062108        flag = True 
    21072109        # Theory 
    2108         if self.data == None and self.enable2D: 
     2110        if self.data is None and self.enable2D: 
    21092111            return flag 
    21102112        for data in self.data_list: 
     
    21122114            radius = numpy.sqrt(data.qx_data * data.qx_data + 
    21132115                                data.qy_data * data.qy_data) 
    2114             #get unmasked index 
     2116            # get unmasked index 
    21152117            index_data = (float(self.qmin.GetValue()) <= radius) & \ 
    2116                             (radius <= float(self.qmax.GetValue())) 
     2118                         (radius <= float(self.qmax.GetValue())) 
    21172119            index_data = (index_data) & (data.mask) 
    21182120            index_data = (index_data) & (numpy.isfinite(data.data)) 
     
    21302132                flag = False 
    21312133            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]))) 
    21332135                self.fitrange = True 
    21342136 
     
    21402142        If valid, setvalues Npts_fit otherwise post msg. 
    21412143        """ 
    2142         #default flag 
     2144        # default flag 
    21432145        flag = True 
    21442146        # Theory 
    2145         if self.data == None: 
     2147        if self.data is None: 
    21462148            return flag 
    21472149        for data in self.data_list: 
    21482150            # q value from qx and qy 
    21492151            radius = data.x 
    2150             #get unmasked index 
     2152            # get unmasked index 
    21512153            index_data = (float(self.qmin.GetValue()) <= radius) & \ 
    2152                             (radius <= float(self.qmax.GetValue())) 
     2154                         (radius <= float(self.qmax.GetValue())) 
    21532155            index_data = (index_data) & (numpy.isfinite(data.y)) 
    21542156 
     
    21652167                flag = False 
    21662168            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]))) 
    21682170                self.fitrange = True 
    21692171 
     
    21852187        is_modified = False 
    21862188        for item in list: 
    2187             #skip angle parameters for 1D 
     2189            # skip angle parameters for 1D 
    21882190            if not self.enable2D and item in self.orientation_params: 
    21892191                continue 
     
    22302232                    max_ctrl.SetBackgroundColour("pink") 
    22312233                    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)) 
    22342238                    continue 
    22352239 
     
    22492253                    # The configuration has changed but it won't change the 
    22502254                    # computed curve so no need to set is_modified to True 
    2251                     #is_modified = True 
     2255                    # is_modified = True 
    22522256                    self.model.details[name][1:3] = low, high 
    22532257 
     
    22672271        Redraw the model with the default dispersity (Gaussian) 
    22682272        """ 
    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: 
    22712275            self.disable_disp.SetValue(True) 
    22722276            msg = "Please select a Model first..." 
     
    22782282        self._reset_dispersity() 
    22792283 
    2280         if self.model == None: 
     2284        if self.model is None: 
    22812285            self.model_disp.Hide() 
    22822286            self.sizer4_4.Clear(True) 
     
    22842288 
    22852289        if self.enable_disp.GetValue(): 
    2286             ## layout for model containing no dispersity parameters 
     2290            # layout for model containing no dispersity parameters 
    22872291 
    22882292            self.disp_list = self.model.getDispParamList() 
     
    22912295                self._layout_sizer_noDipers() 
    22922296            else: 
    2293                 ## set gaussian sizer 
     2297                # set gaussian sizer 
    22942298                self._on_select_Disp(event=None) 
    22952299        else: 
    22962300            self.sizer4_4.Clear(True) 
    22972301 
    2298         ## post state to fit panel 
     2302        # post state to fit panel 
    22992303        self.save_current_state() 
    2300         if event != None: 
     2304        if event is not None: 
    23012305            event = PageInfoEvent(page=self) 
    23022306            wx.PostEvent(self.parent, event) 
    2303         #draw the model with the current dispersity 
    2304  
    2305         #Wojtek P, Oct 8, 2016: Calling draw_model seems to be unessecary. 
    2306         #By comenting it we save an extra Iq calculation 
    2307         #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, 2015 
     2307        # 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 
    23122316        self.FitInside() 
    23132317#        self.sizer4_4.Layout() 
     
    23532357        self.weights = {} 
    23542358 
    2355         #from sas.models.dispersion_models import GaussianDispersion 
     2359        # from sas.models.dispersion_models import GaussianDispersion 
    23562360        from sasmodels.weights import GaussianDispersion 
    23572361        if len(self.disp_cb_dict) == 0: 
     
    23742378                    logging.error(traceback.format_exc()) 
    23752379 
    2376         ## save state into 
     2380        # save state into 
    23772381        self.save_current_state() 
    23782382        self.Layout() 
     
    23862390        self._set_sizer_dispersion() 
    23872391 
    2388         ## Redraw the model 
     2392        # Redraw the model 
    23892393        self._draw_model() 
    2390         #self._undo.Enable(True) 
     2394        # self._undo.Enable(True) 
    23912395        event = PageInfoEvent(page=self) 
    23922396        wx.PostEvent(self.parent, event) 
     
    24032407        """ 
    24042408        # get ready for new event 
    2405         if event != None: 
     2409        if event is not None: 
    24062410            event.Skip() 
    24072411        # Get event object 
     
    24162420            dispersity = disp_box.GetClientData(selection) 
    24172421 
    2418             #disp_model =  GaussianDispersion() 
     2422            # disp_model =  GaussianDispersion() 
    24192423            disp_model = dispersity() 
    24202424            # Get param names to reset the values of the param 
     
    24292433            else: 
    24302434                self._del_array_values(name1) 
    2431                 #self._reset_array_disp(param_name) 
     2435                # self._reset_array_disp(param_name) 
    24322436                self._disp_obj_dict[name1] = disp_model 
    24332437                self.model.set_dispersion(param_name, disp_model) 
     
    25132517        if path is None: 
    25142518            self.disp_cb_dict[name].SetValue(False) 
    2515             #self.noDisper_rbox.SetValue(True) 
     2519            # self.noDisper_rbox.SetValue(True) 
    25162520            return 
    25172521        self._default_save_location = os.path.dirname(path) 
    2518         if self._manager != None: 
     2522        if self._manager is not None: 
    25192523            self._manager.parent._default_save_location = \ 
    25202524                             self._default_save_location 
     
    25332537        wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    25342538        self._set_array_disp_model(name=name, disp=disp, 
    2535                                     values=values, weights=weights) 
     2539                                   values=values, weights=weights) 
    25362540        return basename 
    25372541 
     
    25522556        # Store the object to make it persist outside the 
    25532557        # scope of this method 
    2554         #TODO: refactor model to clean this up? 
     2558        # TODO: refactor model to clean this up? 
    25552559        self.state.values = {} 
    25562560        self.state.weights = {} 
     
    25592563 
    25602564        # Set the new model as the dispersion object for the 
    2561         #selected parameter 
    2562         #self.model.set_dispersion(p, disp_model) 
     2565        # selected parameter 
     2566        # self.model.set_dispersion(p, disp_model) 
    25632567        # Store a reference to the weights in the model object 
    2564         #so that 
     2568        # so that 
    25652569        # it's not lost when we use the model within another thread. 
    25662570        self.state.model = self.model.clone() 
    25672571        self.model._persistency_dict[name.split('.')[0]] = \ 
    2568                                         [values, weights] 
     2572            [values, weights] 
    25692573        self.state.model._persistency_dict[name.split('.')[0]] = \ 
    2570                                         [values, weights] 
     2574            [values, weights] 
    25712575 
    25722576    def _del_array_values(self, name=None): 
     
    26062610            Layout after self._draw_model 
    26072611        """ 
    2608         if ON_MAC == True: 
     2612        if ON_MAC is True: 
    26092613            time.sleep(1) 
    26102614 
     
    26282632        """ 
    26292633        flag = True 
    2630         ##For 3 different cases: Data2D, Data1D, and theory 
    2631         if self.model == None: 
     2634        # For 3 different cases: Data2D, Data1D, and theory 
     2635        if self.model is None: 
    26322636            msg = "Please select a model first..." 
    26332637            wx.MessageBox(msg, 'Info') 
     
    26412645            self.qmin_x = data_min 
    26422646            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) 
    26442648            # check smearing 
    26452649            if not self.disable_smearer.GetValue(): 
    2646                 ## set smearing value whether or 
     2650                # set smearing value whether or 
    26472651                # not the data contain the smearing info 
    26482652                if self.pinhole_smearer.GetValue(): 
     
    26512655                    flag = True 
    26522656 
    2653         elif self.data == None: 
     2657        elif self.data is None: 
    26542658            self.qmin_x = _QMIN_DEFAULT 
    26552659            self.qmax_x = _QMAX_DEFAULT 
     
    26622666            # check smearing 
    26632667            if not self.disable_smearer.GetValue(): 
    2664                 ## set smearing value whether or 
     2668                # set smearing value whether or 
    26652669                # not the data contain the smearing info 
    26662670                if self.slit_smearer.GetValue(): 
     
    26732677            flag = False 
    26742678 
    2675         if flag == False: 
     2679        if flag is False: 
    26762680            msg = "Cannot Plot :Must enter a number!!!  " 
    26772681            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
     
    26902694        self.state.qmax = self.qmax_x 
    26912695 
    2692         #reset the q range values 
     2696        # reset the q range values 
    26932697        self._reset_plotting_range(self.state) 
    26942698        self._draw_model() 
     
    27312735                logging.error(traceback.format_exc()) 
    27322736        # Make sure the resduals plot goes to the last 
    2733         if res_item != None: 
     2737        if res_item is not None: 
    27342738            graphs.append(res_item[0]) 
    27352739            canvases.append(res_item[1]) 
     
    27502754        the # to the browser. 
    27512755 
    2752         :param evt: on Help Button pressed event 
    2753         """ 
    2754  
    2755         if self.model != None: 
     2756        :param event: on Help Button pressed event 
     2757        """ 
     2758 
     2759        if self.model is not None: 
    27562760            name = self.formfactorbox.GetValue() 
    2757             _TreeLocation = 'user/models/'+ name.lower()+'.html' 
     2761            _TreeLocation = 'user/models/' + name.lower()+'.html' 
    27582762            _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
    27592763                                              "", name + " Help") 
     
    27622766            _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
    27632767                                              "", "General Model Help") 
    2764  
    27652768 
    27662769    def on_model_help_clicked(self, event): 
     
    27742777        give the message that none is available. 
    27752778 
    2776         :param evt: on Description Button pressed event 
    2777         """ 
    2778  
    2779         if self.model == None: 
     2779        :param event: on Description Button pressed event 
     2780        """ 
     2781 
     2782        if self.model is None: 
    27802783            name = 'index.html' 
    27812784        else: 
     
    27842787        msg = 'Model description:\n' 
    27852788        info = "Info" 
    2786         if self.model != None: 
    2787 #                frame.Destroy() 
     2789        if self.model is not None: 
     2790            # frame.Destroy() 
    27882791            if str(self.model.description).rstrip().lstrip() == '': 
    27892792                msg += "Sorry, no information is available for this model." 
     
    28542857            for key in self.model.magnetic_params: 
    28552858                if key.count('M0') > 0: 
    2856                     #reset mag value to zero fo safety 
     2859                    # reset mag value to zero fo safety 
    28572860                    self.model.setParam(key, 0.0) 
    28582861 
    28592862        self.Show(False) 
    28602863        self.set_model_param_sizer(self.model) 
    2861         #self._set_sizer_dispersion() 
     2864        # self._set_sizer_dispersion() 
    28622865        self.state.magnetic_on = self.magnetic_on 
    28632866        self.SetupScrolling() 
     
    28742877        running "file:///...." 
    28752878 
    2876         :param evt: Triggers on clicking ? in polydispersity box 
     2879        :param event: Triggers on clicking ? in polydispersity box 
    28772880        """ 
    28782881 
     
    29122915        content = 'sasview_parameter_values:' 
    29132916        # Do it if params exist 
    2914         if  self.parameters != []: 
     2917        if self.parameters: 
    29152918 
    29162919            # go through the parameters 
     
    29562959 
    29572960        # Do it if params exist 
    2958         if  self.parameters != []: 
     2961        if self.parameters: 
    29592962 
    29602963            for param in self.parameters: 
    2961                 content += param[1] #parameter name 
     2964                content += param[1]  # parameter name 
    29622965                content += tab 
    29632966                content += param[1] + "_err" 
     
    29662969            content += crlf 
    29672970 
    2968             #row of values and errors... 
     2971            # row of values and errors... 
    29692972            for param in self.parameters: 
    2970                 content += param[2].GetValue() #value 
     2973                content += param[2].GetValue()  # value 
    29712974                content += tab 
    2972                 content += param[4].GetValue() #error 
     2975                content += param[4].GetValue()  # error 
    29732976                content += tab 
    29742977 
     
    29762979        else: 
    29772980            return False 
    2978  
    29792981 
    29802982    def get_copy_latex(self): 
     
    29983000 
    29993001        # Do it if params exist 
    3000         if  self.parameters != []: 
     3002        if self.parameters: 
    30013003 
    30023004            content += '{|' 
     
    30073009 
    30083010            for index, param in enumerate(self.parameters): 
    3009                 content += param[1].replace('_', '\_') #parameter name 
     3011                content += param[1].replace('_', '\_')  # parameter name 
    30103012                content += ' & ' 
    30113013                content += param[1].replace('_', '\_') + "\_err" 
     
    30153017            content += crlf 
    30163018 
    3017             #row of values and errors... 
     3019            # row of values and errors... 
    30183020            for index, param in enumerate(self.parameters): 
    3019                 content += param[2].GetValue() #parameter value 
     3021                content += param[2].GetValue()  # parameter value 
    30203022                content += ' & ' 
    3021                 content += param[4].GetValue() #parameter error 
     3023                content += param[4].GetValue()  # parameter error 
    30223024                if index < len(self.parameters) - 1: 
    30233025                    content += ' & ' 
     
    30303032        else: 
    30313033            return False 
    3032  
    30333034 
    30343035    def set_clipboard(self, content=None): 
     
    30773078            # 1D 
    30783079            else: 
    3079                 ## for 1D all parameters except orientation 
     3080                # for 1D all parameters except orientation 
    30803081                if not item[1] in orient_param: 
    30813082                    try: 
     
    31093110            except Exception: 
    31103111                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 + ':' 
    31143114 
    31153115        return content 
     
    31893189 
    31903190        # Do it if params exist 
    3191         if  self.parameters != []: 
     3191        if self.parameters: 
    31923192            # go through the parameters 
    31933193            self._get_paste_helper(self.parameters, 
     
    32373237                                pd = int(pd) 
    32383238                        except Exception: 
    3239                             #continue 
     3239                            # continue 
    32403240                            if not pd and pd != '': 
    32413241                                continue 
     
    32653265                    else: 
    32663266                        is_true = None 
    3267                     if is_true != None: 
     3267                    if is_true is not None: 
    32683268                        item[0].SetValue(is_true) 
    32693269            # 1D 
    32703270            else: 
    3271                 ## for 1D all parameters except orientation 
     3271                # for 1D all parameters except orientation 
    32723272                if not item[1] in orient_param: 
    32733273                    name = item[1] 
     
    32783278                        pd = value[0] 
    32793279                        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. 
    32833284                            try: 
    32843285                                pd = float(pd) 
     
    32863287                                    pd = int(pd) 
    32873288                            except: 
    3288                                 #continue 
     3289                                # continue 
    32893290                                if not pd and pd != '': 
    32903291                                    continue 
     
    33143315                        else: 
    33153316                            is_true = None 
    3316                         if is_true != None: 
     3317                        if is_true is not None: 
    33173318                            item[0].SetValue(is_true) 
    33183319 
     
    33813382            logging.error(traceback.format_exc()) 
    33823383            print "Error in BasePage._paste_poly_help: %s" % \ 
    3383                                     sys.exc_info()[1] 
     3384                  sys.exc_info()[1] 
    33843385 
    33853386    def _set_disp_cb(self, isarray, item): 
     
    34473448        self.categorybox.Clear() 
    34483449        cat_list = sorted(self.master_category_dict.keys()) 
    3449         if not uncat_str in cat_list: 
     3450        if uncat_str not in cat_list: 
    34503451            cat_list.append(uncat_str) 
    34513452 
     
    34573458            self.categorybox.SetSelection(0) 
    34583459        else: 
    3459             self.categorybox.SetSelection(\ 
     3460            self.categorybox.SetSelection( 
    34603461                self.categorybox.GetSelection()) 
    3461         #self._on_change_cat(None) 
     3462        # self._on_change_cat(None) 
    34623463 
    34633464    def _on_change_cat(self, event): 
     
    34673468        self.model_name = None 
    34683469        category = self.categorybox.GetStringSelection() 
    3469         if category == None: 
     3470        if category is None: 
    34703471            return 
    34713472        self.model_box.Clear() 
     
    34783479        else: 
    34793480            for (model, enabled) in sorted(self.master_category_dict[category], 
    3480                                       key=lambda name: name[0]): 
     3481                                           key=lambda name: name[0]): 
    34813482                if(enabled): 
    34823483                    self.model_box.Append(model) 
     
    34873488        """ 
    34883489        # 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... 
    34923493        title = "Model" 
    34933494        self.formfactorbox = None 
     
    35213522        self._populate_listbox() 
    35223523        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', 
    35243525        #                                     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, 
    35263527        #                                          "Shape-Independent") 
    3527         #self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY, 
     3528        # self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY, 
    35283529        #                                     "Structure Factor ") 
    3529         #self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY, 
     3530        # self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY, 
    35303531        #                                     "Uncategorized") 
    35313532 
    3532         #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
     3533        # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
    35333534        #                   id=self.shape_rbutton.GetId()) 
    3534         #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
     3535        # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
    35353536        #                    id=self.shape_indep_rbutton.GetId()) 
    3536         #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
     3537        # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
    35373538        #                    id=self.struct_rbutton.GetId()) 
    3538         #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
     3539        # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
    35393540        #                    id=self.plugin_rbutton.GetId()) 
    3540         #MAC needs SetValue 
     3541        # MAC needs SetValue 
    35413542 
    35423543        show_cat_button = wx.Button(self, wx.ID_ANY, "Modify") 
    35433544        cat_tip = "Modify model categories \n" 
    35443545        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)) 
    35463547        show_cat_button.Bind(wx.EVT_BUTTON, self._on_modify_cat) 
    35473548        sizer_cat_box.Add(self.categorybox, 1, wx.RIGHT, 3) 
    3548         sizer_cat_box.Add((10,10)) 
     3549        sizer_cat_box.Add((10, 10)) 
    35493550        sizer_cat_box.Add(show_cat_button) 
    3550         #self.shape_rbutton.SetValue(True) 
     3551        # self.shape_rbutton.SetValue(True) 
    35513552 
    35523553        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)) 
    35563557        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)) 
    35603561        sizer_radiobutton.Add(self.model_help, 1, wx.RIGHT | wx.LEFT, 5) 
    3561 #        sizer_radiobutton.Add((5,5)) 
     3562        # sizer_radiobutton.Add((5,5)) 
    35623563        sizer_radiobutton.Add(self.model_func, 1, wx.RIGHT, 5) 
    35633564        sizer_cat.Add(sizer_cat_box, 1, wx.LEFT, 2.5) 
     
    35753576        self.formfactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    35763577        self.formfactorbox.SetToolTip(wx.ToolTip("Select a Model")) 
    3577         if self.model != None: 
     3578        if self.model is not None: 
    35783579            self.formfactorbox.SetValue(self.model.name) 
    35793580        self.structurebox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     
    35843585        wx.EVT_COMBOBOX(self.structurebox, wx.ID_ANY, self._on_select_model) 
    35853586        wx.EVT_COMBOBOX(self.multifactorbox, wx.ID_ANY, self._on_select_model) 
    3586         ## check model type to show sizer 
    3587         if self.model != None: 
     3587        # check model type to show sizer 
     3588        if self.model is not None: 
    35883589            print "_set_model_sizer_selection: disabled." 
    3589             #self._set_model_sizer_selection(self.model) 
     3590            # self._set_model_sizer_selection(self.model) 
    35903591 
    35913592        sizer_selection.Add(self.text1) 
     
    36823683        """ 
    36833684 
     3685 
    36843686class ModelTextCtrl(wx.TextCtrl): 
    36853687    """ 
     
    36943696 
    36953697    """ 
    3696     ## Set to True when the mouse is clicked while whole string is selected 
     3698    # Set to True when the mouse is clicked while whole string is selected 
    36973699    full_selection = False 
    3698     ## Call back for EVT_SET_FOCUS events 
     3700    # Call back for EVT_SET_FOCUS events 
    36993701    _on_set_focus_callback = None 
    37003702 
     
    37183720            if set_focus_callback is None else set_focus_callback 
    37193721        self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) 
    3720         self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus \ 
    3721             if kill_focus_callback is None else kill_focus_callback) 
    3722         self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \ 
    3723             if text_enter_callback is None else text_enter_callback) 
     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) 
    37243726        if not ON_MAC: 
    3725             self.Bind(wx.EVT_LEFT_UP, self._highlight_text \ 
    3726                 if mouse_up_callback is None else mouse_up_callback) 
     3727            self.Bind(wx.EVT_LEFT_UP, self._highlight_text 
     3728            if mouse_up_callback is None else mouse_up_callback) 
    37273729 
    37283730    def _on_set_focus(self, event): 
     
    37643766 
    37653767        event.Skip() 
    3766         #pass 
     3768        # pass 
  • src/sas/sasgui/perspectives/fitting/fitpage.py

    r3bec50a rc8e1996  
    1414from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS 
    1515 
    16 from sas.sasgui.guiframe.events import StatusEvent 
    17 from sas.sasgui.guiframe.events import NewPlotEvent 
    18 from sas.sasgui.guiframe.events import PlotQrangeEvent 
     16from sas.sasgui.guiframe.events import StatusEvent, NewPlotEvent, \ 
     17    PlotQrangeEvent 
    1918from 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 
     19from sas.sasgui.guiframe.utils import format_number, check_float 
    2220from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
     21 
     22from sas.sasgui.perspectives.fitting.basepage import BasicPage as BasicPage 
     23from sas.sasgui.perspectives.fitting.basepage import PageInfoEvent as \ 
     24    PageInfoEvent 
     25from sas.sascalc.data_util.qsmearing import smear_selection 
     26from .basepage import ModelTextCtrl 
    2327 
    2428(Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() 
     
    2832SMEAR_SIZE_H = 0.00 
    2933 
    30 from sas.sasgui.perspectives.fitting.basepage import BasicPage as BasicPage 
    31 from sas.sasgui.perspectives.fitting.basepage import PageInfoEvent as PageInfoEvent 
    32 from sas.sascalc.data_util.qsmearing import smear_selection 
    33 from .basepage import ModelTextCtrl 
    34  
    3534 
    3635class FitPage(BasicPage): 
     
    4948        BasicPage.__init__(self, parent, color=color) 
    5049 
    51         ## draw sizer 
     50        # draw sizer 
    5251        self._fill_data_sizer() 
    5352        self.is_2D = None 
     
    7271        self.enable_fit_button() 
    7372        self.fill_data_combobox(data_list=self.data_list) 
    74         #create a default data for an empty panel 
     73        # create a default data for an empty panel 
    7574        self.create_default_data() 
    7675        self._manager.frame.Bind(wx.EVT_SET_FOCUS, self.on_set_focus) 
     
    105104        self.data_box_description.SetForegroundColour(dname_color) 
    106105        boxsizer1 = wx.StaticBoxSizer(self.data_box_description, wx.VERTICAL) 
    107         #---------------------------------------------------------- 
     106        # ---------------------------------------------------------- 
    108107        sizer_data = wx.BoxSizer(wx.HORIZONTAL) 
    109108        self.dataSource = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     
    134133        self.enable_datasource() 
    135134        if len(data_list) > 0: 
    136             #find the maximum range covering all data 
     135            # find the maximum range covering all data 
    137136            qmin, qmax, npts = self.compute_data_set_range(data_list) 
    138137            self.qmin_data_set = qmin 
     
    185184 
    186185        :return: True or False 
    187  
    188186        """ 
    189187        if self.data.__class__.__name__ == "Data2D" or \ 
     
    199197        buttons, xi^2, number of points etc. 
    200198        """ 
    201         is_2Ddata = False 
     199        is_2d_data = False 
    202200 
    203201        # Check if data is 2D 
    204202        if self.data.__class__.__name__ == "Data2D" or \ 
    205203                        self.enable2D: 
    206             is_2Ddata = True 
     204            is_2d_data = True 
    207205 
    208206        title = "Fitting" 
    209         #smear messages & titles 
     207        # smear messages & titles 
    210208        smear_message_none = "No smearing is selected..." 
    211209        smear_message_dqdata = "The dQ data is being used for smearing..." 
     
    225223        self._get_smear_info() 
    226224 
    227         #Sizers 
     225        # Sizers 
    228226        box_description_range = wx.StaticBox(self, wx.ID_ANY, str(title)) 
    229227        box_description_range.SetForegroundColour(wx.BLUE) 
     
    244242        sizer_weighting = wx.BoxSizer(wx.HORIZONTAL) 
    245243        weighting_box.SetMinSize((_DATA_BOX_WIDTH, 40)) 
    246         #Filling the sizer containing weighting info. 
     244        # Filling the sizer containing weighting info. 
    247245        self.dI_noweight = wx.RadioButton(self, wx.ID_ANY, 
    248246                                          'No Weighting', style=wx.RB_GROUP) 
     
    286284                        self._on_select_accuracy) 
    287285 
    288         #Fit button 
     286        # Fit button 
    289287        self.btFit = wx.Button(self, self._ids.next(), 'Fit') 
    290288        self.default_bt_colour = self.btFit.GetDefaultAttributes() 
     
    292290        self.btFit.SetToolTipString("Start fitting.") 
    293291 
    294         #General Help button 
     292        # General Help button 
    295293        self.btFitHelp = wx.Button(self, wx.ID_ANY, 'Help') 
    296294        self.btFitHelp.SetToolTipString("General fitting help.") 
    297295        self.btFitHelp.Bind(wx.EVT_BUTTON, self._onFitHelp) 
    298296         
    299         #Resolution Smearing Help button (for now use same technique as 
    300         #used for dI help to get tiniest possible button that works 
    301         #both on MAC and PC.  Should completely rewrite the fitting sizer  
    302         #in future.  This is minimum to get out release 3.1 
     297        # 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 
    303301        #        comment June 14, 2015     --- PDB 
    304302        if sys.platform.count("win32") > 0: 
    305             size_q = (20, 15)  #on PC 
     303            size_q = (20, 15)  # on PC 
    306304        else: 
    307             size_q = (30, 20)  #on MAC 
     305            size_q = (30, 20)  # on MAC 
    308306        self.btSmearHelp = wx.Button(self, wx.ID_ANY, '?', 
    309307                                     style=wx.BU_EXACTFIT, size=size_q) 
     
    311309        self.btSmearHelp.Bind(wx.EVT_BUTTON, self._onSmearHelp) 
    312310         
    313         #textcntrl for custom resolution 
     311        # textcntrl for custom resolution 
    314312        self.smear_pinhole_max = ModelTextCtrl(self, wx.ID_ANY, 
    315313                            size=(_BOX_WIDTH - 25, 20), 
     
    329327                            text_enter_callback=self.onSlitSmear) 
    330328 
    331         ## smear 
     329        # smear 
    332330        self.smear_data_left = BGTextCtrl(self, wx.ID_ANY, 
    333331                                          size=(_BOX_WIDTH - 25, 20), style=0) 
     
    337335        self.smear_data_right.SetValue(str(self.dq_r)) 
    338336 
    339         #set default values for smear 
     337        # set default values for smear 
    340338        self.smear_pinhole_max.SetValue(str(self.dx_max)) 
    341339        self.smear_pinhole_min.SetValue(str(self.dx_min)) 
     
    343341        self.smear_slit_width.SetValue(str(self.dxw)) 
    344342 
    345         #Filling the sizer containing instruments smearing info. 
     343        # Filling the sizer containing instruments smearing info. 
    346344        self.disable_smearer = wx.RadioButton(self, wx.ID_ANY, 
    347345                                              'None', style=wx.RB_GROUP) 
    348346        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.") 
    351349        self.pinhole_smearer = wx.RadioButton(self, wx.ID_ANY, 
    352350                                              'Custom Pinhole Smear') 
    353         #self.pinhole_smearer.SetToolTipString 
    354         #("Click to input custom resolution for pinhole smearing.") 
     351        # self.pinhole_smearer.SetToolTipString 
     352        # ("Click to input custom resolution for pinhole smearing.") 
    355353        self.slit_smearer = wx.RadioButton(self, wx.ID_ANY, 'Custom Slit Smear') 
    356         #self.slit_smearer.SetToolTipString 
    357         #("Click to input custom resolution for slit smearing.") 
     354        # self.slit_smearer.SetToolTipString 
     355        # ("Click to input custom resolution for slit smearing.") 
    358356        self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, 
    359357                  id=self.disable_smearer.GetId()) 
     
    378376        self.Npts_fit = BGTextCtrl(self, wx.ID_ANY, "-", size=(75, 20), style=0) 
    379377        self.Npts_fit.SetToolTipString( 
    380                             " Npts : number of points selected for fitting") 
     378            " Npts : number of points selected for fitting") 
    381379        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) 
    384382        self.Npts_total.SetValue(format_number(self.npts_x)) 
    385         self.Npts_total.SetToolTipString(\ 
    386                                 " Total Npts : total number of data points") 
     383        self.Npts_total.SetToolTipString( 
     384            " Total Npts : total number of data points") 
    387385 
    388386        # Update and Draw button 
     
    429427        self.smear_description_2d_y = wx.StaticText(self, wx.ID_ANY, 
    430428                            smear_message_2d_y_title, style=wx.ALIGN_LEFT) 
    431         self.smear_description_2d_y.SetToolTipString(\ 
     429        self.smear_description_2d_y.SetToolTipString( 
    432430                                    " dQs(perpendicular) in q_phi direction.") 
    433431        self.smear_description_pin_min = wx.StaticText(self, wx.ID_ANY, 
     
    440438                        smear_message_slit_width_title, style=wx.ALIGN_LEFT) 
    441439 
    442         #arrange sizers 
     440        # arrange sizers 
    443441        self.sizer_set_smearer.Add(sizer_smearer) 
    444442        self.sizer_set_smearer.Add((10, 10)) 
    445443        self.sizer_set_smearer.Add(self.smear_description_none, 
    446                                     0, wx.CENTER, 10) 
     444                                   0, wx.CENTER, 10) 
    447445        self.sizer_set_smearer.Add(self.smear_description_dqdata, 
    448                                     0, wx.CENTER, 10) 
     446                                   0, wx.CENTER, 10) 
    449447        self.sizer_set_smearer.Add(self.smear_description_2d, 
    450                                     0, wx.CENTER, 10) 
     448                                   0, wx.CENTER, 10) 
    451449        self.sizer_new_smear.Add(self.smear_description_type, 
    452                                   0, wx.CENTER, 10) 
     450                                 0, wx.CENTER, 10) 
    453451        self.sizer_new_smear.Add(self.smear_description_accuracy_type, 
    454                                   0, wx.CENTER, 10) 
     452                                 0, wx.CENTER, 10) 
    455453        self.sizer_new_smear.Add(self.smear_accuracy) 
    456454        self.sizer_new_smear.Add(self.smear_description_smear_type, 
    457                                   0, wx.CENTER, 10) 
     455                                 0, wx.CENTER, 10) 
    458456        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) 
    461458        self.sizer_new_smear.Add(self.smear_description_pin_min, 
    462                                   0, wx.CENTER, 10) 
     459                                 0, wx.CENTER, 10) 
    463460        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) 
    472466        self.sizer_new_smear.Add((20, -1)) 
    473467        self.sizer_new_smear.Add(self.smear_description_2d_y, 
    474                                   0, wx.CENTER, 10) 
     468                                 0, wx.CENTER, 10) 
    475469        self.sizer_new_smear.Add(self.smear_description_pin_max, 
    476                                   0, wx.CENTER, 10) 
     470                                 0, wx.CENTER, 10) 
    477471        self.sizer_new_smear.Add(self.smear_description_slit_width, 
    478                                   0, wx.CENTER, 10) 
     472                                 0, wx.CENTER, 10) 
    479473 
    480474        self.sizer_new_smear.Add(self.smear_pinhole_max, 0, wx.CENTER, 10) 
     
    501495 
    502496        # Show only the relevant smear messages, etc 
    503         if self.current_smearer == None: 
    504             if not is_2Ddata: 
     497        if self.current_smearer is None: 
     498            if not is_2d_data: 
    505499                self.smear_description_none.Show(True) 
    506500                self.enable_smearer.Disable() 
     
    508502                self.smear_description_none.Show(True) 
    509503                self.slit_smearer.Disable() 
    510             if self.data == None: 
     504            if self.data is None: 
    511505                self.slit_smearer.Disable() 
    512506                self.pinhole_smearer.Disable() 
     
    515509            self._show_smear_sizer() 
    516510        boxsizer_range.Add(self.sizer_set_masking) 
    517         #2D data? default 
    518         is_2Ddata = False 
    519  
    520         #check if it is 2D data 
     511        # 2D data? default 
     512        is_2d_data = False 
     513 
     514        # check if it is 2D data 
    521515        if self.data.__class__.__name__ == "Data2D" or self.enable2D: 
    522             is_2Ddata = True 
     516            is_2d_data = True 
    523517 
    524518        self.sizer5.Clear(True) 
     
    568562        sizer.Add(wx.StaticText(self, wx.ID_ANY, ' Max[1/A]')) 
    569563        sizer.Add(self.EditMask_title) 
    570         sizer.Add((-1,5)) 
     564        sizer.Add((-1, 5)) 
    571565 
    572566        sizer.Add(self.reset_qrange) 
     
    574568        sizer.Add(self.qmax) 
    575569        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)]) 
    579573 
    580574        sizer.Add(box_description_1, 0, 0) 
     
    582576        sizer.Add(self.points_sizer, 0, 0) 
    583577        sizer.Add(self.draw_button, 0, 0) 
    584         sizer.Add((-1,5)) 
     578        sizer.Add((-1, 5)) 
    585579         
    586580        sizer.Add(self.tcChi, 0, 0) 
     
    592586        boxsizer_range.Add(sizer_chi2) 
    593587        boxsizer_range.Add(sizer) 
    594         if is_2Ddata: 
     588        if is_2d_data: 
    595589            self.btEditMask.Enable() 
    596590            self.EditMask_title.Enable() 
     
    598592            self.btEditMask.Disable() 
    599593            self.EditMask_title.Disable() 
    600         ## save state 
     594        # save state 
    601595        self.save_current_state() 
    602596        self.sizer5.Add(boxsizer_range, 0, wx.EXPAND | wx.ALL, 10) 
    603597        self.sizer5.Layout() 
    604598 
    605  
    606599    def _set_sizer_dispersion(self): 
    607600        """ 
     
    613606 
    614607        self.sizer4_4.Clear(True) 
    615         if self.model == None: 
    616             ##no model is selected 
     608        if self.model is None: 
     609            # no model is selected 
    617610            return 
    618611        if not self.enable_disp.GetValue(): 
    619             ## the user didn't select dispersity display 
     612            # the user didn't select dispersity display 
    620613            return 
    621614 
    622615        self._reset_dispersity() 
    623616 
    624         ## fill a sizer with the combobox to select dispersion type 
     617        # fill a sizer with the combobox to select dispersion type 
    625618        model_disp = wx.StaticText(self, wx.ID_ANY, 'Function') 
    626619        CHECK_STATE = False 
     
    645638            err_text = '' 
    646639        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), 
    648641                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    649642 
    650643        ix += 1 
    651644        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), 
    653646                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    654647 
     
    683676                if item in self.model.magnetic_params: 
    684677                    continue 
    685             if not item in self.model.orientation_params: 
    686                 if not item in self.disp_cb_dict: 
     678            if item not in self.model.orientation_params: 
     679                if item not in self.disp_cb_dict: 
    687680                    self.disp_cb_dict[item] = None 
    688681                name0 = "Distribution of " + item 
     
    690683                name2 = item + ".npts" 
    691684                name3 = item + ".nsigmas" 
    692                 if not name1 in self.model.details: 
     685                if name1 not in self.model.details: 
    693686                    self.model.details[name1] = ["", None, None] 
    694687 
     
    716709                        ctl1.SetValue(str(format_number(value, True))) 
    717710                        self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 
    718                         ## text to show error sign 
     711                        # text to show error sign 
    719712                        ix = 2 
    720713                        text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 
     
    776769                        Tct2.SetValue(str(format_number(value))) 
    777770                        self.sizer4_4.Add(Tct2, (iy, ix), (1, 1), 
    778                                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     771                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    779772                        self.fixed_param.append([None, name3, Tct2, 
    780773                                                 None, None, None, 
     
    802795                if item in self.model.magnetic_params: 
    803796                    continue 
    804             if  item in self.model.orientation_params: 
    805                 if not item in self.disp_cb_dict: 
     797            if item in self.model.orientation_params: 
     798                if item not in self.disp_cb_dict: 
    806799                    self.disp_cb_dict[item] = None 
    807800                name0 = "Distribution of " + item 
     
    810803                name3 = item + ".nsigmas" 
    811804 
    812                 if not name1 in self.model.details: 
     805                if name1 not in self.model.details: 
    813806                    self.model.details[name1] = ["", None, None] 
    814807 
     
    855848 
    856849                        self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 
    857                         ## text to show error sign 
     850                        # text to show error sign 
    858851                        ix = 2 
    859852                        text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 
     
    968961 
    969962        self.state.model = self.model.clone() 
    970         ## save state into 
     963        # save state into 
    971964        self._copy_parameters_state(self.parameters, self.state.parameters) 
    972965        self._copy_parameters_state(self.orientation_params_disp, 
     
    978971        wx.PostEvent(self.parent, 
    979972                     StatusEvent(status=" Selected Distribution: Gaussian")) 
    980         #Fill the list of fittable parameters 
     973        # Fill the list of fittable parameters 
    981974        self.get_all_checked_params() 
    982975        self.Layout() 
     
    986979        Update and Draw the model 
    987980        """ 
    988         if self.model == None: 
     981        if self.model is None: 
    989982            msg = "Please select a Model first..." 
    990983            wx.MessageBox(msg, 'Info') 
     
    996989            self.create_default_data() 
    997990        """ 
    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) 
    1001994        if not flag: 
    1002995            msg = "The parameters are invalid" 
     
    10081001        Allow to fit 
    10091002        """ 
    1010         if event != None: 
     1003        if event is not None: 
    10111004            event.Skip() 
    10121005        if self.fit_started: 
     
    10481041            return 
    10491042 
    1050         self.select_param(event=None) 
     1043        self.select_param() 
    10511044 
    10521045        # Remove or do not allow fitting on the Q=0 point, especially 
     
    10591052                                    qmax=self.qmax_x) 
    10601053 
    1061         #single fit 
    1062         #self._manager.onFit(uid=self.uid) 
     1054        # single fit 
     1055        # self._manager.onFit(uid=self.uid) 
    10631056        self.fit_started = self._manager.onFit(uid=self.uid) 
    10641057        wx.CallAfter(self.set_fitbutton) 
     
    10731066        versions of Wx (before 2.9) and thus not the release version of 
    10741067        installers, the help comes up at the top level of the file as 
    1075         webbrowser does not pass anything past the # to the browser when it is 
     1068        web browser does not pass anything past the # to the browser when it is 
    10761069        running "file:///...." 
    10771070 
    1078     :param evt: Triggers on clicking the help button 
    1079     """ 
     1071        :param evt: Triggers on clicking the help button 
     1072        """ 
    10801073 
    10811074        _TreeLocation = "user/sasgui/perspectives/fitting/fitting_help.html" 
     
    10921085        versions of Wx (before 2.9) and thus not the release version of 
    10931086        installers, the help comes up at the top level of the file as 
    1094         webbrowser does not pass anything past the # to the browser when it is 
     1087        web browser does not pass anything past the # to the browser when it is 
    10951088        running "file:///...." 
    10961089 
    1097     :param evt: Triggers on clicking the help button 
    1098     """ 
     1090        :param evt: Triggers on clicking the help button 
     1091        """ 
    10991092 
    11001093        _TreeLocation = "user/sasgui/perspectives/fitting/sm_help.html" 
     
    11081101        """ 
    11091102        # 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". 
    11111104        if self.is_mac: 
    11121105            return 
     
    11181111            label = "Fit" 
    11191112            color = "black" 
    1120         #self.btFit.Enable(False) 
     1113        # self.btFit.Enable(False) 
    11211114        self.btFit.SetLabel(label) 
    11221115        self.btFit.SetForegroundColour(color) 
     
    11491142        Stop fit 
    11501143        """ 
    1151         if event != None: 
     1144        if event is not None: 
    11521145            event.Skip() 
    11531146        self._manager.stop_fit(self.uid) 
     
    11691162        copy_flag = False 
    11701163        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 
    11731166                        and self.structurebox.GetLabel() != 'None')\ 
    11741167                        or event.GetEventObject() == self.structurebox\ 
     
    11831176            self._keep.Enable(False) 
    11841177            self._set_save_flag(False) 
    1185         # TODO: why do we have to variables for one flag?? 
    11861178        self.enable_disp.SetValue(False) 
    11871179        self.disable_disp.SetValue(True) 
     
    12131205                    self._keep.Enable(not self.batch_on) 
    12141206                    self._set_save_flag(True) 
     1207                    self._set_smear(self.data) 
    12151208 
    12161209            # more disables for 2D 
     
    12261219            except: 
    12271220                raise 
    1228                 ## error occured on chisqr computation 
    1229                 #pass 
    1230             ## event to post model to fit to fitting plugins 
     1221                # error occured on chisqr computation 
     1222                # pass 
     1223            # event to post model to fit to fitting plugins 
    12311224            (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 
    12321225 
    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 
    12351227            evt = ModelEventbox(model=self.model, 
    12361228                            smearer=temp_smear, 
     
    12421234 
    12431235            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)) 
    12451238            self.mbox_description.SetForegroundColour(wx.BLUE) 
    12461239            self.state.model = self.model.clone() 
    12471240            self.state.model.name = self.model.name 
    12481241 
    1249         if event != None: 
    1250             ## post state to fit panel 
     1242        if event is not None: 
     1243            # post state to fit panel 
    12511244            new_event = PageInfoEvent(page=self) 
    12521245            wx.PostEvent(self.parent, new_event) 
    1253             #update list of plugins if new plugin is available 
     1246            # update list of plugins if new plugin is available 
    12541247            custom_model = 'Customized Models' 
    12551248            mod_cat = self.categorybox.GetStringSelection() 
     
    12641257                    self.formfactorbox.SetValue(current_val) 
    12651258            # when select a model only from guictr/button 
    1266             if is_poly_enabled != None: 
     1259            if is_poly_enabled is not None: 
    12671260                self.enable_disp.SetValue(is_poly_enabled) 
    12681261                self.disable_disp.SetValue(not is_poly_enabled) 
     
    12921285        when enter value on panel redraw model according to changed 
    12931286        """ 
    1294         if self.model == None: 
     1287        if self.model is None: 
    12951288            msg = "Please select a Model first..." 
    12961289            wx.MessageBox(msg, 'Info') 
    12971290            return 
    12981291 
    1299         #default flag 
     1292        # default flag 
    13001293        flag = False 
    13011294        self.fitrange = True 
    1302         #get event object 
     1295        # get event object 
    13031296        tcrtl = event.GetEventObject() 
    1304         #Clear msg if previously shown. 
     1297        # Clear msg if previously shown. 
    13051298        msg = "" 
    13061299        wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
     
    13131306                if not self.disable_smearer.GetValue(): 
    13141307                    temp_smearer = self.current_smearer 
    1315                     ## set smearing value whether or not 
    1316                     #        the data contain the smearing info 
     1308                    # set smearing value whether or not data contain the 
     1309                    # smearing info 
    13171310                    if self.slit_smearer.GetValue(): 
    13181311                        flag1 = self.update_slit_smear() 
     
    13311324                                              enable_smearer=enable_smearer) 
    13321325                if flag: 
    1333                     #self.compute_chisqr(smearer= temp_smearer) 
    1334  
    1335                     ## new state posted 
     1326                    # self.compute_chisqr(smearer= temp_smearer) 
     1327 
     1328                    # new state posted 
    13361329                    if self.state_change: 
    1337                         #self._undo.Enable(True) 
     1330                        # self._undo.Enable(True) 
    13381331                        event = PageInfoEvent(page=self) 
    13391332                        wx.PostEvent(self.parent, event) 
     
    13451338        else: 
    13461339            self.save_current_state() 
    1347             msg = "Cannot Plot :Must enter a number!!!  " 
     1340            msg = "Cannot Plot: Must enter a number!!!  " 
    13481341            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    13491342 
     
    13561349        """ 
    13571350        tcrtl = event.GetEventObject() 
    1358         #Clear msg if previously shown. 
     1351        # Clear msg if previously shown. 
    13591352        msg = "" 
    13601353        wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
     
    13741367            tcrtl.SetBackgroundColour(wx.WHITE) 
    13751368 
    1376         #self._undo.Enable(True) 
     1369        # self._undo.Enable(True) 
    13771370        self.save_current_state() 
    13781371        event = PageInfoEvent(page=self) 
     
    13841377        ON Qrange focus 
    13851378        """ 
    1386         if event != None: 
     1379        if event is not None: 
    13871380            event.Skip() 
    1388         #tcrtl = event.GetEventObject() 
     1381        # tcrtl = event.GetEventObject() 
    13891382        self._validate_qrange(self.qmin, self.qmax) 
    13901383 
     
    13931386        On Qrange textctrl click, make the qrange lines in the plot 
    13941387        """ 
    1395         if event != None: 
     1388        if event is not None: 
    13961389            event.Skip() 
    13971390        if self.data.__class__.__name__ == "Data2D": 
     
    14111404        #On q range value updated. DO not combine with qrange_click(). 
    14121405        """ 
    1413         if event != None: 
     1406        if event is not None: 
    14141407            event.Skip() 
    14151408        if self.data.__class__.__name__ == "Data2D": 
     
    14391432        length = len(self.data.x) 
    14401433        indx = (numpy.abs(self.data.x - x_data)).argmin() 
    1441         #return array.flat[idx] 
     1434        # return array.flat[idx] 
    14421435        if key == wx.WXK_PAGEUP or key == wx.WXK_NUMPAD_PAGEUP: 
    14431436            indx += 1 
     
    14581451        """ 
    14591452        tcrtl = event.GetEventObject() 
    1460         #Clear msg if previously shown. 
     1453        # Clear msg if previously shown. 
    14611454        msg = "" 
    14621455        wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
     
    14881481                wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    14891482                return 
    1490             #Check if # of points for theory model are valid(>0). 
     1483            # Check if # of points for theory model are valid(>0). 
    14911484            # check for 2d 
    14921485            if self.data.__class__.__name__ == "Data2D" or \ 
     
    14951488                radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + 
    14961489                                    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)) 
    14991491                index_data = (index_data) & (self.data.mask) 
    15001492                index_data = (index_data) & (numpy.isfinite(self.data.data)) 
     
    15061498                    return 
    15071499                else: 
    1508                     #self.data.mask = index_data 
    1509                     #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))) 
    15101502                    self.show_npts2fit() 
    15111503            else: 
    1512                 index_data = ((self.qmin_x <= self.data.x) & \ 
     1504                index_data = ((self.qmin_x <= self.data.x) & 
    15131505                              (self.data.x <= self.qmax_x)) 
    15141506                self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) 
     
    15431535            for item in self.parameters: 
    15441536                if item[0].IsShown(): 
    1545                     #Skip the angle parameters if 1D data 
     1537                    # Skip the angle parameters if 1D data 
    15461538                    if self.data.__class__.__name__ != "Data2D" and \ 
    15471539                            not self.enable2D: 
     
    15501542                    if item in self.param_toFit: 
    15511543                        continue 
    1552                     ## hide statictext +/- 
     1544                    # hide statictext +/- 
    15531545                    if len(item) < 4: 
    15541546                        continue 
    1555                     if item[3] != None and item[3].IsShown(): 
     1547                    if item[3] is not None and item[3].IsShown(): 
    15561548                        item[3].Hide() 
    1557                     ## hide textcrtl  for error after fit 
    1558                     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(): 
    15591551                        item[4].Hide() 
    15601552 
     
    15621554            for item in self.fittable_param: 
    15631555                if item[0].IsShown(): 
    1564                     #Skip the angle parameters if 1D data 
     1556                    # Skip the angle parameters if 1D data 
    15651557                    if self.data.__class__.__name__ != "Data2D" and \ 
    15661558                            not self.enable2D: 
     
    15711563                    if len(item) < 4: 
    15721564                        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(): 
    15751567                        item[3].Hide() 
    1576                     ## hide textcrtl  for error after fit 
    1577                     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(): 
    15781570                        item[4].Hide() 
    15791571        return 
     
    15841576        """ 
    15851577        # get the default values 
    1586         if self.dxl == None: 
     1578        if self.dxl is None: 
    15871579            self.dxl = 0.0 
    1588         if self.dxw == None: 
     1580        if self.dxw is None: 
    15891581            self.dxw = "" 
    1590         if self.dx_min == None: 
     1582        if self.dx_min is None: 
    15911583            self.dx_min = SMEAR_SIZE_L 
    1592         if self.dx_max == None: 
     1584        if self.dx_max is None: 
    15931585            self.dx_max = SMEAR_SIZE_H 
    15941586 
     
    16111603        elif self.data.__class__.__name__ == "Data2D" or \ 
    16121604            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: 
    16141606                return 
    1615             elif self.current_smearer != None \ 
     1607            elif self.current_smearer is not None \ 
    16161608                and data.dqx_data.any() != 0 \ 
    16171609                and data.dqx_data.any() != 0: 
     
    16231615                return 
    16241616        # 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): 
    16261618            self.smear_type = "Pinhole" 
    16271619            self.dq_l = data.dx[0] 
     
    16291621 
    16301622        # 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: 
    16321624            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): 
    16341626                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): 
    16361628                self.dq_r = data.dxw[0] 
    1637         #return self.smear_type,self.dq_l,self.dq_r 
     1629        # return self.smear_type,self.dq_l,self.dq_r 
    16381630 
    16391631    def _show_smear_sizer(self): 
     
    16591651 
    16601652            self.smear_description_dqdata.Show(True) 
    1661             if self.smear_type != None: 
     1653            if self.smear_type is not None: 
    16621654                self.smear_description_smear_type.Show(True) 
    16631655                if self.smear_type == 'Slit': 
     
    17501742        Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low 
    17511743        """ 
    1752         #event.Skip() 
     1744        # event.Skip() 
    17531745        # Check if the accuracy is same as before 
    1754         #self.smear2d_accuracy = event.GetEventObject().GetValue() 
     1746        # self.smear2d_accuracy = event.GetEventObject().GetValue() 
    17551747        self.smear2d_accuracy = self.smear_accuracy.GetValue() 
    17561748        if self.pinhole_smearer.GetValue(): 
     
    17581750        else: 
    17591751            self.onSmear(event=None) 
    1760             if self.current_smearer != None: 
     1752            if self.current_smearer is not None: 
    17611753                self.current_smearer.set_accuracy(accuracy=\ 
    17621754                                                  self.smear2d_accuracy) 
     
    17901782        Build a panel to allow to edit Mask 
    17911783        """ 
    1792         from sas.sasgui.guiframe.local_perspectives.plotting.masking \ 
    1793         import MaskPanel as MaskDialog 
     1784        from sas.sasgui.guiframe.local_perspectives.plotting.masking import \ 
     1785            MaskPanel as MaskDialog 
    17941786 
    17951787        self.panel = MaskDialog(base=self, data=self.data, id=wx.NewId()) 
     
    18021794        is_valid_qrange = self._update_paramv_on_fit() 
    18031795 
    1804         if is_valid_qrange and self.model != None: 
     1796        if is_valid_qrange and self.model is not None: 
    18051797            self.panel.MakeModal(False) 
    18061798            event.Skip() 
     
    18081800            self._draw_model() 
    18091801            self.show_npts2fit() 
    1810         elif self.model == None: 
     1802        elif self.model is None: 
    18111803            self.panel.MakeModal(False) 
    18121804            event.Skip() 
     
    18751867                    npts = len(data.x) 
    18761868                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" %\ 
    18781870                                data.filename 
    18791871                    wx.PostEvent(self._manager.parent, StatusEvent(status=msg, 
     
    18921884                                               info="error")) 
    18931885                    raise ValueError, msg 
    1894                 ## Maximum value of data 
     1886                # Maximum value of data 
    18951887                qmax = math.sqrt(x * x + y * y) 
    18961888                npts = len(data.data) 
     
    19041896        flag = False 
    19051897        is_data = False 
     1898        npts = 0 
    19061899        try: 
    19071900            old_id = self.data.id 
     
    19151908                flag = True 
    19161909        if data is not None: 
    1917             id = data.id 
    19181910            if is_data: 
    19191911                self.graph_id = self.data.group_id 
     
    19301922            self._set_save_flag(False) 
    19311923        else: 
    1932             if self.model != None: 
     1924            if self.model is not None: 
    19331925                self._set_bookmark_flag(not self.batch_on) 
    19341926                self._keep.Enable(not self.batch_on) 
     
    19371929                self._set_preview_flag(True) 
    19381930 
    1939             self._set_smear(data) 
    19401931            # more disables for 2D 
    19411932            if self.data.__class__.__name__ == "Data2D" or \ 
     
    19441935                self.pinhole_smearer.Enable(True) 
    19451936                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): 
    19491940                    self.dI_didata.Enable(False) 
    19501941                    self.dI_noweight.SetValue(True) 
     
    19571948                self.slit_smearer.Enable(True) 
    19581949                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): 
    19621954                    self.dI_didata.Enable(False) 
    19631955                    self.dI_noweight.SetValue(True) 
     
    19671959                    self.dI_didata.SetValue(True) 
    19681960                    self.weightbt_string = self.dI_didata.GetLabelText() 
    1969             # Enable weighting radio uttons 
     1961            # Enable weighting radio buttons 
    19701962            self.dI_noweight.Enable(True) 
    19711963            self.dI_sqrdata.Enable(True) 
     
    19761968            data_name = self.data.name 
    19771969            _, _, npts = self.compute_data_range(self.data) 
    1978             #set maximum range for x in linear scale 
     1970            # set maximum range for x in linear scale 
    19791971            if not hasattr(self.data, "data"):  # Display only for 1D data fit 
    19801972                self.btEditMask.Disable() 
     
    19851977 
    19861978        self.Npts_total.SetValue(str(npts)) 
    1987         #default:number of data points selected to fit 
     1979        # default:number of data points selected to fit 
    19881980        self.Npts_fit.SetValue(str(npts)) 
    19891981        self.Npts_total.SetEditable(False) 
    1990         self.Npts_total.SetBackgroundColour(\ 
     1982        self.Npts_total.SetBackgroundColour( 
    19911983                                    self.GetParent().GetBackgroundColour()) 
    19921984 
     
    19981990        # send graph_id to page_finder 
    19991991        self._manager.set_graph_id(uid=self.uid, graph_id=self.graph_id) 
    2000         #focus the page 
     1992        # focus the page 
    20011993        if check_data_validity(data): 
    20021994            self.data_box_description.SetForegroundColour(wx.BLUE) 
     
    20102002        self.on_set_focus(None) 
    20112003        self.Refresh() 
    2012         #update model plot with new data information 
     2004        # update model plot with new data information 
    20132005        if flag: 
    2014             #set model view button 
    2015             self.onSmear(None) 
    2016  
    20172006            if self.data.__class__.__name__ == "Data2D": 
    20182007                self.enable2D = True 
     
    20222011                self.model_view.SetLabel("1D Mode") 
    20232012            self.model_view.Disable() 
    2024             #replace data plot on combo box selection 
    2025             #by removing the previous selected data 
     2013            #  replace data plot on combo box selection 
     2014            # by removing the previous selected data 
    20262015            try: 
    20272016                wx.PostEvent(self._manager.parent, 
     
    20302019            except: 
    20312020                pass 
    2032             #plot the current selected data 
     2021            # plot the current selected data 
    20332022            wx.PostEvent(self._manager.parent, 
    20342023                         NewPlotEvent(action="check", plot=self.data, 
     
    20502039            self.reset_page_helper(state) 
    20512040 
    2052             self.select_param(event=None) 
    2053             #Save state_fit 
     2041            self.select_param() 
     2042            # Save state_fit 
    20542043            self.save_current_state_fit() 
    20552044        except: 
     
    20902079        else: 
    20912080            for qx in self.data.x: 
    2092                 if qx >= qmin and qx <= qmax: 
     2081                if qmax >= qx >= qmin: 
    20932082                    npts2fit += 1 
    20942083        return npts2fit 
     
    21192108        # make sure stop button to fit button all the time 
    21202109        self._on_fit_complete() 
    2121         if out == None or not numpy.isfinite(chisqr): 
     2110        if out is None or not numpy.isfinite(chisqr): 
    21222111            raise ValueError, "Fit error occured..." 
    21232112 
     
    21262115        dispersity = '' 
    21272116 
    2128         #Hide textctrl boxes of errors. 
     2117        # Hide textctrl boxes of errors. 
    21292118        self._clear_Err_on_Fit() 
    21302119 
    2131         #Check if chi2 is finite 
    2132         if chisqr != None and numpy.isfinite(chisqr): 
    2133             #format chi2 
     2120        # Check if chi2 is finite 
     2121        if chisqr is not None and numpy.isfinite(chisqr): 
     2122            # format chi2 
    21342123            chi2 = format_number(chisqr, True) 
    21352124            self.tcChi.SetValue(chi2) 
     
    21382127            self.tcChi.SetValue("-") 
    21392128 
    2140         #Hide error title 
     2129        # Hide error title 
    21412130        if self.text2_3.IsShown() and not self.is_mac: 
    21422131            self.text2_3.Hide() 
     
    21452134            if self.enable_disp.GetValue(): 
    21462135                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: 
    21482137                        self.text_disp_1.Hide() 
    21492138        except: 
     
    21522141 
    21532142        i = 0 
    2154         #Set the panel when fit result are list 
     2143        # Set the panel when fit result are list 
    21552144 
    21562145        for item in self.param_toFit: 
    2157             if len(item) > 5 and item != None: 
     2146            if len(item) > 5 and item is not None: 
    21582147 
    21592148                if item[0].IsShown(): 
    2160                     ## reset error value to initial state 
     2149                    # reset error value to initial state 
    21612150                    if not self.is_mac: 
    21622151                        item[3].Hide() 
     
    21652154                        if item[1] == p_name[ind]: 
    21662155                            break 
    2167                     if len(out) > 0 and out[ind] != None: 
     2156                    if len(out) > 0 and out[ind] is not None: 
    21682157                        val_out = format_number(out[ind], True) 
    21692158                        item[2].SetValue(val_out) 
    21702159 
    2171                     if(cov != None and len(cov) == len(out)): 
     2160                    if(cov is not None and len(cov) == len(out)): 
    21722161                        try: 
    2173                             if dispersity != None: 
     2162                            if dispersity is not None: 
    21742163                                if self.enable_disp.GetValue(): 
    21752164                                    if hasattr(self, "text_disp_1"): 
    2176                                         if self.text_disp_1 != None: 
     2165                                        if self.text_disp_1 is not None: 
    21772166                                            if not self.text_disp_1.IsShown()\ 
    2178                                                 and not self.is_mac: 
     2167                                                  and not self.is_mac: 
    21792168                                                self.text_disp_1.Show(True) 
    21802169                        except: 
    21812170                            pass 
    21822171 
    2183                         if cov[ind] != None: 
     2172                        if cov[ind] is not None: 
    21842173                            if numpy.isfinite(float(cov[ind])): 
    21852174                                val_err = format_number(cov[ind], True) 
    2186                                 item[4].SetForegroundColour(wx.BLACK) 
     2175                                item[4].SetForegroundColour(wx.BLACK) 
    21872176                            else: 
    21882177                                val_err = 'NaN' 
     
    21962185            else: 
    21972186                raise ValueError, "onsetValues: Invalid parameters..." 
    2198         #Show error title when any errors displayed 
     2187        # Show error title when any errors displayed 
    21992188        if has_error: 
    22002189            if not self.text2_3.IsShown(): 
    22012190                self.text2_3.Show(True) 
    2202         ## save current state 
     2191        # save current state 
    22032192        self.save_current_state() 
    22042193 
     
    22072196            self.Refresh() 
    22082197        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) 
    22102199        self._draw_model(update_chisqr=False, source='fit') 
    22112200 
     
    22232212        # compute weight for the current data 
    22242213        flag_weight = self.get_weight_flag() 
    2225         if is_2D == None: 
     2214        if is_2D is None: 
    22262215            is_2D = self._is_2D() 
    22272216        self._manager.set_fit_weight(uid=self.uid, 
     
    22422231        self._update_paramv_on_fit() 
    22432232 
    2244         if event != None: 
     2233        if event is not None: 
    22452234            tcrtl = event.GetEventObject() 
    22462235            # event case of radio button 
    2247             if tcrtl.GetValue() == True: 
     2236            if tcrtl.GetValue(): 
    22482237                self.dx_min = 0.0 
    22492238                self.dx_max = 0.0 
     
    22632252 
    22642253        self.sizer_set_smearer.Layout() 
    2265         ## we need FitInside here not just self.Layout to ensure all the sizers 
    2266         ## end up with the necessasary space to in the scroll panel. In 
    2267         ## particular the compute and fit buttons end up on top of each other 
    2268         ## 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. 
    22692258        self.FitInside() 
    22702259 
    2271         if event != None: 
     2260        if event is not None: 
    22722261            event.Skip() 
    2273         #self._undo.Enable(True) 
     2262        # self._undo.Enable(True) 
    22742263        self.save_current_state() 
    22752264        event = PageInfoEvent(page=self) 
     
    23462335                get_pin_max.SetBackgroundColour("pink") 
    23472336                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: 
    23492338                if self._is_2D(): 
    23502339                    data.dqx_data[data.dqx_data == 0] = self.dx_min 
     
    23572346                                           self.dx_max + step / 1.1, 
    23582347                                           step) 
    2359             elif self.dx_min != None: 
     2348            elif self.dx_min is not None: 
    23602349                if self._is_2D(): 
    23612350                    data.dqx_data[data.dqx_data == 0] = self.dx_min 
    23622351                else: 
    23632352                    data.dx[data.dx == 0] = self.dx_min 
    2364             elif self.dx_max != None: 
     2353            elif self.dx_max is not None: 
    23652354                if self._is_2D(): 
    23662355                    data.dqy_data[data.dqy_data == 0] = self.dx_max 
     
    23702359            # 2D need to set accuracy 
    23712360            if self._is_2D(): 
    2372                 self.current_smearer.set_accuracy(accuracy=\ 
    2373                                                   self.smear2d_accuracy) 
    2374  
    2375         if msg != None: 
     2361                self.current_smearer.set_accuracy( 
     2362                    accuracy=self.smear2d_accuracy) 
     2363 
     2364        if msg is not None: 
    23762365            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    23772366        else: 
    23782367            get_pin_min.SetBackgroundColour("white") 
    23792368            get_pin_max.SetBackgroundColour("white") 
    2380         ## set smearing value whether or not the data contain the smearing info 
     2369        # set smearing value whether or not the data contain the smearing info 
    23812370 
    23822371        enable_smearer = not self.disable_smearer.GetValue() 
     
    24042393        wx.CallAfter(self.save_current_state) 
    24052394 
    2406         if msg != None: 
     2395        if msg is not None: 
    24072396            return False 
    24082397        else: 
     
    24202409        msg = None 
    24212410        # for event given 
    2422         if event != None: 
     2411        if event is not None: 
    24232412            tcrtl = event.GetEventObject() 
    24242413            # event case of radio button 
     
    24412430        self._show_smear_sizer() 
    24422431        self.sizer_set_smearer.Layout() 
    2443         ## we need FitInside here not just self.Layout to ensure all the sizers 
    2444         ## end up with the necessasary space to in the scroll panel. In 
    2445         ## particular the compute and fit buttons end up on top of each other 
    2446         ## 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. 
    24472436        self.FitInside() 
    24482437 
    2449         if event != None: 
     2438        if event is not None: 
    24502439            event.Skip() 
    24512440        self.save_current_state() 
    24522441        event = PageInfoEvent(page=self) 
    24532442        wx.PostEvent(self.parent, event) 
    2454         if msg != None: 
     2443        if msg is not None: 
    24552444            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    24562445 
     
    25412530 
    25422531        self.current_smearer = smear_selection(data, self.model) 
    2543         ## set smearing value whether or not the data contain the smearing info 
     2532        # set smearing value whether or not the data contain the smearing info 
    25442533        enable_smearer = not self.disable_smearer.GetValue() 
    25452534        self._manager.set_smearer(smearer=self.current_smearer, 
     
    25642553        if self._is_changed_slit(): 
    25652554            msg = self._set_slit_smear() 
    2566         #self._undo.Enable(True) 
     2555        # self._undo.Enable(True) 
    25672556        self.save_current_state() 
    25682557 
    2569         if msg != None: 
     2558        if msg is not None: 
    25702559            return False 
    25712560        else: 
     
    25772566        are computed when fitting 
    25782567        """ 
    2579         if event != None: 
     2568        if event is not None: 
    25802569            event.Skip() 
    25812570        if self.data is None: 
     
    25902579 
    25912580        self.sizer_set_smearer.Layout() 
    2592         ## we need FitInside here not just self.Layout to ensure all the sizers 
    2593         ## end up with the necessasary space to in the scroll panel. In 
    2594         ## particular the compute and fit buttons end up on top of each other 
    2595         ## 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. 
    25962585        self.FitInside() 
    25972586        self._set_weight() 
    25982587 
    2599         ## set smearing value whether or not the data contain the smearing info 
     2588        # set smearing value whether or not the data contain the smearing info 
    26002589        enable_smearer = not self.disable_smearer.GetValue() 
    26012590        wx.CallAfter(self._manager.set_smearer, uid=self.uid, 
     
    26182607        """ 
    26192608        self._get_smear_info() 
    2620         #renew smear sizer 
     2609        # renew smear sizer 
    26212610        if self.smear_type is not None: 
    26222611            self.smear_description_smear_type.SetValue(str(self.smear_type)) 
     
    26582647        """ 
    26592648        try: 
    2660             if event == None: 
     2649            if event is None: 
    26612650                output = "-" 
    26622651            elif not numpy.isfinite(event.output): 
     
    26932682        self._manager.set_param2fit(self.uid, param2fit) 
    26942683 
    2695     def select_param(self, event): 
     2684    def select_param(self, event=None): 
    26962685        """ 
    26972686        Select TextCtrl  checked for fitting purpose and stores them 
     
    27002689        self.param_toFit = [] 
    27012690        for item in self.parameters: 
    2702             #Skip t ifhe angle parameters if 1D data 
     2691            # Skip t ifhe angle parameters if 1D data 
    27032692            if self.data.__class__.__name__ != "Data2D" and\ 
    27042693                        not self.enable2D: 
    27052694                if item in self.orientation_params: 
    27062695                    continue 
    2707             #Select parameters to fit for list of primary parameters 
     2696            # Select parameters to fit for list of primary parameters 
    27082697            if item[0].GetValue() and item[0].IsShown(): 
    27092698                if not (item in self.param_toFit): 
     
    27142703                    self.param_toFit.remove(item) 
    27152704 
    2716         #Select parameters to fit for list of fittable parameters 
     2705        # Select parameters to fit for list of fittable parameters 
    27172706        #        with dispersion 
    27182707        for item in self.fittable_param: 
    2719             #Skip t ifhe angle parameters if 1D data 
     2708            # Skip t ifhe angle parameters if 1D data 
    27202709            if self.data.__class__.__name__ != "Data2D" and\ 
    27212710                        not self.enable2D: 
     
    27262715                    self.param_toFit.append(item) 
    27272716            else: 
    2728                 #remove parameters from the fitting list 
     2717                # remove parameters from the fitting list 
    27292718                if item in self.param_toFit: 
    27302719                    self.param_toFit.remove(item) 
    27312720 
    2732         #Calculate num. of angle parameters 
     2721        # Calculate num. of angle parameters 
    27332722        if self.data.__class__.__name__ == "Data2D" or \ 
    27342723                       self.enable2D: 
     
    27362725        else: 
    27372726            len_orient_para = len(self.orientation_params)  # assume even len 
    2738         #Total num. of angle parameters 
     2727        # Total num. of angle parameters 
    27392728        if len(self.fittable_param) > 0: 
    27402729            len_orient_para *= 2 
    27412730 
    27422731        self.save_current_state_fit() 
    2743         if event != None: 
    2744             ## post state to fit panel 
     2732        if event is not None: 
     2733            # post state to fit panel 
    27452734            event = PageInfoEvent(page=self) 
    27462735            wx.PostEvent(self.parent, event) 
     
    27682757        self.orientation_params_disp = [] 
    27692758 
    2770         if model == None: 
     2759        if model is None: 
    27712760            self.sizer3.Layout() 
    27722761            self.SetupScrolling() 
     
    27762765        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    27772766        sizer = wx.GridBagSizer(5, 5) 
    2778         ## save the current model 
     2767        # save the current model 
    27792768        self.model = model 
    27802769 
    27812770        keys = self.model.getParamList() 
    27822771 
    2783         #list of dispersion parameters 
     2772        # list of dispersion parameters 
    27842773        self.disp_list = self.model.getDispParamList() 
    27852774 
     
    28142803                return -1 
    28152804            # 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: 
    28172806                if num_a > num_b: 
    28182807                    return -1 
     
    28272816                    return 1 
    28282817            # one of them has a number 
    2829             elif num_a != None: 
     2818            elif num_a is not None: 
    28302819                return 1 
    2831             elif num_b != None: 
     2820            elif num_b is not None: 
    28322821                return -1 
    28332822            # no numbers 
     
    28352824                return cmp(a.lower(), b.lower()) 
    28362825         
    2837         # keys obtained now from ordered dict, so commenting alphabetical ordering 
    2838         #keys.sort(custom_compare) 
     2826        # keys obtained now from ordered dict, so commenting alphabetical 
     2827        # ordering keys.sort(custom_compare) 
    28392828 
    28402829        iy = 0 
     
    28442833        ix += 1 
    28452834        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), 
    28472836                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    28482837        ix += 2 
    28492838        self.text2_3 = wx.StaticText(self, wx.ID_ANY, 'Error') 
    2850         sizer.Add(self.text2_3, (iy, ix), (1, 1), \ 
    2851                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     2839        sizer.Add(self.text2_3, (iy, ix), (1, 1), 
     2840                  wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    28522841        if not self.is_mac: 
    28532842            self.text2_3.Hide() 
    28542843        ix += 1 
    28552844        self.text2_min = wx.StaticText(self, wx.ID_ANY, 'Min') 
    2856         sizer.Add(self.text2_min, (iy, ix), (1, 1), \ 
    2857                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    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() 
    28592848        ix += 1 
    28602849        self.text2_max = wx.StaticText(self, wx.ID_ANY, 'Max') 
    2861         sizer.Add(self.text2_max, (iy, ix), (1, 1), \ 
    2862                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    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() 
    28642853        ix += 1 
    28652854        self.text2_4 = wx.StaticText(self, wx.ID_ANY, '[Units]') 
    2866         sizer.Add(self.text2_4, (iy, ix), (1, 1), \ 
    2867                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     2855        sizer.Add(self.text2_4, (iy, ix), (1, 1), 
     2856                  wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    28682857        self.text2_4.Hide() 
    28692858 
     
    28712860        for item in keys: 
    28722861 
    2873             if not item in self.disp_list and not item in \ 
     2862            if item not in self.disp_list and not item in \ 
    28742863                    self.model.orientation_params: 
    28752864 
    2876                 ##prepare a spot to store errors 
    2877                 if not item in self.model.details: 
     2865                # prepare a spot to store errors 
     2866                if item not in self.model.details: 
    28782867                    self.model.details[item] = ["", None, None] 
    28792868 
    28802869                iy += 1 
    28812870                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 
    28842873                    self.temp_multi_functional)\ 
    28852874                    and (item in self.model.non_fittable): 
    28862875                    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), 
    28882877                            wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 21) 
    2889                     ## add parameter value 
     2878                    # add parameter value 
    28902879                    ix += 1 
    28912880                    value = self.model.getParam(item) 
    28922881                    if len(self.model.fun_list) > 0: 
    2893                         #num = item.split('_')[1][5:7] 
     2882                        # num = item.split('_')[1][5:7] 
    28942883                        fun_box = wx.ComboBox(self, wx.ID_ANY, size=(100, -1), 
    28952884                                    style=wx.CB_READONLY, name='%s' % item) 
    28962885                        self._set_fun_box_list(fun_box) 
    28972886                        fun_box.SetSelection(0) 
    2898                         #self.fun_box.SetToolTipString("A function 
     2887                        # self.fun_box.SetToolTipString("A function 
    28992888                        #    describing the interface") 
    29002889                        wx.EVT_COMBOBOX(fun_box, wx.ID_ANY, self._on_fun_box) 
     
    29032892                                                size=(_BOX_WIDTH, 20), 
    29042893                                style=wx.TE_PROCESS_ENTER, name='%s' % item) 
    2905                         fun_box.SetToolTipString(\ 
     2894                        fun_box.SetToolTipString( 
    29062895                                "Hit 'Enter' after typing to update the plot.") 
    29072896                        fun_box.SetValue(format_number(value, True)) 
     
    29112900                                                None, None]) 
    29122901                else: 
    2913                     ## add parameters name with checkbox for selecting to fit 
     2902                    # add parameters name with checkbox for selecting to fit 
    29142903                    cb = wx.CheckBox(self, wx.ID_ANY, item) 
    29152904                    cb.SetValue(CHECK_STATE) 
    29162905                    cb.SetToolTipString(" Check mark to fit.") 
    2917                     #cb.SetValue(True) 
     2906                    # cb.SetValue(True) 
    29182907                    wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 
    29192908 
     
    29212910                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 
    29222911 
    2923                     ## add parameter value 
     2912                    # add parameter value 
    29242913                    ix += 1 
    29252914                    value = self.model.getParam(item) 
    29262915                    ctl1 = ModelTextCtrl(self, wx.ID_ANY, size=(_BOX_WIDTH, 20), 
    29272916                                         style=wx.TE_PROCESS_ENTER) 
    2928                     ctl1.SetToolTipString(\ 
     2917                    ctl1.SetToolTipString( 
    29292918                                "Hit 'Enter' after typing to update the plot.") 
    29302919                    ctl1.SetValue(format_number(value, True)) 
    29312920                    sizer.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 
    2932                     ## text to show error sign 
     2921                    # text to show error sign 
    29332922                    ix += 1 
    29342923                    text2 = wx.StaticText(self, wx.ID_ANY, '+/-') 
    2935                     sizer.Add(text2, (iy, ix), (1, 1), \ 
     2924                    sizer.Add(text2, (iy, ix), (1, 1), 
    29362925                              wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    29372926                    if not self.is_mac: 
     
    29942983        iy += 1 
    29952984        ix = 0 
    2996         #Add tile for orientational angle 
     2985        # Add tile for orientational angle 
    29972986        for item in keys: 
    29982987            if item in self.model.orientation_params: 
     
    30012990                mag_on_button.SetToolTipString("Turn Pol Beam/Mag scatt on/off") 
    30022991                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?") 
    30042994                mag_angle_help_button.SetToolTipString("see angle definitions") 
    30052995                mag_help_button = wx.Button(self, wx.ID_ANY, "Mag HELP") 
    30062996                mag_help_button.SetToolTipString("Help on pol beam/mag fitting") 
    30072997                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, 
    30092999                                            self._on_mag_angle_help) 
    30103000                sizer.Add(orient_angle, (iy, ix), (1, 1), 
     
    30193009                          wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    30203010 
    3021                 #handle the magnetic buttons 
    3022                 #clean this up so that assume mag is off then turn  
    3023                 #all buttons on IF mag has mag and has 2D 
     3011                # 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 
    30243014                if not self._has_magnetic: 
    30253015                    mag_on_button.Show(False) 
     
    30473037                break 
    30483038 
    3049         #For Gaussian only 
     3039        # For Gaussian only 
    30503040        if type.lower() != "array": 
    30513041            for item in self.model.orientation_params: 
     
    30533043                    if item in self.model.magnetic_params: 
    30543044                        continue 
    3055                 if not item in self.disp_list: 
    3056                     ##prepare a spot to store min max 
    3057                     if not item in 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: 
    30583048                        self.model.details[item] = ["", None, None] 
    30593049 
    30603050                    iy += 1 
    30613051                    ix = 0 
    3062                     ## add parameters name with checkbox for selecting to fit 
     3052                    # add parameters name with checkbox for selecting to fit 
    30633053                    cb = wx.CheckBox(self, wx.ID_ANY, item) 
    30643054                    cb.SetValue(CHECK_STATE) 
     
    30733063                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 
    30743064 
    3075                     ## add parameter value 
     3065                    # add parameter value 
    30763066                    ix += 1 
    30773067                    value = self.model.getParam(item) 
    30783068                    ctl1 = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
    30793069                                         style=wx.TE_PROCESS_ENTER) 
    3080                     ctl1.SetToolTipString(\ 
     3070                    ctl1.SetToolTipString( 
    30813071                                "Hit 'Enter' after typing to update the plot.") 
    30823072                    ctl1.SetValue(format_number(value, True)) 
     
    30873077                        ctl1.Hide() 
    30883078                    sizer.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 
    3089                     ## text to show error sign 
     3079                    # text to show error sign 
    30903080                    ix += 1 
    30913081                    text2 = wx.StaticText(self, -1, '+/-') 
    3092                     sizer.Add(text2, (iy, ix), (1, 1), \ 
     3082                    sizer.Add(text2, (iy, ix), (1, 1), 
    30933083                              wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    30943084 
     
    31553145        iy += 1 
    31563146        box_description.SetForegroundColour(wx.BLUE) 
    3157         #Display units text on panel 
     3147        # Display units text on panel 
    31583148        for item in keys: 
    31593149            if item in self.model.details: 
    31603150                self.text2_4.Show() 
    3161         #Fill the list of fittable parameters 
     3151        # Fill the list of fittable parameters 
    31623152        self.get_all_checked_params() 
    31633153        self.save_current_state_fit() 
     
    31713161        Get key stroke event 
    31723162        """ 
    3173         if self.data == None: 
     3163        if self.data is None: 
    31743164            return 
    31753165        # Figuring out key combo: Cmd for copy, Alt for paste 
  • src/sas/sasgui/perspectives/fitting/fitpanel.py

    re6de6b8 rc8e1996  
    187187        """ 
    188188 
    189         # get number of pages 
    190         nop = self.GetPageCount() 
    191189        # use while-loop, for-loop will not do the job well. 
    192         while (nop > 0): 
     190        while (self.GetPageCount() > 0): 
    193191            # delete the first page until no page exists 
    194192            page = self.GetPage(0) 
     
    197195            self._close_helper(selected_page=page) 
    198196            self.DeletePage(0) 
    199             nop = self.GetPageCount() 
    200197        # Clear list of names 
    201198        self.fit_page_name = {} 
     
    240237        # close all panels only when svs file opened 
    241238        self.close_all() 
    242         self._manager.mypanels = [] 
    243239        self.sim_page = None 
    244240        self.batch_page = None 
     
    248244        close page and remove all references to the closed page 
    249245        """ 
    250         nbr_page = self.GetPageCount() 
    251246        selected_page = self.GetPage(self.GetSelection()) 
    252         if nbr_page == 1: 
     247        if self.GetPageCount() == 1: 
    253248            if selected_page.get_data() is not None: 
    254249                if event is not None: 
     
    293288        copy a dictionary of model into its own dictionary 
    294289 
    295         :param m_dict: dictionnary made of model name as key and model class 
     290        :param dict: dictionnary made of model name as key and model class 
    296291            as value 
    297292        """ 
     
    320315        if caption == "Const & Simul Fit": 
    321316            self.sim_page = SimultaneousFitPage(self, page_finder=page_finder, 
    322                                                  id= wx.ID_ANY, batch_on=False) 
     317                                                 id=wx.ID_ANY, batch_on=False) 
    323318            self.sim_page.window_caption = caption 
    324319            self.sim_page.window_name = caption 
     
    397392            raise ValueError, "Fitpanel delete_data expect list of id" 
    398393        else: 
    399             n = self.GetPageCount() 
    400394            for page in self.opened_pages.values(): 
    401395                pos = self.GetPageIndex(page) 
     
    441435        if data_1d_list and data_2d_list: 
    442436            # 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 
    444439            dlg = BatchDataDialog(self) 
    445440            if dlg.ShowModal() == wx.ID_OK: 
     
    461456                page = self.add_empty_page() 
    462457            if data_1d_list and not data_2d_list: 
    463                 #only on type of data 
     458                # only on type of data 
    464459                page.fill_data_combobox(data_1d_list) 
    465460            elif not data_1d_list and data_2d_list: 
     
    477472        Add a fitting page on the notebook contained by fitpanel 
    478473 
    479         :param data: data to fit 
     474        :param data_list: data to fit 
    480475 
    481476        :return panel : page just added for further used. 
  • src/sas/sasgui/perspectives/fitting/pagestate.py

    r467202f rc8e1996  
    4646                            ["npts", "npts", "float"], 
    4747                            ["categorycombobox", "categorycombobox", "string"], 
    48                             ["formfactorcombobox", "formfactorcombobox", "string"], 
    49                             ["structurecombobox", "structurecombobox", "string"], 
     48                            ["formfactorcombobox", "formfactorcombobox", 
     49                             "string"], 
     50                            ["structurecombobox", "structurecombobox", 
     51                             "string"], 
    5052                            ["multi_factor", "multi_factor", "float"], 
    5153                            ["magnetic_on", "magnetic_on", "bool"], 
     
    6567                            ["smearer", "smearer", "float"], 
    6668                            ["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"], 
    6971                            ["dx_max", "dx_max", "float"], 
    7072                            ["dx_min", "dx_min", "float"], 
     
    8082                            ["str_parameters", "str_parameters"], 
    8183                            ["orientation_parameters", "orientation_params"], 
    82                             ["dispersity_parameters", "orientation_params_disp"], 
     84                            ["dispersity_parameters", 
     85                             "orientation_params_disp"], 
    8386                            ["fixed_param", "fixed_param"], 
    8487                            ["fittable_param", "fittable_param"]] 
     
    120123            try: 
    121124                return node.get(item[0]).strip() == "True" 
    122             except: 
     125            except Exception: 
    123126                return None 
    124127        else: 
    125128            try: 
    126129                return float(node.get(item[0])) 
    127             except: 
     130            except Exception: 
    128131                return None 
    129132 
     
    188191        # page name 
    189192        self.page_name = "" 
    190         # Contains link between model, all its parameters, and panel organization 
     193        # Contains link between model, its parameters, and panel organization 
    191194        self.parameters = [] 
    192195        # String parameter list that can not be fitted 
     
    305308        obj.fittable_param = copy.deepcopy(self.fittable_param) 
    306309        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) 
    308312        obj.enable_disp = copy.deepcopy(self.enable_disp) 
    309313        obj.disable_disp = copy.deepcopy(self.disable_disp) 
     
    397401        rep += "data : %s\n" % str(self.data) 
    398402        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)) 
    400404        rep += "Dispersion selection : %s\n" % str(self.disp_box) 
    401405        rep += "Smearing enable : %s\n" % str(self.enable_smearer) 
     
    413417 
    414418        rep += "2D enable : %s\n" % str(self.enable2D) 
    415         rep += "All parameters checkbox selected: %s\n" % str(self.cb1) 
     419        rep += "All parameters checkbox selected: %s\n" % self.cb1 
    416420        rep += "Value of Chisqr : %s\n" % str(self.tcChi) 
    417         rep += "Smear object : %s\n" % str(self.smearer) 
    418         rep += "Smear type : %s\n" % str(self.smear_type) 
     421        rep += "Smear object : %s\n" % self.smearer 
     422        rep += "Smear type : %s\n" % self.smear_type 
    419423        rep += "dq_l  : %s\n" % self.dq_l 
    420424        rep += "dq_r  : %s\n" % self.dq_r 
     
    478482                value = content[1] 
    479483            except Exception: 
    480                 msg = "Report string expected 'name: value' but got %r"%line 
     484                msg = "Report string expected 'name: value' but got %r" % line 
    481485                logging.error(msg) 
    482486            if name.count("State created"): 
     
    493497            if name == "value": 
    494498                param_string += value + ',' 
     499            fixed_parameter = False 
    495500            if name == "selected": 
    496501                if value == u' False': 
    497502                    fixed_parameter = True 
    498                 else: 
    499                     fixed_parameter = False 
    500503            if name == "error value": 
    501504                if fixed_parameter: 
     
    617620        dialog.Show() 
    618621 
    619     def _toXML_helper(self, thelist, element, newdoc): 
     622    def _to_xml_helper(self, thelist, element, newdoc): 
    620623        """ 
    621624        Helper method to create xml file for saving state 
     
    635638            element.appendChild(sub_element) 
    636639 
    637     def toXML(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): 
    639642        """ 
    640643        Writes the state of the fit panel to file, as XML. 
     
    648651        :param entry_node: XML node within the XML document at which we 
    649652                           will append the data [optional] 
     653        :param batch_fit_state: simultaneous fit state 
    650654        """ 
    651655        from xml.dom.minidom import getDOMImplementation 
     
    746750        for item in LIST_OF_STATE_PARAMETERS: 
    747751            element = newdoc.createElement(item[0]) 
    748             self._toXML_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) 
    750754            inputs.appendChild(element) 
    751755 
     
    765769            for constraint in batch_fit_state.constraints_list: 
    766770                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 
    768773                    doc_cons = newdoc.createElement('constraint') 
    769774                    doc_cons.setAttribute('model_cbox', 
     
    808813            return newdoc 
    809814 
    810     def _fromXML_helper(self, node, list): 
     815    def _from_xml_helper(self, node, list): 
    811816        """ 
    812817        Helper function to write state to xml 
     
    858863                         [maximum_displayed, maximum_value], unit]) 
    859864 
    860     def fromXML(self, file=None, node=None): 
     865    def from_xml(self, file=None, node=None): 
    861866        """ 
    862867        Load fitting state from a file 
     
    887892                    logging.error(msg) 
    888893 
    889             # Parse fitting attributes 
    890             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  
    895894            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 
    896901                for item in LIST_OF_STATE_ATTRIBUTES: 
    897902                    node = get_content('ns:%s' % item[0], entry) 
     
    900905                for item in LIST_OF_STATE_PARAMETERS: 
    901906                    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])) 
    903909 
    904910                # Recover _disp_obj_dict from xml file 
     
    950956        """ 
    951957        images = [] 
    952         # some imports 
    953         import wx 
    954958 
    955959        # Reset memory 
     
    958962 
    959963        # 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: 
    961965            figs = [None] 
    962966 
     
    965969        self.imgRAM = wx.MemoryFSHandler() 
    966970        for fig in figs: 
    967             if figs != None: 
     971            if fig is not None: 
    968972                ind = figs.index(fig) 
    969973                canvas = canvases[ind] 
    970974 
    971             #store the image in wx.FileSystem Object 
     975            # store the image in wx.FileSystem Object 
    972976            wx.FileSystem.AddHandler(wx.MemoryFSHandler()) 
    973977 
     
    975979            ind = figs.index(fig) 
    976980 
    977             #AddFile, image can be retrieved with 'memory:filename' 
     981            # AddFile, image can be retrieved with 'memory:filename' 
    978982            self.imgRAM.AddFile('img_fit%s.png' % ind, 
    979983                                canvas.bitmap, wx.BITMAP_TYPE_PNG) 
    980984 
    981             #append figs 
     985            # append figs 
    982986            images.append(fig) 
    983987 
     
    989993    Class to load a .fitv fitting file 
    990994    """ 
    991     ## File type 
     995    # File type 
    992996    type_name = "Fitting" 
    993997 
    994     ## Wildcards 
     998    # Wildcards 
    995999    type = ["Fitting files (*.fitv)|*.fitv" 
    9961000            "SASView file (*.svs)|*.svs"] 
    997     ## List of allowed extensions 
     1001    # List of allowed extensions 
    9981002    ext = ['.fitv', '.FITV', '.svs', 'SVS'] 
    9991003 
     
    10091013 
    10101014        """ 
    1011         ## Call back method to be executed after a file is read 
     1015        # Call back method to be executed after a file is read 
    10121016        self.call_back = call_back 
    1013         ## CanSAS format flag 
     1017        # CanSAS format flag 
    10141018        self.cansas = cansas 
    10151019        self.state = None 
     
    10271031 
    10281032        """ 
    1029         if self.cansas == True: 
     1033        if self.cansas: 
    10301034            return self._read_cansas(path) 
    10311035 
     
    10611065        for item in datainfo.run: 
    10621066            runname = {} 
    1063             if datainfo.run_name.has_key(item) and \ 
     1067            if item in datainfo.run_name and \ 
    10641068                            len(str(datainfo.run_name[item])) > 1: 
    10651069                runname = {'name': datainfo.run_name[item]} 
     
    10761080            root_node = doc.createElement(item[0]) 
    10771081            new_node.appendChild(root_node) 
    1078             temp_list = None 
    10791082            temp_list = getattr(datainfo, item[1]) 
    10801083 
     
    11131116                                       datainfo.sample.position.z, 
    11141117                                       {"unit": datainfo.sample.position_unit}) 
    1115         if written == True: 
     1118        if written: 
    11161119            sample.appendChild(pos) 
    11171120 
     
    11211124        written = written | write_node(doc, ori, "pitch", 
    11221125                                       datainfo.sample.orientation.y, 
    1123                                        {"unit": datainfo.sample.orientation_unit}) 
     1126                                       {"unit": 
     1127                                            datainfo.sample.orientation_unit}) 
    11241128        written = written | write_node(doc, ori, "yaw", 
    11251129                                       datainfo.sample.orientation.z, 
    1126                                        {"unit": datainfo.sample.orientation_unit}) 
    1127         if written == True: 
     1130                                       {"unit": 
     1131                                            datainfo.sample.orientation_unit}) 
     1132        if written: 
    11281133            sample.appendChild(ori) 
    11291134 
     
    11531158                                       datainfo.source.beam_size.z, 
    11541159                                       {"unit": datainfo.source.beam_size_unit}) 
    1155         if written == True: 
     1160        if written: 
    11561161            source.appendChild(size) 
    11571162 
     
    11981203                written = written | write_node(doc, size, "z", apert.size.z, 
    11991204                                               {"unit": apert.size_unit}) 
    1200                 if written == True: 
     1205                if written: 
    12011206                    ap.appendChild(size) 
    12021207 
     
    12101215                                           item.slit_length, 
    12111216                                           {"unit": item.slit_length_unit}) 
    1212             if written == True: 
     1217            if written: 
    12131218                instr.appendChild(det) 
    12141219 
     
    12201225            written = written | write_node(doc, off, "z", item.offset.z, 
    12211226                                           {"unit": item.offset_unit}) 
    1222             if written == True: 
     1227            if written: 
    12231228                det.appendChild(off) 
    12241229 
     
    12321237                                           item.beam_center.z, 
    12331238                                           {"unit": item.beam_center_unit}) 
    1234             if written == True: 
     1239            if written: 
    12351240                det.appendChild(center) 
    12361241 
     
    12421247            written = written | write_node(doc, pix, "z", item.pixel_size.z, 
    12431248                                           {"unit": item.pixel_size_unit}) 
    1244             if written == True: 
     1249            if written: 
    12451250                det.appendChild(pix) 
    12461251 
     
    12531258            written = written | write_node(doc, ori, "yaw", item.orientation.z, 
    12541259                                           {"unit": item.orientation_unit}) 
    1255             if written == True: 
     1260            if written: 
    12561261                det.appendChild(ori) 
    12571262 
     
    12901295                # Create an empty state 
    12911296                state = PageState() 
    1292                 state.fromXML(node=nodes[0]) 
     1297                state.from_xml(node=nodes[0]) 
    12931298 
    12941299        except: 
     
    13141319                simfitstate_0 = simfitstate[0] 
    13151320                all = simfitstate_0.xpath('ns:select_all', 
    1316                                         namespaces={'ns': CANSAS_NS}) 
     1321                                          namespaces={'ns': CANSAS_NS}) 
    13171322                atts = all[0].attrib 
    13181323                checked = atts.get('checked') 
    13191324                sim_fit_state.select_all = bool(checked) 
    13201325                model_list = simfitstate_0.xpath('ns:model_list', 
    1321                                                namespaces={'ns': CANSAS_NS}) 
     1326                                                 namespaces={'ns': CANSAS_NS}) 
    13221327                model_list_items = model_list[0].xpath('ns:model_list_item', 
    1323                                                    namespaces={'ns': CANSAS_NS}) 
     1328                                                       namespaces={'ns': 
     1329                                                                    CANSAS_NS}) 
    13241330                for model in model_list_items: 
    13251331                    attrs = model.attrib 
     
    13681374            return return_value, _ 
    13691375 
    1370         #Parse 2D 
     1376        # Parse 2D 
    13711377        data_info = Data2D() 
    13721378 
     
    15901596        for entry in nodes: 
    15911597            for item in LIST_OF_DATA_2D_ATTR: 
    1592                 #get node 
     1598                # get node 
    15931599                node = get_content('ns:%s' % item[0], entry) 
    15941600                setattr(data_info, item[1], parse_entry_helper(node, item)) 
     
    16331639                    entry_list = root.xpath('ns:SASentry', 
    16341640                                            namespaces={'ns': CANSAS_NS}) 
    1635                     name_map = {} 
    16361641                    for entry in entry_list: 
    16371642                        try: 
     
    16791684                        state.data.is_data = state.is_data 
    16801685                    if output[ind].run_name is not None\ 
    1681                         and len(output[ind].run_name) != 0: 
     1686                         and len(output[ind].run_name) != 0: 
    16821687                        if isinstance(output[ind].run_name, dict): 
    16831688                            name = output[ind].run_name.keys()[0] 
     
    17151720            # Write the XML document 
    17161721        else: 
    1717             doc = fitstate.toXML(file=filename) 
     1722            doc = fitstate.to_xml(file=filename) 
    17181723 
    17191724        # Save the document no matter the type 
     
    17491754 
    17501755        if state is not None: 
    1751             doc = state.toXML(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) 
    17531758 
    17541759        return doc 
Note: See TracChangeset for help on using the changeset viewer.