Changes in / [600bea1:cd5e29b] in sasview


Ignore:
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    ra93d6b1 ra93d6b1  
    1313.pydevproject 
    1414.vagrant 
     15.idea 
     16build 
     17dist 
     18sasview.egg-info 
     19sasview.egg-info 
     20 
    1521.mplconfig 
     22doctrees 
     23html 
     24build 
    1625 
    1726/dist 
    18 /build 
     27**/build 
    1928sasview.egg-info 
    2029sasview-install 
     
    3443/docs/sphinx-docs/source/user/perspectives 
    3544 
     45default_categories.json 
  • run.py

    rf9393dc rf9393dc  
    104104    addpath(joinpath(root, 'src')) 
    105105 
     106    # sasmodels on the path 
     107    addpath(joinpath(root, '../sasmodels/')) 
     108 
    106109    # Import the sasview package from root/sasview as sas.sasview.  It would 
    107110    # be better to just store the package in src/sas/sasview. 
  • setup.py

    r038ccfe6 r038ccfe6  
    244244model_dir = os.path.join("src", "sas","models") 
    245245 
    246 if os.path.isdir(wrapper_dir): 
    247     for file in os.listdir(wrapper_dir):  
    248         file_path =  os.path.join(wrapper_dir, file) 
    249         os.remove(file_path) 
    250 else: 
    251     os.makedirs(wrapper_dir) 
    252 sys.path.append(os.path.join("src", "sas", "models", "c_extension", "python_wrapper")) 
    253 from wrapping import generate_wrappers 
    254 generate_wrappers(header_dir = includedir,  
    255                   output_dir = model_dir, 
    256                   c_wrapper_dir = wrapper_dir) 
     246#if os.path.isdir(wrapper_dir): 
     247#    for file in os.listdir(wrapper_dir): 
     248#        file_path =  os.path.join(wrapper_dir, file) 
     249#        os.remove(file_path) 
     250#else: 
     251#    os.makedirs(wrapper_dir) 
     252#sys.path.append(os.path.join("src", "sas", "models", "c_extension", "python_wrapper")) 
     253#from wrapping import generate_wrappers 
     254#generate_wrappers(header_dir = includedir, 
     255#                  output_dir = model_dir, 
     256#                  c_wrapper_dir = wrapper_dir) 
    257257 
    258258IGNORED_FILES = [".svn"] 
     
    283283model_sources = [] 
    284284append_file(file_list=model_sources, dir_path=igordir) 
    285 append_file(file_list=model_sources, dir_path=c_model_dir) 
    286 append_file(file_list=model_sources, dir_path=wrapper_dir) 
     285#append_file(file_list=model_sources, dir_path=c_model_dir) 
     286#append_file(file_list=model_sources, dir_path=wrapper_dir) 
    287287 
    288288smear_sources = [] 
     
    303303 
    304304c_models = [  
    305     Extension("sas.models.sas_extension.c_models", 
    306         sources=model_sources,                  
    307         include_dirs=[ 
    308             igordir, includedir, c_model_dir, numpy_incl_path, cephes_dir 
    309         ], 
    310     ), 
     305    #Extension("sas.models.sas_extension.c_models", 
     306    #    sources=model_sources, 
     307    #    include_dirs=[ 
     308    #        igordir, includedir, c_model_dir, numpy_incl_path, cephes_dir 
     309    #    ], 
     310    #), 
    311311 
    312312    # Smearer extension 
     
    340340ext_modules.extend(c_models) 
    341341 
     342packages.append("sas.models") 
    342343# SasView 
    343344 
     
    350351                               'test/save_states/*', 
    351352                               'test/upcoming_formats/*',  
    352                                'default_categories.json'] 
     353                                 'default_categories.json'] 
    353354packages.append("sas.sasview") 
    354355 
  • src/sas/models/dispersion_models.py

    rfd5ac0d r0e4e554  
    154154        c_models.set_dispersion_weights(self.cdisp, values, weights) 
    155155         
    156 models = {"gaussian":GaussianDispersion,  "rectangula":RectangleDispersion, 
     156models = {"gaussian":GaussianDispersion,  "rectangular":RectangleDispersion, 
    157157          "array":ArrayDispersion, "schulz":SchulzDispersion,  
    158158          "lognormal":LogNormalDispersion}        
  • src/sas/perspectives/fitting/basepage.py

    r2c8dc19 r2c8dc19  
    5757    ## Title to appear on top of the window 
    5858    window_caption = "Fit Page " 
    59  
     59     
    6060    def __init__(self, parent, color='blue', **kwargs): 
    6161        """ 
     
    6666        #Set window's font size 
    6767        self.SetWindowVariant(variant=FONT_VARIANT) 
    68  
     68       
    6969        self.SetBackgroundColour(color) 
    7070        ## parent of the page 
     
    126126        self.Npts_fit = None 
    127127        self.Npts_total = None 
    128         self.theory_qmin = None 
     128        self.theory_qmin = None  
    129129        self.theory_qmax = None 
    130130        self.theory_qmin_x = None 
     
    135135        self.sld_axes = None 
    136136        self.multi_factor = None 
    137  
     137        
    138138        self.disp_cb_dict = {} 
    139  
     139    
    140140        #self.state = PageState(parent=parent) 
    141141        ## dictionary containing list of models 
    142142        self.model_list_box = {} 
    143  
     143        
    144144        ## Data member to store the dispersion object created 
    145145        self._disp_obj_dict = {} 
     
    169169        self.disp_list = [] 
    170170        self.disp_name = "" 
    171  
     171         
    172172        ## list of orientation parameters 
    173173        self.orientation_params = [] 
    174174        self.orientation_params_disp = [] 
    175 #       Self.model should ALWAYS be None here.  It was set to none above in 
     175#       Self.model should ALWAYS be None here.  It was set to none above in  
    176176#       this long init setting.  no obvious function call in between setting 
    177 #       and this - commenting out on 4/8/2014 by PDB.  Remove once clear 
     177#       and this - commenting out on 4/8/2014 by PDB.  Remove once clear  
    178178#       it is pointless. 
    179179#        if self.model != None: 
     
    198198        ## Create context menu for page 
    199199        self.popUpMenu = wx.Menu() 
    200  
     200     
    201201        id = wx.NewId() 
    202202        self._keep = wx.MenuItem(self.popUpMenu, id, "Add bookmark", 
     
    208208        wx.EVT_MENU(self, id, self.on_bookmark) 
    209209        self.popUpMenu.AppendSeparator() 
    210  
     210     
    211211        ## Default locations 
    212212        self._default_save_location = os.getcwd() 
     
    214214        #self.onSave(event=None) 
    215215        self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 
    216  
     216         
    217217        # bind key event 
    218218        self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) 
    219  
     219         
    220220        ## create the basic structure of the panel with empty sizer 
    221221        self.define_page_structure() 
    222222        ## drawing Initial dispersion parameters sizer 
    223223        self.set_dispers_sizer() 
    224  
     224         
    225225        ## layout 
    226226        self.set_layout() 
    227  
     227     
    228228    def set_index_model(self, index): 
    229229        """ 
     
    231231        """ 
    232232        self.index_model = index 
    233  
     233         
    234234    def create_default_data(self): 
    235235        """ 
     
    248248                else: 
    249249                    self._create_default_1d_data() 
    250  
     250                         
    251251            if self.model != None: 
    252252                if not self.data.is_data: 
     
    258258            self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 
    259259            self.state.slit_smearer = self.slit_smearer.GetValue() 
    260  
     260         
    261261    def _create_default_1d_data(self): 
    262262        """ 
     
    264264        Only when the page is on theory mode. 
    265265        :warning: This data is never plotted. 
    266  
     266         
    267267        """ 
    268268        x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, 
     
    274274        self.data.id = str(self.uid) + " data" 
    275275        self.data.group_id = str(self.uid) + " Model1D" 
    276  
     276          
    277277    def _create_log_1d_data(self): 
    278278        """ 
     
    280280        Only when the page is on theory mode. 
    281281        :warning: This data is never plotted. 
    282  
     282         
    283283        """ 
    284284        if self.qmin_x >= 1.e-10: 
    285285            qmin = numpy.log10(self.qmin_x) 
    286286        else: 
    287             qmin = -10. 
    288  
     287            qmin = -10.     
     288             
    289289        if self.qmax_x <= 1.e10: 
    290290            qmax = numpy.log10(self.qmax_x) 
    291291        else: 
    292             qmax = 10. 
    293  
     292            qmax = 10.  
     293                
    294294        x = numpy.logspace(start=qmin, stop=qmax, 
    295295                           num=self.npts_x, endpoint=True, base=10.0) 
     
    300300        self.data.id = str(self.uid) + " data" 
    301301        self.data.group_id = str(self.uid) + " Model1D" 
    302  
     302       
    303303    def _create_default_2d_data(self): 
    304304        """ 
     
    358358        #xstep = x_size / len(x_bins - 1) 
    359359        #ystep = y_size / len(y_bins - 1) 
    360  
     360   
    361361        self.data.source = Source() 
    362362        self.data.data = numpy.ones(len(mask)) 
     
    381381            wx.PostEvent(self._manager.parent, PanelOnFocusEvent(panel=self)) 
    382382            self.on_tap_focus() 
    383  
     383                
    384384    def on_tap_focus(self): 
    385385        """ 
     
    397397                    self._manager.menu1.FindItemById(self._manager.id_batchfit) 
    398398            batch_menu.Enable(self.batch_on and flag) 
    399  
     399     
    400400    def set_page_info(self, page_info): 
    401401        """ 
    402402        set some page important information at once 
    403403        """ 
    404 #       THIS METHOD/FUNCTION NO LONGE APPEARS TO BE CALLED.  Started up program 
     404#       THIS METHOD/FUNCTION NO LONGE APPEARS TO BE CALLED.  Started up program  
    405405#       and started new fit window and PR and Invariant and a fit in fitting 
    406406#       but never entered this routine which should be an initialization 
    407 #       routine.  Leave for a while but probably something to clean up at 
     407#       routine.  Leave for a while but probably something to clean up at  
    408408#       some point? 
    409409# 
     
    426426        ## Data member to store the dispersion object created 
    427427        self.populate_box(model_dict=self.model_list_box) 
    428  
     428         
    429429    def onContextMenu(self, event): 
    430430        """ 
     
    433433        # Skipping the save state functionality for release 0.9.0 
    434434        #return 
    435  
     435     
    436436        pos = event.GetPosition() 
    437437        pos = self.ScreenToClient(pos) 
    438  
     438        
    439439        self.PopupMenu(self.popUpMenu, pos) 
    440  
     440       
    441441    def onUndo(self, event): 
    442442        """ 
     
    445445        event = PreviousStateEvent(page=self) 
    446446        wx.PostEvent(self.parent, event) 
    447  
     447         
    448448    def onRedo(self, event): 
    449449        """ 
     
    452452        event = NextStateEvent(page=self) 
    453453        wx.PostEvent(self.parent, event) 
    454  
     454     
    455455    def define_page_structure(self): 
    456456        """ 
     
    465465        self.sizer5 = wx.BoxSizer(wx.VERTICAL) 
    466466        self.sizer6 = wx.BoxSizer(wx.VERTICAL) 
    467  
     467         
    468468        self.sizer0.SetMinSize((PANEL_WIDTH, -1)) 
    469469        self.sizer1.SetMinSize((PANEL_WIDTH, -1)) 
     
    473473        self.sizer5.SetMinSize((PANEL_WIDTH, -1)) 
    474474        self.sizer6.SetMinSize((PANEL_WIDTH, -1)) 
    475  
     475         
    476476        self.vbox.Add(self.sizer0) 
    477477        self.vbox.Add(self.sizer1) 
     
    481481        self.vbox.Add(self.sizer5) 
    482482        self.vbox.Add(self.sizer6) 
    483  
     483         
    484484    def set_layout(self): 
    485485        """ 
     
    490490        self.SetSizer(self.vbox) 
    491491        self.Centre() 
    492  
     492  
    493493    def set_owner(self, owner): 
    494494        """ 
    495495        set owner of fitpage 
    496  
     496         
    497497        :param owner: the class responsible of plotting 
    498  
     498         
    499499        """ 
    500500        self.event_owner = owner 
    501501        self.state.event_owner = owner 
    502  
     502         
    503503    def get_state(self): 
    504504        """ 
     
    506506        """ 
    507507        return self.state 
    508  
     508     
    509509    def get_data(self): 
    510510        """ 
     
    512512        """ 
    513513        return self.data 
    514  
     514     
    515515    def get_data_list(self): 
    516516        """ 
     
    518518        """ 
    519519        return self.data_list 
    520  
     520     
    521521    def set_manager(self, manager): 
    522522        """ 
    523523        set panel manager 
    524  
     524         
    525525        :param manager: instance of plugin fitting 
    526  
     526         
    527527        """ 
    528528        self._manager = manager 
    529529        self.state.manager = manager 
    530  
     530         
    531531    def populate_box(self, model_dict): 
    532532        """ 
    533533        Store list of model 
    534  
     534         
    535535        :param model_dict: dictionary containing list of models 
    536  
     536         
    537537        """ 
    538538        self.model_list_box = model_dict 
    539539        self.state.model_list_box = self.model_list_box 
    540540        self.initialize_combox() 
    541  
     541         
    542542    def set_model_dictionary(self, model_dict): 
    543543        """ 
     
    551551        """ 
    552552        put default value in the combobox 
    553         """ 
     553        """   
    554554        ## fill combox box 
    555555        if self.model_list_box is None: 
     
    560560        ## These are called for first time by formfactor_combo_init 
    561561        ## itself called from fitpanel only.  If we find that I'm wrong and 
    562         ## we DO need to initialize somehow here - do it by a call to 
    563         ## formfactor_combo_init 
     562        ## we DO need to initialize somehow here - do it by a call to  
     563        ## formfactor_combo_init  
    564564        ## self.formfator_combo_init() 
    565         ## BUT NOT HERE -- make it last line of this 
     565        ## BUT NOT HERE -- make it last line of this  
    566566        ## method so that structure box is populated before _show_comboox_helper 
    567567        ## is called.  Otherwise wx will complain mightily:-) 
     
    575575#                               self.model_list_box["Shapes"]) 
    576576            self._populate_box(self.structurebox, 
    577                                self.model_list_box["Structure Factors"]) 
     577                                self.model_list_box["Structure Factors"]) 
    578578            self.structurebox.Insert("None", 0, None) 
    579579            self.structurebox.SetSelection(0) 
     
    582582            self.structurebox.Disable() 
    583583            self.text2.Disable() 
    584  
     584              
    585585            if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: 
    586586                self.structurebox.Show() 
     
    589589                self.text2.Enable() 
    590590 
    591  
     591                 
    592592    def set_dispers_sizer(self): 
    593593        """ 
     
    601601        #---------------------------------------------------- 
    602602        self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), 
    603                                            style=wx.RB_GROUP) 
     603                                            style=wx.RB_GROUP) 
    604604        self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 
    605605        # best size for MAC and PC 
     
    614614                               id=self.disp_help_bt.GetId()) 
    615615        self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") 
    616  
     616         
    617617        self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 
    618                   id=self.disable_disp.GetId()) 
     618                     id=self.disable_disp.GetId()) 
    619619        self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 
    620                   id=self.enable_disp.GetId()) 
     620                   id=self.enable_disp.GetId()) 
    621621        #MAC needs SetValue 
    622622        self.disable_disp.SetValue(True) 
     
    630630        sizer_dispersion.Add((25, 20)) 
    631631        sizer_dispersion.Add(self.disp_help_bt) 
    632  
     632         
    633633        ## fill a sizer for dispersion 
    634634        boxsizer1.Add(sizer_dispersion, 0, 
    635                       wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 
    636                       border=5) 
     635                wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 
     636                border=5) 
    637637        self.sizer4_4 = wx.GridBagSizer(6, 5) 
    638638 
     
    643643        self.sizer4.Layout() 
    644644        self.Layout() 
    645  
     645      
    646646        self.Refresh() 
    647647        ## saving the state of enable dispersity button 
     
    649649        self.state.disable_disp = self.disable_disp.GetValue() 
    650650        self.SetupScrolling() 
    651  
     651     
    652652    def onResetModel(self, event): 
    653653        """ 
     
    667667            previous_state = self.saved_states[name] 
    668668            ## reset state of checkbox,textcrtl  and  regular parameters value 
    669  
     669             
    670670            self.reset_page(previous_state) 
    671671        self.state.m_name = self.m_name 
    672672        self.Show(True) 
    673  
     673                
    674674    def on_preview(self, event): 
    675675        """ 
     
    680680        # get the report dialog 
    681681        self.state.report(images, canvases) 
    682  
     682         
    683683    def on_save(self, event): 
    684684        """ 
     
    693693                        self._manager.parent._default_save_location 
    694694        dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, 
    695                             self.window_caption, "*.fitv", wx.SAVE) 
     695                                        self.window_caption, "*.fitv", wx.SAVE) 
    696696 
    697697        if dlg.ShowModal() == wx.ID_OK: 
    698698            path = dlg.GetPath() 
    699699            self._default_save_location = os.path.dirname(path) 
    700             self._manager.parent._default_save_location = \ 
    701                                 self._default_save_location 
     700            self._manager.parent._default_save_location =\ 
     701                                 self._default_save_location 
    702702        else: 
    703703            return None 
     
    709709        self._manager.save_fit_state(filepath=fName, fitstate=new_state) 
    710710        return new_state 
    711  
     711     
    712712    def on_copy(self, event): 
    713713        """ 
     
    726726            wx.CallAfter(self.get_copy) 
    727727 
    728  
     728         
    729729    def on_paste(self, event): 
    730730        """ 
     
    738738        # messages depending on the flag 
    739739        #self._copy_info(True) 
    740  
     740         
    741741    def _copy_info(self, flag): 
    742742        """ 
    743743        Send event dpemding on flag 
    744  
     744         
    745745        : Param flag: flag that distinguish event 
    746746        """ 
     
    758758        # inform msg to wx 
    759759        wx.PostEvent(self._manager.parent, 
    760                      StatusEvent(status=msg, info=infor)) 
    761  
     760                    StatusEvent(status=msg, info=infor)) 
     761         
    762762    def _get_time_stamp(self): 
    763763        """ 
     
    769769        current_date = str(month) + "/" + str(day) + "/" + str(year) 
    770770        return current_time, current_date 
    771  
     771       
    772772    def on_bookmark(self, event): 
    773773        """ 
     
    788788        name += "bookmarked at %s on %s" % (current_time, current_date) 
    789789        self.saved_states[name] = new_state 
    790  
     790         
    791791        ## Add item in the context menu 
    792792        msg = "Model saved at %s on %s" % (current_time, current_date) 
     
    794794        msg += " Saved! right click on this page to retrieve this model" 
    795795        wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    796  
     796         
    797797        id = wx.NewId() 
    798798        self.popUpMenu.Append(id, name, str(msg)) 
     
    802802                                         hint=str(msg), 
    803803                                         handler=self._back_to_bookmark)) 
    804  
     804     
    805805    def _back_to_bookmark(self, event): 
    806806        """ 
     
    810810        self.onResetModel(event) 
    811811        self._draw_model() 
    812  
     812                 
    813813    def onSetFocus(self, evt): 
    814814        """ 
     
    817817        """ 
    818818        return 
    819  
     819     
    820820    def read_file(self, path): 
    821821        """ 
    822822        Read two columns file 
    823  
     823         
    824824        :param path: the path to the file to read 
    825  
     825         
    826826        """ 
    827827        try: 
     
    856856        """ 
    857857        return self.state.clone() 
    858  
     858     
    859859    def save_current_state(self): 
    860860        """ 
     
    866866            self.state.disp_list = copy.deepcopy(self.disp_list) 
    867867            self.state.model = self.model.clone() 
    868  
     868             
    869869            #model combobox: complex code because of mac's silent error 
    870870            if self.structurebox != None: 
     
    885885                self.state.categorycombobox = self.categorybox.\ 
    886886                GetString(cb_select) 
    887  
     887         
    888888        self.state.enable2D = copy.deepcopy(self.enable2D) 
    889889        self.state.values = copy.deepcopy(self.values) 
     
    902902            self.state.enable_disp = self.enable_disp.GetValue() 
    903903            self.state.disable_disp = self.disable_disp.GetValue() 
    904  
     904             
    905905        self.state.smearer = copy.deepcopy(self.current_smearer) 
    906906        if hasattr(self, "enable_smearer"): 
     
    917917        self.state.dxw = copy.deepcopy(self.dxw) 
    918918        self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 
    919  
     919                   
    920920        if len(self._disp_obj_dict) > 0: 
    921921            for k, v in self._disp_obj_dict.iteritems(): 
     
    926926        ## save plotting range 
    927927        self._save_plotting_range() 
    928  
     928         
    929929        self.state.orientation_params = [] 
    930930        self.state.orientation_params_disp = [] 
     
    941941        self._copy_parameters_state(self.orientation_params_disp, 
    942942                                     self.state.orientation_params_disp) 
    943  
     943         
    944944        self._copy_parameters_state(self.parameters, self.state.parameters) 
    945945        self._copy_parameters_state(self.fittable_param, 
     
    948948        #save chisqr 
    949949        self.state.tcChi = self.tcChi.GetValue() 
    950  
     950         
    951951    def save_current_state_fit(self): 
    952952        """ 
     
    958958            self.state.disp_list = copy.deepcopy(self.disp_list) 
    959959            self.state.model = self.model.clone() 
    960  
     960             
    961961        self.state.enable2D = copy.deepcopy(self.enable2D) 
    962962        self.state.values = copy.deepcopy(self.values) 
     
    964964        ## save data 
    965965        self.state.data = copy.deepcopy(self.data) 
    966  
     966         
    967967        if hasattr(self, "enable_disp"): 
    968968            self.state.enable_disp = self.enable_disp.GetValue() 
    969969            self.state.disable_disp = self.disable_disp.GetValue() 
    970  
     970             
    971971        self.state.smearer = copy.deepcopy(self.current_smearer) 
    972972        if hasattr(self, "enable_smearer"): 
     
    975975            self.state.disable_smearer = \ 
    976976                                copy.deepcopy(self.disable_smearer.GetValue()) 
    977  
     977             
    978978        self.state.pinhole_smearer = \ 
    979979                                copy.deepcopy(self.pinhole_smearer.GetValue()) 
     
    998998                for k, v in self._disp_obj_dict.iteritems(): 
    999999                    self.state._disp_obj_dict[k] = v 
    1000  
     1000                         
    10011001            self.state.values = copy.deepcopy(self.values) 
    10021002            self.state.weights = copy.deepcopy(self.weights) 
    1003  
     1003            
    10041004        ## save plotting range 
    10051005        self._save_plotting_range() 
    1006  
     1006         
    10071007        ## save checkbutton state and txtcrtl values 
    10081008        self._copy_parameters_state(self.orientation_params, 
    1009                                     self.state.orientation_params) 
     1009                                     self.state.orientation_params) 
    10101010        self._copy_parameters_state(self.orientation_params_disp, 
    1011                                     self.state.orientation_params_disp) 
     1011                                     self.state.orientation_params_disp) 
    10121012        self._copy_parameters_state(self.parameters, self.state.parameters) 
    10131013        self._copy_parameters_state(self.fittable_param, 
    1014                                     self.state.fittable_param) 
     1014                                             self.state.fittable_param) 
    10151015        self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 
    1016  
     1016     
    10171017    def check_invalid_panel(self): 
    10181018        """ 
     
    10251025            wx.MessageBox(msg, 'Info') 
    10261026            return  True 
    1027  
     1027         
    10281028    def set_model_state(self, state): 
    10291029        """ 
     
    10321032        self.disp_cb_dict = state.disp_cb_dict 
    10331033        self.disp_list = state.disp_list 
    1034  
     1034       
    10351035        ## set the state of the radio box 
    10361036        #self.shape_rbutton.SetValue(state.shape_rbutton) 
     
    10381038        #self.struct_rbutton.SetValue(state.struct_rbutton) 
    10391039        #self.plugin_rbutton.SetValue(state.plugin_rbutton) 
    1040  
     1040         
    10411041        ## fill model combobox 
    10421042        self._show_combox_helper() 
     
    10521052                    category_pos = int(ind_cat) 
    10531053                    break 
    1054  
     1054             
    10551055        self.categorybox.Select(category_pos) 
    10561056        try: 
     
    10641064                    formfactor_pos = int(ind_form) 
    10651065                    break 
    1066  
     1066             
    10671067        self.formfactorbox.Select(formfactor_pos) 
    1068  
     1068         
    10691069        try: 
    10701070            # to support older version 
     
    10771077                    structfactor_pos = int(ind_struct) 
    10781078                    break 
    1079  
     1079                 
    10801080        self.structurebox.SetSelection(structfactor_pos) 
    1081  
     1081         
    10821082        if state.multi_factor != None: 
    10831083            self.multifactorbox.SetSelection(state.multi_factor) 
    1084  
     1084             
    10851085        ## reset state of checkbox,textcrtl  and  regular parameters value 
    10861086        self._reset_parameters_state(self.orientation_params_disp, 
     
    10941094        self.enable_disp.SetValue(state.enable_disp) 
    10951095        self.disable_disp.SetValue(state.disable_disp) 
    1096  
     1096         
    10971097        if hasattr(self, "disp_box") and self.disp_box != None: 
    10981098            self.disp_box.SetSelection(state.disp_box) 
     
    11021102 
    11031103            self._set_dipers_Param(event=None) 
    1104  
     1104        
    11051105            if name == "ArrayDispersion": 
    1106  
     1106                 
    11071107                for item in self.disp_cb_dict.keys(): 
    1108  
     1108                     
    11091109                    if hasattr(self.disp_cb_dict[item], "SetValue"): 
    11101110                        self.disp_cb_dict[item].SetValue(\ 
    11111111                                                    state.disp_cb_dict[item]) 
    11121112                        # Create the dispersion objects 
    1113                         from sas.models.dispersion_models import ArrayDispersion 
     1113                        #from sas.models.dispersion_models import ArrayDispersion 
     1114                        from sasmodels.weights import ArrayDispersion 
    11141115                        disp_model = ArrayDispersion() 
    11151116                        if hasattr(state, "values") and \ 
     
    11221123                            else: 
    11231124                                self._reset_dispersity() 
    1124  
     1125                         
    11251126                        self._disp_obj_dict[item] = disp_model 
    11261127                        # Set the new model as the dispersion object 
    11271128                        #for the selected parameter 
    11281129                        self.model.set_dispersion(item, disp_model) 
    1129  
     1130                     
    11301131                        self.model._persistency_dict[item] = \ 
    11311132                                                [state.values, state.weights] 
    1132  
     1133                     
    11331134            else: 
    11341135                keys = self.model.getParamList() 
     
    11481149        self.pinhole_smearer.SetValue(state.pinhole_smearer) 
    11491150        self.slit_smearer.SetValue(state.slit_smearer) 
    1150  
     1151         
    11511152        self.dI_noweight.SetValue(state.dI_noweight) 
    11521153        self.dI_didata.SetValue(state.dI_didata) 
    11531154        self.dI_sqrdata.SetValue(state.dI_sqrdata) 
    11541155        self.dI_idata.SetValue(state.dI_idata) 
    1155  
     1156         
    11561157        ## we have two more options for smearing 
    11571158        if self.pinhole_smearer.GetValue(): 
     
    11591160        elif self.slit_smearer.GetValue(): 
    11601161            self.onSlitSmear(event=None) 
    1161  
     1162        
    11621163        ## reset state of checkbox,textcrtl  and dispersity parameters value 
    11631164        self._reset_parameters_state(self.fittable_param, state.fittable_param) 
    11641165        self._reset_parameters_state(self.fixed_param, state.fixed_param) 
    1165  
     1166         
    11661167        ## draw the model with previous parameters value 
    11671168        self._onparamEnter_helper() 
     
    11711172        self._lay_out() 
    11721173        self.Refresh() 
    1173  
     1174         
    11741175    def reset_page_helper(self, state): 
    11751176        """ 
    11761177        Use page_state and change the state of existing page 
    1177  
     1178         
    11781179        :precondition: the page is already drawn or created 
    1179  
     1180         
    11801181        :postcondition: the state of the underlying data change as well as the 
    11811182            state of the graphic interface 
     
    12031204        else: 
    12041205            self.set_data(data) 
    1205  
     1206             
    12061207        self.enable2D = state.enable2D 
    12071208        try: 
     
    12131214        self.disp_cb_dict = state.disp_cb_dict 
    12141215        self.disp_list = state.disp_list 
    1215  
     1216       
    12161217        ## set the state of the radio box 
    12171218        #self.shape_rbutton.SetValue(state.shape_rbutton) 
     
    12191220        #self.struct_rbutton.SetValue(state.struct_rbutton) 
    12201221        #self.plugin_rbutton.SetValue(state.plugin_rbutton) 
    1221  
     1222         
    12221223        ## fill model combobox 
    12231224        self._show_combox_helper() 
     
    12331234                    category_pos = int(ind_cat) 
    12341235                    break 
    1235  
     1236             
    12361237        self.categorybox.Select(category_pos) 
    12371238        self._show_combox(None) 
     
    12461247                    formfactor_pos = int(ind_form) 
    12471248                    break 
    1248  
     1249             
    12491250        self.formfactorbox.Select(formfactor_pos) 
    1250  
     1251         
    12511252        try: 
    12521253            # to support older version 
     
    12591260                    structfactor_pos = int(ind_struct) 
    12601261                    break 
    1261  
     1262             
    12621263        self.structurebox.SetSelection(structfactor_pos) 
    12631264 
     
    12671268        #draw the panel according to the new model parameter 
    12681269        self._on_select_model(event=None) 
    1269  
     1270             
    12701271        # take care of 2D button 
    12711272        if data == None and self.model_view.IsEnabled(): 
     
    12741275            else: 
    12751276                self.model_view.SetLabel("1D Mode") 
    1276          
     1277                 
    12771278        ## set the select all check box to the a given state 
    12781279        self.cb1.SetValue(state.cb1) 
    1279  
     1280      
    12801281        ## reset state of checkbox,textcrtl  and  regular parameters value 
    12811282        self._reset_parameters_state(self.orientation_params_disp, 
     
    13161317            self.dI_sqrdata.SetValue(False) 
    13171318            self.dI_idata.SetValue(False) 
    1318  
     1319  
    13191320        ## we have two more options for smearing 
    13201321        if self.pinhole_smearer.GetValue(): 
     
    13321333                self.smear_slit_height.SetValue(str(self.dxl)) 
    13331334            if self.dxw != None: 
    1334                 self.smear_slit_width.SetValue(str(self.dxw)) 
     1335                self.smear_slit_width.SetValue(str(self.dxw))   
    13351336            else: 
    1336                 self.smear_slit_width.SetValue('') 
     1337                self.smear_slit_width.SetValue('')   
    13371338            self.onSlitSmear(event=None) 
    1338  
     1339         
    13391340        ## reset state of checkbox,textcrtl  and dispersity parameters value 
    13401341        self._reset_parameters_state(self.fittable_param, state.fittable_param) 
    13411342        self._reset_parameters_state(self.fixed_param, state.fixed_param) 
    1342  
     1343         
    13431344        ## draw the model with previous parameters value 
    13441345        self._onparamEnter_helper() 
     
    13471348        ## reset context menu items 
    13481349        self._reset_context_menu() 
    1349  
     1350         
    13501351        ## set the value of the current state to the state given as parameter 
    13511352        self.state = state.clone() 
    13521353        self.state.m_name = self.m_name 
    1353  
     1354     
    13541355    def _reset_page_disp_helper(self, state): 
    13551356        """ 
     
    13661367        self.values = copy.deepcopy(state.values) 
    13671368        self.weights = copy.deepcopy(state.weights) 
    1368  
     1369         
    13691370        for key, disp in state._disp_obj_dict.iteritems(): 
    13701371            # From saved file, disp_model can not be sent in model obj. 
     
    13721373            if disp.__class__.__name__ == 'str': 
    13731374                disp_model = None 
    1374                 com_str = "from sas.models.dispersion_models " 
     1375                #com_str = "from sas.models.dispersion_models " 
     1376                com_str = "from sasmodels.weights " 
    13751377                com_str += "import %s as disp_func \ndisp_model = disp_func()" 
    13761378                exec com_str % disp 
     
    14131415                        except: 
    14141416                            logging.error(sys.exc_info()[1]) 
    1415  
     1417     
    14161418        # Make sure the check box updated when all checked 
    14171419        if self.cb1.GetValue(): 
    14181420            self.select_all_param(None) 
    1419  
     1421       
    14201422    def _selectDlg(self): 
    14211423        """ 
    1422         open a dialog file to selected the customized dispersity 
     1424        open a dialog file to selected the customized dispersity  
    14231425        """ 
    14241426        if self.parent != None: 
     
    14261428                        self._manager.parent.get_save_location() 
    14271429        dlg = wx.FileDialog(self, "Choose a weight file", 
    1428                             self._default_save_location, "", 
    1429                             "*.*", wx.OPEN) 
     1430                                self._default_save_location, "", 
     1431                                "*.*", wx.OPEN) 
    14301432        path = None 
    14311433        if dlg.ShowModal() == wx.ID_OK: 
     
    14451447            self.popUpMenu.Append(id, name, msg) 
    14461448            wx.EVT_MENU(self, id, self.onResetModel) 
    1447  
     1449     
    14481450    def _reset_plotting_range(self, state): 
    14491451        """ 
     
    14641466        self.state.formfactorcombobox = self.formfactorbox.GetLabel() 
    14651467        self.state.categorycombobox = self.categorybox.GetLabel() 
    1466  
     1468        
    14671469        ## post state to fit panel 
    14681470        event = PageInfoEvent(page=self) 
    14691471        wx.PostEvent(self.parent, event) 
    1470  
     1472         
    14711473    def _save_plotting_range(self): 
    14721474        """ 
     
    14761478        self.state.qmax = self.qmax_x 
    14771479        self.state.npts = self.npts_x 
    1478  
     1480             
    14791481    def _onparamEnter_helper(self): 
    14801482        """ 
     
    14931495            try: 
    14941496                is_modified = self._check_value_enter(self.fittable_param, 
    1495                                                       is_modified) 
     1497                                                     is_modified) 
    14961498                is_modified = self._check_value_enter(self.fixed_param, 
    14971499                                                      is_modified) 
     
    15131515                    self.qmax_x = tempmax 
    15141516                    is_modified = True 
    1515  
     1517             
    15161518                if is_2Ddata: 
    15171519                    # set mask 
    15181520                    is_modified = self._validate_Npts() 
    1519  
     1521                     
    15201522            else: 
    15211523                self.fitrange = False 
    1522  
     1524                 
    15231525            if not self.data.is_data: 
    15241526                is_modified = True 
     
    15401542                self.Refresh() 
    15411543        return is_modified 
    1542  
     1544     
    15431545    def _update_paramv_on_fit(self): 
    15441546        """ 
     
    15651567            self._check_value_enter(self.parameters, is_modified) 
    15661568 
    1567             # If qmin and qmax have been modified, update qmin and qmax and 
     1569            # If qmin and qmax have been modified, update qmin and qmax and  
    15681570            # Here we should check whether the boundaries have been modified. 
    1569             # If qmin and qmax have been modified, update qmin and qmax and 
     1571            # If qmin and qmax have been modified, update qmin and qmax and  
    15701572            # set the is_modified flag to True 
    15711573            self.fitrange = self._validate_qrange(self.qmin, self.qmax) 
     
    15941596                                                  qmax=float(self.qmax_x), 
    15951597                                                  enable_smearer=enable_smearer, 
    1596                                                   draw=False) 
     1598                                                      draw=False) 
    15971599                elif not self._is_2D(): 
    15981600                    enable_smearer = not self.disable_smearer.GetValue() 
     
    16031605                                              qmax=float(self.qmax_x), 
    16041606                                              enable_smearer=enable_smearer, 
    1605                                               draw=False) 
     1607                                                 draw=False) 
    16061608                    if self.data != None: 
    16071609                        index_data = ((self.qmin_x <= self.data.x) & \ 
     
    16391641            msg += " model or Fitting range is not valid!!!  " 
    16401642            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    1641  
     1643         
    16421644        try: 
    16431645            self.save_current_state() 
    16441646        except: 
    16451647            logging.error(sys.exc_info()[1]) 
    1646  
     1648    
    16471649        return flag 
    1648  
     1650                
    16491651    def _is_modified(self, is_modified): 
    16501652        """ 
     
    16521654        """ 
    16531655        return is_modified 
    1654  
     1656                        
    16551657    def _reset_parameters_state(self, listtorestore, statelist): 
    16561658        """ 
     
    16911693                item_page[5].Show(item_page_info[5][0]) 
    16921694                item_page[5].SetValue(item_page_info[5][1]) 
    1693  
     1695                 
    16941696            if item_page[6] != None: 
    16951697                ## show of hide the text crtl for fitting error 
    16961698                item_page[6].Show(item_page_info[6][0]) 
    16971699                item_page[6].SetValue(item_page_info[6][1]) 
    1698  
     1700                     
    16991701    def _reset_strparam_state(self, listtorestore, statelist): 
    17001702        """ 
     
    17051707 
    17061708        listtorestore = copy.deepcopy(statelist) 
    1707  
     1709         
    17081710        for j in range(len(listtorestore)): 
    17091711            item_page = listtorestore[j] 
    17101712            item_page_info = statelist[j] 
    17111713            ##change the state of the check box for simple parameters 
    1712  
     1714             
    17131715            if item_page[0] != None: 
    17141716                item_page[0].SetValue(format_number(item_page_info[0], True)) 
     
    17221724                item_page[2].SetValue(selection) 
    17231725                self.model.setParam(param_name, selection) 
    1724  
     1726                                       
    17251727    def _copy_parameters_state(self, listtocopy, statelist): 
    17261728        """ 
    17271729        copy the state of button 
    1728  
     1730         
    17291731        :param listtocopy: the list of check button to copy 
    17301732        :param statelist: list of state object to store the current state 
    1731  
     1733         
    17321734        """ 
    17331735        if len(listtocopy) == 0: 
    17341736            return 
    1735  
     1737        
    17361738        for item in listtocopy: 
    1737  
     1739   
    17381740            checkbox_state = None 
    17391741            if item[0] != None: 
     
    17511753                error_value = item[4].GetValue() 
    17521754                error_state = item[4].IsShown() 
    1753  
     1755                 
    17541756            min_value = None 
    17551757            min_state = None 
     
    17571759                min_value = item[5].GetValue() 
    17581760                min_state = item[5].IsShown() 
    1759  
     1761                 
    17601762            max_value = None 
    17611763            max_state = None 
     
    17661768            if item[7] != None: 
    17671769                unit = item[7].GetLabel() 
    1768  
     1770                
    17691771            statelist.append([checkbox_state, parameter_name, parameter_value, 
    17701772                              static_text, [error_state, error_value], 
    17711773                              [min_state, min_value], 
    17721774                              [max_state, max_value], unit]) 
    1773  
    1774  
     1775            
     1776                 
    17751777    def _draw_model(self, update_chisqr=True, source='model'): 
    17761778        """ 
     
    17781780        The method will use the data member from the model page 
    17791781        to build a call to the fitting perspective manager. 
    1780  
     1782         
    17811783        :param chisqr: update chisqr value [bool] 
    17821784        """ 
    17831785        wx.CallAfter(self._draw_model_after, update_chisqr, source) 
    1784  
     1786         
    17851787    def _draw_model_after(self, update_chisqr=True, source='model'): 
    17861788        """ 
     
    17881790        The method will use the data member from the model page 
    17891791        to build a call to the fitting perspective manager. 
    1790  
     1792         
    17911793        :param chisqr: update chisqr value [bool] 
    17921794        """ 
     
    18161818                                    source='model', 
    18171819                                    weight=weight) 
    1818  
     1820        
    18191821    def _on_show_sld(self, event=None): 
    18201822        """ 
     
    18311833        sld_data.name = 'SLD' 
    18321834        sld_data.axes = self.sld_axes 
    1833         self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id= -1) 
     1835        self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id=-1) 
    18341836        self.panel.ShowModal() 
    1835  
     1837         
    18361838    def _set_multfactor_combobox(self, multiplicity=10): 
    18371839        """ 
     
    18431845            self.multifactorbox.Append(str(idx), int(idx)) 
    18441846        self._hide_multfactor_combobox() 
    1845  
     1847         
    18461848    def _show_multfactor_combobox(self): 
    18471849        """ 
     
    18531855        if not self.multifactorbox.IsShown(): 
    18541856            self.multifactorbox.Show(True) 
    1855  
     1857              
    18561858    def _hide_multfactor_combobox(self): 
    18571859        """ 
     
    18631865        if self.multifactorbox.IsShown(): 
    18641866            self.multifactorbox.Hide() 
    1865  
     1867     
    18661868    def formfactor_combo_init(self): 
    18671869        """ 
     
    18691871        """ 
    18701872        self._show_combox(None) 
    1871  
     1873                 
    18721874    def _show_combox_helper(self): 
    18731875        """ 
     
    19021904                         StatusEvent(status=msg, info="error")) 
    19031905        self._populate_box(self.formfactorbox, m_list) 
    1904  
    1905     def _on_modify_cat(self, event=None): 
     1906     
     1907    def _on_modify_cat(self, event=None):   
    19061908        """ 
    19071909        Called when category manager is opened 
    19081910        """ 
    1909         self._manager.parent.on_category_panel(event) 
    1910  
     1911        self._manager.parent.on_category_panel(event)   
     1912         
    19111913    def _show_combox(self, event=None): 
    19121914        """ 
     
    19221924        self.Layout() 
    19231925        self.Refresh() 
    1924  
     1926   
    19251927    def _populate_box(self, combobox, list): 
    19261928        """ 
    19271929        fill combox box with dict item 
    1928  
     1930         
    19291931        :param list: contains item to fill the combox 
    19301932            item must model class 
     
    19351937            name = model.__class__.__name__ 
    19361938            if models.__name__ != "NoStructure": 
    1937                 if hasattr(model, "name"): 
     1939                if hasattr(model, "oldname"): 
     1940                    name = model.oldname 
     1941                elif hasattr(model, "name"): 
    19381942                    name = model.name 
    19391943                mlist.append((name, models)) 
    1940  
     1944                 
    19411945        # Sort the models 
    19421946        mlist_sorted = sorted(mlist) 
     
    19441948            combobox.Append(item[0], item[1]) 
    19451949        return 0 
    1946  
     1950     
    19471951    def _onQrangeEnter(self, event): 
    19481952        """ 
    19491953        Check validity of value enter in the Q range field 
    1950  
     1954         
    19511955        """ 
    19521956        tcrtl = event.GetEventObject() 
     
    20012005            self.create_default_data() 
    20022006        self._draw_model() 
    2003  
     2007                    
    20042008    def _theory_qrange_enter(self, event): 
    20052009        """ 
    20062010        Check validity of value enter in the Q range field 
    20072011        """ 
    2008  
     2012         
    20092013        tcrtl = event.GetEventObject() 
    20102014        #Clear msg if previously shown. 
     
    20582062        self.create_default_data() 
    20592063        self._draw_model() 
    2060  
     2064                    
    20612065    def _on_select_model_helper(self): 
    20622066        """ 
     
    20842088            self.structurebox.Enable() 
    20852089            self.text2.Enable() 
    2086  
     2090             
    20872091        if form_factor != None: 
    20882092            # set multifactor for Mutifunctional models 
     
    21012105                    # default value 
    21022106                    m_id = 1 
    2103  
     2107                     
    21042108                self.multi_factor = self.multifactorbox.GetClientData(m_id) 
    21052109                if self.multi_factor == None: 
     
    21292133            self.show_sld_button.Hide() 
    21302134            self.multi_factor = None 
    2131  
     2135               
    21322136        s_id = self.structurebox.GetCurrentSelection() 
    21332137        struct_factor = self.structurebox.GetClientData(s_id) 
    2134  
     2138         
    21352139        if  struct_factor != None: 
    21362140            from sas.models.MultiplicationModel import MultiplicationModel 
     
    21472151        # check if model has magnetic parameters 
    21482152        if len(self.model.magnetic_params) > 0: 
    2149             self._has_magnetic = True 
     2153            self._has_magnetic = True  
    21502154        else: 
    2151             self._has_magnetic = False 
     2155            self._has_magnetic = False   
    21522156        ## post state to fit panel 
    21532157        self.state.parameters = [] 
     
    21592163        self.on_set_focus(None) 
    21602164        self.Layout() 
    2161  
     2165         
    21622166    def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 
    21632167        """ 
    21642168        Verify that the Q range controls have valid values 
    21652169        and that Qmin < Qmax. 
    2166  
     2170         
    21672171        :param qmin_ctrl: text control for Qmin 
    21682172        :param qmax_ctrl: text control for Qmax 
    2169  
     2173         
    21702174        :return: True is the Q range is value, False otherwise 
    2171  
     2175         
    21722176        """ 
    21732177        qmin_validity = check_float(qmin_ctrl) 
     
    21932197                return False 
    21942198        return True 
    2195  
     2199     
    21962200    def _validate_Npts(self): 
    21972201        """ 
     
    22282232                self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 
    22292233                self.fitrange = True 
    2230  
     2234             
    22312235        return flag 
    22322236 
     
    22632267                self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 
    22642268                self.fitrange = True 
    2265  
     2269             
    22662270        return flag 
    2267  
     2271     
    22682272    def _check_value_enter(self, list, modified): 
    22692273        """ 
     
    22872291            #try: 
    22882292            name = str(item[1]) 
    2289  
     2293             
    22902294            if string.find(name, ".npts") == -1 and \ 
    22912295                                        string.find(name, ".nsigmas") == -1: 
     
    22932297                param_min = None 
    22942298                param_max = None 
    2295  
     2299                
    22962300                ## check minimun value 
    22972301                if item[5] != None and item[5] != "": 
     
    23022306                                if numpy.isfinite(param_min): 
    23032307                                    item[2].SetValue(format_number(param_min)) 
    2304  
     2308                             
    23052309                            item[5].SetBackgroundColour(wx.WHITE) 
    23062310                            item[2].SetBackgroundColour(wx.WHITE) 
    2307  
     2311                                            
    23082312                        except: 
    23092313                            msg = "Wrong fit parameter range entered" 
     
    23202324                                if numpy.isfinite(param_max): 
    23212325                                    item[2].SetValue(format_number(param_max)) 
    2322  
     2326                             
    23232327                            item[6].SetBackgroundColour(wx.WHITE) 
    23242328                            item[2].SetBackgroundColour(wx.WHITE) 
     
    23292333                            raise ValueError, msg 
    23302334                        is_modified = True 
    2331  
     2335                 
    23322336                if param_min != None and param_max != None: 
    23332337                    if not self._validate_qrange(item[5], item[6]): 
     
    23362340                        wx.PostEvent(self._manager.parent, 
    23372341                                     StatusEvent(status=msg)) 
    2338  
     2342                 
    23392343                if name in self.model.details.keys(): 
    23402344                    self.model.details[name][1:3] = param_min, param_max 
     
    23572361                msg = "Wrong Fit parameter value entered " 
    23582362                wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    2359  
     2363                 
    23602364        return is_modified 
    2361  
     2365         
    23622366    def _set_dipers_Param(self, event): 
    23632367        """ 
     
    23782382 
    23792383        self._reset_dispersity() 
    2380  
     2384     
    23812385        if self.model == None: 
    23822386            self.model_disp.Hide() 
     
    23862390        if self.enable_disp.GetValue(): 
    23872391            ## layout for model containing no dispersity parameters 
    2388  
     2392             
    23892393            self.disp_list = self.model.getDispParamList() 
    2390  
     2394              
    23912395            if len(self.disp_list) == 0 and len(self.disp_cb_dict) == 0: 
    23922396                self._layout_sizer_noDipers() 
     
    23962400        else: 
    23972401            self.sizer4_4.Clear(True) 
    2398  
     2402             
    23992403        ## post state to fit panel 
    24002404        self.save_current_state() 
     
    24082412        self.Layout() 
    24092413        self.Refresh() 
    2410  
     2414           
    24112415    def _layout_sizer_noDipers(self): 
    24122416        """ 
     
    24182422        self.fixed_param = [] 
    24192423        self.orientation_params_disp = [] 
    2420  
     2424         
    24212425        self.sizer4_4.Clear(True) 
    24222426        text = "No polydispersity available for this model" 
     
    24262430        self.sizer4_4.Layout() 
    24272431        self.sizer4.Layout() 
    2428  
     2432     
    24292433    def _reset_dispersity(self): 
    24302434        """ 
     
    24392443                if item in self.param_toFit: 
    24402444                    self.param_toFit.remove(item) 
    2441  
     2445          
    24422446        self.fittable_param = [] 
    24432447        self.fixed_param = [] 
     
    24452449        self.values = {} 
    24462450        self.weights = {} 
    2447  
    2448         from sas.models.dispersion_models import GaussianDispersion 
     2451       
     2452        #from sas.models.dispersion_models import GaussianDispersion 
     2453        from sasmodels.weights import GaussianDispersion 
    24492454        if len(self.disp_cb_dict) == 0: 
    24502455            self.save_current_state() 
     
    24572462                # Go back to Gaussian model (with 0 pts) 
    24582463                disp_model = GaussianDispersion() 
    2459  
     2464                
    24602465                self._disp_obj_dict[p] = disp_model 
    24612466                # Set the new model as the dispersion object 
     
    24702475        self.Layout() 
    24712476        self.Refresh() 
    2472  
     2477                   
    24732478    def _on_select_Disp(self, event): 
    24742479        """ 
     
    24832488        event = PageInfoEvent(page=self) 
    24842489        wx.PostEvent(self.parent, event) 
    2485  
     2490         
    24862491        self.sizer4_4.Layout() 
    24872492        self.sizer4.Layout() 
    24882493        self.SetupScrolling() 
    2489  
     2494     
    24902495    def _on_disp_func(self, event=None): 
    24912496        """ 
    24922497        Select a distribution function for the polydispersion 
    2493  
     2498         
    24942499        :Param event: ComboBox event 
    24952500        """ 
     
    25072512            disp_name = disp_box.GetValue() 
    25082513            dispersity = disp_box.GetClientData(selection) 
    2509  
     2514     
    25102515            #disp_model =  GaussianDispersion() 
    25112516            disp_model = dispersity() 
     
    25252530                self.model.set_dispersion(param_name, disp_model) 
    25262531                self.state._disp_obj_dict[name1] = disp_model 
    2527  
     2532  
    25282533                value1 = str(format_number(self.model.getParam(name1), True)) 
    25292534                value2 = str(format_number(self.model.getParam(name2))) 
     
    25532558            for item in self.fixed_param: 
    25542559                if item[1] == name2: 
    2555                     item[2].SetValue(value2) 
     2560                    item[2].SetValue(value2)  
    25562561                    # Disable Npts for array 
    25572562                    if disp_name.lower() == "array": 
     
    25662571                    else: 
    25672572                        item[2].Enable() 
    2568  
     2573                 
    25692574            # Make sure the check box updated when all checked 
    25702575            if self.cb1.GetValue(): 
     
    25872592            wx.PostEvent(self._manager.parent, 
    25882593                         StatusEvent(status=msg, info="error")) 
    2589  
     2594         
    25902595    def _set_array_disp(self, name=None, disp=None): 
    25912596        """ 
    25922597        Set array dispersion 
    2593  
     2598         
    25942599        :param name: name of the parameter for the dispersion to be set 
    25952600        :param disp: the polydisperion object 
     
    26082613        self._default_save_location = os.path.dirname(path) 
    26092614        if self._manager != None: 
    2610             self._manager.parent._default_save_location = \ 
     2615            self._manager.parent._default_save_location =\ 
    26112616                             self._default_save_location 
    26122617 
    26132618        basename = os.path.basename(path) 
    26142619        values, weights = self.read_file(path) 
    2615  
     2620         
    26162621        # If any of the two arrays is empty, notify the user that we won't 
    26172622        # proceed 
     
    26262631                                    values=values, weights=weights) 
    26272632        return basename 
    2628  
     2633     
    26292634    def _set_array_disp_model(self, name=None, disp=None, 
    26302635                              values=[], weights=[]): 
    26312636        """ 
    26322637        Set array dispersion model 
    2633  
     2638         
    26342639        :param name: name of the parameter for the dispersion to be set 
    26352640        :param disp: the polydisperion object 
     
    26602665        self.state.model._persistency_dict[name.split('.')[0]] = \ 
    26612666                                        [values, weights] 
    2662  
     2667                                         
    26632668    def _del_array_values(self, name=None): 
    26642669        """ 
    26652670        Reset array dispersion 
    2666  
     2671         
    26672672        :param name: name of the parameter for the dispersion to be set 
    26682673        """ 
     
    26782683        except: 
    26792684            logging.error(sys.exc_info()[1]) 
    2680  
     2685                                             
    26812686    def _lay_out(self): 
    26822687        """ 
    26832688        returns self.Layout 
    2684  
     2689         
    26852690        :Note: Mac seems to like this better when self. 
    26862691            Layout is called after fitting. 
     
    26892694        self.Layout() 
    26902695        return 
    2691  
     2696     
    26922697    def _sleep4sec(self): 
    26932698        """ 
     
    26982703        if ON_MAC == True: 
    26992704            time.sleep(1) 
    2700  
     2705             
    27012706    def _find_polyfunc_selection(self, disp_func=None): 
    27022707        """ 
    27032708        FInd Comboox selection from disp_func 
    2704  
     2709         
    27052710        :param disp_function: dispersion distr. function 
    27062711        """ 
     
    27162721        except: 
    27172722            return 3 
    2718  
     2723                             
    27192724    def on_reset_clicked(self, event): 
    27202725        """ 
     
    27282733            flag = False 
    27292734            return 
    2730  
     2735             
    27312736        elif self.data.__class__.__name__ == "Data2D": 
    27322737            data_min = 0 
     
    27342739            y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) 
    27352740            self.qmin_x = data_min 
    2736             self.qmax_x = math.sqrt(x * x + y * y) 
     2741            self.qmax_x = math.sqrt(x*x + y*y) 
    27372742            #self.data.mask = numpy.ones(len(self.data.data),dtype=bool) 
    27382743            # check smearing 
     
    27442749                else: 
    27452750                    flag = True 
    2746  
     2751                     
    27472752        elif self.data == None: 
    27482753            self.qmin_x = _QMIN_DEFAULT 
     
    27502755            self.num_points = _NPTS_DEFAULT 
    27512756            self.state.npts = self.num_points 
    2752  
     2757             
    27532758        elif self.data.__class__.__name__ != "Data2D": 
    27542759            self.qmin_x = min(self.data.x) 
     
    27662771        else: 
    27672772            flag = False 
    2768  
     2773             
    27692774        if flag == False: 
    27702775            msg = "Cannot Plot :Must enter a number!!!  " 
     
    27832788        self.state.qmin = self.qmin_x 
    27842789        self.state.qmax = self.qmax_x 
    2785  
     2790         
    27862791        #reset the q range values 
    27872792        self._reset_plotting_range(self.state) 
    27882793        self._draw_model() 
    2789  
     2794         
    27902795    def select_log(self, event): 
    27912796        """ 
     
    27962801        """ 
    27972802        Get the images of the plots corresponding this panel for report 
    2798  
     2803         
    27992804        : return graphs: list of figures 
    28002805        : Need Move to guiframe 
     
    28202825                        # append to the list 
    28212826                        graphs.append(item2.figure) 
    2822                         canvases.append(item2.canvas) 
     2827                        canvases.append(item2.canvas)   
    28232828            except: 
    28242829                # Not for control panels 
     
    28702875        :param evt: on Description Button pressed event 
    28712876        """ 
    2872  
     2877         
    28732878        if self.model == None: 
    28742879            name = 'index.html' 
     
    28762881            name = self.formfactorbox.GetValue() 
    28772882 
    2878         msg = 'Model description:\n' 
     2883                msg = 'Model description:\n' 
    28792884        info = "Info" 
    28802885        if self.model != None: 
    28812886#                frame.Destroy() 
    2882             if str(self.model.description).rstrip().lstrip() == '': 
    2883                 msg += "Sorry, no information is available for this model." 
     2887                if str(self.model.description).rstrip().lstrip() == '': 
     2888                    msg += "Sorry, no information is available for this model." 
     2889                else: 
     2890                    msg += self.model.description + '\n' 
     2891                wx.MessageBox(msg, info) 
    28842892            else: 
    2885                 msg += self.model.description + '\n' 
    2886             wx.MessageBox(msg, info) 
    2887         else: 
    28882893            msg += "You must select a model to get information on this" 
    28892894            wx.MessageBox(msg, info) 
     
    29092914                                          "Magnetic Angle Defintions") 
    29102915 
    2911     def _on_mag_help(self, event): 
     2916    def _on_mag_help(self, event):     
    29122917        """ 
    29132918        Bring up Magnetic Angle definition bmp image whenever the ? button 
     
    29292934                                          "Polarized Beam/Magnetc Help") 
    29302935 
    2931     def _on_mag_on(self, event): 
     2936    def _on_mag_on(self, event):     
    29322937        """ 
    29332938        Magnetic Parameters ON/OFF 
     
    29502955                    #reset mag value to zero fo safety 
    29512956                    self.model.setParam(key, 0.0) 
    2952  
    2953         self.Show(False) 
     2957                     
     2958        self.Show(False)     
    29542959        self.set_model_param_sizer(self.model) 
    29552960        #self._set_sizer_dispersion()  
     
    29572962        self.SetupScrolling() 
    29582963        self.Show(True) 
    2959  
     2964             
    29602965    def on_pd_help_clicked(self, event): 
    29612966        """ 
     
    29672972        webbrowser does not pass anything past the # to the browser when it is 
    29682973        running "file:///...." 
    2969  
     2974         
    29702975        :param evt: Triggers on clicking ? in polydispersity box 
    29712976        """ 
     
    29752980        _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, 
    29762981                                          _PageAnchor, "Polydispersity Help") 
    2977  
     2982         
    29782983    def on_left_down(self, event): 
    29792984        """ 
     
    29902995        # make event free 
    29912996        event.Skip() 
    2992  
     2997         
    29932998    def get_copy(self): 
    29942999        """ 
     
    29993004        self._copy_info(flag) 
    30003005        return flag 
    3001  
     3006             
    30023007    def get_copy_params(self): 
    30033008        """ 
     
    30073012        # Do it if params exist 
    30083013        if  self.parameters != []: 
    3009  
     3014             
    30103015            # go through the parameters 
    30113016            strings = self._get_copy_helper(self.parameters, 
    30123017                                           self.orientation_params) 
    30133018            content += strings 
    3014  
     3019             
    30153020            # go through the fittables 
    30163021            strings = self._get_copy_helper(self.fittable_param, 
     
    30223027                                           self.orientation_params_disp) 
    30233028            content += strings 
    3024  
     3029                 
    30253030            # go through the str params 
    30263031            strings = self._get_copy_helper(self.str_parameters, 
     
    30553060                content += param[1] #parameter name 
    30563061                content += tab 
    3057                 content += param[1] + "_err" 
     3062                content += param[1]+"_err" 
    30583063                content += tab 
    30593064 
     
    30633068            for param in self.parameters: 
    30643069                content += param[2].GetValue() #value 
    3065                 content += tab 
     3070                content +=tab 
    30663071                content += param[4].GetValue() #error 
    3067                 content += tab 
     3072                content +=tab 
    30683073 
    30693074            return content 
     
    31013106 
    31023107            for index, param in enumerate(self.parameters): 
    3103                 content += param[1].replace('_', '\_') #parameter name 
     3108                content += param[1].replace('_','\_') #parameter name 
    31043109                content += ' & ' 
    3105                 content += param[1].replace('_', '\_') + "\_err" 
    3106                 if index < len(self.parameters) - 1: 
     3110                content += param[1].replace('_','\_')+"\_err" 
     3111                if index < len(self.parameters)-1: 
    31073112                    content += ' & ' 
    31083113            content += '\\\\ \\hline' 
     
    31143119                content += ' & ' 
    31153120                content += param[4].GetValue() #parameter error 
    3116                 if index < len(self.parameters) - 1: 
     3121                if index < len(self.parameters)-1: 
    31173122                    content += ' & ' 
    31183123            content += '\\\\ \\hline' 
     
    31373142            return True 
    31383143        return None 
    3139  
     3144     
    31403145    def _get_copy_helper(self, param, orient_param): 
    31413146        """ 
    31423147        Helping get value and name of the params 
    3143  
     3148         
    31443149        : param param:  parameters 
    31453150        : param orient_param = oritational params 
     
    31583163            except: 
    31593164                logging.error(sys.exc_info()[1]) 
    3160  
     3165             
    31613166            # 2D 
    31623167            if self.data.__class__.__name__ == "Data2D": 
     
    31803185            # add to the content 
    31813186            if disfunc != '': 
    3182  
     3187                 
    31833188                disfunc = ',' + disfunc 
    31843189            # Need to support array func for copy/paste 
     
    31963201 
    31973202        return content 
    3198  
     3203    
    31993204    def get_clipboard(self): 
    32003205        """ 
     
    32163221            wx.TheClipboard.Close() 
    32173222        return text 
    3218  
     3223     
    32193224    def get_paste(self): 
    32203225        """ 
     
    32253230        self._copy_info(flag) 
    32263231        return flag 
    3227  
     3232         
    32283233    def get_paste_params(self, text=''): 
    32293234        """ 
     
    32543259                    val = [float(a_val) for a_val in array_values[1:]] 
    32553260                    weit = [float(a_weit) for a_weit in array_weights[1:]] 
    3256  
     3261                     
    32573262                    context[name].append(val) 
    32583263                    context[name].append(weit) 
     
    32773282            self._get_paste_helper(self.fixed_param, 
    32783283                                   self.orientation_params_disp, context) 
    3279  
     3284             
    32803285            # go through the str params 
    32813286            self._get_paste_helper(self.str_parameters, 
    32823287                                   self.orientation_params, context) 
    3283  
     3288                 
    32843289            return True 
    32853290        return None 
    3286  
     3291     
    32873292    def _get_paste_helper(self, param, orient_param, content): 
    32883293        """ 
    32893294        Helping set values of the params 
    3290  
     3295         
    32913296        : param param:  parameters 
    32923297        : param orient_param: oritational params 
     
    33163321                            fun_val = self.model.fun_list[content[name][1]] 
    33173322                            self.model.setParam(name, fun_val) 
    3318  
     3323                     
    33193324                    value = content[name][1:] 
    33203325                    self._paste_poly_help(item, value) 
     
    33623367                        if is_true != None: 
    33633368                            item[0].SetValue(is_true) 
    3364  
     3369                         
    33653370    def _paste_poly_help(self, item, value): 
    33663371        """ 
    33673372        Helps get paste for poly function 
    3368  
     3373         
    33693374        :param item: Gui param items 
    33703375        :param value: the values for parameter ctrols 
     
    34063411                                            [self.state.values, 
    34073412                                             self.state.weights] 
    3408  
     3413                          
    34093414            except: 
    34103415                logging.error(sys.exc_info()[1]) 
    34113416                print "Error in BasePage._paste_poly_help: %s" % \ 
    34123417                                        sys.exc_info()[1] 
    3413  
     3418     
    34143419    def _set_disp_array_cb(self, item): 
    34153420        """ 
     
    34253430        item[6].SetValue('') 
    34263431        item[6].Enable(False) 
    3427  
     3432         
    34283433    def update_pinhole_smear(self): 
    34293434        """ 
     
    34473452            if not os.path.isfile(categorization_file): 
    34483453                categorization_file = CategoryInstaller.get_default_file() 
    3449             cat_file = open(categorization_file, 'rb') 
     3454            cat_file = open(categorization_file, 'rb')                            
    34503455            self.master_category_dict = json.load(cat_file) 
    34513456            self._regenerate_model_dict() 
     
    34593464    def _regenerate_model_dict(self): 
    34603465        """ 
    3461         regenerates self.by_model_dict which has each model name as the 
     3466        regenerates self.by_model_dict which has each model name as the  
    34623467        key and the list of categories belonging to that model 
    34633468        along with the enabled mapping 
     
    34683473                self.by_model_dict[model].append(category) 
    34693474                self.model_enabled_dict[model] = enabled 
    3470  
     3475     
    34713476    def _populate_listbox(self): 
    34723477        """ 
     
    34803485        if not uncat_str in cat_list: 
    34813486            cat_list.append(uncat_str) 
    3482  
     3487         
    34833488        for category in cat_list: 
    34843489            if category != '': 
     
    34883493            self.categorybox.SetSelection(0) 
    34893494        else: 
    3490             self.categorybox.SetSelection(\ 
     3495            self.categorybox.SetSelection( \ 
    34913496                self.categorybox.GetSelection()) 
    34923497        #self._on_change_cat(None) 
     
    35083513 
    35093514        else: 
    3510             for (model, enabled) in sorted(self.master_category_dict[category], 
    3511                                       key=lambda name: name[0]): 
     3515            for (model,enabled) in sorted(self.master_category_dict[category], 
     3516                                      key = lambda name: name[0]): 
    35123517                if(enabled): 
    35133518                    self.model_box.Append(model) 
     
    35393544        hint = "toggle view of model from 1D to 2D  or 2D to 1D" 
    35403545        self.model_view.SetToolTipString(hint) 
    3541  
     3546         
    35423547        cat_set_box = wx.StaticBox(self, -1, 'Category') 
    35433548        sizer_cat_box = wx.StaticBoxSizer(cat_set_box, wx.HORIZONTAL) 
    35443549        sizer_cat_box.SetMinSize((200, 50)) 
    35453550        self.categorybox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    3546         self.categorybox.SetToolTip(wx.ToolTip("Select a Category/Type")) 
     3551        self.categorybox.SetToolTip( wx.ToolTip("Select a Category/Type") ) 
    35473552        self._populate_listbox() 
    35483553        wx.EVT_COMBOBOX(self.categorybox, -1, self._show_combox) 
     
    35533558        #self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") 
    35543559        #self.plugin_rbutton = wx.RadioButton(self, -1, "Uncategorized") 
    3555  
     3560                 
    35563561        #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
    35573562        #                   id=self.shape_rbutton.GetId()) 
     
    35633568        #                    id=self.plugin_rbutton.GetId()) 
    35643569        #MAC needs SetValue 
    3565  
     3570         
    35663571        show_cat_button = wx.Button(self, -1, "Modify") 
    35673572        cat_tip = "Modify model categories \n" 
    35683573        cat_tip += "(also accessible from the menu bar)." 
    3569         show_cat_button.SetToolTip(wx.ToolTip(cat_tip)) 
     3574        show_cat_button.SetToolTip( wx.ToolTip(cat_tip) ) 
    35703575        show_cat_button.Bind(wx.EVT_BUTTON, self._on_modify_cat) 
    35713576        sizer_cat_box.Add(self.categorybox, 1, wx.RIGHT, 3) 
    3572         sizer_cat_box.Add((10, 10)) 
     3577        sizer_cat_box.Add((10,10)) 
    35733578        sizer_cat_box.Add(show_cat_button) 
    35743579        #self.shape_rbutton.SetValue(True) 
    3575  
     3580       
    35763581        sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) 
    35773582        #sizer_radiobutton.Add(self.shape_rbutton) 
    35783583        #sizer_radiobutton.Add(self.shape_indep_rbutton) 
    3579         sizer_radiobutton.Add((5, 5)) 
     3584        sizer_radiobutton.Add((5,5)) 
    35803585        sizer_radiobutton.Add(self.model_view, 1, wx.RIGHT, 5) 
    35813586        #sizer_radiobutton.Add(self.plugin_rbutton) 
     
    35893594        sizer_selection = wx.BoxSizer(wx.HORIZONTAL) 
    35903595        mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) 
    3591  
     3596         
    35923597        self.text1 = wx.StaticText(self, -1, "") 
    35933598        self.text2 = wx.StaticText(self, -1, "P(Q)*S(Q)") 
     
    35983603 
    35993604        self.formfactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    3600         self.formfactorbox.SetToolTip(wx.ToolTip("Select a Model")) 
     3605        self.formfactorbox.SetToolTip( wx.ToolTip("Select a Model") ) 
    36013606        if self.model != None: 
    36023607            self.formfactorbox.SetValue(self.model.name) 
     
    36123617            print "_set_model_sizer_selection: disabled." 
    36133618            #self._set_model_sizer_selection(self.model) 
    3614  
     3619         
    36153620        sizer_selection.Add(self.text1) 
    36163621        sizer_selection.Add((10, 5)) 
     
    36203625        sizer_selection.Add((5, 5)) 
    36213626        sizer_selection.Add(self.structurebox) 
    3622  
     3627        
    36233628        mutifactor_selection.Add((13, 5)) 
    36243629        mutifactor_selection.Add(self.mutifactor_text) 
     
    36343639        boxsizer1.Add((10, 10)) 
    36353640        boxsizer1.Add(mutifactor_selection) 
    3636  
     3641         
    36373642        self._set_multfactor_combobox() 
    36383643        self.multifactorbox.SetSelection(1) 
     
    36403645        sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    36413646        sizer.Layout() 
    3642  
     3647         
    36433648    def on_smear_helper(self, update=False): 
    36443649        """ 
    36453650        Help for onSmear if implemented 
    3646  
     3651         
    36473652        :param update: force or not to update 
    36483653        """ 
     
    36533658    def onSmear(self, event): 
    36543659        """ 
    3655         Create a smear object if implemented 
     3660        Create a smear object if implemented  
    36563661        """ 
    36573662    def onPinholeSmear(self, event): 
  • src/sas/perspectives/fitting/fitpage.py

    r098f3d2 r098f3d2  
    3434    FitPanel class contains fields allowing to display results when 
    3535    fitting  a model and one data 
    36  
     36     
    3737    :note: For Fit to be performed the user should check at least one parameter 
    3838        on fit Panel window. 
     
    4444        """ 
    4545        BasicPage.__init__(self, parent, color=color) 
    46  
     46         
    4747        ## draw sizer 
    4848        self._fill_data_sizer() 
     
    7171        self.create_default_data() 
    7272        self._manager.frame.Bind(wx.EVT_SET_FOCUS, self.on_set_focus) 
    73  
     73     
    7474    def enable_fit_button(self): 
    7575        """ 
     
    111111        self.sizer0.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    112112        self.sizer0.Layout() 
    113  
     113         
    114114    def enable_datasource(self): 
    115115        """ 
     
    120120        else: 
    121121            self.dataSource.Enable() 
    122  
     122             
    123123    def fill_data_combobox(self, data_list): 
    124124        """ 
     
    155155        if len(data_list) == 1: 
    156156            self.dataSource.Disable() 
    157  
     157                 
    158158    def on_select_data(self, event=None): 
    159159        """ 
     
    167167            data = self.dataSource.GetClientData(pos) 
    168168            self.set_data(data) 
    169  
     169     
    170170    def _on_fit_complete(self): 
    171171        """ 
     
    174174        self.fit_started = False 
    175175        self.set_fitbutton() 
    176  
     176         
    177177    def _is_2D(self): 
    178178        """ 
    179179        Check if data_name is Data2D 
    180  
     180         
    181181        :return: True or False 
    182  
     182         
    183183        """ 
    184184        if self.data.__class__.__name__ == "Data2D" or \ 
     
    186186            return True 
    187187        return False 
    188  
     188             
    189189    def _fill_range_sizer(self): 
    190190        """ 
     
    195195        """ 
    196196        is_2Ddata = False 
    197  
     197         
    198198        # Check if data is 2D 
    199199        if self.data.__class__.__name__ == "Data2D" or \ 
    200200                        self.enable2D: 
    201201            is_2Ddata = True 
    202  
     202             
    203203        title = "Fitting" 
    204204        #smear messages & titles 
     
    217217        smear_message_slit_height_title = "Slit height[1/A]:" 
    218218        smear_message_slit_width_title = "Slit width[1/A]:" 
    219  
     219         
    220220        self._get_smear_info() 
    221  
     221         
    222222        #Sizers 
    223223        box_description_range = wx.StaticBox(self, -1, str(title)) 
     
    232232        sizer_smearer_box = wx.StaticBoxSizer(smear_set_box, wx.HORIZONTAL) 
    233233        sizer_smearer_box.SetMinSize((_DATA_BOX_WIDTH, 60)) 
    234  
     234         
    235235        weighting_set_box = wx.StaticBox(self, -1, \ 
    236236                                'Set Weighting by Selecting dI Source') 
     
    267267        self.dI_idata.Enable(False) 
    268268        weighting_box.Add(sizer_weighting) 
    269  
     269         
    270270        # combobox for smear2d accuracy selection 
    271271        self.smear_accuracy = wx.ComboBox(self, -1, size=(50, -1), 
     
    276276        self.smear_accuracy.SetToolTipString(\ 
    277277            "'Higher' uses more Gaussian points for smearing computation.") 
    278  
     278                    
    279279        wx.EVT_COMBOBOX(self.smear_accuracy, -1, self._on_select_accuracy) 
    280280 
     
    284284        self.btFit.Bind(wx.EVT_BUTTON, self._onFit, id=self.btFit.GetId()) 
    285285        self.btFit.SetToolTipString("Start fitting.") 
    286  
     286         
    287287        #General Help button 
    288288        self.btFitHelp = wx.Button(self, -1, 'Help') 
     
    324324        ## smear 
    325325        self.smear_data_left = BGTextCtrl(self, -1, 
    326                                           size=(_BOX_WIDTH - 25, 20), style=0) 
     326                                         size=(_BOX_WIDTH - 25, 20), style=0) 
    327327        self.smear_data_left.SetValue(str(self.dq_l)) 
    328328        self.smear_data_right = BGTextCtrl(self, -1, 
    329                                            size=(_BOX_WIDTH - 25, 20), style=0) 
     329                                        size=(_BOX_WIDTH - 25, 20), style=0) 
    330330        self.smear_data_right.SetValue(str(self.dq_r)) 
    331331 
     
    359359                  id=self.slit_smearer.GetId()) 
    360360        self.disable_smearer.SetValue(True) 
    361  
     361         
    362362        sizer_smearer.Add(self.disable_smearer, 0, wx.LEFT, 10) 
    363363        sizer_smearer.Add(self.enable_smearer) 
     
    366366        sizer_smearer.Add(self.btSmearHelp) 
    367367        sizer_smearer.Add((10, 10)) 
    368  
     368         
    369369        # StaticText for chi2, N(for fitting), Npts + Log/linear spacing 
    370370        self.tcChi = BGTextCtrl(self, -1, "-", size=(75, 20), style=0) 
     
    374374                            " Npts : number of points selected for fitting") 
    375375        self.Npts_total = ModelTextCtrl(self, -1, 
    376                             size=(_BOX_WIDTH, 20), 
    377                             style=wx.TE_PROCESS_ENTER, 
    378                             text_enter_callback=self._onQrangeEnter) 
     376                        size=(_BOX_WIDTH, 20), 
     377                        style=wx.TE_PROCESS_ENTER, 
     378                        text_enter_callback=self._onQrangeEnter) 
    379379        self.Npts_total.SetValue(format_number(self.npts_x)) 
    380380        self.Npts_total.SetToolTipString(\ 
    381381                                " Total Npts : total number of data points") 
    382  
     382                 
    383383        # Update and Draw button 
    384384        self.draw_button = wx.Button(self, wx.NewId(), 'Compute') 
     
    386386                              self._onDraw, id=self.draw_button.GetId()) 
    387387        self.draw_button.SetToolTipString("Compute and Draw.") 
    388  
    389         self.points_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     388         
     389        self.points_sizer = wx.BoxSizer(wx.HORIZONTAL)  
    390390        self.pointsbox = wx.CheckBox(self, -1, 'Log?', (10, 10)) 
    391391        self.pointsbox.SetValue(False) 
    392392        self.pointsbox.SetToolTipString("Check mark to use log spaced points") 
    393393        wx.EVT_CHECKBOX(self, self.pointsbox.GetId(), self.select_log) 
    394  
     394         
    395395        self.points_sizer.Add(wx.StaticText(self, -1, 'Npts    ')) 
    396396        self.points_sizer.Add(self.pointsbox) 
     
    403403                                    smear_message_none, style=wx.ALIGN_LEFT) 
    404404        self.smear_description_dqdata = wx.StaticText(self, 
    405                                 - 1, smear_message_dqdata, style=wx.ALIGN_LEFT) 
     405                                -1, smear_message_dqdata, style=wx.ALIGN_LEFT) 
    406406        self.smear_description_type = wx.StaticText(self, 
    407                                      - 1, "Type:", style=wx.ALIGN_LEFT) 
     407                                     -1, "Type:", style=wx.ALIGN_LEFT) 
    408408        self.smear_description_accuracy_type = wx.StaticText(self, -1, 
    409409                                        "Accuracy:", style=wx.ALIGN_LEFT) 
     
    434434        self.smear_description_slit_width = wx.StaticText(self, -1, 
    435435                        smear_message_slit_width_title, style=wx.ALIGN_LEFT) 
    436  
     436         
    437437        #arrange sizers 
    438438        self.sizer_set_smearer.Add(sizer_smearer) 
     
    467467        self.sizer_new_smear.Add((20, -1)) 
    468468        self.sizer_new_smear.Add(self.smear_description_2d_y, 
    469                                   0, wx.CENTER, 10) 
     469                                  0, wx.CENTER, 10 ) 
    470470        self.sizer_new_smear.Add(self.smear_description_pin_max, 
    471                                   0, wx.CENTER, 10) 
     471                                  0, wx.CENTER, 10 ) 
    472472        self.sizer_new_smear.Add(self.smear_description_slit_width, 
    473                                   0, wx.CENTER, 10) 
     473                                  0, wx.CENTER, 10 ) 
    474474 
    475475        self.sizer_new_smear.Add(self.smear_pinhole_max, 0, wx.CENTER, 10) 
    476476        self.sizer_new_smear.Add(self.smear_slit_width, 0, wx.CENTER, 10) 
    477477        self.sizer_new_smear.Add(self.smear_data_right, 0, wx.CENTER, 10) 
    478  
     478            
    479479        self.sizer_set_smearer.Add(self.smear_message_new_s, 0, wx.CENTER, 10) 
    480480        self.sizer_set_smearer.Add(self.smear_message_new_p, 0, wx.CENTER, 10) 
    481481        self.sizer_set_smearer.Add((5, 2)) 
    482482        self.sizer_set_smearer.Add(self.sizer_new_smear, 0, wx.CENTER, 10) 
    483  
     483         
    484484        # add all to chi2 sizer 
    485485        sizer_smearer_box.Add(self.sizer_set_smearer) 
     
    488488        sizer_chi2.Add(weighting_box) 
    489489        sizer_chi2.Add((-1, 5)) 
    490  
     490         
    491491        # hide all smear messages and textctrl 
    492492        self._hide_all_smear_info() 
    493  
     493         
    494494        # get smear_selection 
    495495        self.current_smearer = smear_selection(self.data, self.model) 
     
    512512        #2D data? default 
    513513        is_2Ddata = False 
    514  
     514         
    515515        #check if it is 2D data 
    516516        if self.data.__class__.__name__ == "Data2D" or self.enable2D: 
    517517            is_2Ddata = True 
    518  
     518             
    519519        self.sizer5.Clear(True) 
    520  
     520      
    521521        self.qmin = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
    522                                   style=wx.TE_PROCESS_ENTER, 
    523                                   set_focus_callback=self.qrang_set_focus, 
    524                                   text_enter_callback=self._onQrangeEnter, 
    525                                   name='qmin') 
     522                                    style=wx.TE_PROCESS_ENTER, 
     523                                    set_focus_callback=self.qrang_set_focus, 
     524                                    text_enter_callback=self._onQrangeEnter, 
     525                                    name='qmin') 
    526526        self.qmin.SetValue(str(self.qmin_x)) 
    527527        q_tip = "Click outside of the axes\n to remove the lines." 
     
    529529        qmin_tip += q_tip 
    530530        self.qmin.SetToolTipString(qmin_tip) 
    531  
     531      
    532532        self.qmax = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
    533                                   style=wx.TE_PROCESS_ENTER, 
    534                                   set_focus_callback=self.qrang_set_focus, 
    535                                   text_enter_callback=self._onQrangeEnter, 
    536                                   name='qmax') 
     533                                       style=wx.TE_PROCESS_ENTER, 
     534                                       set_focus_callback=self.qrang_set_focus, 
     535                                       text_enter_callback=self._onQrangeEnter, 
     536                                       name='qmax') 
    537537        self.qmax.SetValue(str(self.qmax_x)) 
    538538        qmax_tip = "Maximum value of Q.\n" 
     
    547547        wx_id = wx.NewId() 
    548548        self.reset_qrange = wx.Button(self, wx_id, 'Reset') 
    549  
     549       
    550550        self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked, id=wx_id) 
    551551        self.reset_qrange.SetToolTipString("Reset Q range to the default") 
    552  
     552      
    553553        sizer = wx.GridSizer(5, 5, 2, 6) 
    554554 
     
    558558        self.btEditMask.SetToolTipString("Edit Mask.") 
    559559        self.EditMask_title = wx.StaticText(self, -1, ' Masking(2D)') 
    560  
     560         
    561561        sizer.Add(wx.StaticText(self, -1, '   Q range')) 
    562562        sizer.Add(wx.StaticText(self, -1, ' Min[1/A]')) 
     
    598598        self.sizer5.Layout() 
    599599 
    600  
     600         
    601601    def _set_sizer_dispersion(self): 
    602602        """ 
     
    614614            ## the user didn't select dispersity display 
    615615            return 
    616  
     616             
    617617        self._reset_dispersity() 
    618  
     618         
    619619        ## fill a sizer with the combobox to select dispersion type 
    620620        model_disp = wx.StaticText(self, -1, 'Function') 
    621621        CHECK_STATE = self.cb1.GetValue() 
    622         import sas.models.dispersion_models 
    623         self.polydisp = sas.models.dispersion_models.models 
     622        #import sas.models.dispersion_models 
     623        #self.polydisp = sas.models.dispersion_models.models 
     624        import sasmodels.weights 
     625        self.polydisp = sasmodels.weights.models 
    624626 
    625627        ix = 0 
     
    644646        self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), \ 
    645647                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    646  
     648         
    647649        ix += 1 
    648650        self.text_disp_min = wx.StaticText(self, -1, 'Min') 
     
    654656        self.sizer4_4.Add(self.text_disp_max, (iy, ix), (1, 1), 
    655657                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    656  
     658        
    657659        ix += 1 
    658660        npts = wx.StaticText(self, -1, 'Npts') 
     
    672674        self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), 
    673675                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    674  
     676         
    675677        self.text_disp_max.Show(True) 
    676678        self.text_disp_min.Show(True) 
     
    692694                iy += 1 
    693695                for p in self.model.dispersion[item].keys(): 
    694  
     696         
    695697                    if p == "width": 
    696698                        ix = 0 
     
    704706                        value = self.model.getParam(name1) 
    705707                        ctl1 = ModelTextCtrl(self, -1, 
    706                                              size=(_BOX_WIDTH / 1.3, 20), 
    707                                              style=wx.TE_PROCESS_ENTER) 
     708                                                  size=(_BOX_WIDTH / 1.3, 20), 
     709                                                  style=wx.TE_PROCESS_ENTER) 
    708710                        ctl1.SetLabel('PD[ratio]') 
    709711                        poly_text = "Polydispersity (STD/mean) of %s\n" % item 
     
    725727                                           size=(_BOX_WIDTH / 1.3, 20), 
    726728                                           style=0) 
    727  
     729                   
    728730                        self.sizer4_4.Add(ctl2, (iy, ix), (1, 1), 
    729731                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    733735                        ix = 4 
    734736                        ctl3 = ModelTextCtrl(self, -1, 
    735                                              size=(_BOX_WIDTH / 2, 20), 
    736                                              style=wx.TE_PROCESS_ENTER, 
    737                             text_enter_callback=self._onparamRangeEnter) 
    738  
     737                                                  size=(_BOX_WIDTH / 2, 20), 
     738                                                  style=wx.TE_PROCESS_ENTER, 
     739                                text_enter_callback=self._onparamRangeEnter) 
     740                         
    739741                        self.sizer4_4.Add(ctl3, (iy, ix), (1, 1), 
    740742                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    741  
     743                        
    742744                        ix = 5 
    743745                        ctl4 = ModelTextCtrl(self, -1, 
    744                                              size=(_BOX_WIDTH / 2, 20), 
    745                                              style=wx.TE_PROCESS_ENTER, 
     746                                                  size=(_BOX_WIDTH / 2, 20), 
     747                                                  style=wx.TE_PROCESS_ENTER, 
    746748                            text_enter_callback=self._onparamRangeEnter) 
    747  
     749                         
    748750                        self.sizer4_4.Add(ctl4, (iy, ix), (1, 1), 
    749751                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    751753                        ctl3.Show(True) 
    752754                        ctl4.Show(True) 
    753  
     755                                                               
    754756                    elif p == "npts": 
    755757                        ix = 6 
    756758                        value = self.model.getParam(name2) 
    757759                        Tctl = ModelTextCtrl(self, -1, 
    758                                              size=(_BOX_WIDTH / 2.2, 20), 
    759                                              style=wx.TE_PROCESS_ENTER) 
    760  
     760                                                  size=(_BOX_WIDTH / 2.2, 20), 
     761                                                  style=wx.TE_PROCESS_ENTER) 
     762                         
    761763                        Tctl.SetValue(str(format_number(value))) 
    762764                        self.sizer4_4.Add(Tctl, (iy, ix), (1, 1), 
     
    768770                        value = self.model.getParam(name3) 
    769771                        Tct2 = ModelTextCtrl(self, -1, 
    770                                              size=(_BOX_WIDTH / 2.2, 20), 
    771                                              style=wx.TE_PROCESS_ENTER) 
    772  
     772                                                  size=(_BOX_WIDTH / 2.2, 20), 
     773                                                  style=wx.TE_PROCESS_ENTER) 
     774                         
    773775                        Tct2.SetValue(str(format_number(value))) 
    774776                        self.sizer4_4.Add(Tct2, (iy, ix), (1, 1), 
     
    789791                self.fittable_param.append([cb, name1, ctl1, text2, 
    790792                                            ctl2, ctl3, ctl4, disp_box]) 
    791  
     793                            
    792794        ix = 0 
    793795        iy += 1 
     
    806808                name2 = item + ".npts" 
    807809                name3 = item + ".nsigmas" 
    808  
     810                 
    809811                if not name1 in self.model.details: 
    810812                    self.model.details[name1] = ["", None, None] 
    811  
     813  
    812814                iy += 1 
    813815                for p in self.model.dispersion[item].keys(): 
    814  
     816         
    815817                    if p == "width": 
    816818                        ix = 0 
     
    829831                        value = self.model.getParam(name1) 
    830832                        ctl1 = ModelTextCtrl(self, -1, 
    831                                              size=(_BOX_WIDTH / 1.3, 20), 
    832                                              style=wx.TE_PROCESS_ENTER) 
     833                                                  size=(_BOX_WIDTH / 1.3, 20), 
     834                                                  style=wx.TE_PROCESS_ENTER) 
    833835                        poly_tip = "Absolute Sigma for %s." % item 
    834836                        ctl1.SetToolTipString(poly_tip) 
     
    844846                                poly_text += "It is the STD (ratio*mean)" 
    845847                                poly_text += " of the distribution.\n " 
    846  
     848                             
    847849                                values.SetToolTipString(poly_text) 
    848850                                first_orient = False 
     
    850852                        elif ctl1.IsShown(): 
    851853                            ctl1.Hide() 
    852  
     854                         
    853855                        self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 
    854856                        ## text to show error sign 
     
    864866                                           size=(_BOX_WIDTH / 1.3, 20), 
    865867                                           style=0) 
    866  
     868                     
    867869                        self.sizer4_4.Add(ctl2, (iy, ix), (1, 1), 
    868870                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     
    874876                                text2.Show(True) 
    875877                                ctl2.Show(True) 
    876  
     878                             
    877879                        ix = 4 
    878880                        ctl3 = ModelTextCtrl(self, -1, 
    879                                              size=(_BOX_WIDTH / 2, 20), 
    880                                              style=wx.TE_PROCESS_ENTER, 
     881                                                  size=(_BOX_WIDTH / 2, 20), 
     882                                                  style=wx.TE_PROCESS_ENTER, 
    881883                                text_enter_callback=self._onparamRangeEnter) 
    882884 
     
    885887 
    886888                        ctl3.Hide() 
    887  
     889                 
    888890                        ix = 5 
    889891                        ctl4 = ModelTextCtrl(self, -1, 
    890                                              size=(_BOX_WIDTH / 2, 20), 
    891                                              style=wx.TE_PROCESS_ENTER, 
     892                            size=(_BOX_WIDTH / 2, 20), 
     893                            style=wx.TE_PROCESS_ENTER, 
    892894                            text_enter_callback=self._onparamRangeEnter) 
    893895                        self.sizer4_4.Add(ctl4, (iy, ix), (1, 1), 
    894896                                          wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    895897                        ctl4.Hide() 
    896  
     898                         
    897899                        if self.data.__class__.__name__ == "Data2D" or \ 
    898900                                self.enable2D: 
    899901                            ctl3.Show(True) 
    900902                            ctl4.Show(True) 
    901  
     903                              
    902904                    elif p == "npts": 
    903905                        ix = 6 
    904906                        value = self.model.getParam(name2) 
    905907                        Tctl = ModelTextCtrl(self, -1, 
    906                                              size=(_BOX_WIDTH / 2.2, 20), 
    907                                              style=wx.TE_PROCESS_ENTER) 
    908  
     908                                                 size=(_BOX_WIDTH / 2.2, 20), 
     909                                                 style=wx.TE_PROCESS_ENTER) 
     910                         
    909911                        Tctl.SetValue(str(format_number(value))) 
    910912                        if self.data.__class__.__name__ == "Data2D" or \ 
     
    924926                        value = self.model.getParam(name3) 
    925927                        Tct2 = ModelTextCtrl(self, -1, 
    926                                              size=(_BOX_WIDTH / 2.2, 20), 
    927                                              style=wx.TE_PROCESS_ENTER) 
    928  
     928                                                  size=(_BOX_WIDTH / 2.2, 20), 
     929                                                  style=wx.TE_PROCESS_ENTER) 
     930                         
    929931                        Tct2.SetValue(str(format_number(value))) 
    930932                        if self.data.__class__.__name__ == "Data2D" or \ 
     
    938940                        self.fixed_param.append([None, name3, Tct2, 
    939941                                                 None, None, None, None, None]) 
    940  
     942                                                    
    941943                        self.orientation_params_disp.append([None, name3, 
    942944                                        Tct2, None, None, None, None, None]) 
     
    955957                self.orientation_params_disp.append([cb, name1, ctl1, 
    956958                                            text2, ctl2, ctl3, ctl4, disp_box]) 
    957  
     959                        
    958960                if self.data.__class__.__name__ == "Data2D" or \ 
    959961                                self.enable2D: 
     
    961963                else: 
    962964                    disp_box.Hide() 
    963  
     965         
    964966        self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 
    965  
     967           
    966968        self.state.model = self.model.clone() 
    967969        ## save state into 
     
    996998        """ 
    997999        flag = self._update_paramv_on_fit() 
    998  
     1000     
    9991001        wx.CallAfter(self._onparamEnter_helper) 
    10001002        if not flag: 
     
    10021004            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    10031005            return 
    1004  
     1006         
    10051007    def _onFit(self, event): 
    10061008        """ 
     
    10271029                         StatusEvent(status="Fit: %s" % msg, type="stop")) 
    10281030            return 
    1029  
     1031         
    10301032        if len(self.param_toFit) <= 0: 
    10311033            msg = "Select at least one parameter to fit" 
     
    10341036                         StatusEvent(status=msg, type="stop")) 
    10351037            return 
    1036  
     1038         
    10371039        flag = self._update_paramv_on_fit() 
    1038  
     1040         
    10391041        if self.batch_on and not self._is_2D(): 
    10401042            if not self._validate_Npts_1D(): 
    10411043                return 
    1042  
     1044                 
    10431045        if not flag: 
    10441046            msg = "Fitting range or parameters are invalid" 
     
    10461048                         StatusEvent(status=msg, type="stop")) 
    10471049            return 
    1048  
     1050               
    10491051        self.select_param(event=None) 
    10501052 
     
    10621064        self.fit_started = self._manager.onFit(uid=self.uid) 
    10631065        wx.CallAfter(self.set_fitbutton) 
    1064  
     1066     
    10651067    def _onFitHelp(self, event): 
    10661068        """ 
     
    11101112        if self.is_mac: 
    11111113            return 
    1112  
     1114         
    11131115        if self.fit_started: 
    11141116            label = "Stop" 
     
    11211123        self.btFit.SetForegroundColour(color) 
    11221124        self.btFit.Enable(True) 
    1123  
     1125                      
    11241126    def get_weight_flag(self): 
    11251127        """ 
     
    11431145                break 
    11441146        return flag 
    1145  
     1147                 
    11461148    def _StopFit(self, event=None): 
    11471149        """ 
     
    11531155        self._manager._reset_schedule_problem(value=0) 
    11541156        self._on_fit_complete() 
    1155  
     1157          
    11561158    def rename_model(self): 
    11571159        """ 
     
    11601162        if self.model is not None: 
    11611163            self.model.name = "M" + str(self.index_model) 
    1162  
     1164     
    11631165    def _on_select_model(self, event=None): 
    11641166        """ 
     
    11921194        self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 
    11931195        self.state.slit_smearer = self.slit_smearer.GetValue() 
    1194  
     1196     
    11951197        self.state.structurecombobox = self.structurebox.GetLabel() 
    11961198        self.state.formfactorcombobox = self.formfactorbox.GetLabel() 
     
    12081210                    self._keep.Enable(not self.batch_on) 
    12091211                    self._set_save_flag(True) 
    1210  
     1212     
    12111213            # more disables for 2D 
    12121214            self._set_smear_buttons() 
    1213  
     1215             
    12141216            try: 
    12151217                # update smearer sizer 
     
    12251227            ## event to post model to fit to fitting plugins 
    12261228            (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 
    1227  
     1229          
    12281230            ## set smearing value whether or not 
    12291231            #    the data contain the smearing info 
     
    12351237                            caption=self.window_caption, 
    12361238                            qmax=float(self.qmax_x)) 
    1237  
     1239    
    12381240            self._manager._on_model_panel(evt=evt) 
    1239             self.mbox_description.SetLabel("Model [ %s ]" % str(self.model.name)) 
     1241            self.mbox_description.SetLabel("Model [ %s ]"% str(self.model.name)) 
    12401242            self.mbox_description.SetForegroundColour(wx.BLUE) 
    12411243            self.state.model = self.model.clone() 
     
    12701272                self.get_paste_params(copy_flag) 
    12711273                wx.CallAfter(self._onDraw, None) 
    1272  
     1274                 
    12731275        else: 
    12741276            self._draw_model() 
    1275  
     1277             
    12761278        if self.batch_on: 
    12771279            self.slit_smearer.Enable(False) 
     
    12791281            self.btEditMask.Disable() 
    12801282            self.EditMask_title.Disable() 
    1281  
     1283             
    12821284        self.Show(True) 
    12831285        self.SetupScrolling() 
    1284  
     1286          
    12851287    def _onparamEnter(self, event): 
    12861288        """ 
     
    13251327                                              qmax=float(self.qmax_x), 
    13261328                                              enable_smearer=enable_smearer, 
    1327                                               draw=True) 
     1329                                            draw=True) 
    13281330                if flag: 
    13291331                    #self.compute_chisqr(smearer= temp_smearer) 
    1330  
     1332         
    13311333                    ## new state posted 
    13321334                    if self.state_change: 
     
    13431345            msg = "Cannot Plot :Must enter a number!!!  " 
    13441346            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    1345  
     1347              
    13461348        self.save_current_state() 
    13471349        return 
    1348  
     1350    
    13491351    def _onparamRangeEnter(self, event): 
    13501352        """ 
     
    13691371        else: 
    13701372            tcrtl.SetBackgroundColour(wx.WHITE) 
    1371  
     1373            
    13721374        #self._undo.Enable(True) 
    13731375        self.save_current_state() 
     
    13751377        wx.PostEvent(self.parent, event) 
    13761378        self.state_change = False 
    1377  
    1378     def qrang_set_focus(self, event=None): 
     1379         
     1380    def qrang_set_focus(self, event=None):   
    13791381        """ 
    13801382        ON Qrange focus 
     
    13841386        #tcrtl = event.GetEventObject() 
    13851387        self._validate_qrange(self.qmin, self.qmax) 
    1386  
     1388         
    13871389    def qrange_click(self, event): 
    13881390        """ 
     
    13981400            d_group_id = self.data.group_id 
    13991401            act_ctrl = event.GetEventObject() 
    1400             wx.PostEvent(self._manager.parent, 
    1401                          PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, 
     1402            wx.PostEvent(self._manager.parent,  
     1403                         PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id,  
    14021404                                     group_id=d_group_id, leftdown=is_click, 
    14031405                                     active=act_ctrl)) 
    1404  
     1406             
    14051407    def on_qrange_text(self, event): 
    14061408        """ 
     
    14141416        d_id = self.data.id 
    14151417        d_group_id = self.data.group_id 
    1416         wx.PostEvent(self._manager.parent, 
    1417                      PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, 
    1418                                      group_id=d_group_id, leftdown=False, 
     1418        wx.PostEvent(self._manager.parent,  
     1419                     PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id,  
     1420                                     group_id=d_group_id, leftdown=False,  
    14191421                                     active=act_ctrl)) 
    14201422        self._validate_qrange(self.qmin, self.qmax) 
    1421  
    1422     def on_key(self, event): 
     1423     
     1424    def on_key(self, event):    
    14231425        """ 
    14241426        On Key down 
     
    14311433            x_data = float(ctrl.GetValue()) 
    14321434        except: 
    1433             return 
     1435            return  
    14341436        key = event.GetKeyCode() 
    14351437        length = len(self.data.x) 
     
    14481450        ctrl.SetValue(str(self.data.x[indx])) 
    14491451        self._validate_qrange(self.qmin, self.qmax) 
    1450  
     1452                
    14511453    def _onQrangeEnter(self, event): 
    14521454        """ 
     
    15091511                              (self.data.x <= self.qmax_x)) 
    15101512                self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) 
    1511  
     1513             
    15121514            self.npts_x = self.Npts_total.GetValue() 
    15131515            self.create_default_data() 
     
    15171519            msg = "Model Error:wrong value entered!!!" 
    15181520            wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    1519  
     1521         
    15201522        self._draw_model() 
    15211523        self.save_current_state() 
     
    15241526        self.state_change = False 
    15251527        return 
    1526  
     1528     
    15271529    def _clear_Err_on_Fit(self): 
    15281530        """ 
     
    15541556                    if item[4] != None and item[4].IsShown(): 
    15551557                        item[4].Hide() 
    1556  
     1558   
    15571559        if len(self.fittable_param) > 0: 
    15581560            for item in self.fittable_param: 
     
    15741576                        item[4].Hide() 
    15751577        return 
    1576  
     1578                 
    15771579    def _get_defult_custom_smear(self): 
    15781580        """ 
     
    15881590        if self.dx_max == None: 
    15891591            self.dx_max = SMEAR_SIZE_H 
    1590  
     1592         
    15911593    def _get_smear_info(self): 
    15921594        """ 
    15931595        Get the smear info from data. 
    1594  
     1596        
    15951597        :return: self.smear_type, self.dq_l and self.dq_r, 
    15961598            respectively the type of the smear, dq_min and 
     
    16231625            self.dq_l = data.dx[0] 
    16241626            self.dq_r = data.dx[-1] 
    1625  
     1627             
    16261628        # check if it is slit smear and get min max if it is. 
    16271629        elif data.dxl != None or data.dxw != None: 
     
    16321634                self.dq_r = data.dxw[0] 
    16331635        #return self.smear_type,self.dq_l,self.dq_r 
    1634  
     1636     
    16351637    def _show_smear_sizer(self): 
    16361638        """ 
     
    16961698        self.smear_description_2d_y.Hide() 
    16971699        self.smear_description_2d.Hide() 
    1698  
     1700         
    16991701        self.smear_accuracy.Hide() 
    17001702        self.smear_data_left.Hide() 
     
    17101712        self.smear_message_new_p.Hide() 
    17111713        self.smear_message_new_s.Hide() 
    1712  
     1714     
    17131715    def _set_accuracy_list(self): 
    17141716        """ 
     
    17201722        for idx in range(len(list)): 
    17211723            self.smear_accuracy.Append(list[idx], idx) 
    1722  
     1724             
    17231725    def _set_fun_box_list(self, fun_box): 
    17241726        """ 
     
    17411743                    break 
    17421744            ind += 1 
    1743  
     1745         
    17441746    def _on_select_accuracy(self, event): 
    17451747        """ 
     
    17561758            if self.current_smearer != None: 
    17571759                self.current_smearer.set_accuracy(accuracy=\ 
    1758                                                   self.smear2d_accuracy) 
     1760                                                  self.smear2d_accuracy)  
    17591761        event.Skip() 
    17601762 
     
    17811783        # get ready for new event 
    17821784        event.Skip() 
    1783  
     1785         
    17841786    def _onMask(self, event): 
    17851787        """ 
     
    17881790        from sas.guiframe.local_perspectives.plotting.masking \ 
    17891791        import MaskPanel as MaskDialog 
    1790  
     1792         
    17911793        self.panel = MaskDialog(base=self, data=self.data, id=wx.NewId()) 
    17921794        self.panel.ShowModal() 
    1793  
     1795         
    17941796    def _draw_masked_model(self, event): 
    17951797        """ 
     
    18421844        """ 
    18431845        return self.enable2D 
    1844  
     1846     
    18451847    def compute_data_set_range(self, data_list): 
    18461848        """ 
     
    18551857                self.npts_data_set += npts 
    18561858        return self.qmin_data_set, self.qmax_data_set, self.npts_data_set 
    1857  
     1859         
    18581860    def compute_data_range(self, data): 
    18591861        """ 
     
    18711873                    npts = len(data.x) 
    18721874                except: 
    1873                     msg = "Unable to find min/max/length of \n data named %s" % \ 
    1874                                 data.filename 
     1875                    msg = "Unable to find min/max/length of \n data named %s"% \ 
     1876                                data.filename   
    18751877                    wx.PostEvent(self._manager.parent, StatusEvent(status=msg, 
    18761878                                               info="error")) 
    18771879                    raise ValueError, msg 
    1878  
     1880                     
    18791881            else: 
    18801882                qmin = 0 
     
    18831885                    y = max(math.fabs(data.ymin), math.fabs(data.ymax)) 
    18841886                except: 
    1885                     msg = "Unable to find min/max of \n data named %s" % \ 
    1886                                 data.filename 
     1887                    msg = "Unable to find min/max of \n data named %s"% \ 
     1888                                data.filename   
    18871889                    wx.PostEvent(self._manager.parent, StatusEvent(status=msg, 
    18881890                                               info="error")) 
     
    18921894                npts = len(data.data) 
    18931895        return qmin, qmax, npts 
    1894  
     1896             
    18951897    def set_data(self, data): 
    18961898        """ 
     
    19191921            self.graph_id = data.group_id 
    19201922        self.data.group_id = self.graph_id 
    1921  
     1923         
    19221924        if self.data is None: 
    19231925            data_name = "" 
     
    19291931                self._set_bookmark_flag(not self.batch_on) 
    19301932                self._keep.Enable(not self.batch_on) 
    1931             if self.data.is_data: 
     1933            if self.data.is_data:     
    19321934                self._set_save_flag(True) 
    19331935                self._set_preview_flag(True) 
     
    19671969            self.dI_sqrdata.Enable(True) 
    19681970            self.dI_idata.Enable(True) 
    1969  
     1971               
    19701972            self.formfactorbox.Enable() 
    19711973            self.structurebox.Enable() 
     
    19791981                self.btEditMask.Enable() 
    19801982                self.EditMask_title.Enable() 
    1981  
     1983     
    19821984        self.Npts_total.SetValue(str(npts)) 
    19831985        #default:number of data points selected to fit 
     
    19861988        self.Npts_total.SetBackgroundColour(\ 
    19871989                                    self.GetParent().GetBackgroundColour()) 
    1988  
     1990         
    19891991        self.Npts_total.Bind(wx.EVT_MOUSE_EVENTS, self._npts_click) 
    19901992        self.pointsbox.Disable() 
     
    19971999        if check_data_validity(data): 
    19982000            self.data_box_description.SetForegroundColour(wx.BLUE) 
    1999  
     2001         
    20002002        if self.batch_on: 
    20012003            self.slit_smearer.Enable(False) 
     
    20312033                                      title=str(self.data.title))) 
    20322034            self._draw_model() 
    2033  
     2035     
    20342036    def _npts_click(self, event): 
    20352037        """ 
     
    20382040        """ 
    20392041        pass 
    2040  
     2042     
    20412043    def reset_page(self, state, first=False): 
    20422044        """ 
     
    20452047        try: 
    20462048            self.reset_page_helper(state) 
    2047  
     2049     
    20482050            self.select_param(event=None) 
    20492051            #Save state_fit 
     
    20532055            msg = "Error: This model state has missing or outdated " 
    20542056            msg += "information.\n" 
    2055             msg += "%s" % (sys.exc_value) 
     2057            msg += "%s"% (sys.exc_value) 
    20562058            wx.PostEvent(self._manager.parent, 
    20572059                         StatusEvent(status=msg, info="error")) 
    20582060        self._lay_out() 
    20592061        self.Refresh() 
    2060  
     2062         
    20612063    def get_range(self): 
    20622064        """ 
     
    20642066        """ 
    20652067        return float(self.qmin_x), float(self.qmax_x) 
    2066  
     2068     
    20672069    def get_npts2fit(self): 
    20682070        """ 
    20692071        return numbers of data points within qrange 
    2070  
     2072         
    20712073        :Note: This is to normalize chisq by Npts of fit 
    2072  
     2074         
    20732075        """ 
    20742076        if self.data is None: 
     
    20952097        """ 
    20962098        self.Npts_fit.SetValue(str(self.get_npts2fit())) 
    2097  
     2099         
    20982100    def get_chi2(self): 
    20992101        """ 
     
    21012103        """ 
    21022104        return self.tcChi.GetValue() 
    2103  
     2105         
    21042106    def onsetValues(self, chisqr, p_name, out, cov): 
    21052107        """ 
    21062108        Build the panel from the fit result 
    2107  
     2109         
    21082110        :param chisqr: Value of the goodness of fit metric 
    21092111        :param p_name: the name of parameters 
    21102112        :param out: list of parameter with the best value found during fitting 
    21112113        :param cov: Covariance matrix 
    2112  
    2113         """ 
    2114  
     2114    
     2115        """ 
     2116         
    21152117        # make sure stop button to fit button all the time 
    21162118        self._on_fit_complete() 
    21172119        if out == None or not numpy.isfinite(chisqr): 
    21182120            raise ValueError, "Fit error occured..." 
    2119  
     2121         
    21202122        is_modified = False 
    21212123        has_error = False 
    21222124        dispersity = '' 
    2123  
     2125         
    21242126        #Hide textctrl boxes of errors. 
    21252127        self._clear_Err_on_Fit() 
    2126  
     2128         
    21272129        #Check if chi2 is finite 
    21282130        if chisqr != None and numpy.isfinite(chisqr): 
     
    21332135        else: 
    21342136            self.tcChi.SetValue("-") 
    2135  
     2137         
    21362138        #Hide error title 
    21372139        if self.text2_3.IsShown() and not self.is_mac: 
    21382140            self.text2_3.Hide() 
    2139  
     2141       
    21402142        try: 
    21412143            if self.enable_disp.GetValue(): 
     
    21462148            dispersity = None 
    21472149            pass 
    2148  
     2150       
    21492151        i = 0 
    21502152        #Set the panel when fit result are list 
     
    21642166                        val_out = format_number(out[ind], True) 
    21652167                        item[2].SetValue(val_out) 
    2166  
     2168     
    21672169                    if(cov != None and len(cov) == len(out)): 
    21682170                        try: 
     
    21762178                        except: 
    21772179                            pass 
    2178  
     2180                         
    21792181                        if cov[ind] != None: 
    21802182                            if numpy.isfinite(float(cov[ind])): 
    21812183                                val_err = format_number(cov[ind], True) 
    2182                                 item[4].SetForegroundColour(wx.BLACK) 
    2183                             else: 
    2184                                 val_err = 'NaN' 
     2184                                    item[4].SetForegroundColour(wx.BLACK) 
     2185                            else: 
     2186                                val_err = 'NaN' 
    21852187                                item[4].SetForegroundColour(wx.RED) 
    2186                             if not self.is_mac: 
    2187                                 item[3].Show(True) 
    2188                                 item[4].Show(True) 
    2189                             item[4].SetValue(val_err) 
    2190                             has_error = True 
     2188                                if not self.is_mac: 
     2189                                    item[3].Show(True) 
     2190                                    item[4].Show(True) 
     2191                                item[4].SetValue(val_err) 
     2192                                has_error = True 
    21912193                i += 1 
    21922194            else: 
     
    21982200        ## save current state 
    21992201        self.save_current_state() 
    2200  
     2202         
    22012203        if not self.is_mac: 
    22022204            self.Layout() 
     
    22052207        #plot model ( when drawing, do not update chisqr value again) 
    22062208        self._draw_model(update_chisqr=False, source='fit') 
    2207  
     2209     
    22082210    def onWeighting(self, event): 
    22092211        """ 
     
    22122214        self.weightbt_string = event.GetEventObject().GetLabelText() 
    22132215        self._set_weight() 
    2214  
     2216         
    22152217    def _set_weight(self, is_2D=None): 
    22162218        """ 
     
    22252227                                     is2d=is_2D, 
    22262228                                     fid=None) 
    2227  
     2229     
    22282230    def onPinholeSmear(self, event): 
    22292231        """ 
    22302232        Create a custom pinhole smear object that will change the way residuals 
    22312233        are compute when fitting 
    2232  
     2234         
    22332235        :Note: accuracy is given by strings'High','Med', 'Low' FOR 2d, 
    22342236                     None for 1D 
    2235  
     2237                      
    22362238        """ 
    22372239        # Need update param values 
     
    22542256        # hide all silt sizer 
    22552257        self._hide_all_smear_info() 
    2256  
     2258         
    22572259        # show relevant slit sizers 
    22582260        self._show_smear_sizer() 
     
    22602262        self.sizer_set_smearer.Layout() 
    22612263        self.Layout() 
    2262  
     2264         
    22632265        if event != None: 
    22642266            event.Skip() 
     
    22672269        event = PageInfoEvent(page=self) 
    22682270        wx.PostEvent(self.parent, event) 
    2269  
     2271         
    22702272    def _is_changed_pinhole(self): 
    22712273        """ 
    22722274        check if any of pinhole smear is changed 
    2273  
     2275         
    22742276        :return: True or False 
    2275  
     2277         
    22762278        """ 
    22772279        # get the values 
    22782280        pin_min = self.smear_pinhole_min.GetValue() 
    22792281        pin_max = self.smear_pinhole_max.GetValue() 
    2280  
     2282                     
    22812283        # Check changes in slit width 
    22822284        try: 
     
    22862288        if self.dx_min != dx_min: 
    22872289            return True 
    2288  
     2290         
    22892291        # Check changes in slit heigth 
    22902292        try: 
     
    22952297            return True 
    22962298        return False 
    2297  
     2299     
    22982300    def _set_pinhole_smear(self): 
    22992301        """ 
    23002302        Set custom pinhole smear 
    2301  
     2303         
    23022304        :return: msg 
    2303  
     2305         
    23042306        """ 
    23052307        # copy data 
     
    23172319            data.dxw = None 
    23182320        msg = None 
    2319  
     2321    
    23202322        get_pin_min = self.smear_pinhole_min 
    23212323        get_pin_max = self.smear_pinhole_max 
     
    23712373            get_pin_max.SetBackgroundColour("white") 
    23722374        ## set smearing value whether or not the data contain the smearing info 
    2373  
     2375         
    23742376        enable_smearer = not self.disable_smearer.GetValue() 
    23752377        self._manager.set_smearer(smearer=self.current_smearer, 
    2376                                   fid=self.data.id, 
    2377                                   qmin=float(self.qmin_x), 
    2378                                   qmax=float(self.qmax_x), 
     2378                            fid=self.data.id, 
     2379                            qmin=float(self.qmin_x), 
     2380                            qmax=float(self.qmax_x), 
    23792381                                  enable_smearer=enable_smearer, 
    2380                                   uid=self.uid) 
     2382                            uid=self.uid) 
    23812383        return msg 
    2382  
     2384         
    23832385    def update_pinhole_smear(self): 
    23842386        """ 
    23852387        called by kill_focus on pinhole TextCntrl 
    23862388        to update the changes 
    2387  
     2389         
    23882390        :return: False when wrong value was entered 
    2389  
     2391         
    23902392        """ 
    23912393        # msg default 
     
    24002402        else: 
    24012403            return True 
    2402  
     2404                      
    24032405    def onSlitSmear(self, event): 
    24042406        """ 
     
    24232425        else: 
    24242426            is_new_slit = True 
    2425  
     2427         
    24262428        # if any value is changed 
    24272429        if is_new_slit: 
    24282430            msg = self._set_slit_smear() 
    2429  
     2431             
    24302432        # hide all silt sizer 
    24312433        self._hide_all_smear_info() 
     
    24462448        """ 
    24472449        check if any of slit lengths is changed 
    2448  
     2450         
    24492451        :return: True or False 
    2450  
     2452         
    24512453        """ 
    24522454        # get the values 
    24532455        width = self.smear_slit_width.GetValue() 
    24542456        height = self.smear_slit_height.GetValue() 
    2455  
     2457         
    24562458        # check and change the box bg color if it was pink 
    24572459        #    but it should be white now 
     
    24612463        if width.lstrip().rstrip() == "": 
    24622464            self.smear_slit_width.SetBackgroundColour(wx.WHITE) 
    2463  
     2465             
    24642466        # Check changes in slit width 
    24652467        if width == "": 
     
    24722474        if self.dxw != dxw: 
    24732475            return True 
    2474  
     2476         
    24752477        # Check changes in slit heigth 
    24762478        if height == "": 
     
    24852487 
    24862488        return False 
    2487  
     2489     
    24882490    def _set_slit_smear(self): 
    24892491        """ 
    24902492        Set custom slit smear 
    2491  
     2493         
    24922494        :return: message to inform the user about the validity 
    24932495            of the values entered for slit smear 
     
    25022504        data.dxw = None 
    25032505        msg = None 
    2504  
     2506    
    25052507        try: 
    25062508            self.dxl = float(self.smear_slit_height.GetValue()) 
     
    25272529            else: 
    25282530                self.smear_slit_width.SetBackgroundColour(wx.WHITE) 
    2529  
     2531               
    25302532        self.current_smearer = smear_selection(data, self.model) 
    25312533        ## set smearing value whether or not the data contain the smearing info 
    25322534        enable_smearer = not self.disable_smearer.GetValue() 
    25332535        self._manager.set_smearer(smearer=self.current_smearer, 
    2534                                   fid=self.data.id, 
    2535                                   qmin=float(self.qmin_x), 
    2536                                   qmax=float(self.qmax_x), 
     2536                                 fid=self.data.id, 
     2537                                 qmin=float(self.qmin_x), 
     2538                                 qmax=float(self.qmax_x), 
    25372539                                  enable_smearer=enable_smearer, 
    2538                                   uid=self.uid) 
     2540                                 uid=self.uid) 
    25392541        return msg 
    2540  
     2542     
    25412543    def update_slit_smear(self): 
    25422544        """ 
    25432545        called by kill_focus on pinhole TextCntrl 
    25442546        to update the changes 
    2545  
     2547         
    25462548        :return: False when wrong value was entered 
    2547  
     2549         
    25482550        """ 
    25492551        # msg default 
     
    25592561        else: 
    25602562            return True 
    2561  
     2563                             
    25622564    def onSmear(self, event): 
    25632565        """ 
     
    25762578                self._manager.page_finder[self.uid].add_data(data=self.data) 
    25772579        temp_smearer = self.on_smear_helper() 
    2578  
     2580         
    25792581        self.sizer_set_smearer.Layout() 
    25802582        self.Layout() 
    25812583        self._set_weight() 
    2582  
     2584         
    25832585        ## set smearing value whether or not the data contain the smearing info 
    25842586        enable_smearer = not self.disable_smearer.GetValue() 
     
    25902592                     enable_smearer=enable_smearer, 
    25912593                     draw=True) 
    2592  
     2594         
    25932595        self.state.enable_smearer = self.enable_smearer.GetValue() 
    25942596        self.state.disable_smearer = self.disable_smearer.GetValue() 
    25952597        self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 
    25962598        self.state.slit_smearer = self.slit_smearer.GetValue() 
    2597  
     2599         
    25982600    def on_smear_helper(self, update=False): 
    25992601        """ 
    26002602        Help for onSmear 
    2601  
     2603         
    26022604        :param update: force or not to update 
    26032605        """ 
     
    26112613        self._hide_all_smear_info() 
    26122614        data = copy.deepcopy(self.data) 
    2613  
     2615         
    26142616        # make sure once more if it is smearer 
    26152617        temp_smearer = smear_selection(data, self.model) 
     
    26342636            self.onSlitSmear(None) 
    26352637        self._show_smear_sizer() 
    2636  
     2638         
    26372639        return temp_smearer 
    2638  
     2640     
    26392641    def on_complete_chisqr(self, event): 
    26402642        """ 
     
    26532655        except: 
    26542656            pass 
    2655  
     2657             
    26562658    def get_all_checked_params(self): 
    26572659        """ 
     
    26692671                    self.param_toFit.append(item) 
    26702672        self.save_current_state_fit() 
    2671  
     2673        
    26722674        event = PageInfoEvent(page=self) 
    26732675        wx.PostEvent(self.parent, event) 
     
    26772679                param2fit.append(item[1]) 
    26782680        self._manager.set_param2fit(self.uid, param2fit) 
    2679  
     2681                 
    26802682    def select_all_param(self, event): 
    26812683        """ 
     
    27112713                            except: 
    27122714                                pass 
    2713  
     2715     
    27142716                        else: 
    27152717                            ## for 1D all parameters except orientation 
     
    27312733                    item[0].SetValue(False) 
    27322734                self.param_toFit = [] 
    2733  
     2735            
    27342736        self.save_current_state_fit() 
    2735  
     2737        
    27362738        if event != None: 
    27372739            #self._undo.Enable(True) 
     
    27442746                param2fit.append(item[1]) 
    27452747        self.parent._manager.set_param2fit(self.uid, param2fit) 
    2746  
     2748     
    27472749    def select_param(self, event): 
    27482750        """ 
     
    27972799        else: 
    27982800            self.cb1.SetValue(False) 
    2799  
     2801        
    28002802        self.save_current_state_fit() 
    28012803        if event != None: 
     
    28032805            event = PageInfoEvent(page=self) 
    28042806            wx.PostEvent(self.parent, event) 
    2805  
     2807         
    28062808        param2fit = [] 
    28072809        for item in self.param_toFit: 
     
    28092811                param2fit.append(item[1]) 
    28102812        self._manager.set_param2fit(self.uid, param2fit) 
    2811  
     2813         
    28122814    def set_model_param_sizer(self, model): 
    28132815        """ 
    28142816        Build the panel from the model content 
    2815  
     2817         
    28162818        :param model: the model selected in combo box for fitting purpose 
    2817  
     2819         
    28182820        """ 
    28192821        self.sizer3.Clear(True) 
     
    28252827        self.orientation_params = [] 
    28262828        self.orientation_params_disp = [] 
    2827  
     2829         
    28282830        if model == None: 
    28292831            self.sizer3.Layout() 
     
    28362838        ## save the current model 
    28372839        self.model = model 
    2838  
     2840            
    28392841        keys = self.model.getParamList() 
    2840  
     2842         
    28412843        #list of dispersion parameters 
    28422844        self.disp_list = self.model.getDispParamList() 
     
    28942896 
    28952897        keys.sort(custom_compare) 
    2896  
     2898     
    28972899        iy = 0 
    28982900        ix = 0 
     
    29022904        self.cb1.SetToolTipString("To check/uncheck all the boxes below.") 
    29032905        self.cb1.SetValue(True) 
    2904  
     2906         
    29052907        sizer.Add(self.cb1, (iy, ix), (1, 1), \ 
    29062908                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 
     
    29302932                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    29312933        self.text2_4.Hide() 
    2932  
     2934         
    29332935        CHECK_STATE = self.cb1.GetValue() 
    29342936        for item in keys: 
    2935  
     2937             
    29362938            if not item in self.disp_list and not item in \ 
    29372939                    self.model.orientation_params: 
    2938  
     2940                 
    29392941                ##prepare a spot to store errors 
    29402942                if not item in self.model.details: 
    29412943                    self.model.details[item] = ["", None, None] 
    2942  
     2944          
    29432945                iy += 1 
    29442946                ix = 0 
     
    29642966                    else: 
    29652967                        fun_box = ModelTextCtrl(self, -1, 
    2966                                                 size=(_BOX_WIDTH, 20), 
     2968                                                     size=(_BOX_WIDTH, 20), 
    29672969                                style=wx.TE_PROCESS_ENTER, name='%s' % item) 
    29682970                        fun_box.SetToolTipString(\ 
     
    29802982                    #cb.SetValue(True) 
    29812983                    wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 
    2982  
     2984                     
    29832985                    sizer.Add(cb, (iy, ix), (1, 1), 
    29842986                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 
     
    29882990                    value = self.model.getParam(item) 
    29892991                    ctl1 = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
    2990                                          style=wx.TE_PROCESS_ENTER) 
     2992                                        style=wx.TE_PROCESS_ENTER) 
    29912993                    ctl1.SetToolTipString(\ 
    29922994                                "Hit 'Enter' after typing to update the plot.") 
     
    30103012                    ix += 1 
    30113013                    ctl3 = ModelTextCtrl(self, -1, 
    3012                                          size=(_BOX_WIDTH / 1.9, 20), 
    3013                                          style=wx.TE_PROCESS_ENTER, 
     3014                                              size=(_BOX_WIDTH / 1.9, 20), 
     3015                                              style=wx.TE_PROCESS_ENTER, 
    30143016                                text_enter_callback=self._onparamRangeEnter) 
    30153017                    min_bound = self.model.details[item][1] 
     
    30193021                    sizer.Add(ctl3, (iy, ix), (1, 1), 
    30203022                              wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    3021  
     3023             
    30223024                    ix += 1 
    30233025                    ctl4 = ModelTextCtrl(self, -1, 
    3024                                          size=(_BOX_WIDTH / 1.9, 20), 
    3025                                          style=wx.TE_PROCESS_ENTER, 
     3026                                              size=(_BOX_WIDTH / 1.9, 20), 
     3027                                              style=wx.TE_PROCESS_ENTER, 
    30263028                                text_enter_callback=self._onparamRangeEnter) 
    30273029                    max_bound = self.model.details[item][2] 
     
    30303032                    sizer.Add(ctl4, (iy, ix), (1, 1), 
    30313033                              wx.EXPAND | wx.FIXED_MINSIZE, 0) 
    3032  
     3034     
    30333035                    ix += 1 
    30343036                    # Units 
     
    30413043                    sizer.Add(units, (iy, ix), (1, 1), 
    30423044                              wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    3043  
     3045                         
    30443046                    self.parameters.append([cb, item, ctl1, 
    30453047                                            text2, ctl2, ctl3, ctl4, units]) 
    3046  
     3048                                   
    30473049        iy += 1 
    30483050        sizer.Add((10, 10), (iy, ix), (1, 1), 
    30493051                  wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    3050  
     3052         
    30513053        # type can be either Guassian or Array 
    30523054        if len(self.model.dispersion.values()) > 0: 
     
    30543056        else: 
    30553057            type = "Gaussian" 
    3056  
     3058             
    30573059        iy += 1 
    30583060        ix = 0 
     
    30613063            if item in self.model.orientation_params: 
    30623064                orient_angle = wx.StaticText(self, -1, '[For 2D only]:') 
    3063                 mag_on_button = wx.Button(self, -1, "Magnetic ON") 
     3065                mag_on_button = wx.Button(self, -1, "Magnetic ON" ) 
    30643066                mag_on_button.SetToolTipString("Turn Pol Beam/Mag scatt on/off") 
    30653067                mag_on_button.Bind(wx.EVT_BUTTON, self._on_mag_on) 
     
    30683070                mag_help_button = wx.Button(self, -1, "Mag HELP") 
    30693071                mag_help_button.SetToolTipString("Help on pol beam/mag fitting") 
    3070                 mag_help_button.Bind(wx.EVT_BUTTON, self._on_mag_help) 
     3072                mag_help_button.Bind(wx.EVT_BUTTON,self._on_mag_help) 
    30713073                mag_angle_help_button.Bind(wx.EVT_BUTTON, \ 
    30723074                                            self._on_mag_angle_help) 
     
    30743076                          wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    30753077                iy += 1 
    3076                 sizer.Add(mag_on_button, (iy, ix), (1, 1), 
    3077                           wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     3078                sizer.Add(mag_on_button,(iy, ix ),(1,1),  
     3079                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)  
    30783080                ix += 1 
    30793081                sizer.Add(mag_angle_help_button, (iy, ix), (1, 1), 
    30803082                          wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    3081                 sizer.Add(mag_help_button, (iy, ix + 1), (1, 1), 
    3082                           wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    3083  
     3083                sizer.Add(mag_help_button,(iy, ix + 1),(1,1),  
     3084                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)  
     3085                 
    30843086                #handle the magnetic buttons 
    30853087                #clean this up so that assume mag is off then turn  
     
    30963098                    if self.magnetic_on: 
    30973099                        mag_on_button.SetLabel("Magnetic OFF") 
    3098                         mag_help_button.Show(True) 
     3100                        mag_help_button.Show(True)  
    30993101                        mag_angle_help_button.Show(True) 
    31003102                    else: 
     
    31023104                        mag_help_button.Show(False) 
    31033105                        mag_angle_help_button.Show(False) 
    3104  
     3106                         
    31053107                if not self.data.__class__.__name__ == "Data2D" and \ 
    31063108                        not self.enable2D: 
     
    31093111                    orient_angle.Show(True) 
    31103112                break 
    3111  
     3113       
    31123114        #For Gaussian only 
    31133115        if type.lower() != "array": 
     
    31203122                    if not item in self.model.details: 
    31213123                        self.model.details[item] = ["", None, None] 
    3122  
     3124                           
    31233125                    iy += 1 
    31243126                    ix = 0 
     
    31353137                    sizer.Add(cb, (iy, ix), (1, 1), 
    31363138                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 
    3137  
     3139     
    31383140                    ## add parameter value 
    31393141                    ix += 1 
    31403142                    value = self.model.getParam(item) 
    31413143                    ctl1 = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
    3142                                          style=wx.TE_PROCESS_ENTER) 
     3144                                        style=wx.TE_PROCESS_ENTER) 
    31433145                    ctl1.SetToolTipString(\ 
    31443146                                "Hit 'Enter' after typing to update the plot.") 
     
    31643166 
    31653167                    ctl2.Hide() 
    3166  
     3168                     
    31673169                    ix += 1 
    31683170                    ctl3 = ModelTextCtrl(self, -1, 
    3169                                          size=(_BOX_WIDTH / 1.8, 20), 
    3170                                          style=wx.TE_PROCESS_ENTER, 
     3171                                              size=(_BOX_WIDTH / 1.8, 20), 
     3172                                              style=wx.TE_PROCESS_ENTER, 
    31713173                                text_enter_callback=self._onparamRangeEnter) 
    3172  
     3174                     
    31733175                    sizer.Add(ctl3, (iy, ix), (1, 1), 
    31743176                              wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    31753177                    ctl3.Hide() 
    3176  
     3178                  
    31773179                    ix += 1 
    31783180                    ctl4 = ModelTextCtrl(self, -1, 
    3179                                          size=(_BOX_WIDTH / 1.8, 20), 
    3180                                          style=wx.TE_PROCESS_ENTER, 
     3181                                              size=(_BOX_WIDTH / 1.8, 20), 
     3182                                              style=wx.TE_PROCESS_ENTER, 
    31813183                            text_enter_callback=self._onparamRangeEnter) 
    31823184                    sizer.Add(ctl4, (iy, ix), (1, 1), 
    31833185                              wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    3184  
     3186                    
    31853187                    ctl4.Hide() 
    3186  
     3188                     
    31873189                    if self.data.__class__.__name__ == "Data2D" or \ 
    31883190                            self.enable2D: 
     
    31923194                        ctl3.Show(True) 
    31933195                        ctl4.Show(True) 
    3194  
     3196                     
    31953197                    ix += 1 
    31963198                    # Units 
     
    32073209                    else: 
    32083210                        units.Hide() 
    3209  
     3211                     
    32103212                    sizer.Add(units, (iy, ix), (1, 1), 
    32113213                              wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    3212  
     3214                                           
    32133215                    self.parameters.append([cb, item, ctl1, 
    32143216                                            text2, ctl2, ctl3, ctl4, units]) 
    32153217                    self.orientation_params.append([cb, item, ctl1, 
    32163218                                            text2, ctl2, ctl3, ctl4, units]) 
    3217  
     3219               
    32183220        iy += 1 
    32193221        box_description.SetForegroundColour(wx.BLUE) 
     
    32513253            wx.PostEvent(self._manager.parent, 
    32523254                        StatusEvent(status=msg, info=infor)) 
    3253  
     3255         
    32543256    def _onModel2D(self, event): 
    32553257        """ 
     
    32593261            self.model_view.SetLabel("Show 1D") 
    32603262            self.enable2D = True 
    3261  
     3263               
    32623264        else: 
    32633265            self.model_view.SetLabel("Show 2D") 
     
    32743276        self.SetupScrolling() 
    32753277        self._draw_model() 
    3276  
     3278         
    32773279        self.state.enable2D = copy.deepcopy(self.enable2D) 
    3278  
     3280     
    32793281    def _set_smear_buttons(self): 
    32803282        """ 
     
    32903292            self.slit_smearer.Enable(True) 
    32913293            self.pinhole_smearer.Enable(True) 
    3292  
    3293  
     3294             
     3295             
    32943296class BGTextCtrl(wx.TextCtrl): 
    32953297    """ 
     
    33023304        self.SetEditable(False) 
    33033305        self.SetBackgroundColour(self.GetParent().parent.GetBackgroundColour()) 
    3304  
     3306         
    33053307        # Bind to mouse event to avoid text highlighting 
    33063308        # The event will be skipped once the call-back 
    33073309        # is called. 
    33083310        self.Bind(wx.EVT_MOUSE_EVENTS, self._click) 
    3309  
     3311         
    33103312    def _click(self, event): 
    33113313        """ 
  • src/sas/perspectives/fitting/models.py

    r415fb82 r415fb82  
    66import os 
    77import sys 
     8import math 
    89import os.path 
    910# Time is needed by the log method 
     
    1213import py_compile 
    1314import shutil 
     15from sas.guiframe.events import StatusEvent 
    1416# Explicitly import from the pluginmodel module so that py2exe 
    1517# places it in the distribution. The Model1DPlugin class is used 
    1618# as the base class of plug-in models. 
    1719from sas.models.pluginmodel import Model1DPlugin 
     20from sas.models.BaseComponent import BaseComponent 
    1821from sas.guiframe.CategoryInstaller import CategoryInstaller 
    1922 
     23from sasmodels.sasview_model import make_class 
     24    
    2025PLUGIN_DIR = 'plugin_models' 
    2126 
     
    314319 
    315320        # regular model names only 
    316         base_message = "Unable to load model {0}" 
    317         try: 
    318             self.model_name_list = [] 
    319             from sas.models.SphereModel import SphereModel 
    320             self.model_dictionary[SphereModel.__name__] = SphereModel 
    321             #        self.shape_list.append(SphereModel) 
    322             self.multiplication_factor.append(SphereModel) 
    323             self.model_name_list.append(SphereModel.__name__) 
    324         except: 
    325             logging.error(base_message.format(SphereModel.__name__)) 
     321        self.model_name_list = [] 
     322 
     323        #Build list automagically from sasmodels package 
     324        import pkgutil 
     325        from importlib import import_module 
     326        import sasmodels.models 
     327        for importer,modname,ispkg in pkgutil.iter_modules(sasmodels.models.__path__): 
     328            if not ispkg: 
     329                module = import_module('.'+modname,'sasmodels.models') 
     330                self.model_dictionary[module.oldname] = make_class(module, dtype='single',namestyle='oldname') 
     331                self.model_name_list.append(module.oldname) 
     332 
     333 
     334        ### NASTY HACK - Comment out most of these lines as models are added to sasmodels. 
     335        ### Still need the lines that put models into multiplication etc 
     336 
     337        try: 
     338        #     # from sas.models.SphereModel import SphereModel 
     339        #     from sasmodels.models import sphere 
     340        #     SphereModel = make_class(sphere, dtype='single',namestyle='oldname') 
     341        #     self.model_dictionary[SphereModel.__name__] = SphereModel 
     342        #     #        self.shape_list.append(SphereModel) 
     343             self.multiplication_factor.append(SphereModel) 
     344        #     self.model_name_list.append(SphereModel.__name__) 
     345        except: 
     346            pass 
    326347 
    327348        try: 
     
    10681089        new_plugins = _findModels(dir) 
    10691090        for name, plug in  new_plugins.iteritems(): 
    1070             for stored_name, _ in self.stored_plugins.iteritems(): 
     1091            for stored_name, stored_plug in self.stored_plugins.iteritems(): 
    10711092                if name == stored_name: 
    10721093                    del self.stored_plugins[name] 
Note: See TracChangeset for help on using the changeset viewer.