Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/perspectives/fitting/models.py

    r415fb82 rf0d720b  
    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.